zoukankan      html  css  js  c++  java
  • 短信发送

    中国短信网的发送接口:

        /// <summary>
        /// 发送短信并返回结果
        /// </summary>
        /// <param name="hm">号码</param>
        /// <param name="nr">内容</param>
        /// <returns></returns>
        public static String fs(string hm, string nr)
        {
            StringBuilder sbTemp = new StringBuilder();

            sbTemp.Append("uid=*****&pwd=*****&mobile=" + hm + "&content=" + nr);
            byte[] bTemp = System.Text.Encoding.GetEncoding("GBK").GetBytes(sbTemp.ToString());
            String postReturn = Define.doPostRequest("http://http.c123.com/tx/", bTemp);
            return postReturn;
        }
        //POST方式发送得结果
        public static String doPostRequest(string url, byte[] bData)
        {
            System.Net.HttpWebRequest hwRequest;
            System.Net.HttpWebResponse hwResponse;

            string strResult = string.Empty;
            try
            {
                hwRequest = (System.Net.HttpWebRequest)System.Net.WebRequest.Create(url);
                hwRequest.Timeout = 5000;
                hwRequest.Method = "POST";
                hwRequest.ContentType = "application/x-www-form-urlencoded";
                hwRequest.ContentLength = bData.Length;

                System.IO.Stream smWrite = hwRequest.GetRequestStream();
                smWrite.Write(bData, 0, bData.Length);
                smWrite.Close();
            }
            catch (System.Exception err)
            {
                WriteErrLog(err.ToString());
                return strResult;
            }

            //get response
            try
            {
                hwResponse = (HttpWebResponse)hwRequest.GetResponse();
                StreamReader srReader = new StreamReader(hwResponse.GetResponseStream(), Encoding.ASCII);
                strResult = srReader.ReadToEnd();
                srReader.Close();
                hwResponse.Close();
            }
            catch (System.Exception err)
            {
                WriteErrLog(err.ToString());
            }

            return strResult;
        }
        public static void WriteErrLog(string strErr)
        {
            Console.WriteLine(strErr);
            System.Diagnostics.Trace.WriteLine(strErr);
        }

     这个网站只能接收到别人回复的短信,不能设置接收的号码,跟我的需求不同,就没继续使用下去,过几天我用其他的接口实现了短信查询功能后,再贴出来…

  • 相关阅读:
    vs编译器好多下划波浪线但不报错
    scala学习——(1)scala基础(下)
    scala学习——(1)scala基础(上)
    未能正确加载包“Microsoft.Data.Entity.Design.Package.MicrosoftDataEntityDesignPackage(转)
    如何完全卸载VS2010(亲自体验过) (转)
    2_C语言中的数据类型 (十)数组
    C++ STL 学习笔记__(8)map和multimap容器
    opencv配置(转)
    2_C语言中的数据类型 (九)数组
    郑捷《机器学习算法原理与编程实践》学习笔记(第五章 梯度寻优)5.2 Logistic梯度下降法
  • 原文地址:https://www.cnblogs.com/_zjl/p/2021873.html
Copyright © 2011-2022 走看看