• 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

  • 相关阅读:
    属性绑定与双向数据绑定
    vue基础
    tp5提交留言入库
    tp5表单提交
    TP5分页
    TP5模板与数据组合
    vue3.x使用Proxy做双向数据绑定总结
    vue2.x响应式原理总结
    HTML5移动端自适应解决方案
    springMVC实现文件上传
  • 原文地址:https://www.cnblogs.com/xiaobuild/p/4585872.html
Copyright © 2020-2023  润新知