接口使用說明

  1. 獲取token(token有效期一個(gè)月,不用每次重復(fù)獲取)
    HttpClient client = new HttpClient();
    client.BaseAddress = new Uri(string.Concat("http://auth.beimai.com", "/"));
    client.DefaultRequestHeaders.Accept.Add(new MediaTypeWithQualityHeaderValue("application/json"));
    client.DefaultRequestHeaders.Add("client_id", "1001");
    client.DefaultRequestHeaders.Add("client_secret", "T1lPsaX1HfeZxOFiVFgQK9R3cST9vwO3");
    HttpResponseMessage response = client.PostAsync("api/auth/token", null).Result;
    object obj=null;
    if (response.IsSuccessStatusCode)
    {
        obj = response.Content.ReadAsAsync<object>().Result;
    }
    然后提取json對象中的access_token 即可
                            
                    
  2. 每一個(gè)接口都有的默認(rèn)參數(shù),不再對每一個(gè)接口調(diào)用做說明
    1.app_key:在sass平臺唯一標(biāo)識
    2.access_token:參考補(bǔ)充說明1獲取token
    3.sign:根據(jù) access_token app_key 秘鑰 順序組合得到Md5值   秘鑰可以登錄sass平臺上設(shè)置
                        
  3. 實(shí)例:商品同步接口
    HttpClient
    HttpClient client = new HttpClient();
    client = new HttpClient();
    client.BaseAddress = new Uri(string.Concat("http://cloudapi.beimai.com", "/"));
    client.DefaultRequestHeaders.Accept.Add(new MediaTypeWithQualityHeaderValue("application/json"));
    string pstr = "{\"page\":1,\"pagesize\":10}";
    string timestamp = DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss");
    string sign=Tool.SignHelper.Sign("access_token=" + access_token + "&app_key=1001&bm_param="+pstr+"&timestamp="+ timestamp, "從第三方平臺獲取");
    
    /*=====================兩種方式針對不同的接口使用不同的調(diào)用方式===================*/
    
    //下訂單采購單等數(shù)據(jù)提交類的,使用以下代碼,如:
    var content = new FormUrlEncodedContent(new Dictionary<string, string>() { 
                { "SourceId", orderItem.SourceId.ToString() },
                { "SourceOrderId", orderItem.SourceOrderId } ,
                { "ReceiveWay", orderItem.ReceiveWay.ToString() } ,
                { "ProvinceId", orderItem.ProvinceId.ToString() } ,
                { "CityId", orderItem.CityId.ToString() } ,
                { "AreaId", orderItem.AreaId.ToString() },
                { "Address", orderItem.Address } ,
                { "ZipCode", orderItem.ZipCode } ,
                { "Receiver", orderItem.Receiver} ,
                { "TelPhone", orderItem.TelPhone } ,
                { "OrderTotal", orderItem.OrderTotal.ToString() },
                { "ProductAmount", orderItem.ProductAmount.ToString() } ,
                { "IsOpenInvoice", orderItem.IsOpenInvoice.ToString() } ,
                { "PList", pstr }
                });
    HttpResponseMessage response02 = client.PostAsync("api/order/placeorder?app_key=1001&access_token=" + HttpUtility.UrlEncode(token.access_token) + "&sign=" + HttpUtility.UrlEncode(sign), content).Result;
    
    //非數(shù)據(jù)提交類的,使用以下調(diào)用方式,如:
    HttpResponseMessage response02 = client.PostAsync("api/ps/gsbmpd?app_key=1001&access_token=" + HttpUtility.UrlEncode(access_token) + 
            "&sign=" + HttpUtility.UrlEncode(sign) + "&bm_param=" + HttpUtility.UrlEncode(pstr) + "&timestamp=" + HttpUtility.UrlEncode(timestamp), null).Result;
    
    /*=====================兩種方式針對不同的接口使用不同的調(diào)用方式===================*/
    
    object obj=null;
    if (response02.IsSuccessStatusCode)
    {
        obj = response02.Content.ReadAsAsync<object>().Result;
    }
    然后提取json對象中的result 即可,可分頁循環(huán)處理直到取不到結(jié)果為止。
                        
  4. 配置
    北邁測試client_secret:T1lPsaX1HfeZxOFiVFgQK9R3cST9vwO3
    北邁測試token: E/kNDwzStbDUdEyr+M8BuQogRfNYWDuR7/6c88eFj6rDHn3I2A2Nh3jmrnrn1wtA4cdpIV9POdqFtKf53CMyEBjzMmO0NHHChylSUl+HEjy+S04ht8ysWzlfgcnhUZwgD94ZAnA4YqHN8R5i0Z83mV6HDoP+vFcHNzhhXGhvwYphrxtq1rFLgm18tdZXjXeh0ewmuaslGPbdyyiyZD1ZU0MMugKyRq4mBKDlYBI+D4hn87MhPT/1VSBacXm1FMpf7FWDEV/p5vKhTZ0LXCz64FQCSAg3ixmrlI+Ale9waVlbaHHGm8XaNsyfInNg9XU7acOCsX7lt+YcAaUU8NsbTg==
                    
  5. 加密算法
    /// <param name="prestr">需要簽名的字符串</param>
    /// <param name="key">密鑰</param>
    /// <returns>簽名結(jié)果</returns>
    public static string Sign(string prestr, string key)
    {
        StringBuilder sb = new StringBuilder(32);
        prestr = prestr + key;
        MD5 md5 = new MD5CryptoServiceProvider();
        byte[] t = md5.ComputeHash(Encoding.GetEncoding(_input_charset).GetBytes(prestr));
        for (int i = 0; i < t.Length; i++)
        {
            sb.Append(t[i].ToString("x").PadLeft(2, '0'));
        }
        return sb.ToString();
    }