|
- using System;
- using System.Collections.Generic;
- using System.IO;
- using System.Linq;
- using System.Net;
- using System.Net.Http;
- using System.Net.Http.Headers;
- using System.Security.Cryptography;
- using System.Text;
- using System.Threading.Tasks;
- using Learun.Util;
- using Newtonsoft.Json;
- using Newtonsoft.Json.Linq;
- using Quanjiang.DigitalScholl.SendSms.Banling.Sms;
-
- namespace Quanjiang.DigitalScholl.SendSms.Banling
- {
- /// <summary>
- /// 斑羚短信平台
- /// </summary>
- public class BanLingSms : ISms
- {
- private static readonly string SdkAppId = ConfigManager.AppSettings["sdkappid"].Value;
- private static readonly string AppKey = ConfigManager.AppSettings["appkey"].Value;
- public async Task<(string code, string randomNum, string message, string errorType)> SendSmsToSingle(string phoneNumber, SmsType st, List<string> sendParams = null)
- {
- (string code, string randomNum, string message, string errorType) result;
- var (templatecode, templateparam, randomNum) = GetSmsTemplate(st, sendParams);
- try
- {
- var singleSender = new SmsSingleSender(SdkAppId, AppKey);
- var singleResult = await Task.FromResult(singleSender.SendWithParam("86", phoneNumber, templatecode, templateparam, "深圳国际公益学院", "", ""));
- result = singleResult.result==0 ? ("OK", randomNum, "", "") : (singleResult.result.ToString(), "", singleResult.errmsg, "Client");
- }
- catch (Exception e)
- {
- result = ("", "", e.Message, e.GetType().ToString());
- }
- return result;
- }
-
- public async Task<(string code, string randomNum, string message, string errorType)> SendSmsToMulti(List<string> phoneNumbers, SmsType st, List<string> sendParams = null)
- {
- (string code, string randomNum, string message, string errorType) result;
- var (templatecode, templateparam, randomNum) = GetSmsTemplate(st, sendParams);
- try
- {
- var multiSender = new SmsMultiSender(SdkAppId, AppKey);
- var multiResult = await Task.FromResult(multiSender.SendWithParam("86", phoneNumbers, templatecode, templateparam, "深圳国际公益学院", "", ""));
- result = multiResult.result == 0 ? ("OK", randomNum, "", "") : (multiResult.result.ToString(), "", multiResult.errmsg, "Client");
- }
- catch (Exception e)
- {
- result = ("", "", e.Message, e.GetType().ToString());
- }
- return result;
- }
- /// <summary>
- /// 根据短信通知类型获取短信模板
- /// </summary>
- /// <param name="st"></param>
- /// <param name="sendParams"></param>
- /// <returns></returns>
- private (string templateCode, List<string> templateParam, string randomNum) GetSmsTemplate(SmsType st, List<string> sendParams)
- {
- (string templateCode, List<string> templateParam, string randomNum) result;
- var randomNum = CommonHelper.RandNum(6);
- switch (st)
- {
- case SmsType.Register:
- result = ("141577", new List<string>() { randomNum, "5" }, randomNum);
- break;
- case SmsType.LoginBind:
- result = ("141578", new List<string>() { randomNum, "5" }, randomNum);
- break;
- case SmsType.ForgetPassWord:
- result = ("141581", new List<string>() { randomNum, "5" }, randomNum);
- break;
- case SmsType.LessionNotification:
- result = ("141583", sendParams, randomNum);
- break;
- case SmsType.LeaveNotification:
- result = ("141585", sendParams, randomNum);
- break;
- case SmsType.MakeUpMissedLessonsNotification:
- result = ("141588", sendParams, randomNum);
- break;
- case SmsType.ClassManagerLeaveNotification:
- result = ("156728", sendParams, randomNum);
- break;
- case SmsType.ClassManagerMakeUpMissedLessonsNotification:
- result = ("156729", sendParams, randomNum);
- break;
- default:
- throw new ArgumentOutOfRangeException(nameof(st), st, null);
- }
- return result;
- }
- }
- }
|