/// <summary> /// OMS调用订单辅助系统接口参数 /// </summary> /// <returns></returns> public OrderAssistParamsModel OrderAssistOmsApi(string method, string app_key, string v, string sd_id, string order_state, string page_no, string page_size, string data = null) { //string temp_app_key = app_key; //SortedDictionary<string, string> sParams = new SortedDictionary<string, string>(); //sParams.Add("method",method); //sParams.Add("app_key", app_key); //sParams.Add("v",v); //sParams.Add("sd_id",sd_id); //sParams.Add("order_state", order_state); //sParams.Add("page_no",page_no); //sParams.Add("page_size",page_size); //sParams.Add("timestamp", DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss")); //if (!string.IsNullOrEmpty(data)) { // sParams.Add("data",data); //} //string sign = CommonTools.getSign(sParams, temp_app_key); //var postUrl = _configuration.GetSection("OrderAssistOmsApi")["domain"]; //string post_data = CommonTools.getPostData(sParams,sign); //string requestData = CommonTools.PostToUrl(postUrl, post_data); //return requestData; OrderAssistParamsModel orderAssistParamsModel = new OrderAssistParamsModel { method = method, app_key = app_key, v = v, sd_id = sd_id, order_state = order_state, page_no = page_no, page_size = page_size, timestamp = DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss"), data = data }; string sgin = MD5Util.GetMD5_ToUpper(app_key, "utf-8"); orderAssistParamsModel.sgin = sgin; return(orderAssistParamsModel); }
public async Task <bool> OmsSyncWineWorldOrder() { try { //防止多次抓取订单造成错误 Monitor.Enter(_MyLock); //获取排它锁 string method = "wineworld.order.search"; string app_key = "oms"; string v = "1.0"; string sd_id = "501"; string order_state = "WAIT_SELLER_STOCK_OUT"; string page_no = "1"; string page_size = "50"; string data = null; OrderAssistParamsModel orderAssistParamsModel = _orderSyncService.OrderAssistOmsApi(method, app_key, v, sd_id, order_state, page_no, page_size, data); //处理SSL问题 var httpClientHandler = new HttpClientHandler { ServerCertificateCustomValidationCallback = (message, certificate2, arg3, arg4) => true }; using (var http = new HttpClient(httpClientHandler)) { var postParamJson = orderAssistParamsModel.ToJson(); //#region JWTBearer授权校验信息 //_workContext.CurrentHttpContext.Request.Cookies.TryGetValue("wms_token", out string token); //if (string.IsNullOrEmpty(token)) { token = await GetWMSOauthToken(); } //http.DefaultRequestHeaders.Add("Authorization", string.Format("Bearer {0}", token)); //#endregion var content = new StringContent(postParamJson, Encoding.UTF8, "application/json"); var postUrl = _configuration.GetSection("OrderAssistOmsApi")["domain"].ToString(); var response = http.PostAsync(postUrl, content).Result; var result = await response.Content.ReadAsStringAsync(); //if (response.StatusCode == System.Net.HttpStatusCode.Unauthorized) // 未授权 //{ // await GetWMSOauthToken(); // Logger.Error("OMS抓取商城下单信息同步到订单表失败,原因是API授权失败!请重试。"); // return false; //} if (response.StatusCode == System.Net.HttpStatusCode.OK) { //var account = _workContext.CurrentUser.Id; var test = JsonMapper.ToObject <RespDataOrderInfo>(result); if (test != null) { OrderSearchResponse orderSearchResponse = test.resp_data; if (orderSearchResponse != null) { List <OrderInfo> orderInfoList = orderSearchResponse.order_info_list; List <OrderNotification> orderNotifications = new List <OrderNotification>(); if (orderInfoList.Count > 0 && orderInfoList != null) { _orderSyncService.OrderSync(orderInfoList, sd_id, out orderNotifications); } if (orderNotifications.Count > 0 && orderNotifications != null) { OrderNotification(orderNotifications); } } } return(true); } else { _logService.Error(string.Format("OMS抓取商城下单信息同步到订单表失败,状态码:{0},RequestMessage:{1}", response.StatusCode, response.RequestMessage)); return(false); } } } catch (Exception ex) { _logService.Error(string.Format("OMS抓取商城下单信息同步到订表异常:{0}", ex.Message)); return(false); } finally { Monitor.Exit(_MyLock); //释放排它锁 } }