移動 雲MAS 發簡訊 .net HTTP 要求

來源:互聯網
上載者:User

標籤:messages   string   accept   upload   png   win   class   result   get   

本人開發移動雲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 = "中午吃啥子,收到DingTalk我一下 --胡超";//內容 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 }
View Code

圖1,使用者密碼設定

簽名:sign  下載

 

移動 雲MAS 發簡訊 .net HTTP 要求

相關文章

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.