1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
|
using System; using System.Net; using System.Security.Cryptography; using System.Text; using System.Web;
namespace GroupDemo { class Program {
private const string Account = ""; //您在云智信平台注册的手机号 private const string TradeKey = "";//您申请的交易密钥 private const string RequestUrl = "http://api.yunzhixin.com:11140/txp/smsGroup";//提交批量短信的地址 public static void Main(string[] args) { //接收方手机号(以英文逗号隔开) string mobile = ""; //模版编号 string tplId = ""; //模版所需参数 string param = ""; //拼接加密原串 string signSource = $"{Account}|{tplId}#{TradeKey}"; //调用加密方法,取得加密密文 string sign = Md5Encrypt(signSource, Encoding.UTF8); //拼接请求参数 try { string response = HttpPost(RequestUrl, postData, Encoding.UTF8); Console.WriteLine(response); } catch { //ignore } } public static string Md5Encrypt(string input) { var md5 = new MD5CryptoServiceProvider(); var buffer = md5.ComputeHash(Encoding.UTF8.GetBytes(input)); var builder = new StringBuilder(32); foreach (var t in buffer) { builder.Append(t.ToString("x").PadLeft(2, '0')); } return builder.ToString(); } private static string HttpPost(string Url, string data,Encoding enc) { var postdata = enc.GetBytes(data); var webClient = new WebClient { Encoding = enc }; webClient.Headers.Add(HttpRequestHeader.KeepAlive, "False"); webClient.Headers.Add("Content-Type", "application/x-www-form-urlencoded"); var response = webClient.UploadData(url, "POST", postdata); return enc.GetString(response); }
} } |