using System;
|
using System.Collections.Generic;
|
using System.Globalization;
|
using System.Linq;
|
using System.Text;
|
using System.Threading.Tasks;
|
using Newtonsoft.Json;
|
namespace XhOA.Untity
|
{
|
/// <summary>
|
/// 乐秀获取Token
|
/// </summary>
|
public class XhHttpClient
|
{
|
#if DEBUG
|
private static string name="xherp";
|
private static string PWD = "dee61b6f3f8d515e3fbedd094017d683273e";
|
private static string url = "http://106.14.62.116:13221/xhmall-dockingplatform/api";
|
#else
|
private static string name = "xherp";
|
private static string PWD = "dee61b6f3f8d515e3fbedd094017d683273e";
|
public static string url = "https://dock.xhgjmall.com/xhmall_dockingplatform/api";
|
#endif
|
|
public static XhToken GetToken() {
|
string time = DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss", DateTimeFormatInfo.InvariantInfo);
|
System.Security.Cryptography.MD5CryptoServiceProvider md5 = new System.Security.Cryptography.MD5CryptoServiceProvider();
|
string sign = BitConverter.ToString(md5.ComputeHash(System.Text.Encoding.UTF8.GetBytes(name + PWD + time + PWD))).Replace("-", "").ToLower();//MD5加密
|
Dictionary<string, string> _params = new Dictionary<string, string>()
|
{
|
{"timestamp",time }, {"username",name }, {"password",PWD }, {"sign",sign }
|
};
|
|
|
var result= HttpClient.Post(url + "/auth2/access_token", _params);
|
|
return JsonConvert.DeserializeObject<XhToken>(result);
|
}
|
|
|
public class XhToken {
|
public bool success { get; set; }
|
public string access_token { get; set; }
|
public DateTime expires_at { get; set; }
|
}
|
}
|
}
|