public static payAPIRequest ( string requestURL, string datastring, bool post ) : string | ||
requestURL | string | 完整的URL |
datastring | string | |
post | bool | 是否发生post请求 |
리턴 | string |
/// <summary> /// 将请求接口中的业务明文参数加密并请求一键支付接口,单不对返回的数据进行解密,用于获取清算对账单接口--商户通用接口 /// </summary> /// <param name="sd"></param> /// <param name="apiUri"></param> /// <returns></returns> private string createMerchantDataAndRequestYb2(SortedDictionary <string, object> sd, string apiUri, bool ispost) { //随机生成商户AESkey string merchantAesKey = AES.GenerateAESKey(); //生成RSA签名 string sign = EncryptUtil.handleRSA(sd, merchantPrivatekey); sd.Add("sign", sign); //将对象转换为json字符串 string bpinfo_json = Newtonsoft.Json.JsonConvert.SerializeObject(sd); string datastring = AES.Encrypt(bpinfo_json, merchantAesKey); //将商户merchantAesKey用RSA算法加密 string encryptkey = RSAFromPkcs8.encryptData(merchantAesKey, yibaoPublickey, "UTF-8"); String ybResult = ""; if (ispost) { ybResult = YJPayUtil.payAPIRequest(apimercahntprefix + apiUri, datastring, encryptkey, true); } else { ybResult = YJPayUtil.payAPIRequest(apimercahntprefix + apiUri, datastring, encryptkey, false); } return(YJPayUtil.checkYbClearResult(ybResult)); }
public ActionResult YeePay(string orderNo) { //var order = OrderContract.OrderInfos.Where(p => p.OrderNo == orderNo).SingleOrDefault(); //if (order == null) return Content("订单不存在"); string serverHost = ConfigurationManager.AppSettings["ServerHost"]; //一键支付URL前缀 string apiprefix = APIURLConfig.mobilePrefix; //网页支付地址 string mobilepayURI = APIURLConfig.webpayURI; //商户账户编号 string customernumber = YeePayConfig.merchantAccount; string hmacKey = YeePayConfig.merchantKey; string AesKey = YeePayConfig.AescKey; //日志字符串 StringBuilder logsb = new StringBuilder(); logsb.Append(DateTime.Now.ToString() + "\n"); Random ra = new Random(); string payproducttype = "ONEKEY"; // "支付方式"; string amount = /*order.TotalPrice + */ ""; //支付金额为单位元 string requestid = orderNo; //订单号 string productcat = ""; //商品类别码,商户支持的商品类别码由易宝支付运营人员根据商务协议配置 string productdesc = "订单商品"; //商品描述 string productname = "订单商品"; //商品名称 string assure = "0"; //是否需要担保,1是,0否 string divideinfo = ""; //分账信息,格式”ledgerNo:分账比 string bankid = ""; //银行编码 string period = ""; //担保有效期,单位 :天;当assure=1 时必填,最大值:30 string memo = ""; //商户备注 string userno = /*order.UserInfo.Id +*/ ""; //用户标识 string ip = ""; //IP string cardname = ""; //持卡人姓名 string idcard = ""; //身份证 string bankcardnum = ""; //银行卡号 //商户提供的商户后台系统异步支付回调地址 string callbackurl = string.Format("{0}Admin/Pay/YeePayNotifyUrl", serverHost); //商户提供的商户前台系统异步支付回调地址 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("userno", userno); sd.Add("ip", ip); sd.Add("cardname", cardname); sd.Add("idcard", idcard); sd.Add("bankcardnum", bankcardnum); 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"); string ybResult = YJPayUtil.payAPIRequest(apiprefix + mobilepayURI, datastring, false); logsb.Append("请求支付结果:" + ybResult + "\n"); //将支付结果json字符串反序列化为对象 RespondJson respJson = Newtonsoft.Json.JsonConvert.DeserializeObject <RespondJson>(ybResult); string yb_data = respJson.data; yb_data = AESUtil.Decrypt(yb_data, YeePayConfig.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) { //重定向跳转到易宝支付收银台 return(Redirect(result.payurl)); } else { return(Content("回调验签失败")); } } else { return(Content(result.msg)); } }