Example of VB6 Sample SMS Code - Messaging API


/ Published in: Visual Basic
Save to your folder(s)

The following example of VB6 sample SMS code uses an expedient object, contingent on the HTTP API.


Copy this code and paste it in your HTML
  1. Imports System.Net
  2.  
  3. Public Class SmsAPI
  4. // <summary>
  5. // Specify complete Url of SMS gateway
  6. // </summary>
  7. Public Property ApiUrl() As String
  8. Get
  9. Return m_ApiUrl
  10. End Get
  11. Set(value As String)
  12. m_ApiUrl = value
  13. End Set
  14. End Property
  15. Private m_ApiUrl As String
  16. // <summary>
  17. // User name supplied by Broadnet
  18. // </summary>
  19. Public Property user() As String
  20. Get
  21. Return m_user
  22. End Get
  23. Set(value As String)
  24. m_user = value
  25. End Set
  26. End Property
  27. Private m_user As String
  28. // <summary>
  29. // Password supplied by Broadnet
  30. // </summary>
  31. Public Property pass() As String
  32. Get
  33. Return m_pass
  34. End Get
  35. Set(value As String)
  36. m_pass = value
  37. End Set
  38. End Property
  39. Private m_pass As String
  40. // <summary>
  41. // SID supplied by Broadnet
  42. // </summary>
  43. Public Property sid() As String
  44. Get
  45. Return m_sid
  46. End Get
  47. Set(value As String)
  48. m_sid = value
  49. End Set
  50. End Property
  51. Private m_sidAs String
  52.  
  53.  
  54. Public Sub New()
  55. End Sub
  56.  
  57. Public Sub New(ApiUrl As String, user As String, pass As String, sid As String)
  58. Me.ApiUrl = ApiUrl
  59. Me.user = user
  60. Me.pass = pass
  61. Me.sid = sid
  62. End Sub
  63.  
  64. Public Function SendSMS(Recipient As String, MessageData As String) As String
  65.  
  66. If ApiUrl.Trim() = "" OrElse user.Trim() = "" OrElse pass.Trim() = "" OrElse sid.Trim() = "" Then
  67. Throw New Exception("All Properties were required")
  68. End If
  69.  
  70. 'Status = SMS(User, SURL, SPort, Passw, number, MessageData, MessageType); //Sending SMS
  71. '''///// string createdURL = "http://78.108.164.67" + ":" + "8080" + "/websmpp/websms" +
  72. '''/////"?user=" + "SPDDLC" +
  73. '''/////"&pass=" + "s@KJ8QH9" +
  74. '''/////"&sid=" + "SPDDLC" +
  75. '''/////"&mno=" + Recipient +
  76. '''/////"&text=" + MessageData +
  77. '''/////"&type=" + "1" +
  78. '''/////"&esm=" + "0" +
  79. '''/////"&dcs=" + "0";
  80.  
  81. ' MessageBox.Show(createdURL);
  82. Dim createdURL As String = ApiUrl & "?user=" & user & "&pass=" & pass & "&sid=" & sid & "&mno=" & Recipient & "&text=" & MessageData & "&type=" & "1" & "&esm=" & "0" & "&dcs=" & "0"
  83. Try
  84.  
  85.  
  86. Dim myReq As HttpWebRequest = DirectCast(WebRequest.Create(createdURL), HttpWebRequest)
  87. 'MessageBox.Show("2");
  88. ' Get response from SMS Gateway Server and read the answer
  89. Dim myResp As HttpWebResponse = DirectCast(myReq.GetResponse(), HttpWebResponse)
  90.  
  91. ' MessageBox.Show("21");
  92. Dim respStreamReader As New System.IO.StreamReader(myResp.GetResponseStream())
  93. ' MessageBox.Show("22");
  94. Dim responseString As String = respStreamReader.ReadToEnd()
  95. ' MessageBox.Show("2");
  96. respStreamReader.Close()
  97.  
  98.  
  99. myResp.Close()
  100. Catch ex As Exception
  101. Throw ex
  102. Finally
  103. End Try
  104. Return "success"
  105. End Function
  106. End Class

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

Report this snippet


Comments

RSS Icon Subscribe to comments

You need to login to post a comment.