本人开发移动云MAS .net Http 请求 代码如下
1 using Newtonsoft.Json.Linq; 2 using System; 3 using System.Collections.Generic; 4 using System.Linq; 5 using System.Net; 6 using System.Security.Cryptography; 7 using System.Text; 8 using System.Threading.Tasks; 9 10 namespace MessageSendProj 11 { 12 class Program 13 { 14 static void Main(string[] args) 15 { 16 //发送信息快捷键 17 Console.WriteLine(SendMsg()); 18 Console.ReadLine(); 19 20 } 21 22 public static string SendMsg() 23 { 24 25 JObject obj = new JObject(); 26 var ecName = "企业名称";//企业名称 27 var apId = "mayun";//注意: 此处不是MAS云网站的用户名,这个要在管理里面新建用户密码,如图下1, 28 var secretKey = "asd2018";//密码 29 var mobiles = "15655521119,17612345651";//电话 30 var content = "中午吃啥子,收到钉钉我一下 --胡超";//内容 31 var sign1 = "XtXYO12LyQJ";//编码 32 var addSerial = "123";//可以随便写,三位数 33 obj.Add("ecName", new JValue(ecName)); 34 obj.Add("apId", new JValue(apId)); 35 obj.Add("secretKey", new JValue(secretKey)); 36 obj.Add("mobiles", new JValue(mobiles)); 37 obj.Add("content", new JValue(content)); 38 obj.Add("sign", new JValue(sign1)); 39 obj.Add("addSerial", new JValue(addSerial)); 40 var mac = ecName + apId + secretKey + mobiles + content + sign1 + addSerial; 41 var mac1 = UserMd5(mac);//要进行32位MD5加密 42 var length = mac1.Length; 43 obj.Add("mAC", new JValue(mac1)); 44 string paras = obj.ToString(); 45 var jiami = Base64Code(paras);//传参数前要进行64位加密 46 System.Net.WebClient pWebClient = new System.Net.WebClient(); 47 pWebClient.Headers.Add("Content-Type", "application/json;charset=UTF-8"); //charset=UTF-8 48 pWebClient.Headers.Add(HttpRequestHeader.Accept, "*/*"); 49 pWebClient.Headers.Add("user-agent", "Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.1; SV1)"); 50 byte[] returnBytes = pWebClient.UploadData("http://112.35.1.155:1992/sms/norsubmit", "POST", System.Text.Encoding.UTF8.GetBytes(jiami)); 51 52 return System.Text.Encoding.UTF8.GetString(returnBytes); 53 54 //var aa = Base64Decode(result1); 55 } 56 57 58 /// <summary> 59 /// Base64加密 60 /// </summary> 61 /// <param name="Message"></param> 62 /// <returns></returns> 63 public static string Base64Code(string Message) 64 { 65 byte[] bytes = Encoding.UTF8.GetBytes(Message);//这里要注意不是Default 因为Default默认GB2312 66 return Convert.ToBase64String(bytes); 67 } 68 69 70 /// <summary> 71 /// Base64解密 72 /// </summary> 73 /// <param name="Message"></param> 74 /// <returns></returns> 75 public static string Base64Decode(string Message) 76 { 77 byte[] bytes = Convert.FromBase64String(Message); 78 return Encoding.UTF8.GetString(bytes); 79 } 80 /// <summary> 81 /// Base64加密 82 /// </summary> 83 /// <param name="encodeType">加密采用的编码方式</param> 84 /// <param name="source">待加密的明文</param> 85 /// <returns></returns> 86 public static string Base64Encode(Encoding encodeType, string source) 87 { 88 string encode = string.Empty; 89 byte[] bytes = encodeType.GetBytes(source); 90 try 91 { 92 encode = Convert.ToBase64String(bytes); 93 } 94 catch 95 { 96 encode = source; 97 } 98 return encode; 99 } 100 101 /// <summary> 102 /// Md5 加密 103 /// </summary> 104 /// <param name="str"></param> 105 /// <returns></returns> 106 public static string UserMd5(string str) 107 { 108 string cl = str; 109 string pwd = ""; 110 MD5 md5 = MD5.Create();//实例化一个md5对像 111 // 加密后是一个字节类型的数组,这里要注意编码UTF8/Unicode等的选择 112 byte[] s = md5.ComputeHash(Encoding.UTF8.GetBytes(cl)); 113 // 通过使用循环,将字节类型的数组转换为字符串,此字符串是常规字符格式化所得 114 for (int i = 0; i < s.Length; i++) 115 { 116 // 将得到的字符串使用十六进制类型格式。格式后的字符是小写的字母,如果使用大写(X)则格式后的字符是大写字符 117 pwd = pwd + s[i].ToString("x2"); 118 } 119 return pwd; 120 } 121 122 123 } 124 }
图1,用户密码设置
签名:sign 下载
时间: 2024-10-18 02:56:56