82 lines
3.2 KiB
C#
82 lines
3.2 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 TbTxtToVoice : IMsgSend
|
||
{
|
||
string appkey = "";
|
||
string appSecret = "";
|
||
string url = "";
|
||
string calledShowNum = "";
|
||
public TbTxtToVoice(string _account = "", string _password = "")
|
||
{
|
||
TbTxtToVoiceConfig config = new InterfaceModel.TbTxtToVoiceConfig();
|
||
appkey = config.appkey;
|
||
appSecret = config.appSecret;
|
||
url = config.url;
|
||
calledShowNum = config.calledShowNum;
|
||
if (!string.IsNullOrEmpty(_account) && !string.IsNullOrEmpty(_password))
|
||
{
|
||
appSecret = _password;
|
||
appkey = _account;
|
||
}
|
||
}
|
||
public 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("【淘宝文本转语音短信】TbTxtToVoice:" + "号码不能为空!"));
|
||
}
|
||
if (mobiles.Count() > 1)
|
||
{
|
||
throw new Exception(string.Concat("【淘宝文本转语音短信】TbTxtToVoice:" + "只能发送单个号码!"));
|
||
}
|
||
string mobilesStr = string.Join(",", mobiles);
|
||
InterfaceModel.ReturnResult result = new InterfaceModel.ReturnResult();
|
||
result.SendStr = mobilesStr;
|
||
try
|
||
{
|
||
//短信格式:模板ID|参数,例如:T0001|{\"product\":\"UP\",\"code\":\"6898\"}
|
||
string[] ms = msg.Split('|');
|
||
ITopClient client = new DefaultTopClient(url, appkey, appSecret);
|
||
AlibabaAliqinFcTtsNumSinglecallRequest req = new AlibabaAliqinFcTtsNumSinglecallRequest();
|
||
req.Extend = System.DateTime.Now.ToString("yyyyMMddHHssfff");
|
||
req.TtsParam = ms[1]; //"{\"product\":\"UP\",\"code\":\"6898\"}"; //您正在进行${product}身份验证,验证码${code},打死不要告诉别人哦!
|
||
req.CalledNum = mobilesStr;
|
||
req.CalledShowNum = calledShowNum;
|
||
req.TtsCode = ms[0];
|
||
AlibabaAliqinFcTtsNumSinglecallResponse 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("TbTxtToVoice.Send:" + ex.Message + ex.StackTrace);
|
||
}
|
||
return result;
|
||
}
|
||
#endregion
|
||
}
|
||
}
|