• .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
        }
    }

  • 相关阅读:
    vue 无缝无限滚动横条实现
    小程序 recycle-view 个人demo
    js 笔记
    java整理的一些面试资料
    使用js获取浏览器地址栏里的参数
    java面试题
    sql中索引不会被用到的几种情况
    常用linux命令
    shiro登录成功之后跳转原路径
    springboot 整合 mongodb实现 批量更新数据
  • 原文地址:https://www.cnblogs.com/wybshyy/p/16042712.html
Copyright © 2020-2023  润新知