熱點推薦:
您现在的位置: 電腦知識網 >> 編程 >> .NET編程 >> 正文

移動和聯通接口 發送短信

2013-11-13 10:12:48  來源: .NET編程 
    using System;
    using SystemData;
    using SystemConfiguration;
    using SystemWeb;
    using SystemWebSecurity;
    using SystemWebUI;
    using SystemWebUIWebControls;
    using SystemWebUIWebControlsWebParts;
    using SystemWebUIHtmlControls;
    using SystemText;
    using SystemNet;
    using SystemIO;
    using cnshunicomgroupsms;
    ///
    /// Mobmsg 的摘要說明
    ///
    public class Mobmsg
    {
    private string _MobNum;
    private string _MobMsg;
    public Mobmsg()
    {
    //
    // TODO: 在此處添加構造函數邏輯
    //
    }
    public Mobmsg(string MobNum string MobMsg)
    {
    this_MobNum = MobNum;
    this_MobMsg = MobMsg;
    }
    public void SendMsg()
    {
    if (CheckType(this_MobNum))
    ToMobile()
    else
    ToUnicom()
    }
    public void ToMobile()
    {//移動的接口
    Encoding encoding = EncodingGetEncoding(gb
    string enterpriseid = ;//企業代碼
    string accountid = ;
    string pwd = yourpwd;
    string postData = enterpriseid= + enterpriseid + &accountid= + accountid + &pswd= + pwd + &mobs= + this_MobNum + &msg= + this_MobMsg;
    string strUrl = ;
    byte[] data = encodingGetBytes(postData)
    // 准備請求…
    HttpWebRequest myRequest = (HttpWebRequest)WebRequestCreate(strUrl)
    myRequestMethod = POST;
    myRequestContentType = application/xwwwformurlencoded;
    myRequestContentLength = dataLength;
    Stream newStream = myRequestGetRequestStream()
    // 發送數據
    newStreamWrite(data dataLength)
    newStreamClose()
    }
    public void ToUnicom()
    {//聯通的接口
    cnshunicomgroupsmsLogin myLogin = new cnshunicomgroupsmsLogin()
    string MySessionID = ;
    myLoginusername = yourname; //用戶名
    myLoginuserType = ;
    myLoginpassword = yourpwd;  //密碼
    LoginMes mes = new LoginMes()
    meslogin = myLogin;
    SmWSImplService Binding = new SmWSImplService()
    OpResult Value = new OpResult()
    try
    {
    Value = mberLogin(mes
    }
    catch
    {
    ;
    }
    MySessionID = ValuesessionId;//得到sessionid
    SendBatchSMS(Binding MySessionID this_MobMsg companycode//companycode為企業代號
    Value = Bindinglogout(mes
    }
    public bool CheckType(string MobileNum)
    {
    string ForeStr = MobileNumSubstring(
    int ForeNum = ConvertToInt(ForeStr)
    if (ForeNum <=
    return false;
    else
    return true;
    }
    public void SendBatchSMS(SmWSImplService Binding string SessionID string SmsMsg string AccountID)
    {
    BatchMsg MySendSM = new BatchMsg()
    OpResult Value = new OpResult()
    string[] SendAddrs = new string[];
    SendAddrs[] = this_MobNum; //發送號碼數組 手機號碼
    MySendSMsessionId = SessionID;
    MySendSMmsgContent = SmsMsg;
    MySendSMdestAddrs = SendAddrs;
    Value = BindingSendBatchMessage(MySendSM)
    MySendSM=null;
    Value = null;
    }
    }
    在調用聯通的接口的時候還要添加一個 webservice
    然後我們可以在其它頁面使用
    Mobmsg msg = new Mobmsg(要發送信息的手機號碼要發送的內容
    msgSendMsg()
    這樣就可以了
From:http://tw.wingwit.com/Article/program/net/201311/12928.html
    推薦文章
    Copyright © 2005-2013 電腦知識網 Computer Knowledge   All rights reserved.