/// <summary> /// 掌柜通支付通知信息 /// </summary> /// <param name="data"></param> public void Notify(string data) { data = AESUtil.Decrypt(data, MerchantKey); PayResultJson result = Newtonsoft.Json.JsonConvert.DeserializeObject <PayResultJson>(data); string opstate = "1"; ///支付结果回调验签 bool r = Digest.PayResultVerifyHMAC(result.customernumber, result.requestid, result.code, result.notifytype, result.externalid, result.amount, result.cardno, this.MerchantKey, result.hmac); if (r) { if (result.code == 1) { decimal amt = 0; string msg = string.Empty; if (decimal.TryParse(result.amount, out amt)) { opstate = "0"; msg = "成功"; } OrderBankUtils.SuppNotify(suppid, "", result.requestid , 2 , opstate , msg , amt , amt , "Success" , "Failure"); } } }
/// <summary> /// 支付信息提交 /// </summary> /// <param name="orderid">订单号</param> /// <param name="orderAmt">金额(元)</param> /// <param name="autoSubmit">是否自动提交</param> /// <returns></returns> public string PayBank(string orderid, decimal orderAmt, string bankCode, bool autoSubmit) { //请求移动终端网页收银台支付 //一键支付URL前缀 string apiprefix = APIURLConfig.mobilePrefix; //网页支付地址 string mobilepayURI = APIURLConfig.webpayURI; //商户账户编号 string customernumber = this.MerchantAccount; string hmacKey = this.MerchantKey; string AesKey = this.AesKey; //日志字符串 StringBuilder logsb = new StringBuilder(); logsb.Append(DateTime.Now.ToString() + "\n"); Random ra = new Random(); string payproducttype = "SALES"; // "支付方式"; string requestid = orderid; //订单号 string amount = orderAmt.ToString(); //金额 string productcat = ""; //商品类别码,商户支持的商品类别码由易宝支付运营人员根据商务协议配置 string productdesc = ""; //商品描述 string productname = "在线储值"; //商品名称 string assure = "0"; //是否需要担保,1是,0否 string divideinfo = ""; //分账信息,格式”ledgerNo:分账比 string bankid = GetBankCode(bankCode); //银行编码 string period = ""; //担保有效期,单位 :天;当assure=1 时必填,最大值:30 string memo = ""; //商户备注 //商户提供的商户后台系统异步支付回调地址 string callbackurl = CallbackUrl; //商户提供的商户前台系统异步支付回调地址 string webcallbackurl = ""; string hmac = ""; hmac = Digest.GetHMAC(customernumber, requestid, amount, assure, productname, productcat, productdesc, divideinfo, callbackurl, webcallbackurl, bankid, period, memo, hmacKey); SortedDictionary <string, object> sd = new SortedDictionary <string, object>(); sd.Add("customernumber", customernumber); sd.Add("amount", amount); sd.Add("requestid", requestid); sd.Add("assure", assure); sd.Add("productname", productname); sd.Add("productcat", productcat); sd.Add("productdesc", productdesc); sd.Add("divideinfo", divideinfo); sd.Add("callbackurl", callbackurl); sd.Add("webcallbackurl", webcallbackurl); sd.Add("bankid", bankid); sd.Add("period", period); sd.Add("memo", memo); sd.Add("payproducttype", payproducttype); sd.Add("hmac", hmac); //将网页支付对象转换为json字符串 string wpinfo_json = Newtonsoft.Json.JsonConvert.SerializeObject(sd); logsb.Append("网银支付明文数据json格式为:" + wpinfo_json + "\n"); string datastring = AESUtil.Encrypt(wpinfo_json, AesKey); logsb.Append("网银支付业务数据经过AES加密后的值为:" + datastring + "\n"); //打开浏览器访问一键支付网页支付链接地址,请求方式为get string postParams = "data=" + HttpUtility.UrlEncode(datastring) + "&customernumber=" + customernumber; string url = apiprefix + mobilepayURI + "?" + postParams; logsb.Append("网银支付链接地址为:" + url + "\n"); #if DEBUG SoftLog.LogStr(logsb.ToString(), "ECPayLog"); #endif string ybResult = YJPayUtil.payAPIRequest(apiprefix + mobilepayURI, datastring, false, this.MerchantAccount); logsb.Append("请求支付结果:" + ybResult + "\n"); //返回的PayForm string payForm = string.Empty; //将支付结果json字符串反序列化为对象 RespondJson respJson = Newtonsoft.Json.JsonConvert.DeserializeObject <RespondJson>(ybResult); string yb_data = respJson.data; if (string.IsNullOrEmpty(yb_data)) { payForm = ybResult; return(payForm); } yb_data = AESUtil.Decrypt(yb_data, this.MerchantKey); PayRequestJson result = Newtonsoft.Json.JsonConvert.DeserializeObject <PayRequestJson>(yb_data); if (result.code == 1) { bool r = Digest.PayRequestVerifyHMAC(result.customernumber, result.requestid, result.code, result.externalid, result.amount, result.payurl, hmacKey, result.hmac); if (r) { HttpContext.Current.Response.Redirect(result.payurl); //重定向跳转到易宝支付收银台 payForm = "<form id='frm1' action='" + result.payurl + "' method='get'></form>"; payForm += "<script type='text/javascript' language='javascript'>setTimeout(document.getElementById('frm1').submit(),100);</script>"; } else { payForm = "回调验签失败"; } } else { payForm = result.msg; } return(payForm); }