.NET短信接口 实例
来源:互联网 发布:再顾科技有限公司 知乎 编辑:程序博客网 时间:2024/06/06 18:35
<!--短信接口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
}
}
0 0
- .NET短信接口 实例
- ASP.NET短信接口
- 面向短信接口开发实例
- .net 调用JAVA短信接口
- 短信验证平台接口调用实例
- c#网易云信短信接口实例
- php调用云片网接口发送短信实例
- C#和JAVA调用短信接口发短信实例
- java调用短信api接口发送短信demo实例
- .net调用阿里云短信接口
- 阿里大鱼短信接口PHP版,精简版阿里大鱼短信SMS发送接口PHP实例
- SP 短信开发-PROVISION接口实现-反向取消实例代码
- SP 短信开发-PROVISION接口实现-正向订购实例代码
- c#的飞信fetion短信API接口使用实例
- c#的飞信fetion短信API接口使用实例
- c#的飞信fetion短信API接口使用实例
- 分享一个php短信验证码接口实例
- 短信接口
- 如何解决IIS错误_HTTP 错误 500.21 - Internal Server Error
- ashx中Session怎么存取?
- js获取FCK编辑器信息/取值/赋值具体方法
- jquery select取值,赋值操作
- 【转】jQuery实现的简单文字提示效果模拟title
- .NET短信接口 实例
- 防止SQL注入
- 布局
- 防止SQL注入2
- HDU 5458 Stability (2015 ACM/ICPC Asia Regional Shenyang Online)
- .NET 二维码生成(ThoughtWorks.QRCode)
- 上拉刷新下拉加载中的values
- 转。WEB前端特效。统计图,3D切换图片,摇号,转盘抽奖
- 【技术晨读】缓存更新的套路