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;
            }
        }
    }

转载于:https://www.cnblogs.com/hualiuliu/p/11458133.html

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值