You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 
 
 
 

118 lines
3.4 KiB

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using Newtonsoft.Json.Linq;
using Newtonsoft.Json;
using Sog;
namespace SMAgent
{
public static class SmsSDKSenderUtils
{
private static int sdkappid = 1400098819;
private static string appkey = "e217c57428fd2dd1a3b4f9ec38ace323";
private static string nationCode = "86";
private static List<string> phoneNumber = new List<string>() {"13576277430"};
private static int tmplId = 131533;
private static SmsSingleSender singleSender = new SmsSingleSender(sdkappid, appkey);
private static SmsMultiSender multiSender = new SmsMultiSender(sdkappid, appkey);
//单发短信(很容易出错,需要content和配置的模板一致)
private static void SingleSmsSDKSender(string content)
{
try
{
SmsSingleSenderResult singleResult;
//普通单发
singleResult = singleSender.Send(0, nationCode, phoneNumber[0], content, "", "");
if (singleResult.result != 0)
{
TraceLog.Error("SmsSDKSenderUtils.SingleSmsSDKSender fail msg {0}", singleResult.errmsg);
}
}
catch (Exception e)
{
TraceLog.Error("SmsSDKSenderUtils.SingleSmsSDKSender Exception msg {0}", e);
}
}
//按模板单发短信
public static void SingleTemplSmsSDKSender(string hostName, string serverID,string serverType)
{
try
{
SmsSingleSenderResult singleResult;
List<string> templParams = new List<string>();
templParams.Add(hostName);
templParams.Add(serverID);
templParams.Add(serverType);
singleResult = singleSender.SendWithParam(nationCode, phoneNumber[0], tmplId, templParams, "小盟商", "", "");
if (singleResult.result != 0)
{
TraceLog.Error("SmsSDKSenderUtils.SingletemplSmsSDKSender fail msg {0}", singleResult.errmsg);
}
}
catch (Exception e)
{
TraceLog.Error("SmsSDKSenderUtils.SingleTemplSmsSDKSender Exception msg {0}", e);
}
}
//群发短信
private static void MultiSmsSDKSender(string content)
{
try
{
var multiResult = multiSender.Send(0, nationCode, phoneNumber, content, "", "");
if (multiResult.result != 0)
{
foreach (var info in multiResult.detail)
{
if (info.result != 0)
{
TraceLog.Error("SmsSDKSenderUtils.MultiSmsSDKSender send to phone {0} fail msg {1}", info.mobile,info.errmsg);
}
}
}
}
catch (Exception e)
{
TraceLog.Error("SmsSDKSenderUtils.MultiSmsSDKSender Exception msg {0}", e);
}
}
//按模板群发短信
public static void MultiTemplSmsSDKSender(string hostName, string serverID, string serverType)
{
try
{
List<string> templParams = new List<string>();
templParams.Add(hostName);
templParams.Add(serverID);
templParams.Add(serverType);
var multiResult = multiSender.SendWithParam(nationCode, phoneNumber, tmplId, templParams, "小盟商", "", "");
if (multiResult.result != 0)
{
foreach (var info in multiResult.detail)
{
if (info.result != 0)
{
TraceLog.Error("SmsSDKSenderUtils.MultiTemplSmsSDKSender send to phone {0} fail msg {1}", info.mobile, info.errmsg);
}
}
}
}
catch (Exception e)
{
TraceLog.Error("SmsSDKSenderUtils.MultiTemplSmsSDKSender Exception msg {0}", e);
}
}
}
}