
一种是http请求的方式,另一种就是提供WebService接口供调用的。
- //服务商 sms.webchinese.cn
- //sms_url="http://sms.webchinese.cn/web_api/?Uid=账号&Key=接口密钥&smsMob=手机号码&smsText=短信内容"
- /// <summary>
- /// 发送短信接口sms.webchinese.cn
- /// </summary>
- /// <param name="mobilenumber">手机号,多个号码用‘,’分开</param>
- /// <param name="message">信息内容</param>
- /// <returns>
- /// 返回值情况如下
- /// -1 没有该用户账户
- ///-2 密钥不正确 [查看密钥]
- ///-3 短信数量不足
- ///-11 该用户被禁用
- ///-14 短信内容出现非法字符
- ///-4 手机号格式不正确
- ///-41 手机号码为空
- ///-42 短信内容为空
- ///大于0 短信发送数量
- /// </returns>
- public int SendMSG(string mobilenumber, string message)
- {
- //发送短信请求的地址
- string url = string.Format("http://sms.webchinese.cn/web_api/?Uid=账号&Key=接口密钥&smsMob={0}&smsText={1}", mobilenumber, message);
- string strRet = null;
- url = HttpUtility.UrlEncode(url);//urlencode
- if (url == null || url.Trim().ToString() == "")
- {
- return 0;
- }
- try
- {
- HttpWebRequest hr = (HttpWebRequest)WebRequest.Create(url);
- hr.UserAgent = "Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.1)";
- hr.Method = "GET";
- hr.Timeout = 30 * 60 * 1000;
- WebResponse hs = hr.GetResponse();
- Stream sr = hs.GetResponseStream();
- StreamReader ser = new StreamReader(sr, Encoding.Default);
- strRet = ser.ReadToEnd();
- }
- catch (Exception)
- {
- strRet = null;
- }
- if (strRet == null || strRet == "") return 0;
- return Convert.ToInt32(strRet);
- }
- #endregion
- #region www.56dxw.com 发送短信
- //添加服务引用 http://jiekou.56dxw.com/WebServiceInterface.asmx
- //输入命名空间:MobileMessage_56
- private MobileMessage_56.WebServiceInterfaceSoapClient _ws_56 = null;
- /// <summary>
- /// www.56dxw.com短信接口服务
- /// </summary>
- public MobileMessage_56.WebServiceInterfaceSoapClient ws_56
- {
- get
- {
- if (_ws_56 == null) _ws_56 = new MobileMessage_56.WebServiceInterfaceSoapClient();
- return _ws_56;
- }
- }
- private string username_56 = "test";//网站的用户名
- private string password_56 = "test";//网站的登陆密码
- private string cid_56 = "";//企业id
- /// <summary>
- /// 发送短信接口函数 www.56dxw.com
- /// </summary>
- /// <param name="mobilenumber">手机号英文半角逗号隔开,一次1000个以内</param>
- /// <param name="message">信息内容</param>
- /// <returns>
- /// -1 用户名密码不正确
- ///-2 内容不能大于70个字
- ///-3 验证此平台是否存在
- ///-4 提交号码不能为空或客户余额为0
- ///-5 客户剩余条数不够要发送的短信数量
- ///-6 非法短信内容
- ///-7 返回系统故障
- ///-8 网络性错误,请稍后再试
- ///1 代表发送成功
- /// </returns>
- public int SendMSG_56(string mobilenumber, string message)
- {
- string sendtime = "";//格式:"2010-1-27 11:10:20"---发送时间,为空则立即发送
- string smsnumber = "";//平台
- return ws_56.SendNote(mobilenumber, message, username_56, password_56, cid_56, sendtime, smsnumber);
- }
- /// <summary>
- /// 查询剩余短信条数
- /// </summary>
- /// <returns>
- /// -1 代表用户名密码不正确
- /// 其它值 代表返回具体条数
- /// </returns>
- public int ReturnUserFullMoney_56()
- {
- return ws_56.ReturnUserFullMoney(username_56, password_56, cid_56);
- }
- /// <summary>
- /// 修改密码
- /// </summary>
- /// <param name="oldpwd">旧密码</param>
- /// <param name="newpwd">新密码</param>
- /// <returns>
- /// 1 代表密码修改成功
- /// -1 代表密码编辑失败
- /// -2 用户名密码错误
- /// </returns>
- public int EditUserPwd(string oldpwd,string newpwd)
- {
- return ws_56.EditUserPwd(username_56, oldpwd, newpwd, cid_56);
- }
- #endregion