public async Task <IHttpActionResult> onPaymentNotified() { var f = new FormUrlEncodedMediaTypeFormatter(); var raw = await Request.Content.ReadAsByteArrayAsync(); var collection = await Request.Content.ReadAsAsync <FormDataCollection>(); var payment = new PaymentInfo(); var paymentType = payment.GetType(); foreach (var keyValuePair in collection) { var p = paymentType.GetProperty(keyValuePair.Key); if (p != null) { p.SetValue(payment, keyValuePair.Value); } } new NotificationProcessor(raw, payment).startProcess(); return(Ok()); }
/// <summary> /// 生成rd中的支付信息 /// </summary> /// <param name="xmlRd">rd字符串</param> /// <param name="payment">支付信息</param> /// <param name="seq">支付顺序</param> /// <returns></returns> private string dealwithPaymentRd(string xmlRd, PaymentInfo payment, int seq) { string ret = string.Empty; string error = string.Empty; var acct = payment.bankAcnt.acntNo.Trim(); //工行账户,支付方 if (acct.Length < 19) { error = string.Format("账号长度错误!", payment.bankAcnt.acntNo); throw new Exception(error); } InstallContext ic = new InstallContext(); //初始化数据 string name = string.Empty; object obj = null; //本方账户 Type type = payment.bankAcnt.GetType(); PropertyInfo[] ps = type.GetProperties(); foreach (PropertyInfo i in ps) { obj = i.GetValue(payment.bankAcnt, null); name = "bankAcnt_" + i.Name; if (obj != null) { ic.Set(name, obj.ToString()); } else { ic.Set(name, " "); } } //对方账户 type = payment.oppoBankAcnt.GetType(); ps = type.GetProperties(); foreach (PropertyInfo i in ps) { obj = i.GetValue(payment.oppoBankAcnt, null); name = "oppoBankAcnt_" + i.Name; if (obj != null) { ic.Set(name, obj.ToString()); } else { ic.Set(name, " "); } } //付款单 type = payment.GetType(); ps = type.GetProperties(); foreach (PropertyInfo i in ps) { obj = i.GetValue(payment, null); name = i.Name; if (obj != null) { if (string.IsNullOrWhiteSpace(obj.ToString().Trim())) { ic.Set(name, " "); } else { ic.Set(name, obj.ToString()); } } else { ic.Set(name, " "); } } //是否加绩 if (payment.isUrgent == (int)enumYesNo.Yes) { ic.Set("isUrgent", "1"); //加急 } else { ic.Set("isUrgent", "2"); //普通 } //是否同城 if (payment.sameCity == (int)enumYesNo.Yes) { ic.Set("sameCity", "1"); //同城 } else { ic.Set("sameCity", "2"); //异地 } //是否跨行 if (payment.sameBank == (int)enumYesNo.Yes) { ic.Set("sameBank", "1"); //系统内,工行 //把跨行数据置空 ic.Set("oppoBankAcnt_city", " "); ic.Set("oppoBankAcnt_bankInfo_bankCode", " "); ic.Set("oppoBankAcnt_bankInfo_bankName", " "); } else { ic.Set("sameBank", "2"); //跨行 //跨行数据 ic.Set("oppoBankAcnt_city", payment.oppoBankAcnt.city); ic.Set("oppoBankAcnt_bankInfo_bankCode", payment.oppoBankAcnt.bankInfo.bankCode); ic.Set("oppoBankAcnt_bankInfo_bankName", payment.oppoBankAcnt.bankInfo.bankName); } //如果不写币种,则默认人民币 string currency = payment.currency; if (string.IsNullOrEmpty(currency)) { currency = "001"; //默认人名币 } payment.amount = payment.amount * 100; //工行按分来计算,元转分要乘以100 ic.Set("currency", currency); ic.Set("bankCode", payment.bankAcnt.swiftCode); //工行为 "102" ic.Set("cis", ConfigurationManager.AppSettings["cis"]); ic.Set("id", ConfigurationManager.AppSettings["id"]); ic.Set("iSeqno", seq.ToString()); //支付顺序号 //替换模板中的键为对应的值 var newXmlStr = ReplaceHelper.ReplaceStringVar(xmlRd, ic); _xmlTool.SetXML(newXmlStr); _xmlTool.SetXMLNode("PayAmt", payment.amount.ToString("f0")); //必须是整数 newXmlStr = _xmlTool.GetXML(); return(newXmlStr); }