123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150 |
- using System;
- using System.Collections.Generic;
- using System.IO;
- using System.Net;
- using System.Text;
- using GxPress.Common.Encrypt;
- using Newtonsoft.Json;
- namespace GxPress.Common.Sms
- {
- public static class MasSms
- {
- /// <summary>
- /// 广西短信
- /// </summary>
- /// <param name="phone"></param>
- /// <param name="code"></param>
- /// <returns></returns>
- public static bool SendSms(string phone, string code)
- {
- var url = "http://112.35.1.155:1992/sms/norsubmit";
- try
- {
- var content = $"打死也不能告诉别人,短信验证码:{code}";
- var md5 = EncryptProvider.Md5($"接口联调账号impactpasswd@1342{phone}{content}bM16CfN2B").ToLower();
- var json = "{\"ecName\":\"接口联调账号\", \"apId\":\"impact\", \"mobiles\":\"" + phone + "\", \"content\":\"" + content + "\", \"sign\":\"bM16CfN2B\", \"addSerial\":\"\", \"mac\":\"" + md5 + "\"}";
- var base64Encode = EncryptProvider.Base64Encode(json);
- byte[] byteArray = System.Text.Encoding.UTF8.GetBytes(base64Encode); //转化
- HttpWebRequest webReq = (HttpWebRequest)WebRequest.Create(new Uri(url));
- webReq.Method = "POST";
- webReq.ContentType = "application/x-www-form-urlencoded";
- //webReq.ContentType = "application/json";
- webReq.ContentLength = byteArray.Length;
- Stream newStream = webReq.GetRequestStream();
- newStream.Write(byteArray, 0, byteArray.Length);//写入参数
- newStream.Close();
- HttpWebResponse response = (HttpWebResponse)webReq.GetResponse();
- StreamReader sr = new StreamReader(response.GetResponseStream(), Encoding.UTF8);
- var ret = sr.ReadToEnd();
- sr.Close();
- response.Close();
- newStream.Close();
- var success = JsonConvert.DeserializeObject<SmsSuccess>(ret);
- return success.Success;
- }
- catch (Exception ex)
- {
- throw new Common.Exceptions.BusinessException(ex.Message);
- }
- }
- /// <summary>
- /// 广西短信模板
- /// </summary>
- /// <param name="phone"></param>
- /// <param name="code"></param>
- /// <returns></returns>
- public static bool SendSmsTemplate(string phone, string code, string templateId)
- {
- var url = "http://112.35.10.201:5992/sms/tmpsubmit";
- try
- {
- var ecName = "广西出版传媒集团有限公司";
- var appId = "gxcbcm";
- var sign = "FOdugjqlG";
- var secretKey = "gxcbcm";
- //phone = "+ phone + ";
- var paramsValue = string.IsNullOrEmpty(code) ? "[\"\"]" : "[\\\"" + code + "\\\"]";
- var paramsValueMd5 = string.IsNullOrEmpty(code) ? "[\"\"]" : "[\"" + code + "\"]";
- var addSerial = "";
- var md5 = EncryptProvider.Md5($"{ecName}{appId}{secretKey}{templateId}{phone}{paramsValueMd5}{sign}{addSerial}").ToLower();
- var json = "{\"ecName\":\"" + ecName + "\", \"apId\":\"" + appId + "\", \"templateId\":\"" + templateId + "\", \"mobiles\":\"" + phone + "\",\"params\":\"" + paramsValue + "\", \"sign\":\"" + sign + "\", \"addSerial\":\"\", \"mac\":\"" + md5 + "\"}";
- var base64Encode = EncryptProvider.Base64Encode(json);
- byte[] byteArray = System.Text.Encoding.UTF8.GetBytes(base64Encode); //转化
- HttpWebRequest webReq = (HttpWebRequest)WebRequest.Create(new Uri(url));
- webReq.Method = "POST";
- webReq.ContentType = "application/x-www-form-urlencoded";
- //webReq.ContentType = "application/json";
- webReq.ContentLength = byteArray.Length;
- Stream newStream = webReq.GetRequestStream();
- newStream.Write(byteArray, 0, byteArray.Length);//写入参数
- newStream.Close();
- HttpWebResponse response = (HttpWebResponse)webReq.GetResponse();
- StreamReader sr = new StreamReader(response.GetResponseStream(), Encoding.UTF8);
- var ret = sr.ReadToEnd();
- sr.Close();
- response.Close();
- newStream.Close();
- var success = JsonConvert.DeserializeObject<SmsSuccess>(ret);
- return success.Success;
- }
- catch (Exception ex)
- {
- throw new Common.Exceptions.BusinessException(ex.Message);
- }
- }
- /// <summary>
- /// 广西短信模板
- /// </summary>
- /// <param name="phone"></param>
- /// <param name="code"></param>
- /// <returns></returns>
- public static bool SendSmsTemplate(List<string> phones, string templateId)
- {
- var url = "http://112.35.10.201:5992/sms/tmpsubmit";
- try
- {
- var ecName = "广西出版传媒集团有限公司";
- var appId = "gxcbcm";
- var sign = "FOdugjqlG";
- var secretKey = "gxcbcm";
- var phone = Common.Tools.StringUtils.ObjectCollectionToString(phones);
- var paramsValue = "[\\\"\\\"]";
- var paramsValueMd5 = "[\"\"]";
- var addSerial = "";
- var md5 = EncryptProvider.Md5($"{ecName}{appId}{secretKey}{templateId}{phone}{paramsValueMd5}{sign}{addSerial}").ToLower();
- var json = "{\"ecName\":\"" + ecName + "\", \"apId\":\"" + appId + "\", \"templateId\":\"" + templateId + "\", \"mobiles\":\"" + phone + "\",\"params\":\"" + paramsValue + "\", \"sign\":\"" + sign + "\", \"addSerial\":\"\", \"mac\":\"" + md5 + "\"}";
- var base64Encode = EncryptProvider.Base64Encode(json);
- byte[] byteArray = System.Text.Encoding.UTF8.GetBytes(base64Encode); //转化
- HttpWebRequest webReq = (HttpWebRequest)WebRequest.Create(new Uri(url));
- webReq.Method = "POST";
- webReq.ContentType = "application/x-www-form-urlencoded";
- //webReq.ContentType = "application/json";
- webReq.ContentLength = byteArray.Length;
- Stream newStream = webReq.GetRequestStream();
- newStream.Write(byteArray, 0, byteArray.Length);//写入参数
- newStream.Close();
- HttpWebResponse response = (HttpWebResponse)webReq.GetResponse();
- StreamReader sr = new StreamReader(response.GetResponseStream(), Encoding.UTF8);
- var ret = sr.ReadToEnd();
- sr.Close();
- response.Close();
- newStream.Close();
- var success = JsonConvert.DeserializeObject<SmsSuccess>(ret);
- return success.Success;
- }
- catch (Exception ex)
- {
- throw new Common.Exceptions.BusinessException(ex.Message);
- }
- }
- }
- public class SmsSuccess
- {
- public string MsgGroup { get; set; }
- public string Rspcod { get; set; }
- public bool Success { get; set; }
- }
- }
|