<!--短信接口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
}
}