C#编写移动与联通接口
- //页面调用
- private void SendMassage(string Telephone, string text)
- {
- SendMobile sm = new SendMobile(Telephone, text);
- sm.SendMsg();
- }
- //引用
- using System.Text;
- using System.Net;
- using System.IO;
- //using cn.sh.unicom.groupsms;
- /// <summary>
- /// SendMobile 的摘要说明
- /// </summary>
- public class SendMobile
- {
- public SendMobile()
- {
- //
- // TODO: 在此处添加构造函数逻辑
- //
- }
- private string _MobNum;
- private string _MobMsg;
- public SendMobile(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 = Encoding.GetEncoding("gb2312");
- string enterpriseid = "123456";//企业代码
- string accountid = "15811150014";//帐号
- string pwd = "630420";//密码
- string postData = "enterpriseid=" enterpriseid "&accountid=" accountid "&pswd=" pwd "&mobs=" this._MobNum "&msg=" this._MobMsg;
- string strUrl = "http://211.136.163.68:8000/httpserver";
- byte[] data = encoding.GetBytes(postData);
- // 准备请求...
- HttpWebRequest myRequest = (HttpWebRequest)WebRequest.Create(strUrl);
- myRequest.Method = "POST";
- myRequest.ContentType = "application/x-www-form-urlencoded";
- myRequest.ContentLength = data.Length;
- Stream newStream = myRequest.GetRequestStream();
- // 发送数据
- newStream.Write(data, 0, data.Length);
- newStream.Close();
- }
- public void ToUnicom()
- {//联通的接口
- cn.sh.unicom.groupsms.Login myLogin = new cn.sh.unicom.groupsms.Login();
- string MySessionID = "";
- myLogin.username = "yourname"; //用户名123456789
- myLogin.userType = "0";
- myLogin.password = "yourpwd"; //密码
- LoginMes mes1 = new LoginMes();
- mes1.login = myLogin;
- SmWSImplService Binding = new SmWSImplService();
- OpResult Value1 = new OpResult();
- try
- {
- Value1 = Binding.memberLogin(mes1);
- }
- catch
- {
-
- }
- MySessionID = Value1.sessionId;//得到sessionid
- SendBatchSMS(Binding, MySessionID, this._MobMsg, "companycode");//companycode为企业代号1112345
- Value1 = Binding.logout(mes1);
- }
- public bool CheckType(string MobileNum)
- {
- string ForeStr = MobileNum.Substring(0, 3);
- int ForeNum = Convert.ToInt32(ForeStr);
- if (ForeNum <= 134)
- return false;
- else
- return true;
- }
- }
补充:软件开发 , C# ,