Send 彩信Message with VB .NET

通过以下链接发布了一个用于通过NowSMS发送MMS消息的VB.NET示例: http://www.zgbianpofanghuwang.com/download/sendmms.vb.txt

有关此示例的C#.NET版本,请参见相关文章。 Send 彩信Message with C# .NET.

其他环境(PHP,Java,命令行)的MMS示例可在以下位置找到 http://www.zgbianpofanghuwang.com/sending-mms-messages-with-nowsms.

正如在 Sending 彩信Messages with NowSMS,与NowSMS进行交互以发送MMS消息的最简单方法之一就是使用我们所谓的专有URL提交接口。此界面是用于通过内置NowSMS Web界面中的表单发送消息的界面。通过此接口发送MMS消息只需使用HTTP POST即可使用MIME类型以表格形式提交MMS内容。“multipart/form-data”。这种技术通常称为“HTTP File Upload”并与具有“Browse”按钮,允许上传文件。

那里’s a great C#.NET HTTP文件上传 library at: http://aspnetupload.com/Upload-File-POST-HttpWebRequest-WebClient-RFC-1867.aspx

下载库的直接链接在这里(仅需要UploadHelper组件): http://aspnetupload.com/AspNetUploadSamples.zip

如果此链接将来无法使用,我们已在以下链接中归档了该库的副本:

 

应用程序/ x-zip压缩AspNetUploadSamples.zip
AspNetUploadSamples.zip(388.7千)

 

 

下面的VB.NET代码示例使用该库中的代码发送MMS消息:

(注意:此示例可以从以下位置下载 http://www.zgbianpofanghuwang.com/download/sendmms.vb.txt

Imports System.Text

Imports System.IO

Imports System.Net

Imports System.Web

Imports System.Web.Services

Imports ClassLibrary1

Imports ClassLibrary1.Krystalware

Imports ClassLibrary1.Krystalware.UploadHelper

Imports ClassLibrary1.Krystalware.UploadHelper.HttpUploadHelper

Imports ClassLibrary1.Krystalware.UploadHelper.MimePart

Imports ClassLibrary1.Krystalware.UploadHelper.StreamMimePart

Imports ClassLibrary1.Krystalware.UploadHelper.StringMimePart

Imports ClassLibrary1.Krystalware.UploadHelper.UploadFile

Imports System.Collections.Specialized



Public Class Form1

    Public Sub SendMMS()

        ' Set the following variables as appropriate for your system. 

        ' URL that points to NowSMS web interface 

        Dim url As New Uri(" http://127.0.0.1:8800/ ")



        ' Valid username/password for account defined in NowSMS under "短信Users". 

        Dim username As [String] = "testuser"

        Dim password As [String] = "testpass"



        ' Images & Files to be included in the message. 

        ' First parameter is filename and path. 

        ' Second parameter must be MMSFILE 

        ' Third parameter should be MIME type 



        Dim files As UploadFile() = New UploadFile() {

         New UploadFile("c:\mms\tts.mp3", "MMSFILE", "audio/mpeg"),

         New UploadFile("c:\mms\image.png", "MMSFILE", "image/png")}



        ' Create additional form parameters for sending 彩信

        Dim form As New NameValueCollection()



        ' "PhoneNumber" variable contains recipient phone number 

        形成("PhoneNumber")="09059999999"

        ' "MMSFROM" variable contains sender phone number or address

        '  (Note: Ignored when sending via modem) 

        形成("MMSFROM")="09058888888"

        ' "MMSSUBJECT" variable contains subject line for message 

        形成("MMSSUBJECT")="test subject"

        ' "MMSTEXT" variable contains test to appear in message (optional) 

        形成("MMSTEXT")="this is a test message"



        ' Send the request to NowSMS, creating an HttpWebRequest and 

        ' then use HttpUploadHelper to send files in 多部分/表单数据 format 

        Dim req As HttpWebRequest = DirectCast(WebRequest.Create(url), HttpWebRequest)



        Dim credCache = New CredentialCache()

        credCache.Add(url, "Basic", New NetworkCredential(username, password))

        req.Credentials = credCache



        Dim resp As HttpWebResponse = HttpUploadHelper.Upload(req, files, form)



        ' Read the HTTP response and echo to console 

        Using s As Stream = resp.GetResponseStream()

            Using sr As New StreamReader(s)

                Dim response As String = sr.ReadToEnd()

                MsgBox(response)

                System.Console.WriteLine(response)

            End Using

        End Using

    End Sub



    Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click

        SendMMS()

    End Sub

End Class

 

其他MMS选项可以使用 形成(“variablename”) = “value” 上面示例中显示的语法。其他选项/变量在下面更详细地描述 http://www.zgbianpofanghuwang.com/sending-mms-messages-with-nowsms.

使用此脚本的系统要求:

该脚本连接到NowSMS服务器,并将请求发送到NowSMS服务器以发送消息。

如果您没有安装NowSMS服务器,则此脚本将不起作用。

NowSMS服务器软件已安装在Windows PC上,并且能够发送SMS或MMS消息,NowSMS还需要GSM调制解调器,Android手机或SMS服务提供商连接。

可以从以下位置下载NowSMS软件的试用版: http://www.zgbianpofanghuwang.com/download-free-trial

现在的SMS / MMS网关或 NowSMS Lite 可以使用。 NowSMS Lite 可以使用单个GSM调制解调器或Android手机作为调制解调器连接来发送SMS和MMS消息。完整产品支持多个调制解调器和/或服务提供商连接。

在尝试使用脚本与NowSMS进行交互之前,您应验证NowSMS的配置正确,并且可以使用其内置的Web界面发送SMS消息。对于Android手机或GSM调制解调器连接,可在此处找到快速入门指南: http://www.zgbianpofanghuwang.com/doc/quick-start-guide

一旦确认NowSMS可以独立运行,就必须更改脚本中引用的IP地址以指向NowSMS服务器。我们的示例脚本使用的IP地址为127.0.0.1,这是当前PC的特殊回送地址。如果您的脚本在不同于NowSMS服务器的系统上运行,请将127.0.0.1更改为对您的环境有效的主机名或IP地址。还需要在NowSMS服务器上定义一个与脚本中的用户帐户匹配的帐户凭据的SMS用户帐户。