public CMPayDRequest() { this.ipAddress = IPosMUtil.getIpAddress(); this.characterSet = "02"; this.callbackUrl = string.Empty; this.notifyUrl = string.Empty; this.requestId = IPosMUtil.getTicks(); this.signType = "MD5"; this.type = "DirectPayConfirm"; this.version = "2.0.0"; this.merchantCert = string.Empty; this.hmac = string.Empty; this.amount = "0"; this.bankAbbr = string.Empty; this.currency = "00"; this.orderDate = string.Empty; this.merAcDate = string.Empty; this.orderId = string.Empty; this.period = "3"; this.periodUnit = "03"; this.merchantAbbr = string.Empty; this.productDesc = string.Empty; this.productId = string.Empty; this.productName = string.Empty; this.productNum = string.Empty; this.reserved1 = string.Empty; this.reserved2 = string.Empty; this.userToken = string.Empty; this.showUrl = string.Empty; this.couponsFlag = "00"; }
protected void Page_Load(object sender, EventArgs e) { ///页面初始化 amount.Text = "100"; period.Text = "7"; productDesc.Text = "1"; productId.Text = "2"; productName.Text = "2"; reserved1.Text = "保留1"; reserved2.Text = "字段2"; userToken.Text = "15116410263"; orderDate.Text = string.Format("{0:yyyyMMdd}", DateTime.Now); merAcDate.Text = string.Format("{0:yyyyMMdd}", DateTime.Now); orderId.Text = IPosMUtil.getTicks(); }
public CMPayDRequest(string orderId, decimal amount, string subject, string body, string buyerEmail, DateTime date, string showUrl, string returnUrl, string notifyUrl, string attach) { this.ipAddress = IPosMUtil.getIpAddress(); this.characterSet = "02"; this.callbackUrl = string.Empty; this.notifyUrl = string.Empty; this.requestId = IPosMUtil.getTicks(); this.signType = "MD5"; this.type = "DirectPayConfirm"; this.version = "2.0.0"; this.merchantCert = string.Empty; this.hmac = string.Empty; this.amount = "0"; this.bankAbbr = string.Empty; this.currency = "00"; this.orderDate = string.Empty; this.merAcDate = string.Empty; this.orderId = string.Empty; this.period = "3"; this.periodUnit = "03"; this.merchantAbbr = string.Empty; this.productDesc = string.Empty; this.productId = string.Empty; this.productName = string.Empty; this.productNum = string.Empty; this.reserved1 = string.Empty; this.reserved2 = string.Empty; this.userToken = string.Empty; this.showUrl = string.Empty; this.couponsFlag = "00"; this.productName = orderId; this.callbackUrl = returnUrl; this.notifyUrl = notifyUrl; this.amount = Convert.ToInt32((decimal)(amount * 100M)).ToString(CultureInfo.InvariantCulture); this.orderId = orderId; this.orderDate = this.merAcDate = date.ToString("yyyyMMdd", CultureInfo.InvariantCulture); }
protected void Page_Load(object sender, EventArgs e) { try { PerrMsg.Text = ""; //获取页面输入 String orderId = Request.Form["orderId"]; ///获取参数输入 String callbackUrl = GlobalParam.getInstance().callbackUrl; String notifyUrl = GlobalParam.getInstance().notifyUrl; String merchantId = GlobalParam.getInstance().merchantId; String requestId = IPosMUtil.getTicks(); String signType = GlobalParam.getInstance().signType; String type = "OrderQuery"; String version = GlobalParam.getInstance().version; String signKey = GlobalParam.getInstance().signKey; String reqUrl = GlobalParam.getInstance().reqUrl; ///组织发送报文的签名原文 String signData = merchantId + requestId + signType + type + version + orderId; ///生成发送报文的签名 String reqHmac1 = SignUtil.HmacSign(signData); String reqHmac = SignUtil.HmacSign(reqHmac1, signKey); ///组织支付请求原始报文 String reqData = "merchantId=" + merchantId + "&requestId=" + requestId + "&signType=" + signType + "&type=" + type + "&version=" + version + "&orderId=" + orderId + "&hmac=" + reqHmac; ///发送支付请求,并接收手机支付平台返回的支付地址 String recData = IPosMUtil.httpRequest(reqUrl, reqData); Hashtable ht = IPosMUtil.parseStringToMap(recData); String recHmac = (String)ht["hmac"]; String recReturnCode = (String)ht["returnCode"]; if ("000000".Equals(recReturnCode)) { ///组织接收报文的签名原文 String verData = (String)ht["merchantId"] + (String)ht["payNo"] + (String)ht["returnCode"] + (String)ht["message"] + (String)ht["signType"] + (String)ht["type"] + (String)ht["version"] + (String)ht["amount"] + (String)ht["amtItem"] + (String)ht["bankAbbr"] + (String)ht["mobile"] + (String)ht["orderId"] + (String)ht["payDate"] + (String)ht["reserved1"] + (String)ht["reserved2"] + (String)ht["status"] + (String)ht["orderDate"] + (String)ht["fee"]; ///验签 Boolean flag = SignUtil.verifySign(verData, signKey, recHmac); if (flag) { Pamount.Text = (String)ht["amount"]; PamtItem.Text = (String)ht["amtItem"]; PbankAbbr.Text = (String)ht["bankAbbr"]; Pmobile.Text = (String)ht["mobile"]; PorderId.Text = (String)ht["orderId"]; PpayDate.Text = (String)ht["payDate"]; Preserved1.Text = HttpUtility.UrlDecode((String)ht["reserved1"], Encoding.UTF8); Preserved2.Text = HttpUtility.UrlDecode((String)ht["reserved2"], Encoding.UTF8); Pstatus.Text = (String)ht["status"]; PorderDate.Text = (String)ht["orderDate"]; Pfee.Text = (String)ht["fee"]; } else { PerrMsg.Text = "验签失败"; PreturnCode.Text = recReturnCode; Pmessage.Text = HttpUtility.UrlDecode((String)ht["message"], Encoding.UTF8); } } else { PerrMsg.Text = "查询订单失败"; PreturnCode.Text = recReturnCode; Pmessage.Text = HttpUtility.UrlDecode((String)ht["message"], Encoding.UTF8); } } catch (Exception el) { PerrMsg.Text = el.Message; } }
protected void Page_Load(object sender, EventArgs e) { try{ //页面初始化 PerrMsg.Text = ""; //页面传输参数 String orderId = (String)Request.Form["orderId"]; String amount = (String)Request.Form["amount"]; ///获取参数输入 String merchantId = GlobalParam.getInstance().merchantId; String requestId = IPosMUtil.getTicks(); String signType = GlobalParam.getInstance().signType; String type = "OrderRefund"; String version = GlobalParam.getInstance().version; String signKey = GlobalParam.getInstance().signKey; String reqUrl = GlobalParam.getInstance().reqUrl; ///组织发送报文的签名原文 String signData = merchantId + requestId + signType + type + version + orderId + amount; ///生成发送报文的签名 String reqHmac1 = SignUtil.HmacSign(signData); String reqHmac = SignUtil.HmacSign(reqHmac1, signKey); ///组织支付请求原始报文 String reqData = "merchantId=" + merchantId + "&requestId=" + requestId + "&signType=" + signType + "&type=" + type + "&version=" + version + "&orderId=" + orderId + "&amount=" + amount + "&hmac=" + reqHmac; ///发送支付请求,并接收手机支付平台返回的支付地址 String recData = IPosMUtil.httpRequest(reqUrl, reqData); Hashtable ht = IPosMUtil.parseStringToMap(recData); String recHmac = (String)ht["hmac"]; String recReturnCode = (String)ht["returnCode"]; if ("000000".Equals(recReturnCode)) { ///组织接收报文的签名原文 String verData = (String)ht["merchantId"] + (String)ht["payNo"] + (String)ht["returnCode"] + (String)ht["message"] + (String)ht["signType"] + (String)ht["type"] + (String)ht["version"] + (String)ht["amount"] + (String)ht["orderId"] + (String)ht["status"]; ///验签 Boolean flag = SignUtil.verifySign(verData, signKey, recHmac); if (flag) { Pamount.Text = (String)ht["amount"]; PorderId.Text = (String)ht["orderId"]; Pstatus.Text = (String)ht["status"]; } else { PerrMsg.Text = "验签失败"; PreturnCode.Text = recReturnCode; Pmessage.Text = HttpUtility.UrlDecode((String)ht["message"], Encoding.GetEncoding("UTF-8")); } } else { PerrMsg.Text = "退款失败"; PreturnCode.Text = recReturnCode; Pmessage.Text = HttpUtility.UrlDecode((String)ht["message"], Encoding.GetEncoding("UTF-8")); } } catch (Exception el) { PerrMsg.Text = el.Message; } }
public void Button1_Click(object sender, EventArgs e) { ///获取客户端IP String ipAddress = IPosMUtil.getIpAddress(); ///获取参数输入 String characterSet = GlobalParam.getInstance().characterSet; String callbackUrl = GlobalParam.getInstance().callbackUrl; String notifyUrl = GlobalParam.getInstance().notifyUrl; String merchantId = GlobalParam.getInstance().merchantId; String requestId = IPosMUtil.getTicks(); String signType = GlobalParam.getInstance().signType; String type = "DirectPayConfirm"; String version = GlobalParam.getInstance().version; String signKey = GlobalParam.getInstance().signKey; String reqUrl = GlobalParam.getInstance().reqUrl; ///获取页面输入 String amount = (String)Request.Form["amount"]; String bankAbbr = (String)Request.Form["bankAbbr"]; String currency = (String)Request.Form["currency"]; String orderDate = (String)Request.Form["orderDate"]; String merAcDate = (String)Request.Form["merAcDate"]; String orderId = (String)Request.Form["orderId"]; String period = (String)Request.Form["period"]; String periodUnit = (String)Request.Form["periodUnit"]; String merchantAbbr = (String)Request.Form["merchantAbbr"]; String productDesc = (String)Request.Form["productDesc"]; String productId = (String)Request.Form["productId"]; String productName = (String)Request.Form["productName"]; String productNum = (String)Request.Form["productNum"]; String reserved1 = (String)Request.Form["reserved1"]; String reserved2 = (String)Request.Form["reserved2"]; String userToken = (String)Request.Form["userToken"]; String showUrl = (String)Request.Form["showUrl"]; String couponsFlag = (String)Request.Form["couponsFlag"]; ///组织发送报文的签名原文 String signData = characterSet + callbackUrl + notifyUrl + ipAddress + merchantId + requestId + signType + type + version + amount + bankAbbr + currency + orderDate + orderId + merAcDate + period + periodUnit + merchantAbbr + productDesc + productId + productName + productNum + reserved1 + reserved2 + userToken + showUrl + couponsFlag; ///生成发送报文的签名 String reqHmac1 = SignUtil.HmacSign(signData); String reqHmac = SignUtil.HmacSign(reqHmac1, signKey); ///组织支付请求原始报文 String reqData = "characterSet=" + characterSet + "&callbackUrl=" + callbackUrl + "¬ifyUrl=" + notifyUrl + "&ipAddress=" + ipAddress + "&merchantId=" + merchantId + "&requestId=" + requestId + "&signType=" + signType + "&type=" + type + "&version=" + version + "&amount=" + amount + "&bankAbbr=" + bankAbbr + "¤cy=" + currency + "&orderDate=" + orderDate + "&orderId=" + orderId + "&merAcDate=" + merAcDate + "&period=" + period + "&periodUnit=" + periodUnit + "&merchantAbbr=" + merchantAbbr + "&productDesc=" + productDesc + "&productId=" + productId + "&productName=" + productName + "&productNum=" + productNum + "&reserved1=" + reserved1 + "&reserved2=" + reserved2 + "&userToken=" + userToken + "&showUrl=" + showUrl + "&couponsFlag=" + couponsFlag + "&hmac=" + reqHmac; ///发送支付请求,并接收手机支付平台返回的支付地址 String recData = IPosMUtil.httpRequest(reqUrl, reqData); Hashtable ht = IPosMUtil.parseStringToMap(recData); String recHmac = (String)ht["hmac"]; String recReturnCode = (String)ht["returnCode"]; String message = (String)ht["message"]; if ("000000".Equals(recReturnCode)) { ///组织接收报文的签名原文 String verData = (String)ht["merchantId"] + (String)ht["requestId"] + (String)ht["signType"] + (String)ht["type"] + (String)ht["version"] + recReturnCode + message + (String)ht["payUrl"]; ///验签 Boolean flag = SignUtil.verifySign(verData, signKey, recHmac); if (flag) { String recPayUrl = (String)ht["payUrl"]; Response.Redirect(IPosMUtil.getRedirectUrl(recPayUrl)); } else { Response.Write("验签失败:"); Response.Write("returnCode = " + recReturnCode); Response.Write("&message = " + HttpUtility.UrlDecode(message, Encoding.UTF8)); } } else { Response.Write("下单失败:"); Response.Write("returnCode = " + recReturnCode + "&"); Response.Write("message = " + HttpUtility.UrlDecode(message, Encoding.UTF8)); } }
public void Button1_Click(object sender, EventArgs e) { ///获取客户端IP String ipAddress = IPosMUtil.getIpAddress(); ///获取参数输入 String characterSet = GlobalParam.getInstance().characterSet; String callbackUrl = GlobalParam.getInstance().callbackUrl; String notifyUrl = GlobalParam.getInstance().notifyUrl; String merchantId = GlobalParam.getInstance().merchantId; String requestId = IPosMUtil.getTicks(); String signType = GlobalParam.getInstance().signType; String type = "GWDirectPay"; String version = GlobalParam.getInstance().version; String signKey = GlobalParam.getInstance().signKey; String reqUrl = GlobalParam.getInstance().reqUrl; String amount = (String)Request.Form["amount"]; String bankAbbr = (String)Request.Form["bankAbbr"]; String currency = (String)Request.Form["currency"]; String orderDate = (String)Request.Form["orderDate"]; String merAcDate = (String)Request.Form["merAcDate"]; String orderId = (String)Request.Form["orderId"]; String period = (String)Request.Form["period"]; String periodUnit = (String)Request.Form["periodUnit"]; String merchantAbbr = (String)Request.Form["merchantAbbr"]; String productDesc = (String)Request.Form["productDesc"]; String productId = (String)Request.Form["productId"]; String productName = (String)Request.Form["productName"]; String productNum = (String)Request.Form["productNum"]; String reserved1 = (String)Request.Form["reserved1"]; String reserved2 = (String)Request.Form["reserved2"]; String userToken = (String)Request.Form["userToken"]; String showUrl = (String)Request.Form["showUrl"]; String couponsFlag = (String)Request.Form["couponsFlag"]; ///组织发送报文的签名原文 String signData = characterSet + callbackUrl + notifyUrl + ipAddress + merchantId + requestId + signType + type + version + amount + bankAbbr + currency + orderDate + orderId + merAcDate + period + periodUnit + merchantAbbr + productDesc + productId + productName + productNum + reserved1 + reserved2 + userToken + showUrl + couponsFlag; ///生成发送报文的签名 String reqHmac1 = SignUtil.HmacSign(signData); String reqHmac = SignUtil.HmacSign(reqHmac1, signKey); ///组织支付请求原始报文 String reqData = "characterSet=" + characterSet + "&callbackUrl=" + callbackUrl + "¬ifyUrl=" + notifyUrl + "&ipAddress=" + ipAddress + "&merchantId=" + merchantId + "&requestId=" + requestId + "&signType=" + signType + "&type=" + type + "&version=" + version + "&amount=" + amount + "&bankAbbr=" + bankAbbr + "¤cy=" + currency + "&orderDate=" + orderDate + "&orderId=" + orderId + "&merAcDate=" + merAcDate + "&period=" + period + "&periodUnit=" + periodUnit + "&merchantAbbr=" + merchantAbbr + "&productDesc=" + productDesc + "&productId=" + productId + "&productName=" + productName + "&productNum=" + productNum + "&reserved1=" + reserved1 + "&reserved2=" + reserved2 + "&userToken=" + userToken + "&showUrl=" + showUrl + "&couponsFlag=" + couponsFlag + "&hmac=" + reqHmac; log.Info(reqData); Server.Transfer("DoGWDirectPayment.aspx?" + reqData, true); }