24小时在线 - 古典小说 - 文学小说 - 关于我们
您的当前位置:首页 > .NET > C# >

用“网筑”平台发手机短信的C#代码

来源:比特技术 编辑:比特技术网 时间:2018-03-30点击:
导读:用“网建”平台发手机短信的C#代码 一直都用这个平台发手机短信的,今天做新项目的时候用到了,但是上来
用“网建”平台发手机短信的C#代码

一直都用这个平台发手机短信的,今天做新项目的时候用到了,但是上来博客搜索不到,只好翻以前的源代码翻了好久才找到了,先记下来,以作备用:

 

using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Net;
using System.Text;
using System.Web;

namespace Niunan.CardShop.Web.Code
{
    public class SendMobile
    {

        /// <summary>返回发送短信的状态说明
        ///
        /// </summary>
        /// <param name="str"></param>
        /// <returns></returns>
        public static string GetMobileMSMStatus(string str)
        {
            string s = "";
            switch (str)
            {
                case "-1":
                    s = "没有该用户账户";
                    break;
                case "-2":
                    s = "密钥不正确(不是用户密码)";
                    break;
                case "-3":
                    s = "短信数量不足";
                    break;
                case "-11":
                    s = "该用户被禁用";
                    break;
                case "-14":
                    s = "短信内容出现非法字符";
                    break;
                case "-4":
                    s = "手机号格式不正确";
                    break;
                case "-41":
                    s = "手机号码为空";
                    break;
                case "-42":
                    s = "短信内容为空";
                    break;
                default:
                    s = "成功发送" + str + "条短信";
                    break;
            }
            return s;
        }
        /// <summary>发送手机短信
        ///
        /// </summary>
        /// <param name="mobile">手机号码,多个手机号以,号相隔</param>
        /// <param name="body">短信内容</param>
        public static string SendMobileMSM(string mobile, string body)
        {
 
            string url = "http://utf8.sms.webchinese.cn/?Uid=xxxxxx&Key=xxxxxx&smsMob=" + mobile + "&smsText=" + body;
            string targeturl = url.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);
                return GetMobileMSMStatus(ser.ReadToEnd());
            }
            catch (Exception ex)
            {
                throw ex;
            }
        }
    }
}

来源:比特技术在线(www.byte.online),欢迎分享本文,转载请保留出处!
http://www.byte.online/a/_NET/C_/2018/485550.html
责任编辑:比特技术网

    打赏

    取消

    感谢您的支持,我会继续努力的!

    扫码支持
    扫码打赏,你说多少就多少

    打开支付宝扫一扫,即可进行扫码打赏哦

    上一篇:没有了
    下一篇:C#编码轨范参考

    网友评论:

    Copyright © www.byte.online 比特技术在线 版权所有 粤ICP备15038486号-3
    本站所有资料来源于网络,由个人收集整理,仅限于个人学习和研究,如果侵犯您的权益请联系我们删除!
    Top