天天看點

C#彩信接口開發經驗及具體開發實作

一、配置檔案app.config

<?xml version="1.0" encoding="utf-8" ?>
<configuration>
    <configSections>
        <sectionGroup name="applicationSettings" type="System.Configuration.ApplicationSettingsGroup, System, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" >
            <section name="MMSsend.Properties.Settings" type="System.Configuration.ClientSettingsSection, System, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" requirePermission="false" />
        </sectionGroup>
    </configSections>
    <applicationSettings>
        <MMSsend.Properties.Settings>
            <setting name="MMSsend_MmsSend_WebService" serializeAs="String">
                <value>http://sdk3.entinfo.cn:8060/webservice.asmx</value>
            </setting>
        </MMSsend.Properties.Settings>
    </applicationSettings>
</configuration>
           

二、群發彩信WebServices(部分代碼)

//------------------------------------------------------------------------------
// <auto-generated>
//     此代碼由工具生成。
//     運作時版本:4.0.30319.1
//
//     對此檔案的更改可能會導緻不正确的行為,并且如果
//     重新生成代碼,這些更改将會丢失。
// </auto-generated>
//------------------------------------------------------------------------------

// 
// 此源代碼是由 Microsoft.VSDesigner 4.0.30319.1 版自動生成。
// 
#pragma warning disable 1591

namespace MMSsend.MmsSend {
    using System;
    using System.Web.Services;
    using System.Diagnostics;
    using System.Web.Services.Protocols;
    using System.ComponentModel;
    using System.Xml.Serialization;
    
    
    /// < remarks/>
    [System.CodeDom.Compiler.GeneratedCodeAttribute("System.Web.Services", "4.0.30319.1")]
    [System.Diagnostics.DebuggerStepThroughAttribute()]
    [System.ComponentModel.DesignerCategoryAttribute("code")]
    [System.Web.Services.WebServiceBindingAttribute(Name="WebServiceSoap", Namespace="http://tempuri.org/")]
    .......
	.......
	  /// < remarks/>
        [System.Web.Services.Protocols.SoapDocumentMethodAttribute("http://tempuri.org/mdMmsSend", RequestNamespace="http://tempuri.org/", ResponseNamespace="http://tempuri.org/", Use=System.Web.Services.Description.SoapBindingUse.Literal, ParameterStyle=System.Web.Services.Protocols.SoapParameterStyle.Wrapped)]
        public string mdMmsSend(string sn, string pwd, string title, string mobile, string content, string stime) {
            object[] results = this.Invoke("mdMmsSend", new object[] {
                        sn,
                        pwd,
                        title,
                        mobile,
                        content,
                        stime});
            return ((string)(results[0]));
        }
           

三、C#調用實作

參數名稱 說明 是否必須    備注
Sn 軟體序列号 格式XXX-XXX-XXX-XXXXX
Pwd 密碼 md5(sn+password) 32位大寫密文
title 彩信主題 限制在30字元以内
Mobile 手機号 手機号碼多個以英文逗号隔開
Content 内容 base64編碼(檔案名1,檔案base64編碼串;檔案名2,檔案base64編碼串);實際發送檔案小于等于50*1024 位元組
stime 定時時間 例如:2010-12-29 16:27:03(非定時置空)

函數傳回值:String。

content是您發送的彩信的内容:包含圖檔和聲音及文本;

1.檔案類型: 文本是.txt 圖檔是.jpg或者.gif 聲音是.mid或者.amr

2.内容格式:

幀數_檔案類型.擴充名 + 英文逗号 + 檔案的base64編碼字元串 + 分号 ;

例如:“1_1.txt,” + 檔案base64編碼字元串 + “;” + “1_2.jpg,” + 檔案base64編碼字元串+”;”+”1_3.mid”+檔案base64編碼字元串

文本是 n_1.txt  圖檔是 n_2.jpg 或者是 n_2.gif  聲音是 n_3.mid ;

N表示目前第幾幀,字尾不變,編碼均為GB2312。

接口位址:http://sdk3.entinfo.cn:8060/webservice.asmx?op=mdMmsSend

示例1

SN= SDK-SSD-010-00001

PWD=3B5D3C427365F40C1D27682D78BB31E0

title:彩信測試

Mobile:139***404,138***213…………….

Content:測試

Stime: ""

輸出結果:

XML格式:

C#彩信接口開發經驗及具體開發實作

具體函數C#實作:

using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
using System.IO;
using System.Web.Security;
namespace MMSsend
{
    public partial class Form1 : Form
    {
        
        public Form1()
        {
            InitializeComponent();
        }

        //用于送出彩信
        MmsSend.WebService mms = new MMSsend.MmsSend.WebService();
        //該Demo很簡單,隻送出一幀,一幀裡隻有一種元素。

        //byte[] byte2 = System.Text.Encoding.Default.GetBytes("彩信文字測試");
        //  string      content = "1_1.txt," + Convert.ToBase64String(byte2) + ";";
        //以上2句話是将字元串轉換成base64字元串

        string extension;
        private void selectFile_Click(object sender, EventArgs e)
        {
            OpenFileDialog ofd = new OpenFileDialog();
            ofd.Filter = "所有檔案|*.*";
            ofd.Multiselect = true;
            ofd.ShowDialog();
            if (ofd.FileName!="")
            {
                path.Text = ofd.FileName;
            }
            int k = path.Text.IndexOf('.');
             extension = path.Text.Substring(k + 1);
            extension = extension.ToLower();

        }

        private void btn_send_Click(object sender, EventArgs e)
        {
            //序列号密碼
            string sn = "SDK-SSD-010-xxxxx";
            string password = "XXXXXX";
            //這裡的密碼是序列号和密碼的MD5碼
            string pwd = FormsAuthentication.HashPasswordForStoringInConfigFile(sn + password, "md5");

            //讀取檔案流
            FileStream fs = new FileStream(path.Text, FileMode.Open);
            byte[] sendbyte = new byte[fs.Length];
            fs.Read(sendbyte, 0, sendbyte.Length);
             fs.Close();
             if (extension == "txt")
             {
                 string content = "1_1.txt," + Convert.ToBase64String(sendbyte);
                 label1.Text = mms.mdMmsSend(sn, pwd, "新彩信接口c# demo測試", "18636800125", content, "");//換成您自己的手機号
             
             }
             else {
                 string content = "1_2." + extension + "," + Convert.ToBase64String(sendbyte);

                 label1.Text = mms.mdMmsSend(sn, pwd, "新彩信接口c# demo測試", "18636924700", content, "");//換成您自己的手機号
             
             }
            
            
        }
    }
}
           

四、webservice傳回集合對照表:

傳回值 傳回值說明
1 沒有資料需要接收
-2 帳号/密碼不正确 
-3 重複登陸
-4 餘額不足
-5 資料格式錯誤
-6 參數有誤
-8 流量控制錯誤
-11 資料庫錯誤
-12 序列号狀态錯誤
-13 沒有送出增值内容
-14 伺服器寫檔案失敗
-17 該接口禁止使用該方法
-18  等上一批送出結果傳回再繼續下一批送出
-15 内容長度長
-22 Ip綁定

五、附加說明:

1.彩信語音SDK位址:

常用接口位址:http://sdk3.entinfo.cn:8060/webservice.asmx

2.其它說明:

(1)開發使用的帳号必須為SDK開頭,如SDK-SSD-010-00001,帳号第一次需要調用Register方法注冊一次.僅需注冊一次即可,資訊必須真實

(2)UnRegister與Register配合使用, 連續使用不得超過10次/天;

3. 鄭重聲明:

(1)禁止相同的内容多個手機号連續一條一條送出. 否則禁用帳号,由此帶來損失由客戶自行負責.

(2)請客戶提供外網伺服器IP以便于綁定IP發送,提高賬号的安全性!

(3)在程式裡最好有配置檔案,程式自動判斷當某個接口連接配接逾時送出速度變慢時.程式可以自動切換其它的接口以下是推薦的幾個伺服器,僅接口位址不同而已.方法全部相同;

位址1:http://sdk3.entinfo.cn:8060/webservice.asmx

這些位址都是标準的webservice位址,C#,Java客戶可以按照自己熟悉的方式去解析String   

或者

位址1:http://sdk3.entinfo.cn:8060/webservice.asmx?wsdl

六、示例Demo源代碼下載下傳:

DEMO      SDK彩信接口文檔   所有下載下傳