Python Sample SMS Code - SMS Messaging API


/ Published in: Python
Save to your folder(s)

 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! 


Copy this code and paste it in your HTML
  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=" + "s@KJ8QH9" +
  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"

URL: https://broadnet.me/developer-tools/sms-sample-code/python-sample-code-sms.html

Report this snippet


Comments

RSS Icon Subscribe to comments

You need to login to post a comment.