ComplianceServer/oldcode/CoreService/PkgSms/InterfaceExec/TencentBatchSms.cs

76 lines
2.5 KiB
C#

using CRM.Core.CoreService.PkgSms.InterfaceModel;
using Newtonsoft.Json;
using qcloudsms_csharp;
using System;
using WX.CRM.Common;
namespace CRM.Core.CoreService.PkgSms.InterfaceExec
{
public class TencentBatchSms : IMsgSend
{
private readonly int _appId;
private readonly string _appKey;
public TencentBatchSms(string appId = "", string appKey = "")
{
_appId = int.Parse(appId);
_appKey = appKey;
}
public ReturnResult Execute(string[] mobiles, string msg, string typeCode)
{
var mobilesStr = string.Join(",", mobiles);
var result = new ReturnResult
{
SendStr = mobilesStr,
ReturnStr = mobilesStr
};
try
{
// 短信应用SDK AppID
//int appid = 1400157076;
// 短信应用SDK AppKey
//string appkey = "7defb5fad78e9d28179d29d6a36896be";
var ssender = new SmsMultiSender(_appId, _appKey);
SmsMultiSenderResult res = null;
if (typeCode == "ResetPwd")
{
var message = Utility.JSONToObject<WebOrderMessageTemplate>(msg);
res = ssender.sendWithParam("86", mobiles, message.TemplateId, new string[] { }, message.SmsSign, "", "");
}
else
{
var msgData = JsonConvert.DeserializeAnonymousType(msg, new { TemplateId = 0, SmsSign = string.Empty });
res = ssender.sendWithParam("86", mobiles, msgData.TemplateId, new string[] { }, msgData.SmsSign, "", "");
//LogHelper.Error("短信没有找到合适的发送类型,请确认!");
}
LogHelper.Info(res.ToJson());
if (res.result == 0)
result.submitStatus = SubmitStatus.success;
else
result.submitStatus = SubmitStatus.fail;
}
catch (Exception ex)
{
result.submitStatus = SubmitStatus.fail;
LogHelper.Error("TencentSms.Send:" + ex.Message + ex.StackTrace);
}
return result;
}
public decimal queryAmt()
{
throw new NotImplementedException();
}
public class WebOrderMessageTemplate
{
public int TemplateId { get; set; }
public string SmsSign { get; set; }
}
}
}