项目上要做个发手机短信的功能。网上找找了,用的微米的短信接口。
注册后,获得UID和UID key,C#代码中需要这个
调用代码很简单
string mobile = "12345678", 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, 0, 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();
后台的短信平台上可以看到发的记录
手机上
手机上收到短信的效果如下: