protected void Page_Load(object sender, EventArgs e) { if (!IsPostBack) { // 校验返回数据包 BuyCallbackResult result = Buy.VerifyCallback(FormatQueryString.GetQueryString("p1_MerId"), FormatQueryString.GetQueryString("r0_Cmd"), FormatQueryString.GetQueryString("r1_Code"), FormatQueryString.GetQueryString("r2_TrxId"), FormatQueryString.GetQueryString("r3_Amt"), FormatQueryString.GetQueryString("r4_Cur"), FormatQueryString.GetQueryString("r5_Pid"), FormatQueryString.GetQueryString("r6_Order"), FormatQueryString.GetQueryString("r7_Uid"), FormatQueryString.GetQueryString("r8_MP"), FormatQueryString.GetQueryString("r9_BType"), FormatQueryString.GetQueryString("rp_PayDate"), FormatQueryString.GetQueryString("hmac")); if (string.IsNullOrEmpty(result.ErrMsg)) { if (result.R1_Code == "1") { if (result.R9_BType == "1") { // callback方式:浏览器重定向 Response.Write("支付成功!<br>商品ID:" + result.R5_Pid + "<br>商户订单号:" + result.R6_Order + "<br>支付金额:" + result.R3_Amt + "<br>易宝支付交易流水号:" + result.R2_TrxId + "<BR>"); } else if (result.R9_BType == "2") { // * 如果是服务器返回则需要回应一个特定字符串'SUCCESS',且在'SUCCESS'之前不可以有任何其他字符输出,保证首先输出的是'SUCCESS'字符串 Response.Write("SUCCESS"); } } else { Response.Write("支付失败!"); } } else { Response.Write("交易签名无效!"); } } }
/// <summary> /// 获取支付成功返回信息 /// </summary> /// <param name="p1_MerId">商户编号</param> /// <param name="keyValue">商户密钥</param> /// <returns></returns> private BuyCallbackResult GetPayResult() { BuyCallbackResult payResult = Buy.VerifyCallback(FormatQueryString.GetQueryString("p1_MerId"), keyValue, FormatQueryString.GetQueryString("r0_Cmd"), FormatQueryString.GetQueryString("r1_Code"), FormatQueryString.GetQueryString("r2_TrxId"), FormatQueryString.GetQueryString("r3_Amt"), FormatQueryString.GetQueryString("r4_Cur"), FormatQueryString.GetQueryString("r5_Pid"), FormatQueryString.GetQueryString("r6_Order"), FormatQueryString.GetQueryString("r7_Uid"), FormatQueryString.GetQueryString("r8_MP"), FormatQueryString.GetQueryString("r9_BType"), FormatQueryString.GetQueryString("rp_PayDate"), FormatQueryString.GetQueryString("hmac")); return(payResult); }
/// <summary> /// 退款 /// </summary> /// <param name="p1_MerId">商户编号</param> /// <param name="keyValue">商户密钥</param> /// <param name="pb_TrxId">yeepay流水号</param> /// <param name="p3_Amt">退款金额</param> /// <param name="p4_Cur">币种</param> /// <param name="p5_Desc">退款说明</param> /// <returns></returns> public static BuyRefundOrdResult RefundOrd(string pb_TrxId, string p3_Amt, string p4_Cur, string p5_Desc) { string sbOld = ""; sbOld += "RefundOrd"; sbOld += merchantId; sbOld += pb_TrxId; sbOld += p3_Amt; sbOld += p4_Cur; sbOld += p5_Desc; string hmac = Digest.HmacSign(sbOld, keyValue); logstr(pb_TrxId, sbOld, hmac); string para = ""; para += "?p0_Cmd=RefundOrd"; para += "&p1_MerId=" + merchantId; //加入商家ID para += "&pb_TrxId=" + pb_TrxId; para += "&p3_Amt=" + p3_Amt; //加入购买订单号码 para += "&p4_Cur=" + p4_Cur; para += "&p5_Desc=" + HttpUtility.UrlEncode(p5_Desc, System.Text.Encoding.GetEncoding("gb2312")); para += "&hmac=" + hmac; //加入校验码 logstr(pb_TrxId, queryRefundReqURL + para, ""); string reqResult = HttpUtils.SendRequest(queryRefundReqURL, para); //记录退款通讯返回 logstr(pb_TrxId, reqResult, ""); string r0_Cmd = FormatQueryString.GetQueryString("r0_Cmd", reqResult, '\n'); string r1_Code = FormatQueryString.GetQueryString("r1_Code", reqResult, '\n'); string r2_TrxId = FormatQueryString.GetQueryString("r2_TrxId", reqResult, '\n'); string r3_Amt = FormatQueryString.GetQueryString("r3_Amt", reqResult, '\n'); string r4_Cur = FormatQueryString.GetQueryString("r4_Cur", reqResult, '\n'); hmac = FormatQueryString.GetQueryString("hmac", reqResult, '\n'); //校验返回的hmac sbOld = ""; sbOld += r0_Cmd; sbOld += r1_Code; sbOld += r2_TrxId; sbOld += r3_Amt; sbOld += r4_Cur; string nhmac = Digest.HmacSign(sbOld, keyValue); logstr("退款返回流水号:" + r2_TrxId, sbOld, nhmac); if (hmac == nhmac) { BuyRefundOrdResult result = new BuyRefundOrdResult(r0_Cmd, r1_Code, r2_TrxId, r3_Amt, r4_Cur, hmac, ""); return(result); } else { BuyRefundOrdResult result = new BuyRefundOrdResult(r0_Cmd, r1_Code, r2_TrxId, r3_Amt, r4_Cur, hmac, "交易签名无效"); return(result); } }
/// <summary> /// /// </summary> public void Return() { string opstate = "-1"; int status = 4; BuyCallbackResult result = Buy.VerifyCallback(SuppAccount , SuppKey , FormatQueryString.GetQueryString("r0_Cmd") , FormatQueryString.GetQueryString("r1_Code") , FormatQueryString.GetQueryString("r2_TrxId") , FormatQueryString.GetQueryString("r3_Amt") , FormatQueryString.GetQueryString("r4_Cur") , FormatQueryString.GetQueryString("r5_Pid") , FormatQueryString.GetQueryString("r6_Order") , FormatQueryString.GetQueryString("r7_Uid") , FormatQueryString.GetQueryString("r8_MP") , FormatQueryString.GetQueryString("r9_BType") , FormatQueryString.GetQueryString("rp_PayDate") , FormatQueryString.GetQueryString("hmac")); if (string.IsNullOrEmpty(result.ErrMsg)) { string msg = "支付失败"; if (result.R1_Code == "1") { msg = "支付成功"; opstate = "0"; status = 2; } decimal tranAmt = 0M; decimal.TryParse(result.R3_Amt, out tranAmt); if (result.R9_BType == "1") { OrderBankUtils.SuppPageReturn(SuppId , result.R6_Order , result.R2_TrxId , status , opstate , msg , tranAmt, 0M); } else if ((result.R9_BType == "2") || (result.R9_BType == "3")) { OrderBankUtils.SuppNotify(SuppId , result.R6_Order , result.R2_TrxId , status , opstate , msg , tranAmt, tranAmt , Succflag , Failflag); } } }
public static global::viviapi.ETAPI.YeePay.Lib.com.yeepay.cmbn.SZXResult AnnulCard(string keyValue, string p1_MerId, string p2_Order, string p3_Amt, string p4_verifyAmt, string p5_Pid, string p6_Pcat, string p7_Pdesc, string p8_Url, string pa_MP, string pa7_cardAmt, string pa8_cardNo, string pa9_cardPwd, string pd_FrpId, string pr_NeedResponse, string pz_userId, string pz1_userRegTime) { string aValue = ""; aValue = ((((((((aValue + "ChargeCardDirect") + p1_MerId + p2_Order) + p3_Amt + p4_verifyAmt) + p5_Pid + p6_Pcat) + p7_Pdesc + p8_Url) + pa_MP + pa7_cardAmt) + pa8_cardNo + pa9_cardPwd) + pd_FrpId + pr_NeedResponse) + pz_userId + pz1_userRegTime; string hmac = Digest.HmacSign(aValue, keyValue); logHmac(p2_Order, aValue, keyValue, hmac); string para = ""; para = (((((((((((((((((para + "?p0_Cmd=ChargeCardDirect") + "&p1_MerId=" + p1_MerId) + "&p2_Order=" + p2_Order) + "&p3_Amt=" + p3_Amt) + "&p4_verifyAmt=" + p4_verifyAmt) + "&p5_Pid=" + HttpUtility.UrlEncode(p5_Pid, Encoding.GetEncoding("gb2312"))) + "&p6_Pcat=" + HttpUtility.UrlEncode(p6_Pcat, Encoding.GetEncoding("gb2312"))) + "&p7_Pdesc=" + HttpUtility.UrlEncode(p7_Pdesc, Encoding.GetEncoding("gb2312"))) + "&p8_Url=" + HttpUtility.UrlEncode(p8_Url, Encoding.GetEncoding("gb2312"))) + "&pa_MP=" + HttpUtility.UrlEncode(pa_MP, Encoding.GetEncoding("gb2312"))) + "&pa7_cardAmt=" + HttpUtility.UrlEncode(pa7_cardAmt, Encoding.GetEncoding("gb2312"))) + "&pa8_cardNo=" + HttpUtility.UrlEncode(pa8_cardNo, Encoding.GetEncoding("gb2312"))) + "&pa9_cardPwd=" + HttpUtility.UrlEncode(pa9_cardPwd, Encoding.GetEncoding("gb2312"))) + "&pd_FrpId=" + pd_FrpId) + "&pr_NeedResponse=" + pr_NeedResponse) + "&pz_userId=" + pz_userId) + "&pz1_userRegTime=" + HttpUtility.UrlEncode(pz1_userRegTime, Encoding.GetEncoding("gb2312"))) + "&hmac=" + hmac; logURL(_nodeAuthorizationUrl + para); string reqResult = HttpUtils.SendRequest(_nodeAuthorizationUrl, para); logReqResult(reqResult); string str5 = FormatQueryString.GetQueryString("r0_Cmd", reqResult, '\n'); string str6 = FormatQueryString.GetQueryString("r1_Code", reqResult, '\n'); string str7 = FormatQueryString.GetQueryString("r6_Order", reqResult, '\n'); string str8 = FormatQueryString.GetQueryString("rq_ReturnMsg", reqResult, '\n'); return(new global::viviapi.ETAPI.YeePay.Lib.com.yeepay.cmbn.SZXResult(str5, str6, str7, str8, FormatQueryString.GetQueryString("hmac", reqResult, '\n'), _nodeAuthorizationUrl + para, reqResult)); }
protected void Page_Load(object sender, EventArgs e) { if (!IsPostBack) { SZX.logURL(Request.RawUrl); // 校验返回数据包 SZXCallbackResult result = SZX.VerifyCallback(FormatQueryString.GetQueryString("r0_Cmd"), FormatQueryString.GetQueryString("r1_Code"), FormatQueryString.GetQueryString("p1_MerId"), FormatQueryString.GetQueryString("p2_Order"), FormatQueryString.GetQueryString("p3_Amt"), FormatQueryString.GetQueryString("p4_FrpId"), FormatQueryString.GetQueryString("p5_CardNo"), FormatQueryString.GetQueryString("p6_confirmAmount"), FormatQueryString.GetQueryString("p7_realAmount"), FormatQueryString.GetQueryString("p8_cardStatus"), FormatQueryString.GetQueryString("p9_MP"), FormatQueryString.GetQueryString("pb_BalanceAmt"), FormatQueryString.GetQueryString("pc_BalanceAct"), FormatQueryString.GetQueryString("hmac")); if (string.IsNullOrEmpty(result.ErrMsg)) { // 使用应答机制时 必须回写success Response.Write("SUCCESS"); //在接收到支付结果通知后,判断是否进行过业务逻辑处理,不要重复进行业务逻辑处理 Logic(result); } else { HmacError(result); } } }
/// <summary> /// 获取支付成功返回信息 /// </summary> /// <param name="actionData"></param> /// <param name="actionMsg"></param> /// <returns></returns> public WKT.Model.FinancePayDetailEntity GetPayResult(Action <String> actionMsg) { BuyCallbackResult result = GetPayResult(); if (!string.IsNullOrEmpty(result.ErrMsg)) { actionMsg("交易签名无效!"); return(null); } if (result.R1_Code.Equals("1")) { actionMsg("支付成功!"); WKT.Model.FinancePayDetailEntity model = new Model.FinancePayDetailEntity(); //model.BankID = result.R6_Order; model.TransactionID = result.R2_TrxId; model.Currency = result.R4_Cur; model.TotalFee = Convert.ToDecimal(result.R3_Amt); model.IsInCome = 1; model.PayStatus = 1; model.UserAccount = ""; model.BankID = FormatQueryString.GetQueryString("rb_BankId"); model.BankNo = FormatQueryString.GetQueryString("ro_BankOrderId"); string[] arrMP = result.R8_MP.Split(','); model.PayType = arrMP[0].TryParse <Byte>(); model.ProductTable = arrMP[1]; model.ProductID = arrMP[2]; model.ProductDes = arrMP[3]; model.NoticeID = arrMP[4].TryParse <Int64>(); return(model); } else { actionMsg("支付失败!"); return(null); } }
public static QueryOrdResult QueryOrder(string p1_MerId, string keyValue, string p2_Order) { string aValue = ""; aValue = (aValue + "QueryOrdDetail") + p1_MerId + p2_Order; string para = ""; para = (((para + "?p0_Cmd=QueryOrdDetail") + "&p1_MerId=" + p1_MerId) + "&p2_Order=" + p2_Order) + "&hmac=" + Digest.HmacSign(aValue, keyValue); string strUrl = HttpUtils.SendRequest(nodeAuthorizationURL, para); string str4 = FormatQueryString.GetQueryString("r0_Cmd", strUrl, '\n'); string returnCode = FormatQueryString.GetQueryString("r1_Code", strUrl, '\n'); string returnTrxId = FormatQueryString.GetQueryString("r2_TrxId", strUrl, '\n'); string returnAmt = FormatQueryString.GetQueryString("r3_Amt", strUrl, '\n'); string str8 = FormatQueryString.GetQueryString("r4_Cur", strUrl, '\n'); string returnPid = FormatQueryString.GetQueryString("r5_Pid", strUrl, '\n'); string returnOrder = FormatQueryString.GetQueryString("r6_Order", strUrl, '\n'); string returnAllPara = FormatQueryString.GetQueryString("r8_MP", strUrl, '\n'); string returnStatus = FormatQueryString.GetQueryString("rb_PayStatus", strUrl, '\n'); string returnRefundCount = FormatQueryString.GetQueryString("rc_RefundCount", strUrl, '\n'); string str14 = FormatQueryString.GetQueryString("rd_RefundAmt", strUrl, '\n'); string str15 = FormatQueryString.GetQueryString("hmac", strUrl, '\n'); return(new QueryOrdResult(returnCode, returnTrxId, returnAmt, returnPid, returnOrder, returnStatus, returnAllPara, returnAmt, returnRefundCount)); }
/// <summary> /// 查询订单明细 /// </summary> /// <param name="p1_MerId">商户编号</param> /// <param name="keyValue">商户密钥</param> /// <param name="p2_Order">商户订单号</param> /// <returns>BuyQueryOrdDetailResult</returns> public static BuyQueryOrdDetailResult QueryOrdDetail(string p2_Order) { string sbOld = ""; sbOld += "QueryOrdDetail"; sbOld += merchantId; sbOld += p2_Order; string hmac = Digest.HmacSign(sbOld, keyValue); logstr(p2_Order, sbOld, hmac); string para = ""; para += "?p0_Cmd=QueryOrdDetail"; para += "&p1_MerId=" + merchantId; //加入商家ID para += "&p2_Order=" + p2_Order; //加入购买订单号码 para += "&hmac=" + hmac; //加入校验码 logstr(p2_Order, queryRefundReqURL + para, ""); string reqResult = HttpUtils.SendRequest(queryRefundReqURL, para); //记录查询通讯返回 logstr(p2_Order, reqResult, ""); string r0_Cmd = FormatQueryString.GetQueryString("r0_Cmd", reqResult, '\n'); string r1_Code = FormatQueryString.GetQueryString("r1_Code", reqResult, '\n'); string p1_MerId = FormatQueryString.GetQueryString("p1_MerId", reqResult, '\n'); string r2_TrxId = FormatQueryString.GetQueryString("r2_TrxId", reqResult, '\n'); string r3_Amt = FormatQueryString.GetQueryString("r3_Amt", reqResult, '\n'); string r4_Cur = FormatQueryString.GetQueryString("r4_Cur", reqResult, '\n'); string r5_Pid = FormatQueryString.GetQueryString("r5_Pid", reqResult, '\n'); string r6_Order = FormatQueryString.GetQueryString("r6_Order", reqResult, '\n'); string r8_MP = FormatQueryString.GetQueryString("r8_MP", reqResult, '\n'); string rb_PayStatus = FormatQueryString.GetQueryString("rb_PayStatus", reqResult, '\n'); string rc_RefundCount = FormatQueryString.GetQueryString("rc_RefundCount", reqResult, '\n'); string rd_RefundAmt = FormatQueryString.GetQueryString("rd_RefundAmt", reqResult, '\n'); hmac = FormatQueryString.GetQueryString("hmac", reqResult, '\n'); //查单返回校验hmac sbOld = ""; sbOld += r0_Cmd; sbOld += r1_Code; sbOld += p1_MerId; sbOld += r2_TrxId; sbOld += r3_Amt; sbOld += r4_Cur; sbOld += r5_Pid; sbOld += r6_Order; sbOld += r8_MP; sbOld += rb_PayStatus; sbOld += rc_RefundCount; sbOld += rd_RefundAmt; string nhmac = Digest.HmacSign(sbOld, keyValue); logstr(p2_Order, sbOld, nhmac); if (hmac == nhmac) { BuyQueryOrdDetailResult result = new BuyQueryOrdDetailResult(r0_Cmd, r1_Code, r2_TrxId, r3_Amt, r4_Cur, r5_Pid, r6_Order, r8_MP, rb_PayStatus, rc_RefundCount, rd_RefundAmt, hmac, ""); return(result); } else { BuyQueryOrdDetailResult result = new BuyQueryOrdDetailResult(r0_Cmd, r1_Code, r2_TrxId, r3_Amt, r4_Cur, r5_Pid, r6_Order, r8_MP, rb_PayStatus, rc_RefundCount, rd_RefundAmt, hmac, "交易签名无效"); return(result); } }
public ActionResult CallBack() { Buy.logstr(FormatQueryString.GetQueryString("r6_Order"), Request.Url.Query, ""); BuyCallbackResult result = Buy.VerifyCallback(FormatQueryString.GetQueryString("p1_MerId"), FormatQueryString.GetQueryString("r0_Cmd"), FormatQueryString.GetQueryString("r1_Code"), FormatQueryString.GetQueryString("r2_TrxId"), FormatQueryString.GetQueryString("r3_Amt"), FormatQueryString.GetQueryString("r4_Cur"), FormatQueryString.GetQueryString("r5_Pid"), FormatQueryString.GetQueryString("r6_Order"), FormatQueryString.GetQueryString("r7_Uid"), FormatQueryString.GetQueryString("r8_MP"), FormatQueryString.GetQueryString("r9_BType"), FormatQueryString.GetQueryString("rp_PayDate"), FormatQueryString.GetQueryString("hmac")); if (string.IsNullOrEmpty(result.ErrMsg)) { //在接收到支付结果通知后,判断是否进行过业务逻辑处理,不要重复进行业务逻辑处理 if (result.R1_Code == "1") { order = om.GetOrder(result.R6_Order); if (result.R9_BType == "1") { try { if (order.State == 0) { if (om.UpdateOrder(result.R6_Order)) { result_info = "您的订单:" + result.R6_Order + "已支付成功!"; isok = true; //gu = gum.GetGameUser(order.UserName); #region 返利券暂未开放 //是否使用返利券 //if (order.RebateId > 0) //{ // //返利券暂未开放 //} //else //{ // if (order.ConvertId > 0) // { // // new DAL.convertnum().UpdateField(order.convertid, " state=1,usergettime='" + DateTime.Now.ToString() + "'"); // } // else // { // string scale1 = new DAL.rebatetype().GetRange(order.PayMoney); //获得返利比 // if (!string.IsNullOrEmpty(scale1)) // { // //生成返利券 // Model.rebatenum rebatenum = new Model.rebatenum(); // Random ran = new Random(); // string code5 = ran.Next(10, 99).ToString(); // string no1 = DateTime.Now.ToString("yyyyMMddhhmmss") + DateTime.Now.Millisecond; // rebatenum.no = code5 + no1.Substring(2, no1.Length - 2); // rebatenum.pwd = "000"; // rebatenum.num = int.Parse(scale1); // rebatenum.userid = gu.Id; // rebatenum.typeid = 0; // new DAL.rebatenum().Add(rebatenum); // } // } //} #endregion //根据订单进行充值 result_info = gm.PayManager(result.R6_Order); } else { result_info = "您的订单:" + result.R6_Order + "更新订单状态失败!"; } } else { return(RedirectToAction("Index", "Home")); } } catch (Exception ex) { result_info = "出错啦!" + ex.Message; } } else if (result.R9_BType == "2") { Response.Write("SUCCESS"); try { if (order.State == 0) { if (om.UpdateOrder(result.R6_Order)) { result_info = "您的订单:" + result.R6_Order + "已支付成功!"; isok = true; //gu = gum.GetGameUser(order.UserName); #region 返利券暂未开放 //是否使用返利券 //if (order.RebateId > 0) //{ // //返利券暂未开放 //} //else //{ // if (order.ConvertId > 0) // { // // new DAL.convertnum().UpdateField(order.convertid, " state=1,usergettime='" + DateTime.Now.ToString() + "'"); // } // else // { // string scale1 = new DAL.rebatetype().GetRange(order.PayMoney); //获得返利比 // if (!string.IsNullOrEmpty(scale1)) // { // //生成返利券 // Model.rebatenum rebatenum = new Model.rebatenum(); // Random ran = new Random(); // string code5 = ran.Next(10, 99).ToString(); // string no1 = DateTime.Now.ToString("yyyyMMddhhmmss") + DateTime.Now.Millisecond; // rebatenum.no = code5 + no1.Substring(2, no1.Length - 2); // rebatenum.pwd = "000"; // rebatenum.num = int.Parse(scale1); // rebatenum.userid = gu.Id; // rebatenum.typeid = 0; // new DAL.rebatenum().Add(rebatenum); // } // } //} #endregion //根据订单进行充值 result_info = gm.PayManager(result.R6_Order); } else { result_info = "您的订单:" + result.R6_Order + "更新订单状态失败!"; } } else { return(RedirectToAction("Index", "Home")); } } catch (Exception ex) { result_info = "出错啦!" + ex.Message; } } } else { result_info = "支付失败!"; } } else { result_info = "交易签名无效!"; } ViewData["ImgUrl"] = "../Images/onebit_33.png"; if (isok) { ViewData["ImgUrl"] = "../Images/onebit_34.png"; } ViewData["Msg"] = result_info; return(View()); }
/// <summary> /// 非银行卡支付支付请求(通讯) /// </summary> /// <param name="p1_MerId">商户编号</param> /// <param name="keyValue">商户密钥</param> /// <param name="p2_Order">订单号</param> /// <param name="p3_Amt">支付卡金额</param> /// <param name="p8_Url">回报Url</param> /// <param name="pa_MP">商户扩展参数</param> /// <param name="pa7_cardNo">支付卡序列号</param> /// <param name="pa8_cardPwd">支付卡密码</param> /// <param name="pd_FrpId">银行编码</param> /// <param name="pa0_Mode">支付卡支付传递模式</param> /// <param name="pr_NeedResponse">应答机制</param> /// <returns>SZXResult</returns> public static SZXResult AnnulCard(string p2_Order, string p3_Amt, string p4_verifyAmt, string p5_Pid, string p6_Pcat, string p7_Pdesc, string p8_Url, string pa_MP, string pa7_cardAmt, string pa8_cardNo, string pa9_cardPwd, string pd_FrpId, string pr_NeedResponse, string pz_userId, string pz1_userRegTime) { if (ub.GetSub("FinanceAmtType", "/Controls/finance.xml") == "1") { merchantId = ub.GetSub("FinanceSZXNo", "/Controls/finance.xml"); keyValue = ub.GetSub("FinanceSZXPass", "/Controls/finance.xml"); } string sbOld = ""; sbOld += "ChargeCardDirect"; sbOld += merchantId; sbOld += p2_Order; sbOld += p3_Amt; sbOld += p4_verifyAmt; sbOld += p5_Pid; sbOld += p6_Pcat; sbOld += p7_Pdesc; sbOld += p8_Url; sbOld += pa_MP; sbOld += pa7_cardAmt; sbOld += pa8_cardNo; sbOld += pa9_cardPwd; sbOld += pd_FrpId; sbOld += pr_NeedResponse; sbOld += pz_userId; sbOld += pz1_userRegTime; string hmac = Digest.HmacSign(sbOld, keyValue); logHmac(p2_Order, sbOld, keyValue, hmac); string para = ""; para += "?p0_Cmd=ChargeCardDirect"; para += "&p1_MerId=" + merchantId; para += "&p2_Order=" + p2_Order; para += "&p3_Amt=" + p3_Amt; para += "&p4_verifyAmt=" + p4_verifyAmt; para += "&p5_Pid=" + System.Web.HttpUtility.UrlEncode(p5_Pid, System.Text.Encoding.GetEncoding("gb2312")); para += "&p6_Pcat=" + System.Web.HttpUtility.UrlEncode(p6_Pcat, System.Text.Encoding.GetEncoding("gb2312")); para += "&p7_Pdesc=" + System.Web.HttpUtility.UrlEncode(p7_Pdesc, System.Text.Encoding.GetEncoding("gb2312")); para += "&p8_Url=" + System.Web.HttpUtility.UrlEncode(p8_Url, System.Text.Encoding.GetEncoding("gb2312")); para += "&pa_MP=" + System.Web.HttpUtility.UrlEncode(pa_MP, System.Text.Encoding.GetEncoding("gb2312")); para += "&pa7_cardAmt=" + System.Web.HttpUtility.UrlEncode(pa7_cardAmt, System.Text.Encoding.GetEncoding("gb2312")); para += "&pa8_cardNo=" + System.Web.HttpUtility.UrlEncode(pa8_cardNo, System.Text.Encoding.GetEncoding("gb2312")); para += "&pa9_cardPwd=" + System.Web.HttpUtility.UrlEncode(pa9_cardPwd, System.Text.Encoding.GetEncoding("gb2312")); para += "&pd_FrpId=" + pd_FrpId; para += "&pr_NeedResponse=" + pr_NeedResponse; para += "&pz_userId=" + pz_userId; para += "&pz1_userRegTime=" + System.Web.HttpUtility.UrlEncode(pz1_userRegTime, System.Text.Encoding.GetEncoding("gb2312")); para += "&hmac=" + hmac; logURL(nodeAuthorizationURL + para); string reqResult = HttpUtils.SendRequest(nodeAuthorizationURL, para); logReqResult(reqResult); string r0_Cmd = FormatQueryString.GetQueryString("r0_Cmd", reqResult, '\n'); string r1_Code = FormatQueryString.GetQueryString("r1_Code", reqResult, '\n'); string r6_Order = FormatQueryString.GetQueryString("r6_Order", reqResult, '\n'); string rq_ReturnMsg = FormatQueryString.GetQueryString("rq_ReturnMsg", reqResult, '\n'); hmac = FormatQueryString.GetQueryString("hmac", reqResult, '\n'); SZXResult result = new SZXResult(r0_Cmd, r1_Code, r6_Order, rq_ReturnMsg, hmac, nodeAuthorizationURL + para, reqResult); return(result); }
protected void Page_Load(object sender, EventArgs e) { Response.ContentEncoding = System.Text.Encoding.GetEncoding("GB2312"); if (!string.IsNullOrEmpty(FormatQueryString.GetQueryString("p1_MerId")) && !string.IsNullOrEmpty(FormatQueryString.GetQueryString("pz1_userRegTime"))) { #region 这是我的获取第三方接入过来的提交参数 origin_p1_MerId = System.Web.HttpUtility.UrlDecode(FormatQueryString.GetQueryString("p1_MerId"), System.Text.Encoding.GetEncoding("gb2312")); origin_p2_Order = System.Web.HttpUtility.UrlDecode(FormatQueryString.GetQueryString("p2_Order"), System.Text.Encoding.GetEncoding("gb2312")); p3_Amt = System.Web.HttpUtility.UrlDecode(FormatQueryString.GetQueryString("p3_Amt"), System.Text.Encoding.GetEncoding("gb2312")); p4_verifyAmt = System.Web.HttpUtility.UrlDecode(FormatQueryString.GetQueryString("p4_verifyAmt"), System.Text.Encoding.GetEncoding("gb2312")); p5_Pid = System.Web.HttpUtility.UrlDecode(FormatQueryString.GetQueryString("p5_Pid"), System.Text.Encoding.GetEncoding("gb2312")); p6_Pcat = System.Web.HttpUtility.UrlDecode(FormatQueryString.GetQueryString("p6_Pcat"), System.Text.Encoding.GetEncoding("gb2312")); p7_Pdesc = System.Web.HttpUtility.UrlDecode(FormatQueryString.GetQueryString("p7_Pdesc"), System.Text.Encoding.GetEncoding("gb2312")); origin_p8_Url = System.Web.HttpUtility.UrlDecode(FormatQueryString.GetQueryString("p8_Url"), System.Text.Encoding.GetEncoding("gb2312")); pa_MP = System.Web.HttpUtility.UrlDecode(FormatQueryString.GetQueryString("pa_MP"), System.Text.Encoding.GetEncoding("gb2312")); pa7_cardAmt = System.Web.HttpUtility.UrlDecode(FormatQueryString.GetQueryString("pa7_cardAmt"), System.Text.Encoding.GetEncoding("gb2312")); pa8_cardNo = System.Web.HttpUtility.UrlDecode(FormatQueryString.GetQueryString("pa8_cardNo"), System.Text.Encoding.GetEncoding("gb2312")); pa9_cardPwd = System.Web.HttpUtility.UrlDecode(FormatQueryString.GetQueryString("pa9_cardPwd"), System.Text.Encoding.GetEncoding("gb2312")); pd_FrpId = System.Web.HttpUtility.UrlDecode(FormatQueryString.GetQueryString("pd_FrpId"), System.Text.Encoding.GetEncoding("gb2312")); pr_NeedResponse = "1"; pz_userId = System.Web.HttpUtility.UrlDecode(FormatQueryString.GetQueryString("pz_userId"), System.Text.Encoding.GetEncoding("gb2312")); pz1_userRegTime = System.Web.HttpUtility.UrlDecode(FormatQueryString.GetQueryString("pz1_userRegTime"), System.Text.Encoding.GetEncoding("gb2312")); origin_hmac = FormatQueryString.GetQueryString("hmac"); #endregion #region 这是我修改提交的参数 p1_MerId = ConfigurationManager.AppSettings["p1_MerId"].ToString(); p8_Url = ConfigurationManager.AppSettings["p8_Url"].ToString(); p2_Order = "789" + origin_p2_Order; #endregion #region 业务逻辑的处理 #endregion SZXResult result = SZX.AnnulCard(p2_Order, p3_Amt, p4_verifyAmt, p5_Pid, p6_Pcat, p7_Pdesc, p8_Url, pa_MP, pa7_cardAmt, pa8_cardNo, pa9_cardPwd, pd_FrpId, pr_NeedResponse, pz_userId, pz1_userRegTime); #region 提交的返回值处理 //得到的返回的数值 string call_hmac = result.Hmac; string call_r0_cmd = result.R0_Cmd; string call_r1_code = result.R1_Code; string call_r6_order = result.R6_Order; string call_rq_returnmsg = result.Rq_ReturnMsg; string call_req_result = result.ReqResult; string real_call_req_result = ""; if (result.R1_Code.Equals("1")) { real_call_req_result = getReturnValue(call_r1_code, origin_p2_Order, call_rq_returnmsg, origin_hmac); } else { real_call_req_result = getReturnValue(call_r1_code, origin_p2_Order, call_rq_returnmsg, call_hmac); } Response.Write(real_call_req_result); #endregion //p1_MerId = FormatQueryString.GetQueryString("p1_MerId"); //p2_Order = FormatQueryString.GetQueryString("p2_Order"); //p3_Amt = FormatQueryString.GetQueryString("p3_Amt"); //p4_verifyAmt = FormatQueryString.GetQueryString("p4_verifyAmt"); //p5_Pid = FormatQueryString.GetQueryString("p5_Pid"); //p6_Pcat = FormatQueryString.GetQueryString("p6_Pcat"); //p7_Pdesc = FormatQueryString.GetQueryString("p7_Pdesc"); //p8_Url = FormatQueryString.GetQueryString("p8_Url"); //pa_MP = FormatQueryString.GetQueryString("pa_MP"); //pa7_cardAmt = FormatQueryString.GetQueryString("pa7_cardAmt"); //pa8_cardNo = FormatQueryString.GetQueryString("pa8_cardNo"); //pa9_cardPwd = FormatQueryString.GetQueryString("pa9_cardPwd"); //pd_FrpId = FormatQueryString.GetQueryString("pd_FrpId"); //pr_NeedResponse="1"; //pz_userId = FormatQueryString.GetQueryString("pz_userId"); //pz1_userRegTime = FormatQueryString.GetQueryString("pz1_userRegTime"); } }
protected void Page_Load(object sender, EventArgs e) { if (!IsPostBack) { // 校验返回数据包 BuyCallbackResult result = Buy.VerifyCallback(FormatQueryString.GetQueryString("p1_MerId"), FormatQueryString.GetQueryString("r0_Cmd"), FormatQueryString.GetQueryString("r1_Code"), FormatQueryString.GetQueryString("r2_TrxId"), FormatQueryString.GetQueryString("r3_Amt"), FormatQueryString.GetQueryString("r4_Cur"), FormatQueryString.GetQueryString("r5_Pid"), FormatQueryString.GetQueryString("r6_Order"), FormatQueryString.GetQueryString("r7_Uid"), FormatQueryString.GetQueryString("r8_MP"), FormatQueryString.GetQueryString("r9_BType"), FormatQueryString.GetQueryString("rp_PayDate"), FormatQueryString.GetQueryString("hmac")); if (string.IsNullOrEmpty(result.ErrMsg)) { //写易宝记录 ReturnYPDetailInfo resultYB = new ReturnYPDetailInfo(); resultYB.P1_MerId = FormatQueryString.GetQueryString("p1_MerId"); resultYB.R0_Cmd = FormatQueryString.GetQueryString("r0_Cmd"); resultYB.R1_Code = FormatQueryString.GetQueryString("r1_Code"); resultYB.R2_TrxId = FormatQueryString.GetQueryString("r2_TrxId"); resultYB.R3_Amt = Convert.ToDecimal(FormatQueryString.GetQueryString("r3_Amt")); resultYB.R4_Cur = FormatQueryString.GetQueryString("r4_Cur"); resultYB.R5_Pid = FormatQueryString.GetQueryString("r5_Pid"); resultYB.R6_Order = FormatQueryString.GetQueryString("r6_Order"); resultYB.R7_Uid = FormatQueryString.GetQueryString("r7_Uid"); resultYB.R8_MP = FormatQueryString.GetQueryString("r8_MP"); resultYB.R9_BType = FormatQueryString.GetQueryString("r9_BType"); resultYB.Rb_BankId = FormatQueryString.GetQueryString("rb_BankId"); resultYB.Ro_BankOrderId = FormatQueryString.GetQueryString("ro_BankOrderId"); resultYB.Rp_PayDate = FormatQueryString.GetQueryString("rp_PayDate"); resultYB.Rq_CardNo = FormatQueryString.GetQueryString("rq_CardNo"); resultYB.Ru_Trxtime = FormatQueryString.GetQueryString("ru_Trxtime"); resultYB.Hmac = FormatQueryString.GetQueryString("hmac"); treasureFacade.WriteReturnYBDetail(resultYB); if (result.R1_Code == "1") { if (result.R9_BType == "1") { // 写充值记录 ShareDetialInfo detailInfo = new ShareDetialInfo(); detailInfo.OrderID = resultYB.R6_Order; detailInfo.IPAddress = Utility.UserIP; detailInfo.PayAmount = resultYB.R3_Amt; treasureFacade.FilliedOnline(detailInfo, 0); // callback方式:浏览器重定向 Response.Write("支付成功!<br>商品ID:" + result.R5_Pid + "<br>商户订单号:" + result.R6_Order + "<br>支付金额:" + result.R3_Amt + "<br>易宝支付交易流水号:" + result.R2_TrxId + "<BR>"); } else if (result.R9_BType == "2") { // * 如果是服务器返回则需要回应一个特定字符串'SUCCESS',且在'SUCCESS'之前不可以有任何其他字符输出,保证首先输出的是'SUCCESS'字符串 Response.Write("SUCCESS"); } } else { Response.Write("支付失败!"); } } else { Response.Write("交易签名无效!"); } } }
protected void Page_Load(object sender, EventArgs e) { if (!IsPostBack) { // 校验返回数据包 Buy.logstr(FormatQueryString.GetQueryString("r6_Order"), Request.Url.Query, ""); BuyCallbackResult result = Buy.VerifyCallback(FormatQueryString.GetQueryString("p1_MerId"), FormatQueryString.GetQueryString("r0_Cmd"), FormatQueryString.GetQueryString("r1_Code"), FormatQueryString.GetQueryString("r2_TrxId"), FormatQueryString.GetQueryString("r3_Amt"), FormatQueryString.GetQueryString("r4_Cur"), FormatQueryString.GetQueryString("r5_Pid"), FormatQueryString.GetQueryString("r6_Order"), FormatQueryString.GetQueryString("r7_Uid"), FormatQueryString.GetQueryString("r8_MP"), FormatQueryString.GetQueryString("r9_BType"), FormatQueryString.GetQueryString("rp_PayDate"), FormatQueryString.GetQueryString("hmac")); if (string.IsNullOrEmpty(result.ErrMsg)) { //在接收到支付结果通知后,判断是否进行过业务逻辑处理,不要重复进行业务逻辑处理 if (result.R1_Code == "1") { if (result.R9_BType == "1") { Request.Cookies.Remove("ErrorMsg"); Response.Redirect("/showPayInfo.html"); // callback方式:浏览器重定向 // Response.Write("支付成功!" + // "<br>接口类型:" + result.R0_Cmd + // "<br>返回码:" + result.R1_Code + //"<br>商户号:" + result.P1_MerId + // "<br>交易流水号:" + result.R2_TrxId + // "<br>商户订单号:" + result.R6_Order + // "<br>交易金额:" + result.R3_Amt + // "<br>交易币种:" + result.R4_Cur + // "<br>订单完成时间:" + result.Rp_PayDate + // "<br>回调方式:" + result.R9_BType + // "<br>错误信息:" + result.ErrMsg + "<BR>"); } else if (result.R9_BType == "2") { // * 如果是服务器返回则需要回应一个特定字符串'SUCCESS',且在'SUCCESS'之前不可以有任何其他字符输出,保证首先输出的是'SUCCESS'字符串 Response.Write("SUCCESS"); ShareDetialInfo detailInfo = new ShareDetialInfo(); detailInfo.OrderID = result.R6_Order; detailInfo.IPAddress = Utility.UserIP; detailInfo.PayAmount = decimal.Parse(result.R3_Amt); treasureFacade.FilliedOnline(detailInfo, 0); } } else { HttpCookie UserCookie2 = new HttpCookie("ErrorMsg"); UserCookie2["error"] = HttpUtility.UrlEncode(result.ErrMsg); UserCookie2.Expires = DateTime.Now.AddMinutes(7); Response.Cookies.Add(UserCookie2); Response.Redirect("/showPayInfo.html"); } } else { HttpCookie UserCookie2 = new HttpCookie("ErrorMsg"); UserCookie2["error"] = HttpUtility.UrlEncode("交易签名无效"); UserCookie2.Expires = DateTime.Now.AddMinutes(7); Response.Cookies.Add(UserCookie2); Response.Redirect("/showPayInfo.html"); } } }
protected void Button1_Click(object sender, EventArgs e) { StringBuilder log = new StringBuilder(); log.Append(DateTime.Now.ToString() + "\n"); log.Append("测试功能:" + theme.InnerText + "\n"); //***********************修改内容**************************** string requestUrl = APIURLConfig.QueryableOrder; string[] list = { "p0_Cmd", "p1_MerId", "pb_TrxId", "pv_Ver" }; string[] list_response = { "r0_Cmd", "r1_Code" }; //*********************************************************** log.Append("请求地址:" + requestUrl + "\n"); log.Append("商户编号:" + p1_MerId.Value + "\n"); log.Append("商户密钥:" + CustomerConfig.merchantKey + "\n"); //存储前台数据 string data_hmac = ""; //循环生成 foreach (string listname in list) { if (Request[listname] != "") { data_hmac = data_hmac + Request[listname]; } } //生成hmac签名 string hmac = Digest.CreateHmac(data_hmac); log.Append("请求加密的字符串:" + data_hmac + "\n"); log.Append("请求hmac:" + hmac + "\n"); //循环生成要请求链接的数据 string data_request = ""; foreach (string listname in list) { data_request = data_request + listname + "=" + Request[listname] + "&"; } //最终字符串 data_request = data_request + "hmac=" + hmac; log.Append("请求链接:" + requestUrl + "?" + data_request + "\n"); //发出请求 string reqResult = YJPayUtil.payAPIRequestOnlince(requestUrl, data_request, true); log.Append("返回的原始信息:" + reqResult + "\n"); //存储响应信息 SortedDictionary <string, string> sd = new SortedDictionary <string, string>(); //循环存储response foreach (string listname in list_response) { sd.Add(listname, FormatQueryString.GetQueryString(listname, reqResult, '\n')); } sd.Add("hmac", FormatQueryString.GetQueryString("hmac", reqResult, '\n')); string response_json = Newtonsoft.Json.JsonConvert.SerializeObject(sd); string type = ""; if (sd["r1_Code"] == "1") { //回调验证签名 string response_data = ""; //循环生成 foreach (string listname in list_response) { response_data = response_data + sd[listname]; } //回调信息生成HMAC string hmac_location = Digest.CreateHmac(response_data); //验证签名 StringComparer comparer = StringComparer.OrdinalIgnoreCase; if (0 == comparer.Compare(hmac_location, sd["hmac"])) { type = "验证签名成功"; } else { type = "验证签名失败"; } } else { type = "请检查数据"; } //返回数据data string data = response_json.ToString(); SoftLog.LogStr(log.ToString(), theme.InnerText); //跳转页面 Response.Redirect("http://localhost:58903/CallBack.aspx?data=" + data + "&type=" + type); }
protected void Page_Load(object sender, EventArgs e) { if (!IsPostBack) { // 校验返回数据包 Buy.logstr(FormatQueryString.GetQueryString("r6_Order"), Request.Url.Query, ""); BuyCallbackResult result = Buy.VerifyCallback(FormatQueryString.GetQueryString("p1_MerId"), FormatQueryString.GetQueryString("r0_Cmd"), FormatQueryString.GetQueryString("r1_Code"), FormatQueryString.GetQueryString("r2_TrxId"), FormatQueryString.GetQueryString("r3_Amt"), FormatQueryString.GetQueryString("r4_Cur"), FormatQueryString.GetQueryString("r5_Pid"), FormatQueryString.GetQueryString("r6_Order"), FormatQueryString.GetQueryString("r7_Uid"), FormatQueryString.GetQueryString("r8_MP"), FormatQueryString.GetQueryString("r9_BType"), FormatQueryString.GetQueryString("rp_PayDate"), FormatQueryString.GetQueryString("hmac")); if (string.IsNullOrEmpty(result.ErrMsg)) { //在接收到支付结果通知后,判断是否进行过业务逻辑处理,不要重复进行业务逻辑处理 if (result.R1_Code == "1") { Response.Write("SUCCESS"); if (result.R9_BType == "1") { // callback方式:浏览器重定向 Response.Write("支付成功!" + "<br>接口类型:" + result.R0_Cmd + "<br>返回码:" + result.R1_Code + //"<br>商户号:" + result.P1_MerId + "<br>交易流水号:" + result.R2_TrxId + "<br>商户订单号:" + result.R6_Order + "<br>交易金额:" + result.R3_Amt + "<br>交易币种:" + result.R4_Cur + "<br>订单完成时间:" + result.Rp_PayDate + "<br>回调方式:" + result.R9_BType + "<br>错误信息:" + result.ErrMsg + "<BR>"); } else if (result.R9_BType == "2") { // * 如果是服务器返回则需要回应一个特定字符串'SUCCESS',且在'SUCCESS'之前不可以有任何其他字符输出,保证首先输出的是'SUCCESS'字符串 Response.Write("支付成功!" + "<br>接口类型:" + result.R0_Cmd + "<br>返回码:" + result.R1_Code + //"<br>商户号:" + result.P1_MerId + "<br>交易流水号:" + result.R2_TrxId + "<br>商户订单号:" + result.R6_Order + "<br>交易金额:" + result.R3_Amt + "<br>交易币种:" + result.R4_Cur + "<br>订单完成时间:" + result.Rp_PayDate + "<br>回调方式:" + result.R9_BType + "<br>错误信息:" + result.ErrMsg + "<BR>"); } } else { Response.Write("支付失败!" + "<br>接口类型:" + result.R0_Cmd + "<br>返回码:" + result.R1_Code + //"<br>商户号:" + result.P1_MerId + "<br>交易流水号:" + result.R2_TrxId + "<br>商户订单号:" + result.R6_Order + "<br>交易金额:" + result.R3_Amt + "<br>交易币种:" + result.R4_Cur + "<br>订单完成时间:" + result.Rp_PayDate + "<br>回调方式:" + result.R9_BType + "<br>错误信息:" + result.ErrMsg + "<BR>"); } } else { Response.Write("交易签名无效!"); } } }
public void Return(HttpContext context) { //SZX.logURL(context.Request.RawUrl); // 校验返回数据包 SZXCallbackResult result = SZX.VerifyCallback(SuppKey , FormatQueryString.GetQueryString("r0_Cmd") , FormatQueryString.GetQueryString("r1_Code") , FormatQueryString.GetQueryString("p1_MerId") , FormatQueryString.GetQueryString("p2_Order") , FormatQueryString.GetQueryString("p3_Amt") , FormatQueryString.GetQueryString("p4_FrpId") , FormatQueryString.GetQueryString("p5_CardNo") , FormatQueryString.GetQueryString("p6_confirmAmount") , FormatQueryString.GetQueryString("p7_realAmount") , FormatQueryString.GetQueryString("p8_cardStatus") , FormatQueryString.GetQueryString("p9_MP") , FormatQueryString.GetQueryString("pb_BalanceAmt") , FormatQueryString.GetQueryString("pc_BalanceAct") , FormatQueryString.GetQueryString("hmac")); if (string.IsNullOrEmpty(result.ErrMsg)) { //使用应答机制时 必须回写success string viewMsg = ""; string msg = GetMsgInfo(result.P8_cardStatus); string opstate = "-1"; /*成功还是失败*/ int status = (result.R1_Code == "1") ? 2 : 4; if (status == 2) { opstate = "0"; viewMsg = "支付成功"; } else { viewMsg = msg; } var response = new CardOrderSupplierResponse() { SupplierId = SuppId, SuppTransNo = "", SysOrderNo = result.P2_Order, OrderAmt = decimal.Parse(result.P3_Amt), SuppAmt = 0M, OrderStatus = status, SuppErrorCode = result.P8_cardStatus, Opstate = opstate, SuppErrorMsg = result.ErrMsg, ViewMsg = viewMsg, Method = 1 }; OrderCardUtils.SuppNotify(response, Succflag); } else { context.Response.Write("交易签名无效!"); context.Response.Write("<BR>YeePay-HMAC:" + result.Hmac); context.Response.Write("<BR>LocalHost:" + result.ErrMsg); } }