MasSms.cs 7.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150
  1. using System;
  2. using System.Collections.Generic;
  3. using System.IO;
  4. using System.Net;
  5. using System.Text;
  6. using GxPress.Common.Encrypt;
  7. using Newtonsoft.Json;
  8. namespace GxPress.Common.Sms
  9. {
  10. public static class MasSms
  11. {
  12. /// <summary>
  13. /// 广西短信
  14. /// </summary>
  15. /// <param name="phone"></param>
  16. /// <param name="code"></param>
  17. /// <returns></returns>
  18. public static bool SendSms(string phone, string code)
  19. {
  20. var url = "http://112.35.1.155:1992/sms/norsubmit";
  21. try
  22. {
  23. var content = $"打死也不能告诉别人,短信验证码:{code}";
  24. var md5 = EncryptProvider.Md5($"接口联调账号impactpasswd@1342{phone}{content}bM16CfN2B").ToLower();
  25. var json = "{\"ecName\":\"接口联调账号\", \"apId\":\"impact\", \"mobiles\":\"" + phone + "\", \"content\":\"" + content + "\", \"sign\":\"bM16CfN2B\", \"addSerial\":\"\", \"mac\":\"" + md5 + "\"}";
  26. var base64Encode = EncryptProvider.Base64Encode(json);
  27. byte[] byteArray = System.Text.Encoding.UTF8.GetBytes(base64Encode); //转化
  28. HttpWebRequest webReq = (HttpWebRequest)WebRequest.Create(new Uri(url));
  29. webReq.Method = "POST";
  30. webReq.ContentType = "application/x-www-form-urlencoded";
  31. //webReq.ContentType = "application/json";
  32. webReq.ContentLength = byteArray.Length;
  33. Stream newStream = webReq.GetRequestStream();
  34. newStream.Write(byteArray, 0, byteArray.Length);//写入参数
  35. newStream.Close();
  36. HttpWebResponse response = (HttpWebResponse)webReq.GetResponse();
  37. StreamReader sr = new StreamReader(response.GetResponseStream(), Encoding.UTF8);
  38. var ret = sr.ReadToEnd();
  39. sr.Close();
  40. response.Close();
  41. newStream.Close();
  42. var success = JsonConvert.DeserializeObject<SmsSuccess>(ret);
  43. return success.Success;
  44. }
  45. catch (Exception ex)
  46. {
  47. throw new Common.Exceptions.BusinessException(ex.Message);
  48. }
  49. }
  50. /// <summary>
  51. /// 广西短信模板
  52. /// </summary>
  53. /// <param name="phone"></param>
  54. /// <param name="code"></param>
  55. /// <returns></returns>
  56. public static bool SendSmsTemplate(string phone, string code, string templateId)
  57. {
  58. var url = "http://112.35.10.201:5992/sms/tmpsubmit";
  59. try
  60. {
  61. var ecName = "广西出版传媒集团有限公司";
  62. var appId = "gxcbcm";
  63. var sign = "FOdugjqlG";
  64. var secretKey = "gxcbcm";
  65. //phone = "+ phone + ";
  66. var paramsValue = string.IsNullOrEmpty(code) ? "[\"\"]" : "[\\\"" + code + "\\\"]";
  67. var paramsValueMd5 = string.IsNullOrEmpty(code) ? "[\"\"]" : "[\"" + code + "\"]";
  68. var addSerial = "";
  69. var md5 = EncryptProvider.Md5($"{ecName}{appId}{secretKey}{templateId}{phone}{paramsValueMd5}{sign}{addSerial}").ToLower();
  70. var json = "{\"ecName\":\"" + ecName + "\", \"apId\":\"" + appId + "\", \"templateId\":\"" + templateId + "\", \"mobiles\":\"" + phone + "\",\"params\":\"" + paramsValue + "\", \"sign\":\"" + sign + "\", \"addSerial\":\"\", \"mac\":\"" + md5 + "\"}";
  71. var base64Encode = EncryptProvider.Base64Encode(json);
  72. byte[] byteArray = System.Text.Encoding.UTF8.GetBytes(base64Encode); //转化
  73. HttpWebRequest webReq = (HttpWebRequest)WebRequest.Create(new Uri(url));
  74. webReq.Method = "POST";
  75. webReq.ContentType = "application/x-www-form-urlencoded";
  76. //webReq.ContentType = "application/json";
  77. webReq.ContentLength = byteArray.Length;
  78. Stream newStream = webReq.GetRequestStream();
  79. newStream.Write(byteArray, 0, byteArray.Length);//写入参数
  80. newStream.Close();
  81. HttpWebResponse response = (HttpWebResponse)webReq.GetResponse();
  82. StreamReader sr = new StreamReader(response.GetResponseStream(), Encoding.UTF8);
  83. var ret = sr.ReadToEnd();
  84. sr.Close();
  85. response.Close();
  86. newStream.Close();
  87. var success = JsonConvert.DeserializeObject<SmsSuccess>(ret);
  88. return success.Success;
  89. }
  90. catch (Exception ex)
  91. {
  92. throw new Common.Exceptions.BusinessException(ex.Message);
  93. }
  94. }
  95. /// <summary>
  96. /// 广西短信模板
  97. /// </summary>
  98. /// <param name="phone"></param>
  99. /// <param name="code"></param>
  100. /// <returns></returns>
  101. public static bool SendSmsTemplate(List<string> phones, string templateId)
  102. {
  103. var url = "http://112.35.10.201:5992/sms/tmpsubmit";
  104. try
  105. {
  106. var ecName = "广西出版传媒集团有限公司";
  107. var appId = "gxcbcm";
  108. var sign = "FOdugjqlG";
  109. var secretKey = "gxcbcm";
  110. var phone = Common.Tools.StringUtils.ObjectCollectionToString(phones);
  111. var paramsValue = "[\\\"\\\"]";
  112. var paramsValueMd5 = "[\"\"]";
  113. var addSerial = "";
  114. var md5 = EncryptProvider.Md5($"{ecName}{appId}{secretKey}{templateId}{phone}{paramsValueMd5}{sign}{addSerial}").ToLower();
  115. var json = "{\"ecName\":\"" + ecName + "\", \"apId\":\"" + appId + "\", \"templateId\":\"" + templateId + "\", \"mobiles\":\"" + phone + "\",\"params\":\"" + paramsValue + "\", \"sign\":\"" + sign + "\", \"addSerial\":\"\", \"mac\":\"" + md5 + "\"}";
  116. var base64Encode = EncryptProvider.Base64Encode(json);
  117. byte[] byteArray = System.Text.Encoding.UTF8.GetBytes(base64Encode); //转化
  118. HttpWebRequest webReq = (HttpWebRequest)WebRequest.Create(new Uri(url));
  119. webReq.Method = "POST";
  120. webReq.ContentType = "application/x-www-form-urlencoded";
  121. //webReq.ContentType = "application/json";
  122. webReq.ContentLength = byteArray.Length;
  123. Stream newStream = webReq.GetRequestStream();
  124. newStream.Write(byteArray, 0, byteArray.Length);//写入参数
  125. newStream.Close();
  126. HttpWebResponse response = (HttpWebResponse)webReq.GetResponse();
  127. StreamReader sr = new StreamReader(response.GetResponseStream(), Encoding.UTF8);
  128. var ret = sr.ReadToEnd();
  129. sr.Close();
  130. response.Close();
  131. newStream.Close();
  132. var success = JsonConvert.DeserializeObject<SmsSuccess>(ret);
  133. return success.Success;
  134. }
  135. catch (Exception ex)
  136. {
  137. throw new Common.Exceptions.BusinessException(ex.Message);
  138. }
  139. }
  140. }
  141. public class SmsSuccess
  142. {
  143. public string MsgGroup { get; set; }
  144. public string Rspcod { get; set; }
  145. public bool Success { get; set; }
  146. }
  147. }