93 lines
3.5 KiB
C#
93 lines
3.5 KiB
C#
using System;
|
||
using System.Linq;
|
||
using Top.Api;
|
||
using Top.Api.Request;
|
||
using Top.Api.Response;
|
||
using WX.CRM.CRMServices.SMS.InterfaceModel;
|
||
|
||
namespace WX.CRM.CRMServices.SMS.InterfaceExec
|
||
{
|
||
public class TbTxt : IMsgSend
|
||
{
|
||
string appkey = "";
|
||
string appSecret = "";
|
||
string url = "";
|
||
string sinName = "";
|
||
|
||
public TbTxt(string _account = "", string _password = "")
|
||
{
|
||
TbTxtConfig config = new InterfaceModel.TbTxtConfig();
|
||
appkey = config.appkey;
|
||
appSecret = config.appSecret;
|
||
url = config.url;
|
||
sinName = config.sinName;
|
||
if (!string.IsNullOrEmpty(_account) && !string.IsNullOrEmpty(_password))
|
||
{
|
||
appSecret = _password;
|
||
appkey = _account;
|
||
}
|
||
}
|
||
|
||
public SMS.InterfaceModel.ReturnResult Execute(string[] mobiles, string msg)
|
||
{
|
||
return Send(mobiles, msg);
|
||
}
|
||
|
||
public decimal queryAmt()
|
||
{
|
||
throw new NotImplementedException();
|
||
}
|
||
|
||
#region
|
||
InterfaceModel.ReturnResult Send(string[] mobiles, string msg)
|
||
{
|
||
if (mobiles == null)
|
||
{
|
||
throw new Exception(string.Concat("【淘宝文本短信】TbTxt:" + "号码不能为空!"));
|
||
}
|
||
//if (mobiles.Count() > 1)
|
||
//{
|
||
// throw new Exception(string.Concat("【淘宝文本短信】TbTxt:" + "只能发送单个号码!"));
|
||
//}
|
||
string mobilesStr = string.Join(",", mobiles);
|
||
InterfaceModel.ReturnResult result = new InterfaceModel.ReturnResult();
|
||
result.SendStr = mobilesStr;
|
||
try
|
||
{
|
||
|
||
//查找签名
|
||
string[] sin = sinName.Split('|');
|
||
string k = sin.FirstOrDefault(p => p.Contains(appkey));
|
||
string sname = "";
|
||
if (k != null)
|
||
sname = k.Split(',')[1];
|
||
|
||
//短信格式:模板ID|参数,例如:T0001|{\"product\":\"UP\",\"code\":\"6898\"}
|
||
string[] ms = msg.Split('|');
|
||
ITopClient client = new DefaultTopClient(url, appkey, appSecret);
|
||
AlibabaAliqinFcSmsNumSendRequest req = new AlibabaAliqinFcSmsNumSendRequest();
|
||
req.Extend = System.DateTime.Now.ToString("yyyyMMddHHssfff"); //可选,扩展参数,可作唯一标示
|
||
req.SmsType = "normal";
|
||
req.SmsFreeSignName = sname; //模板对应的签名
|
||
req.SmsParam = ms[1]; // "{\"code\":\"5898\",\"product\":\"UP团队\"}";//与模板参数一一对应
|
||
req.RecNum = mobilesStr;
|
||
req.SmsTemplateCode = ms[0]; //模板ID
|
||
AlibabaAliqinFcSmsNumSendResponse rsp = client.Execute(req);
|
||
result.ReturnStr = rsp.Body;
|
||
//检查反回结果
|
||
if (result.ReturnStr.ToLower().IndexOf("<err_code>0</err_code>") > 0)
|
||
result.submitStatus = SubmitStatus.success;
|
||
else
|
||
result.submitStatus = SubmitStatus.fail;
|
||
}
|
||
catch (Exception ex)
|
||
{
|
||
result.submitStatus = SubmitStatus.fail;
|
||
WX.CRM.Common.LogHelper.Error("TbTxt.Send:" + ex.Message + ex.StackTrace);
|
||
}
|
||
return result;
|
||
}
|
||
#endregion
|
||
}
|
||
}
|