93 lines
3.9 KiB
C#
93 lines
3.9 KiB
C#
using System;
|
|
using System.IO;
|
|
using System.Net;
|
|
using System.Text;
|
|
using WX.CRM.CRMServices.SMS.InterfaceModel;
|
|
|
|
namespace WX.CRM.CRMServices.SMS.InterfaceExec
|
|
{
|
|
public class LianTong : IMsgSend
|
|
{
|
|
public string url = "";
|
|
public string Spcode = "";
|
|
public string LoginName = "";
|
|
public string Password = "";
|
|
public LianTong(string _account = "", string _password = "")
|
|
{
|
|
LianTongConfig config = new LianTongConfig();
|
|
LoginName = config.account;
|
|
Password = config.pwd;
|
|
url = config.url;
|
|
if (!string.IsNullOrEmpty(_account) && !string.IsNullOrEmpty(_password))
|
|
{
|
|
Spcode = _account;
|
|
Password = _password;
|
|
}
|
|
LoginName = config.GetUserName(Spcode);
|
|
//Common.LogHelper.Error(string.Format("【联通帐号信息】,url{0},loginname:{1},spcode:{2}",url,LoginName,Spcode));
|
|
}
|
|
public SMS.InterfaceModel.ReturnResult Execute(string[] mobiles, string msg)
|
|
{
|
|
return Send(mobiles, msg);
|
|
}
|
|
|
|
public decimal queryAmt()
|
|
{
|
|
throw new NotImplementedException();
|
|
}
|
|
|
|
InterfaceModel.ReturnResult Send(string[] mobiles, string msg)
|
|
{
|
|
string mobilesStr = string.Join(",", mobiles);
|
|
InterfaceModel.ReturnResult result = new InterfaceModel.ReturnResult();
|
|
//result.SendStr = mobilesStr;
|
|
|
|
string MessageContent = ToHex(msg, "GBK", false); //短信内容
|
|
string UserNumber = mobilesStr; //手机号
|
|
string SerialNumber = DateTime.Now.ToString("yyyyMMddHHmmssfff") + "001"; //流水号
|
|
string ScheduleTime = ""; //预约发送时间
|
|
string ExtendAccessNum = ""; //接入号扩展号
|
|
StringBuilder sb = new StringBuilder();
|
|
sb.Append("SpCode=" + Spcode + "&LoginName=" + LoginName + "&Password=" + Password + "&MessageContent=" + MessageContent + "&UserNumber=" + UserNumber + "&SerialNumber=" + SerialNumber + "&ScheduleTime=" + ScheduleTime + "&ExtendAccessNum=" + ExtendAccessNum + "&f=1");
|
|
result.SendStr = sb.ToString().Length > 500 ? sb.ToString().Substring(0, 500) : sb.ToString();
|
|
byte[] bData = Encoding.GetEncoding("GBK").GetBytes(sb.ToString());
|
|
HttpWebRequest hwRequest;
|
|
HttpWebResponse hwResponse;
|
|
string strResult = "";
|
|
try
|
|
{
|
|
hwRequest = (HttpWebRequest)WebRequest.Create(url);
|
|
hwRequest.Method = "POST";
|
|
hwRequest.ContentType = "application/x-www-form-urlencoded";
|
|
hwRequest.ContentLength = bData.Length;
|
|
Stream smWrite = hwRequest.GetRequestStream();
|
|
smWrite.Write(bData, 0, bData.Length);
|
|
smWrite.Close();
|
|
hwResponse = (HttpWebResponse)hwRequest.GetResponse();
|
|
StreamReader srReader = new StreamReader(hwResponse.GetResponseStream(), Encoding.Default);
|
|
strResult = srReader.ReadToEnd();
|
|
srReader.Close();
|
|
hwResponse.Close();
|
|
result.ReturnStr = strResult;
|
|
if (strResult.IndexOf("result=0") >= 0) //发送成功
|
|
result.submitStatus = SubmitStatus.success;
|
|
else
|
|
result.submitStatus = SubmitStatus.fail;
|
|
return result;
|
|
}
|
|
catch (Exception ex)
|
|
{
|
|
result.submitStatus = SubmitStatus.fail;
|
|
WX.CRM.Common.LogHelper.Error("LianTong.Send:" + ex.Message + ex.StackTrace);
|
|
}
|
|
return result;
|
|
}
|
|
string ToHex(string s, string charset, bool fenge)
|
|
{
|
|
byte[] buffer = Encoding.GetEncoding("GBK").GetBytes(s);
|
|
s = Encoding.GetEncoding("GBK").GetString(buffer);
|
|
return s;
|
|
}
|
|
}
|
|
}
|