90 lines
3.5 KiB
C#
90 lines
3.5 KiB
C#
using System;
|
|
using System.Collections.Generic;
|
|
using System.Collections.Specialized;
|
|
using System.Net;
|
|
using System.Text;
|
|
using WX.CRM.CRMServices.SMS.InterfaceModel;
|
|
|
|
namespace WX.CRM.CRMServices.SMS.InterfaceExec
|
|
{
|
|
internal class ExecRuiXin : IMsgSend
|
|
{
|
|
string Account = "";
|
|
string password = "";
|
|
string url = "";
|
|
System.Random rd = new Random();
|
|
|
|
public ExecRuiXin(string _account = "", string _password = "")
|
|
{
|
|
RuiXinConfig config = new RuiXinConfig();
|
|
Account = config.Account;
|
|
password = config.Password;
|
|
url = config.PkgUrl;
|
|
if (!string.IsNullOrEmpty(_account) && !string.IsNullOrEmpty(_password))
|
|
{
|
|
Account = _account;
|
|
password = _password;
|
|
}
|
|
}
|
|
|
|
public InterfaceModel.ReturnResult Execute(string[] mobiles, string msg)
|
|
{
|
|
return sendPkg(mobiles, msg);
|
|
}
|
|
|
|
public decimal queryAmt()
|
|
{
|
|
throw new NotImplementedException();
|
|
}
|
|
|
|
#region 发送短信
|
|
InterfaceModel.ReturnResult sendPkg(string[] mobiles, string msg)
|
|
{
|
|
InterfaceModel.ReturnResult result = new InterfaceModel.ReturnResult();
|
|
string Url = url;
|
|
List<SMS.InterfaceModel.RuiXin_Msg> msgs = new List<SMS.InterfaceModel.RuiXin_Msg>();
|
|
for (int i = 0; i < mobiles.Length; i++)
|
|
{
|
|
msgs.Add(new SMS.InterfaceModel.RuiXin_Msg() { content = msg, msid = "0", mobile = string.Format("{0}", mobiles[i]) });
|
|
}
|
|
SMS.InterfaceModel.RuiXin_Pkg pkg = new SMS.InterfaceModel.RuiXin_Pkg();
|
|
pkg.size = mobiles.Length;
|
|
pkg.list = msgs;
|
|
pkg.resend = 0;
|
|
try
|
|
{
|
|
string jsonStr = WX.CRM.Common.Utility.ObjectToJson<SMS.InterfaceModel.RuiXin_Pkg>(pkg);
|
|
result.SendStr = jsonStr;
|
|
jsonStr = System.Web.HttpUtility.UrlEncode(WX.CRM.Common.Utility.ObjectToJson<SMS.InterfaceModel.RuiXin_Pkg>(pkg), System.Text.Encoding.UTF8);
|
|
WebClient webClient = new WebClient();
|
|
webClient.Headers.Add("Content-Type", "application/x-www-form-urlencoded");
|
|
NameValueCollection postValues = new NameValueCollection();
|
|
webClient.Encoding = Encoding.UTF8;
|
|
postValues.Add("jsondata", jsonStr);
|
|
postValues.Add("Account", Account);
|
|
postValues.Add("Password", password);
|
|
postValues.Add("Exno", "0");
|
|
byte[] responseArray = webClient.UploadValues(url, postValues);
|
|
result.ReturnStr = Encoding.UTF8.GetString(responseArray);
|
|
|
|
SMS.InterfaceModel.RuiXin_Result info = WX.CRM.Common.Utility.JSONToObject<SMS.InterfaceModel.RuiXin_Result>(result.ReturnStr);
|
|
if (info != null)
|
|
{
|
|
result.submitStatus = info.code == "9001" ? SMS.InterfaceModel.SubmitStatus.success : SMS.InterfaceModel.SubmitStatus.fail;
|
|
}
|
|
else
|
|
{
|
|
throw new Exception("反序列化异常,返回值:" + result.ReturnStr);
|
|
}
|
|
}
|
|
catch (Exception ex)
|
|
{
|
|
result.submitStatus = SubmitStatus.fail;
|
|
WX.CRM.Common.LogHelper.Error("ExecRuiXin.sendPkg:" + ex.Message);
|
|
}
|
|
return result;
|
|
}
|
|
#endregion
|
|
}
|
|
}
|