public FormFEPBillPost() { InitializeComponent(); ResultData = new FEPBillPostResponseResult(); FEPBillPostBiz = new FEPBillPostProcessor(); FEPBillPostBiz.PostComplateEvent += FEPBillPostBiz_PostComplateEvent; }
protected virtual void OnPostComplate(object sender, FEPBillPostResponseResult e) { var handler = m_PostComplateEvent; if (handler != null) { handler(sender, e); } }
void FEPBillPostBiz_PostComplateEvent(object sender, FEPBillPostResponseResult result) { this.Invoke(new Action <FEPBillPostResponseResult>(e => { string message = string.Format("结算账单创建失败:{0}", e.Desc); if (e.Code == 0) { ResultData.Data = e.Data; message = string.Format("结算账单创建成功, 结算账单号: {0}, 结算金额:{1:F2}", e.Data.FEPBillId, e.Data.PurchasingTotalAmount); } txtBoxLog.Text += message + "\r\n"; }), result); }
private async void AsyncFEPBillPost(FEPBillPostRequestInfo contractInfo, ConfigData configData) { FEPBillPostResponseResult result = new FEPBillPostResponseResult() { Data = new FEPBillPostResponseData() }; var parameters = new NameValueCollection(); parameters.Add("method", "Invoice.FEPBillPost"); parameters.Add("data", JsonSerializer.Serialize(contractInfo)); parameters.Add("format", "json"); parameters.Add("version", "1.0"); parameters.Add("nonce", new Random().NextDouble().ToString()); parameters.Add("appid", configData.AppId); parameters.Add("timestamp", DateTime.Now.ToString("yyyyMMddhhmmss")); string sign = SignatureUtil.Build(parameters, configData.SecretKey); StringBuilder httpContentStringBuilder = new StringBuilder(); foreach (string key in parameters.AllKeys) { httpContentStringBuilder.AppendFormat("&{0}={1}", key, SignatureUtil.UrlEncode(parameters[key])); } httpContentStringBuilder.AppendFormat("&{0}={1}", "sign", sign); var content = httpContentStringBuilder.ToString().TrimStart('&'); var httpContent = new StringContent(content); httpContent.Headers.ContentType = new MediaTypeHeaderValue("application/x-www-form-urlencoded"); var httpClient = new HttpClient(); try { var task = await httpClient.PostAsync(new Uri(configData.OpenApiUrl), httpContent); var responseData = await task.Content.ReadAsStringAsync(); result = JsonSerializer.Deserialize <FEPBillPostResponseResult>(responseData); if (result.Data == null) { result.Data = new FEPBillPostResponseData(); } } catch (AggregateException aex) { result.Code = -10; var egex = (AggregateException)aex; Exception innerExp = null; if (egex.InnerExceptions != null && egex.InnerExceptions.Count > 0) { innerExp = egex.InnerExceptions[0]; } if (innerExp == null) { result.Desc = egex.Message; } else { Exception tempExp; GetInnerException(innerExp, out tempExp); if (tempExp != null) { result.Desc = tempExp.Message; } else { result.Desc = innerExp.Message; } } } catch (Exception ex) { result.Code = -10; result.Desc = ex.Message; } OnPostComplate(this, result); }