Python短信示例代码-短信API

Posted

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了Python短信示例代码-短信API相关的知识,希望对你有一定的参考价值。

 Just try the following Python Sample SMS Code scripts and you will find that sending SMS to your contact via this programming script is fun! 
  1. class SmsAPI(object):
  2. # <summary>
  3. # Specify complete Url of SMS gateway
  4. # </summary>
  5. def get_ApiUrl(self):
  6.  
  7. def set_ApiUrl(self, value):
  8.  
  9. ApiUrl = property(fget=get_ApiUrl, fset=set_ApiUrl)
  10.  
  11. # <summary>
  12. # User name supplied by provider
  13. # </summary>
  14. def get_user(self):
  15.  
  16. def set_user(self, value):
  17.  
  18. user = property(fget=get_user, fset=set_user)
  19.  
  20. # <summary>
  21. # Password supplied by provider
  22. # </summary>
  23. def get_pass(self):
  24.  
  25. def set_pass(self, value):
  26.  
  27. pass = property(fget=get_pass, fset=set_pass)
  28.  
  29. # <summary>
  30. # SID supplied by provider
  31. # </summary>
  32. def get_sid(self):
  33.  
  34. def set_sid(self, value):
  35.  
  36. sid = property(fget=get_sid, fset=set_sid)
  37.  
  38. def __init__(self, ApiUrl, user, pass, sid):
  39. self.ApiUrl = ApiUrl
  40. self.user = user
  41. self.pass = pass
  42. self.sid = sid
  43.  
  44. def __init__(self, ApiUrl, user, pass, sid):
  45. self.ApiUrl = ApiUrl
  46. self.user = user
  47. self.pass = pass
  48. self.sid = sid
  49.  
  50. def SendSMS(self, Recipient, MessageData):
  51. if self.ApiUrl.Trim() == "" or self.user.Trim() == "" or self.pass.Trim() == "" or self.sid.Trim() == "":
  52. raise Exception("All Properties were required")
  53. #Status = SMS(User, SURL, SPort, Passw, number, MessageData, MessageType); //Sending SMS
  54. #///// string createdURL = "http://78.108.164.67" + ":" + "8080" + "/websmpp/websms" +
  55. #/////"?user=" + "SPDDLC" +
  56. #/////"&pass=" + "[email protected]" +
  57. #/////"&sid=" + "SPDDLC" +
  58. #/////"&mno=" + Recipient +
  59. #/////"&text=" + MessageData +
  60. #/////"&type=" + "1" +
  61. #/////"&esm=" + "0" +
  62. #/////"&dcs=" + "0";
  63. # MessageBox.Show(createdURL);
  64. createdURL = self.ApiUrl + "?user=" + self.user + "&pass=" + self.pass + "&sid=" + self.sid + "&mno=" + Recipient + "&text=" + MessageData + "&type=" + "1" + "&esm=" + "0" + "&dcs=" + "0"
  65. try:
  66. myReq = WebRequest.Create(createdURL)
  67. #MessageBox.Show("2");
  68. # Get response from SMS Gateway Server and read the answer
  69. myResp = myReq.GetResponse()
  70. # MessageBox.Show("21");
  71. respStreamReader = System.IO.StreamReader(myResp.GetResponseStream())
  72. # MessageBox.Show("22");
  73. responseString = respStreamReader.ReadToEnd()
  74. # MessageBox.Show("2");
  75. respStreamReader.Close()
  76. myResp.Close()
  77. except Exception, ex:
  78. raise ex
  79. finally:
  80. return "success"

以上是关于Python短信示例代码-短信API的主要内容,如果未能解决你的问题,请参考以下文章

验证码短信 API 接入指南:Java 语言示例代码

企业信使短信接口API代码示例

VB6示例短信代码-消息API

PYTHON创蓝253云通讯平台国际短信API接口DEMO

向手机发送短信的python源代码,该怎么解决

短信验证码api