using BBWY.Common.Http; using BBWY.Common.Models; using BBWY.Server.Model; using BBWY.Server.Model.Dto; using Microsoft.Extensions.Options; using Newtonsoft.Json.Linq; using System; using System.Collections.Generic; using System.Linq; using System.Net.Http; namespace BBWY.Server.Business { public class MDSBusiness : IDenpendency { private RestApiService restApiService; private GlobalConfig globalConfig; private IDictionary mdsApiHeader; public MDSBusiness(RestApiService restApiService, IOptions options) { this.restApiService = restApiService; this.globalConfig = options.Value; mdsApiHeader = new Dictionary() { { "qy","qy"} }; } public ShopResponse GetShopInfoByShopId(long shopId) { var shopResult = restApiService.SendRequest(globalConfig.MdsApi, "/TaskList/Shop/GetShopsByShopId", $"shopId={shopId}", mdsApiHeader, HttpMethod.Get, enableRandomTimeStamp: true); if (shopResult.StatusCode != System.Net.HttpStatusCode.OK) throw new Exception($"SyncOrder 获取店铺信息失败 shopId:{shopId} httpCode:{shopResult.StatusCode} httpContent:{shopResult.Content}"); var shopResponseJToken = JToken.Parse(shopResult.Content); if (shopResponseJToken.Value("Success") != true) throw new Exception($"SyncOrder 获取店铺信息失败 shopId:{shopId} ErrorMsg:{shopResponseJToken.Value("Msg")}"); var shopJToken = shopResponseJToken["Data"].FirstOrDefault(); var shopResponse = new ShopResponse() { AppKey = shopJToken.Value("AppKey"), AppSecret = shopJToken.Value("AppSecret"), AppToken = shopJToken.Value("AppToken"), PlatformId = (Enums.Platform)shopJToken.Value("PlatformId"), ShopType = shopJToken.Value("ShopType"), ShopId = shopId.ToString(), ShopName = shopJToken.Value("ShopName"), ManagePwd = shopJToken.Value("ManagePwd") }; try { shopResponse.PlatformCommissionRatio = shopJToken.Value("PlatformCommissionRatio"); } catch { } return shopResponse; } } }