zoukankan      html  css  js  c++  java
  • c#简单易用的短信发送服务 悠逸企业短信服务

      悠逸企业短信发送服务,是一种比较简单易操作的短信发送服务,使用POST的方式,请求相应地址就可以实现短信发送功能
    1
    /// <summary> 2 /// 短信发送服务 3 /// </summary> 4 public class ShortMsgHelper 5 { 6 /// <summary> 7 /// 短信服务 账号 8 /// </summary> 9 private static string uid = ConfigurationManager.AppSettings["ShortMSGUid"]; 10 /// <summary> 11 /// 短信服务 密码 12 /// </summary> 13 private static string pwd = ConfigurationManager.AppSettings["ShortMSGPwd"]; 14 /// <summary> 15 /// 客服 手机号字符串 16 /// </summary> 17 private static string CustomerServicePhoneList = ConfigurationManager.AppSettings["CustomerServicePhoneList"]; 18 /// <summary> 19 /// 短信服务 签名(短信内容后面加上 此签名 才能发送成功!形式为:【签名内容】)如果不加,则发送无效 20 /// </summary> 21 private static string ShortMSGSignature = ConfigurationManager.AppSettings["ShortMSGSignature"]; 22 /// <summary> 23 /// 短信服务 开关 24 /// open:打开 close:关闭 25 /// </summary> 26 private static string ShortMSGSwitch = ConfigurationManager.AppSettings["ShortMSGSwitch"]; 27 28 /// <summary> 29 /// 发送短信开放方法 30 /// </summary> 31 /// <param name="msgContent"></param> 32 /// <returns></returns> 33 public static bool Send(string msgContent,List<string> pList) 34 { 35 //依据短信服务开关 36 if (ShortMSGSwitch=="close") 37 { 38 return false; 39 } 40 List<string> phoneList = new List<string>(); 41 if (pList==null||pList.Count==0) 42 { 43 phoneList = CustomerServicePhoneList.Split(new char[] { ',' }, StringSplitOptions.RemoveEmptyEntries).ToList(); 44 } 45 else 46 { 47 phoneList = pList; 48 } 49 50 return SendMobileMsg(uid, pwd, msgContent, phoneList); 51 } 52 /// <summary> 53 /// 短信发送 54 /// </summary> 55 /// <param name="uid">悠逸企业短信ID</param> 56 /// <param name="pwd">悠逸企业短信密码</param> 57 /// <param name="msgContent">短信内容</param> 58 /// <param name="destListPhones">手机号列表</param> 59 /// <returns></returns> 60 private static bool SendMobileMsg(string uid, string pwd, string msgContent, List<string> destListPhones) 61 { 62 try 63 { 64 bool result = false; 65 string strPhones = string.Join(";", destListPhones.ToArray()); 66 strPhones += ";"; 67 var encoding = System.Text.Encoding.GetEncoding("GB2312"); 68 69 string postData = string.Format("uid={0}&pwd={1}&mobile={2};&msg={3}&dtime=", uid, pwd, strPhones, msgContent + ShortMSGSignature); 70 71 byte[] data = encoding.GetBytes(postData); 72 73 // 定义 WebRequest 74 HttpWebRequest myRequest = 75 (HttpWebRequest)WebRequest.Create("http://www.smsadmin.cn/smsmarketing/wwwroot/api/post_send/"); 76 77 myRequest.Method = "POST"; 78 myRequest.ContentType = "application/x-www-form-urlencoded"; 79 myRequest.ContentLength = data.Length; 80 81 Stream newStream = myRequest.GetRequestStream(); 82 83 //发送数据 84 newStream.Write(data, 0, data.Length); 85 newStream.Close(); 86 87 // 得到 Response 88 HttpWebResponse myResponse = (HttpWebResponse)myRequest.GetResponse(); 89 StreamReader reader = new StreamReader(myResponse.GetResponseStream(), Encoding.Default); 90 string content = reader.ReadToEnd(); 91 92 if (content.Substring(0, 1) == "0") 93 result = true; 94 else 95 { 96 if (content.Substring(0, 1) == "2") //余额不足 97 { 98 //"手机短信余额不足"; 99 //TODO 100 } 101 else 102 { 103 //短信发送失败的其他原因,请参看官方API 104 } 105 result = false; 106 } 107 108 return result; 109 } 110 catch 111 { 112 return false; 113 } 114 115 } 116 }
  • 相关阅读:
    Comet OJ CCPC-Wannafly Winter Camp Day1 (Div2, online mirror) F.爬爬爬山-最短路(Dijkstra)(两个板子)+思维(mdzz...) zhixincode
    Codeforces 1104 D. Game with modulo-交互题-二分-woshizhizhang(Codeforces Round #534 (Div. 2))
    POJ 1655.Balancing Act-树的重心(DFS) 模板(vector存图)
    Codeforces gym102058 J. Rising Sun-简单的计算几何+二分 (2018-2019 XIX Open Cup, Grand Prix of Korea (Division 2))
    BZOJ 3261: 最大异或和位置-贪心+可持久化01Trie树
    51nod 1295 XOR key-区间异或最大值-可持久化01Trie树(模板)
    BZOJ 2588: Spoj 10628. Count on a tree-可持久化线段树+LCA(点权)(树上的操作) 无语(为什么我的LCA的板子不对)
    Codeforces 1099 D. Sum in the tree-构造最小点权和有根树 贪心+DFS(Codeforces Round #530 (Div. 2))
    Codeforces 586D. Phillip and Trains 搜索
    Codeforces 734E. Anton and Tree 搜索
  • 原文地址:https://www.cnblogs.com/bsyblog/p/6115701.html
Copyright © 2011-2022 走看看