public async Task <GetSFCreateOrderServiceResponse> getSFCreateOrderServiceResponse(SFCreateOrderServiceRequest sFCreateOrderServiceRequest) { GetSFCreateOrderServiceResponse getSFCreateOrderServiceResponse = new GetSFCreateOrderServiceResponse(); //string verifyText = sFCreateOrderServiceRequest.Checkword; try { string toVerifyText = sFCreateOrderServiceRequest.RequestOrderXMLMessage + sFCreateOrderServiceRequest.Checkword; System.Security.Cryptography.MD5 hs = System.Security.Cryptography.MD5.Create(); byte[] base64Encryption = hs.ComputeHash(System.Text.Encoding.UTF8.GetBytes(toVerifyText)); string base64VeirificatioCode = Convert.ToBase64String(base64Encryption); Dictionary <String, String> map = new Dictionary <string, string>(); map.Add("xml", sFCreateOrderServiceRequest.RequestOrderXMLMessage); map.Add("verifyCode", base64VeirificatioCode); map.Add("checkCode", sFCreateOrderServiceRequest.Checkcode); IEnumerable <KeyValuePair <string, string> > keyValuePairs = new List <KeyValuePair <string, string> >(); keyValuePairs = map; string resultContent = string.Empty; HttpClient httpClient = null; if (string.Equals(MapProxy.WebProxyEnable, false.ToString(), StringComparison.OrdinalIgnoreCase)) { httpClient = new HttpClient(); } else { httpClient = new HttpClient(GetHttpClientHandler()); } using (var client = httpClient) { client.BaseAddress = new Uri(sFCreateOrderServiceRequest.BaseURI); var content = new FormUrlEncodedContent(keyValuePairs); var result = await client.PostAsync(sFCreateOrderServiceRequest.RequestURI, content); resultContent = await result.Content.ReadAsStringAsync(); getSFCreateOrderServiceResponse.OrderResponse = resultContent; getSFCreateOrderServiceResponse.Response = true; } } catch (Exception exception) { getSFCreateOrderServiceResponse.exception = exception; await iCustomLog.AddLogEntry(new UPS.DataObjects.LogData.LogDataModel() { apiTypes = UPS.DataObjects.LogData.APITypes.SFExpress, apiType = Enum.GetName(typeof(UPS.DataObjects.LogData.APITypes), 1), dateTime = System.DateTime.Now, LogInformation = new UPS.DataObjects.LogData.LogInformation() { LogException = exception.InnerException.ToString(), LogRequest = JsonConvert.SerializeObject(sFCreateOrderServiceRequest), LogResponse = null } }); } return(getSFCreateOrderServiceResponse); }
public static GetSFCreateOrderServiceResponse SFExpressCreateOrder(SFCreateOrderServiceRequest sFCreateOrderServiceRequest) { GetSFCreateOrderServiceResponse getSFCreateOrderServiceResponse = new SFExpressProxy().getSFCreateOrderServiceResponse(sFCreateOrderServiceRequest).Result; return(getSFCreateOrderServiceResponse); }
public async Task <ActionResult> CreateOrderShipment([FromBody] List <UIOrderRequestBodyData> uIOrderRequestBodyDatas) { string customerID = uIOrderRequestBodyDatas[0].spC_CST_ID_TE;//_shipmentService.GetShipmentCustomCodesInformation().CST_ID; _workflowID = uIOrderRequestBodyDatas[0].wfL_ID; CreateOrderShipmentResponse createOrderShipmentResponse = new CreateOrderShipmentResponse(); createOrderShipmentResponse.FailedToProcessShipments = new List <string>(); createOrderShipmentResponse.ProcessedShipments = new List <string>(); //ShipmentService shipmentService = new ShipmentService(); //List<UIOrderRequestBodyData> uIOrderRequestBodyDatas = new List<UIOrderRequestBodyData>(); foreach (var orderRequest in uIOrderRequestBodyDatas) { string XMLMessage = string.Empty; XMLMessage = "<Request lang=\"zh-CN\" service=\"OrderService\">"; XMLMessage += "<Head>" + configuration["SFExpress:Access Number"] + "</Head>"; XMLMessage += "<Body>"; XMLMessage += "<Order orderid=\"" + orderRequest.pkG_NR_TE + "\" custid=\"" + orderRequest.spC_CST_ID_TE + "\""; XMLMessage += " parcel_quantity=\"" + orderRequest.pcS_QTY_NR + "\""; XMLMessage += " total_net_weight=\"" + orderRequest.pkG_WGT_DE + "\""; XMLMessage += " j_company=\"" + orderRequest.shP_CPY_NA.ampReplacment() + "\""; XMLMessage += " j_address=\"" + orderRequest.shP_ADR_TE.ampReplacment() + "\""; XMLMessage += " j_city=\"" + orderRequest.orG_CTY_TE.ampReplacment() + "\""; XMLMessage += " j_post_code=\"" + orderRequest.orG_PSL_CD + "\""; XMLMessage += " j_contact=\"" + orderRequest.shP_CTC_TE.ampReplacment() + "\""; XMLMessage += " j_tel=\"" + orderRequest.shP_PH_TE + "\""; XMLMessage += " d_company=\"" + orderRequest.rcV_CPY_TE.ampReplacment() + "\""; XMLMessage += " d_city=\"" + orderRequest.dsT_CTY_TE.ampReplacment() + "\""; XMLMessage += " d_post_code=\"" + orderRequest.dsT_PSL_TE + "\""; XMLMessage += " d_contact=\"" + orderRequest.csG_CTC_TE.ampReplacment() + "\""; XMLMessage += " d_tel=\"" + orderRequest.pH_NR + "\""; XMLMessage += " specifications=\"" + orderRequest.fsT_INV_LN_DES_TE + "\""; XMLMessage += " routelabelService=\"1\""; XMLMessage += " d_address=\"" + orderRequest.shP_ADR_TR_TE + "\" cargo_total_weight=\"" + orderRequest.pkG_WGT_DE + "\""; XMLMessage += " pay_method=\"1\" is_docall=\"" + 0 + "\" need_return_tracking_no=\"" + orderRequest.poD_RTN_SVC + "\" express_type=\"6\""; XMLMessage += " >"; XMLMessage += " </Order>"; if (!string.IsNullOrEmpty(orderRequest.coD_TE)) { XMLMessage += "<AddedService name='COD' value=\"" + orderRequest.coD_TE + "\"></AddedService>"; } XMLMessage += "</Body></Request>"; SFCreateOrderServiceRequest sFCreateOrderServiceRequest = new SFCreateOrderServiceRequest() { AccessNumber = configuration["SFExpress:Access Number"], BaseURI = configuration["SFExpress:Base URI"], Checkword = configuration["SFExpress:Checkword"], RequestURI = configuration["SFExpress:Place Order URI"], Checkcode = configuration["SFExpress:CheckCode"], RequestOrderXMLMessage = XMLMessage, }; GetSFCreateOrderServiceResponse getSFCreateOrderServiceResponse = QuincusService.SFExpressCreateOrder(sFCreateOrderServiceRequest); //shipmentDataResponse = shipmentService.UpdateShipmentStatusById(shipmentDataRequest); //if (!shipmentDataResponse.Success) //{ // AuditEventEntry.WriteEntry(new Exception(shipmentDataResponse.OperationExceptionMsg)); //} if (getSFCreateOrderServiceResponse.Response) { XmlDocument xmlDocumentShipmentResponse = new XmlDocument(); xmlDocumentShipmentResponse.LoadXml(getSFCreateOrderServiceResponse.OrderResponse); string xmlDocumentShipmentResponseParser = xmlDocumentShipmentResponse.InnerXml; if (xmlDocumentShipmentResponseParser.Contains("<ERROR")) { XmlDocument xmlDocument = new XmlDocument(); xmlDocument.LoadXml(getSFCreateOrderServiceResponse.OrderResponse); //if (xmlDocumentShipmentResponseParser.Contains("8019")) //{ // createOrderShipmentResponse.FailedToProcessShipments.Add("Customer order number(" + orderRequest.pkG_NR_TE + ") is already confirmed"); //} //else if (xmlDocumentShipmentResponseParser.Contains("8016")) //{ // createOrderShipmentResponse.FailedToProcessShipments.Add("Repeat order numbers ( " + orderRequest.pkG_NR_TE + " )"); //} //else //{ createOrderShipmentResponse.FailedToProcessShipments.Add( string.Format("{0}:{1}:{2}", orderRequest.pkG_NR_TE, xmlDocument.GetElementsByTagName("ERROR")[0].Attributes[0].InnerText, xmlDocument.GetElementsByTagName("ERROR")[0].InnerXml)); //} } else { createOrderShipmentResponse.ProcessedShipments.Add(orderRequest.pkG_NR_TE); ShipmentDataRequest shipmentDataRequest = new ShipmentDataRequest(); shipmentDataRequest.ID = orderRequest.id; shipmentDataRequest.WFL_ID = orderRequest.wfL_ID; shipmentDataRequest.SMT_STA_NR = ((int)Enums.ATStatus.Completed); shipmentDataRequest.SMT_STA_TE = "Completed"; _workflowID = orderRequest.wfL_ID; _shipmentService.UpdateShipmentStatusById(shipmentDataRequest); } createOrderShipmentResponse.Response = true; } else { createOrderShipmentResponse.Response = false; } } //we need to update the workflow status int? workflowstatus = _shipmentService.SelectShipmentTotalStatusByWorkflowId(_workflowID); WorkflowService workflowService = new WorkflowService(_context, _addressBookService, _entityValidationService); WorkflowDataRequest workflowDataRequest = new WorkflowDataRequest(); workflowDataRequest.ID = _workflowID; workflowDataRequest.WFL_STA_TE = workflowstatus; workflowService.UpdateWorkflowStatusById(workflowDataRequest); await iCustomLog.AddLogEntry(new UPS.DataObjects.LogData.LogDataModel() { apiTypes = UPS.DataObjects.LogData.APITypes.SFExpress, apiType = Enum.GetName(typeof(UPS.DataObjects.LogData.APITypes), 1), dateTime = System.DateTime.Now, LogInformation = new UPS.DataObjects.LogData.LogInformation() { LogException = null, LogRequest = JsonConvert.SerializeObject(uIOrderRequestBodyDatas), LogResponse = JsonConvert.SerializeObject(createOrderShipmentResponse) } }); return(Ok(createOrderShipmentResponse)); }
public async Task <GetSFCreateOrderServiceResponse> getSFCreateOrderServiceResponse(SFCreateOrderServiceRequest sFCreateOrderServiceRequest) { GetSFCreateOrderServiceResponse getSFCreateOrderServiceResponse = new GetSFCreateOrderServiceResponse(); //string verifyText = sFCreateOrderServiceRequest.Checkword; try { string toVerifyText = sFCreateOrderServiceRequest.RequestOrderXMLMessage + sFCreateOrderServiceRequest.AccessNumber; System.Security.Cryptography.MD5 hs = System.Security.Cryptography.MD5.Create(); byte[] base64Encryption = hs.ComputeHash(System.Text.Encoding.UTF8.GetBytes(toVerifyText)); string base64VeirificatioCode = Convert.ToBase64String(base64Encryption); Dictionary <String, String> map = new Dictionary <string, string>(); map.Add("xml", sFCreateOrderServiceRequest.RequestOrderXMLMessage); map.Add("verifyCode", base64VeirificatioCode); map.Add("checkCode", sFCreateOrderServiceRequest.Checkword); IEnumerable <KeyValuePair <string, string> > keyValuePairs = new List <KeyValuePair <string, string> >(); keyValuePairs = map; string resultContent = string.Empty; HttpClient httpClient = null; if (string.Equals(MapProxy.WebProxyEnable, false.ToString(), StringComparison.OrdinalIgnoreCase)) { httpClient = new HttpClient(); } else { httpClient = new HttpClient(GetHttpClientHandler()); } using (var client = httpClient) { client.BaseAddress = new Uri(sFCreateOrderServiceRequest.BaseURI); var content = new FormUrlEncodedContent(keyValuePairs); var result = await client.PostAsync(sFCreateOrderServiceRequest.RequestURI, content); resultContent = await result.Content.ReadAsStringAsync(); getSFCreateOrderServiceResponse.OrderResponse = resultContent; getSFCreateOrderServiceResponse.Response = true; } } catch (Exception exception) { getSFCreateOrderServiceResponse.exception = exception; } return(getSFCreateOrderServiceResponse); }
public async Task <ActionResult> CreateOrderShipment([FromBody] List <UIOrderRequestBodyData> uIOrderRequestBodyDatas) { _workflowID = uIOrderRequestBodyDatas[0].wfL_ID; CreateOrderShipmentResponse createOrderShipmentResponse = new CreateOrderShipmentResponse(); createOrderShipmentResponse.FailedToProcessShipments = new List <string>(); createOrderShipmentResponse.ProcessedShipments = new List <string>(); ShipmentService shipmentService = new ShipmentService(); //List<UIOrderRequestBodyData> uIOrderRequestBodyDatas = new List<UIOrderRequestBodyData>(); foreach (var orderRequest in uIOrderRequestBodyDatas) { string XMLMessage = string.Empty; XMLMessage = "<Request lang=\"zh-CN\" service=\"OrderService\">"; XMLMessage += "<Head>LJ_T6NVV</Head>"; XMLMessage += "<Body>"; XMLMessage += "<Order orderid=\"" + orderRequest.pkG_NR_TE + "\" custid=\"" + 7551234567 + "\""; XMLMessage += " j_tel=\"" + orderRequest.shP_CTC_TE + "\""; XMLMessage += " j_address=\"" + orderRequest.shP_ADR_TE + "\""; XMLMessage += " d_tel=\"" + orderRequest.pH_NR + "\""; XMLMessage += " d_address=\"" + orderRequest.shP_ADR_TR_TE + "\" cargo_total_weight=\"" + orderRequest.pkG_WGT_DE + "\""; XMLMessage += " pay_method=\"1\" is_docall=\"" + 1 + "\" need_return_tracking_no=\"" + orderRequest.poD_RTN_SVC + "\" express_type=\"6\""; XMLMessage += " >"; XMLMessage += " </Order></Body></Request>"; SFCreateOrderServiceRequest sFCreateOrderServiceRequest = new SFCreateOrderServiceRequest() { AccessNumber = configuration["SFExpress:Access Number"], BaseURI = configuration["SFExpress:Base URI"], Checkword = configuration["SFExpress:Checkword"], RequestURI = configuration["SFExpress:Place Order URI"], RequestOrderXMLMessage = XMLMessage, }; GetSFCreateOrderServiceResponse getSFCreateOrderServiceResponse = QuincusService.SFExpressCreateOrder(sFCreateOrderServiceRequest); //shipmentDataResponse = shipmentService.UpdateShipmentStatusById(shipmentDataRequest); //if (!shipmentDataResponse.Success) //{ // AuditEventEntry.WriteEntry(new Exception(shipmentDataResponse.OperationExceptionMsg)); //} if (getSFCreateOrderServiceResponse.Response) { XmlDocument xmlDocumentShipmentResponse = new XmlDocument(); xmlDocumentShipmentResponse.LoadXml(getSFCreateOrderServiceResponse.OrderResponse); string xmlDocumentShipmentResponseParser = xmlDocumentShipmentResponse.InnerXml; if (xmlDocumentShipmentResponseParser.Contains("<ERROR")) { if (xmlDocumentShipmentResponseParser.Contains("8019")) { createOrderShipmentResponse.FailedToProcessShipments.Add("Customer order number(" + orderRequest.pkG_NR_TE + ") is already confirmed"); } else if (xmlDocumentShipmentResponseParser.Contains("8016")) { createOrderShipmentResponse.FailedToProcessShipments.Add("Repeat order numbers ( " + orderRequest.pkG_NR_TE + " )"); } else { createOrderShipmentResponse.FailedToProcessShipments.Add(orderRequest.pkG_NR_TE); } } else { createOrderShipmentResponse.ProcessedShipments.Add(orderRequest.pkG_NR_TE); ShipmentDataRequest shipmentDataRequest = new ShipmentDataRequest(); shipmentDataRequest.ID = orderRequest.id; shipmentDataRequest.WFL_ID = orderRequest.wfL_ID; shipmentDataRequest.SMT_STA_NR = ((int)Enums.ATStatus.Completed); shipmentDataRequest.SMT_STA_TE = "Completed"; _workflowID = orderRequest.wfL_ID; shipmentService.UpdateShipmentStatusById(shipmentDataRequest); } createOrderShipmentResponse.Response = true; } else { createOrderShipmentResponse.Response = false; if (getSFCreateOrderServiceResponse.exception != null) { AuditEventEntry.WriteEntry(new Exception(getSFCreateOrderServiceResponse.exception.ToString())); } } } //we need to update the workflow status int? workflowstatus = shipmentService.SelectShipmentTotalStatusByWorkflowId(_workflowID); WorkflowService workflowService = new WorkflowService(); WorkflowDataRequest workflowDataRequest = new WorkflowDataRequest(); workflowDataRequest.ID = _workflowID; workflowDataRequest.WFL_STA_TE = workflowstatus; workflowService.UpdateWorkflowStatusById(workflowDataRequest); return(Ok(createOrderShipmentResponse)); }