王 垚
2021-02-28 d5ddf535c11458df512e62b504773401656ae74c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
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; }
        }
    }
}