c# 调用短信平台接口,给手机发送短信

项目上要做个发手机短信的功能。网上找找了,用的微米的短信接口。

c# 调用短信平台接口,给手机发送短信

注册后,获得UID和UID key,C#代码中需要这个

调用代码很简单

  string mobile = "",
con = "【微米】您的验证码是:610912,3分钟内有效。如非您本人操作,可忽略本消息。",
uid = "xxx",
pas = "xxx",
url = "http://api.weimi.cc/2/sms/send.html";
byte[] byteArray = Encoding.UTF8.GetBytes("mob=" + mobile + "&con=" + con + "&uid=" + uid + "&pas=" + pas + "&type=json");
HttpWebRequest webRequest = (HttpWebRequest)WebRequest.Create(new Uri(url));
webRequest.Method = "POST";
webRequest.ContentType = "application/x-www-form-urlencoded";
webRequest.ContentLength = byteArray.Length;
Stream newStream = webRequest.GetRequestStream();
newStream.Write(byteArray, , byteArray.Length);
newStream.Close();
HttpWebResponse response = (HttpWebResponse)webRequest.GetResponse();
StreamReader php = new StreamReader(response.GetResponseStream(), Encoding.UTF8);
string Message = php.ReadToEnd();
System.Console.Write(Message);
System.Console.Read();

后台的短信平台上可以看到发的记录

手机上c# 调用短信平台接口,给手机发送短信

手机上收到短信的效果如下:

c# 调用短信平台接口,给手机发送短信

上一篇:C++模拟键盘消息


下一篇:Metrics监控应用