• 短信平台接口调用


    http请求

    复制代码
           string url="http://xxx.com/api/MsgSend.asmx";
    
            protected string sendmsgByPost() //POST方式请求
            {
                StringBuilder sb = new StringBuilder();
                sb.Append("userCode=用户名&");
                sb.Append("userPass=密码&");
                sb.Append("DesNo=手机号&");
                sb.Append("Msg=短信内容【签名】&");
                sb.Append("Channel=通道号");
    
                string result = httpPost(url + "/sendMes", sb.ToString());
    
                return result;
            }
    
            protected string sendmsgByGet() //Get方式请求
            {
                StringBuilder sb = new StringBuilder();
                sb.Append("userCode=用户名&");
                sb.Append("userPass=密码&");
                sb.Append("DesNo=手机号&");
                sb.Append("Msg=短信内容【签名】&");
                sb.Append("Channel=通道号");
    
                string result = httpGet(url + "/sendMes", sb.ToString());
                return result;
            }        
    
    
    
            protected string httpGet(string url, string data) //http get请求
            {
                try
                {
                    HttpWebRequest request = (HttpWebRequest)WebRequest.Create(url + "?" + data);
                    request.Method = "GET";
                    request.ContentType = "text/html;charset=UTF-8";
                    HttpWebResponse response = (HttpWebResponse)request.GetResponse();
                    Stream myResponseStream = response.GetResponseStream();
                    StreamReader myStreamReader = new StreamReader(myResponseStream, Encoding.GetEncoding("utf-8"));
                    string retString = myStreamReader.ReadToEnd();
                    myStreamReader.Close();
                    myResponseStream.Close();
                    return retString;
                }
                catch (Exception ex)
                {
    
                    return ex.Message;
                }
            }
            protected string httpPost(string url, string data) //http post请求
            {
                try
                {
                    HttpWebRequest request = (HttpWebRequest)WebRequest.Create(url);
                    request.Method = "POST";
                    request.ContentType = "application/x-www-form-urlencoded";
                    byte[] info = Encoding.UTF8.GetBytes(data);
                    using (Stream stream = request.GetRequestStream())
                    {
                        stream.Write(info, 0, info.Length);
                    }
                    HttpWebResponse response = (HttpWebResponse)request.GetResponse();
                    Stream myResponseStream = response.GetResponseStream();
                    StreamReader myStreamReader = new StreamReader(myResponseStream, Encoding.GetEncoding("utf-8"));
                    string retString = myStreamReader.ReadToEnd();
                    myStreamReader.Close();
                    myResponseStream.Close();
                    return retString;
                }
                catch (Exception ex)
                {
                    return ex.Message;
                }
    
            }
    复制代码

    webservice请求

    复制代码
        private void SendSms() //webservice请求方式
                {
                    TopenServiceReference.MsgSendSoapClient topen = new TopenServiceReference.MsgSendSoapClient();
                    string userName = "用户名";
                    string passWord = "密码";
                    string mobiles = "13900000000,13800000000,13100000000,……";
                    string msgContent = "短信内容(含签名)";
                    string channel = "由拓鹏给您的通道编号";
                    string sendResult = topen.sendMes(userName, passWord, mobiles, msgContent, channel); //此处的sendMes可能因接口文档不同而不同,请注意。返回批次号,可保存下来,作为获取发送报告凭据
    
                    //然后,根据返回的sendResult作相应处理
                }
    复制代码
  • 相关阅读:
    c++中利用宏定义简化for循环使用
    UVA1152- 枚举 /二分查找
    acm 模板
    Xwindow的文章
    编程语言博客
    csh与bash比较
    关于锁与并发的资料总结
    linux su和sudo命令的区别
    对Memcached使用的总结和使用场景
    iptables配置——NAT地址转换
  • 原文地址:https://www.cnblogs.com/wyongqi/p/7660532.html
Copyright © 2020-2023  润新知