C#实现发送短信到手机

C#实现发送短信到手机

具体实现如下:

1. 从网上(http://sms.webchinese.cn/)申请账号,记住用户名,密码会发到手机上,这仅是登陆密码。里面还有短信秘钥,这个要得到,这是后面要用到的,要在里面写好签名,还有,具体实现,要参考SMS短信通API下行接口参数(http://sms.webchinese.cn/api.shtml),这个网页上就有各种语言的实现方式,我用C#实现,熟悉java的可以用java。

2. 现在就可以编程实现了,这个也很简单,参考接口参数网页的C#实现即可,下面给出我的例子!

其界面如下:

这个就是密匙。不是要注册的登录密码,是要受用这个密匙。

注册完成后会有5条免费试用短信,用完后就需要收费(充值)。


代码如下。可以直接复制使用

using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;

using System.Net;
using System.IO;

namespace sendPhpneMessage
{
    public partial class Form1 : Form
    {
        private string url = "http://utf8.sms.webchinese.cn/?";//发送短信平台网址SMS
        private string strUid = "Uid=";//注册的SMS平台的账号ID
        private string strKey = "&key=0955bbe00e418b6e2e47";//注册的SMS平台的接口密匙
        private string strMob = "&smsMob=";//手机号码
        private string strContent = "&smsText=";// 发送的内容
        public Form1()
        {
            InitializeComponent();
        }
        /// <summary>
        /// 按钮单机事件
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void button1_Click(object sender, EventArgs e)
        {
            if (!string.IsNullOrEmpty(txtUserName.Text) && !string.IsNullOrEmpty(txtAttnNum.Text)
                && !string.IsNullOrEmpty(txtContent.Text))
            {
                url = url + strUid + txtUserName.Text + strKey + strMob + txtAttnNum.Text + strContent + txtContent.Text;
                string Result = GetHtmlFromUrl(url);
                MessageBox.Show(Result);
            }
        }
        /// <summary>
        ///  发送消息机制
        /// </summary>
        /// <param name="url"></param>
        /// <returns></returns>
        public string GetHtmlFromUrl(string url)
        {
            string strRet = null;
            if (string.IsNullOrEmpty(url))
            {
                return strRet;
            }
            string targeturl = url.Trim().ToString();
            try
            {
                HttpWebRequest hr = (HttpWebRequest)WebRequest.Create(targeturl);
                hr.UserAgent = "Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.1)";
                hr.Method = "GET";
                hr.Timeout = 30 * 60 * 1000;
                WebResponse hs = hr.GetResponse();
                Stream sr = hs.GetResponseStream();
                StreamReader ser = new StreamReader(sr, Encoding.Default);
                strRet = ser.ReadToEnd();
            }
            catch (Exception)
            {

                strRet = null;
            }
            return strRet;
        }
    }
}


这是一些规则。程序下载地址  点击下载,免积分。

  • 9
    点赞
  • 62
    收藏
    觉得还不错? 一键收藏
  • 5
    评论
评论 5
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值