移动和联通短信发送接口

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()
    这样就可以了

posted @ 2013-12-03 19:33  lanyefeng2008  阅读(708)  评论(0)    收藏  举报