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
{
///
/// 广西短信
///
///
///
///
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(ret);
return success.Success;
}
catch (Exception ex)
{
throw new Common.Exceptions.BusinessException(ex.Message);
}
}
///
/// 广西短信模板
///
///
///
///
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(ret);
return success.Success;
}
catch (Exception ex)
{
throw new Common.Exceptions.BusinessException(ex.Message);
}
}
///
/// 广西短信模板
///
///
///
///
public static bool SendSmsTemplate(List 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(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; }
}
}