asp.net Twilio

Imports System.Net

Imports System.Text

Imports Twilio



Public Class clsTwilioSMS



    Public Shared Function Send(ByVal pToNumber As String, ByVal pSMSMessage As String) As String

        Dim strReturn As String = "0"

        Dim strLog As String = Now.ToString("yyyy-MM-dd HH:mm:ss") & " Send Sms to " & pToNumber & vbLet



        Try

            Dim AccountSid As String = My.MySettings.Default.SMSAccountSid.ToString

            Dim AuthToken As String = My.MySettings.Default.SMSAuthToken.ToString

            Dim FromNumber As String = My.MySettings.Default.SMSFromNumber.ToString



            Dim Twilio As TwilioRestClient = New TwilioRestClient(AccountSid, AuthToken)

            Dim message As SMSMessage = Twilio.SendSmsMessage(FromNumber, pToNumber, pSMSMessage, "")

            If (message.Sid Is Nothing) Then

                strLog += " >>>Send Sms Failed , detail: " & message.RestException.ToString

                strReturn = "-1"

            Else

                strLog += " >>>Send Sms Success  , Sid: " & message.Sid & vbLet

                strReturn = "1"

            End If

        Catch ex As Exception

            strLog += " >>>Send Sms Exception , detail:" & ex.ToString & vbLet

        Finally

            LogByLine(strLog)

        End Try

        Return strReturn

    End Function



    Private Shared Sub LogByLine(ByVal pLine As String)

        Try

            If Trim(pLine) <> "" Then

                Dim p12File As String = "SMSLog.txt"

                Dim p12Filename As String = System.IO.Path.Combine(System.Web.Hosting.HostingEnvironment.MapPath("~/"), p12File)



                Dim aa As System.IO.StreamWriter = New System.IO.StreamWriter(p12Filename, True, System.Text.Encoding.UTF8)

                aa.WriteLine(pLine)

                aa.Close()

                aa.Dispose()

            End If

        Catch ex As Exception

        End Try

    End Sub









End Class

主要的Dll:

http://files.cnblogs.com/files/xiaobuild/TwilioDLL.zip

参考网站:

https://www.twilio.com/user/account/developer-tools/api-explorer/message-create

 

你可能感兴趣的:(asp.net)