本人开发移动云MAS .net Http 请求 代码如下
using Newtonsoft.Json.Linq;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Net;
using System.Security.Cryptography;
using System.Text;
using System.Threading.Tasks; namespace MessageSendProj
{
class Program
{
static void Main(string[] args)
{
//发送信息快捷键
Console.WriteLine(SendMsg());
Console.ReadLine(); } public static string SendMsg()
{ JObject obj = new JObject();
var ecName = "企业名称";//企业名称
var apId = "mayun";//注意: 此处不是MAS云网站的用户名,这个要在管理里面新建用户密码,如图下1,
var secretKey = "asd2018";//密码
var mobiles = "15655521119,17612345651";//电话
var content = "中午吃啥子,收到钉钉我一下 --胡超";//内容
var sign1 = "XtXYO12LyQJ";//编码
var addSerial = "";//可以随便写,三位数
obj.Add("ecName", new JValue(ecName));
obj.Add("apId", new JValue(apId));
obj.Add("secretKey", new JValue(secretKey));
obj.Add("mobiles", new JValue(mobiles));
obj.Add("content", new JValue(content));
obj.Add("sign", new JValue(sign1));
obj.Add("addSerial", new JValue(addSerial));
var mac = ecName + apId + secretKey + mobiles + content + sign1 + addSerial;
var mac1 = UserMd5(mac);//要进行32位MD5加密
var length = mac1.Length;
obj.Add("mAC", new JValue(mac1));
string paras = obj.ToString();
var jiami = Base64Code(paras);//传参数前要进行64位加密
System.Net.WebClient pWebClient = new System.Net.WebClient();
pWebClient.Headers.Add("Content-Type", "application/json;charset=UTF-8"); //charset=UTF-8
pWebClient.Headers.Add(HttpRequestHeader.Accept, "*/*");
pWebClient.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)); return System.Text.Encoding.UTF8.GetString(returnBytes); //var aa = Base64Decode(result1);
} /// <summary>
/// Base64加密
/// </summary>
/// <param name="Message"></param>
/// <returns></returns>
public static string Base64Code(string Message)
{
byte[] bytes = Encoding.UTF8.GetBytes(Message);//这里要注意不是Default 因为Default默认GB2312
return Convert.ToBase64String(bytes);
} /// <summary>
/// Base64解密
/// </summary>
/// <param name="Message"></param>
/// <returns></returns>
public static string Base64Decode(string Message)
{
byte[] bytes = Convert.FromBase64String(Message);
return Encoding.UTF8.GetString(bytes);
}
/// <summary>
/// Base64加密
/// </summary>
/// <param name="encodeType">加密采用的编码方式</param>
/// <param name="source">待加密的明文</param>
/// <returns></returns>
public static string Base64Encode(Encoding encodeType, string source)
{
string encode = string.Empty;
byte[] bytes = encodeType.GetBytes(source);
try
{
encode = Convert.ToBase64String(bytes);
}
catch
{
encode = source;
}
return encode;
} /// <summary>
/// Md5 加密
/// </summary>
/// <param name="str"></param>
/// <returns></returns>
public static string UserMd5(string str)
{
string cl = str;
string pwd = "";
MD5 md5 = MD5.Create();//实例化一个md5对像
// 加密后是一个字节类型的数组,这里要注意编码UTF8/Unicode等的选择
byte[] s = md5.ComputeHash(Encoding.UTF8.GetBytes(cl));
// 通过使用循环,将字节类型的数组转换为字符串,此字符串是常规字符格式化所得
for (int i = ; i < s.Length; i++)
{
// 将得到的字符串使用十六进制类型格式。格式后的字符是小写的字母,如果使用大写(X)则格式后的字符是大写字符
pwd = pwd + s[i].ToString("x2");
}
return pwd;
} }
}
图1,用户密码设置
签名:sign 下载