zoukankan      html  css  js  c++  java
  • .NET短信接口 实例

      <!--短信接口Url-->
      <add key="SendUrl" value="http://api.sms7.cn/tx/" />
      <!--用户名-->
      <add key="Uid" value="98816" />
      <!--密码-->
      <add key="Pwd" value="std5805122" />
      <!-- ================== 8:短信接口配置 END================== -->

    using DotNet.Kernel;
    using System;
    using System.Collections.Generic;
    using System.IO;
    using System.Linq;
    using System.Net;
    using System.Text;
    using System.Web.Security;

    namespace DotNet.Utilities
    {
        public class MessageInterface
        {
            #region 数据发送
            public static bool send(string strMessage, string Mobile)
            {
                string sendurl = ConfigHelper.GetValue("SendUrl");//"http://api.sms7.cn/tx/";
                string mobile = Mobile;//发送号码
                string uid = ConfigHelper.GetValue("Uid");
                string pwd = ConfigHelper.GetValue("Pwd");
                string strContent ="";
                //判断是否已存在“【刷咯】”
                if (strMessage.IndexOf("【刷咯】") > 0)
                {
                    strContent = strMessage;
                }
                else
                {
                    strContent = strMessage + "【刷咯】";
                }
                StringBuilder sbTemp = new StringBuilder();

                string Pass = FormsAuthentication.HashPasswordForStoringInConfigFile(pwd + uid, "MD5"); //密码进行MD5加密
                //POST 传值
                sbTemp.Append("uid=" + uid + "&pwd=" + Pass + "&mobile=" + mobile + "&content=" + strContent);
                byte[] bTemp = System.Text.Encoding.GetEncoding("GBK").GetBytes(sbTemp.ToString());
                String postReturn = doPostRequest(sendurl, bTemp);
                DotNet.Kernel.DbLog.WriteLog("Post response is: " + postReturn);//测试返回结果
                if (postReturn.Contains("100"))
                {
                    return true;
                }
                else
                {
                    return false;
                }
            }
            //POST方式发送得结果
            private 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)
                {
                    DbLog.WriteException(err);
                    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)
                {
                    DbLog.WriteException(err);
                }
                return strResult;
            }
            #endregion
        }
    }

  • 相关阅读:
    生物信息学常用的在线网站及数据库汇总
    Python入门--6--今天抄袭人家一篇日志--numpy这个
    Perl语言--一些关于赋值、引用的东西
    Python入门--5--列表
    Idea下 调试Spring源代码
    Java OOM出现场景
    分布式事务解决方案
    mybatis generator 根据表生成对应的mapper文件
    签名工具类
    BPMN2.0
  • 原文地址:https://www.cnblogs.com/wybshyy/p/13783769.html
Copyright © 2011-2022 走看看