首页 诗词 字典 板报 句子 名言 友答 励志 学校 网站地图
当前位置: 首页 > 教程频道 > 网站开发 > ASP >

asp.net两种模式的短信接口使用(提供接口的都是收费的)

2013-01-28 
asp.net两种方式的短信接口使用(提供接口的都是收费的)一种是http请求的方式,另一种就是提供WebService接

asp.net两种方式的短信接口使用(提供接口的都是收费的)

一种是http请求的方式,另一种就是提供WebService接口供调用的。


        #region sms.webchinese.cn 发送短信         //服务商 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

上面就是一般的调用服务的方法。。。


热点排行