C#&.Net干货分享- 构造SMSWebChineseApi对接第三方短信平台

你们想要的短信对接,要舍得点钱哦。。。。

 

    /// <summary>
    /// http://sms.webchinese.cn/api.shtml
    /// </summary>
    public class SMSWebChineseApi
    {
        private string SMS_UID = string.Empty; //用户名
        private string SMS_KEY = string.Empty; //接口秘钥

        private Dictionary<string, string> dcReurnKeyValue = new Dictionary<string, string>()
        {
        {"-1","没有该用户账户"},
        {"-2","接口密钥不正确,不是账户登陆密码"},
        {"-21","MD5接口密钥加密不正确"},
        {"-3","短信数量不足"},
        {"-11","该用户被禁用"},
        {"-14","短信内容出现非法字符"},
        {"-4","手机号格式不正确"},
        {"-41","手机号码为空"},
        {"-42","短信内容为空"},
        {"-51","短信签名格式不正确,接口签名格式为:【签名内容】"},
        {"-6","IP限制"},
        {"大于0","短信发送数量:"}
        };


        /// <summary>
        /// 返回UTF-8编码发送接口地址
        /// </summary>
        /// <param name="receivePhoneNumber">目的手机号码(多个手机号请用半角逗号隔开)</param>
        /// <param name="receiveSms">短信内容,最多支持400个字,普通短信70个字/条,长短信64个字/条计费</param>
        /// <returns>返回UTF-8编码发送接口地址</returns>
        public string GetPostUrl(string receivePhoneNumber, string receiveSms)
        {
            return "http://utf8.sms.webchinese.cn/?Uid=" + SMS_UID + "&key=" + SMS_KEY + "&smsMob=" + receivePhoneNumber + "&smsText=" + receiveSms;
        }

        /// <summary>
        /// 调用时只需要把拼成的URL传给该函数即可。判断返回值即可
        /// </summary>
        /// <param name="receivePhoneNumber">目的手机号码(多个手机号请用半角逗号隔开)</param>
        /// <param name="receiveSms">短信内容,最多支持400个字,普通短信70个字/条,长短信64个字/条计费</param>
        /// <returns></returns>
        public string SendWebChineseSmsInfo(string receivePhoneNumber, string receiveSms)
        {
            string postUrl = GetPostUrl(receivePhoneNumber, receiveSms);
            string strReturnMsg = string.Empty;
            if (string.IsNullOrEmpty(postUrl))
            {
                return strReturnMsg;
            }
            string targeturl = postUrl.Trim().ToString();
            try
            {
                HttpWebRequest hr = (HttpWebRequest)WebRequest.Create(targeturl);
                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);
                strReturnMsg = ser.ReadToEnd();
            }
            catch
            {
                strReturnMsg = null;
            }
            if (string.IsNullOrEmpty(strReturnMsg))
            {
                return string.Empty;
            }
            if (dcReurnKeyValue.Keys.Contains(strReturnMsg))
            {
                return dcReurnKeyValue[strReturnMsg];
            }
            else
            {
                return dcReurnKeyValue["大于0"] + strReturnMsg;
            }
        }
    }

C#&.Net干货分享- 构造SMSWebChineseApi对接第三方短信平台

上一篇:APP-7-百度地图移动轨迹


下一篇:Windows 系统日志ID分析