asp.net兩種方式的短信接口使用(提供接口的都是收費的)

一種是http請求的方式,另外一種就是提供WebService接口供調用的。web

 

 

#region sms.webchinese.cn 發送短信   
  1. //服務商 sms.webchinese.cn  
  2. //sms_url="http://sms.webchinese.cn/web_api/?Uid=帳號&Key=接口密鑰&smsMob=手機號碼&smsText=短信內容"  
  3. /// <summary>  
  4. /// 發送短信接口sms.webchinese.cn  
  5. /// </summary>  
  6. /// <param name="mobilenumber">手機號,多個號碼用‘,’分開</param>  
  7. /// <param name="message">信息內容</param>  
  8. /// <returns>  
  9. /// 返回值狀況以下  
  10. /// -1  沒有該用戶帳戶  
  11. ///-2   密鑰不正確 [查看密鑰]  
  12. ///-3   短信數量不足  
  13. ///-11  該用戶被禁用  
  14. ///-14  短信內容出現非法字符  
  15. ///-4   手機號格式不正確  
  16. ///-41  手機號碼爲空  
  17. ///-42  短信內容爲空  
  18. ///大於0  短信發送數量  
  19. /// </returns>  
  20. public int SendMSG(string mobilenumber, string message)  
  21. {  
  22.     //發送短信請求的地址  
  23.     string url = string.Format("http://sms.webchinese.cn/web_api/?Uid=帳號&Key=接口密鑰&smsMob={0}&smsText={1}", mobilenumber, message);  
  24.     string strRet = null;  
  25.     url = HttpUtility.UrlEncode(url);//urlencode  
  26.     if (url == null || url.Trim().ToString() == "")  
  27.     {  
  28.         return 0;  
  29.     }  
  30.     try  
  31.     {  
  32.         HttpWebRequest hr = (HttpWebRequest)WebRequest.Create(url);  
  33.         hr.UserAgent = "Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.1)";  
  34.         hr.Method = "GET";  
  35.         hr.Timeout = 30 * 60 * 1000;  
  36.         WebResponse hs = hr.GetResponse();  
  37.         Stream sr = hs.GetResponseStream();  
  38.         StreamReader ser = new StreamReader(sr, Encoding.Default);  
  39.         strRet = ser.ReadToEnd();  
  40.     }  
  41.     catch (Exception)  
  42.     {  
  43.         strRet = null;  
  44.     }  
  45.     if (strRet == null || strRet == ""return 0;  
  46.     return Convert.ToInt32(strRet);  
  47. }  
  48. #endregion  
  49.  
  50. #region www.56dxw.com 發送短信  
  51. //添加服務引用  http://jiekou.56dxw.com/WebServiceInterface.asmx  
  52. //輸入命名空間:MobileMessage_56  
  53. private MobileMessage_56.WebServiceInterfaceSoapClient _ws_56 = null;  
  54. /// <summary>  
  55. /// www.56dxw.com短信接口服務  
  56. /// </summary>  
  57. public MobileMessage_56.WebServiceInterfaceSoapClient ws_56  
  58. {  
  59.     get  
  60.     {  
  61.         if (_ws_56 == null) _ws_56 = new MobileMessage_56.WebServiceInterfaceSoapClient();  
  62.         return _ws_56;  
  63.     }  
  64. }  
  65. private string username_56 = "test";//網站的用戶名  
  66. private string password_56 = "test";//網站的登錄密碼  
  67. private string cid_56 = "";//企業id  
  68. /// <summary>  
  69. /// 發送短信接口函數 www.56dxw.com  
  70. /// </summary>  
  71. /// <param name="mobilenumber">手機號英文半角逗號隔開,一次1000個之內</param>  
  72. /// <param name="message">信息內容</param>  
  73. /// <returns>  
  74. /// -1  用戶名密碼不正確  
  75. ///-2   內容不能大於70個字  
  76. ///-3   驗證此平臺是否存在  
  77. ///-4   提交號碼不能爲空或客戶餘額爲0  
  78. ///-5   客戶剩餘條數不夠要發送的短信數量  
  79. ///-6   非法短信內容  
  80. ///-7   返回系統故障  
  81. ///-8   網絡性錯誤,請稍後再試  
  82. ///1    表明發送成功  
  83. /// </returns>  
  84. public int SendMSG_56(string mobilenumber, string message)  
  85. {  
  86.     string sendtime = "";//格式:"2010-1-27 11:10:20"---發送時間,爲空則當即發送  
  87.     string smsnumber = "";//平臺  
  88.     return ws_56.SendNote(mobilenumber, message, username_56, password_56, cid_56, sendtime, smsnumber);  
  89. }  
  90.   
  91. /// <summary>  
  92. /// 查詢剩餘短信條數  
  93. /// </summary>  
  94. /// <returns>  
  95. /// -1  表明用戶名密碼不正確  
  96. /// 其它值 表明返回具體條數  
  97. /// </returns>  
  98. public int ReturnUserFullMoney_56()  
  99. {  
  100.     return ws_56.ReturnUserFullMoney(username_56, password_56, cid_56);  
  101. }  
  102. /// <summary>  
  103. /// 修改密碼  
  104. /// </summary>  
  105. /// <param name="oldpwd">舊密碼</param>  
  106. /// <param name="newpwd">新密碼</param>  
  107. /// <returns>  
  108. /// 1   表明密碼修改爲功  
  109. /// -1  表明密碼編輯失敗  
  110. /// -2  用戶名密碼錯誤  
  111. /// </returns>  
  112. public int EditUserPwd(string oldpwd,string newpwd)  
  113. {  
  114.     return ws_56.EditUserPwd(username_56, oldpwd, newpwd, cid_56);  
  115. }  
  116.  
  117. #endregion
相關文章
相關標籤/搜索