Mobile Cloud MAS texting. NET HTTP Requests

Source: Internet
Author: User
Tags md5 encryption sendmsg

I developed the mobile cloud MAS. NET Http request code as follows

1 usingNewtonsoft.Json.Linq;2 usingSystem;3 usingSystem.Collections.Generic;4 usingSystem.Linq;5 usingSystem.Net;6 usingSystem.Security.Cryptography;7 usingSystem.Text;8 usingSystem.Threading.Tasks;9 Ten namespacemessagesendproj One { A class Program - { - Static voidMain (string[] args) the { - //send information shortcut keys - Console.WriteLine (sendmsg ()); - console.readline (); +  - } +  A  Public Static stringsendmsg () at { -  -Jobject obj =Newjobject (); - varEcname ="Company Name";//Company Name - varApId ="Mayun";//Note: This is not the user name of the MAS Cloud website, this should be in the management of the new user password, the next 1, - varSecretkey ="asd2018";//Password in varMobiles ="15655521119,17612345651";//Telephone - varContent ="What to eat at noon, receive nails me--Hu Chao";//content to varSIGN1 ="XTXYO12LYQJ";//Coding + varAddserial ="123";//can be written casually, three-digit -Obj. ADD ("Ecname",NewJvalue (Ecname)); theObj. ADD ("apId",NewJvalue (apId)); *Obj. ADD ("Secretkey",NewJvalue (Secretkey)); $Obj. ADD ("Mobiles",Newjvalue (mobiles));Panax NotoginsengObj. ADD ("content",Newjvalue (content)); -Obj. ADD (" Sign",NewJvalue (SIGN1)); theObj. ADD ("addserial",NewJvalue (addserial)); + varMac = Ecname + apId + secretkey + mobiles + content + sign1 +addserial; A varMAC1 = UserMd5 (MAC);//to perform 32-bit MD5 encryption the varLength =Mac1. Length; +Obj. ADD ("MAC",NewJvalue (MAC1)); - stringparas =obj. ToString (); $ varJiami = Base64code (paras);//64-bit encryption before passing parameters $System.Net.WebClient pwebclient =NewSystem.Net.WebClient (); -PWEBCLIENT.HEADERS.ADD ("Content-type","Application/json;charset=utf-8");//Charset=utf-8 -PWEBCLIENT.HEADERS.ADD (Httprequestheader.accept,"*/*"); thePWEBCLIENT.HEADERS.ADD ("user-agent","mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.1; SV1)"); - byte[] returnbytes = Pwebclient.uploaddata ("Http://112.35.1.155:1992/sms/norsubmit","POST", System.Text.Encoding.UTF8.GetBytes (Jiami));Wuyi  the returnSystem.Text.Encoding.UTF8.GetString (returnbytes); -  Wu //var aa = Base64decode (RESULT1); - } About  $  - /// <summary> - ///Base64 Encryption - /// </summary> A /// <param name= "Message" ></param> + /// <returns></returns> the  Public Static stringBase64code (stringMessage) - { $ byte[] bytes = Encoding.UTF8.GetBytes (Message);//It's important to note that this is not default, because defaults GB2312 the returnconvert.tobase64string (bytes); the } the  the  - /// <summary> in ///Base64 Decryption the /// </summary> the /// <param name= "Message" ></param> About /// <returns></returns> the  Public Static stringBase64decode (stringMessage) the { the byte[] bytes =convert.frombase64string (Message); + returnEncoding.UTF8.GetString (bytes); - } the /// <summary>Bayi ///Base64 Encryption the /// </summary> the /// <param name= "Encodetype" >encoding used for encryption</param> - /// <param name= "source" >plaintext to encrypt</param> - /// <returns></returns> the  Public Static stringBase64Encode (Encoding Encodetype,stringsource) the { the stringEncode =string. Empty; the byte[] bytes =encodetype.getbytes (source); - Try the { theEncode =convert.tobase64string (bytes); the }94 Catch the { theEncode =Source; the }98 returnencode; About } - 101 /// <summary>102 ///MD5 Encryption103 /// </summary>104 /// <param name= "str" ></param> the /// <returns></returns>106  Public Static stringUSERMD5 (stringstr)107 {108 stringCL =str;109 stringPWD =""; theMD5 MD5 = MD5. Create ();//instantiate a MD5 pair of images111 //after the encryption is an array of byte type, here should pay attention to the choice of coding utf8/unicode, etc. the byte[] s =Md5.computehash (Encoding.UTF8.GetBytes (CL));113 //converts an array of byte types to a string by using a loop, which is a regular character formatting the resulting the  for(inti =0; i < s.length; i++) the { the //The resulting string is formatted using the hexadecimal type. The formatted character is a lowercase letter, and if uppercase (X) is used, the character after the format is uppercase characters117PWD = pwd + s[i]. ToString ("X2");118 }119 returnpwd; - }121 122 123 }124}
View Code

Figure 1, User password settings

Signature: Sign Download

Mobile Cloud MAS texting. NET HTTP Requests

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

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.