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"; }
public override void SendRequest() { string str3 = SignUtil.HmacSign(SignUtil.HmacSign(this.characterSet + this.callbackUrl + this.notifyUrl + this.ipAddress + this.MerchantAcctId + this.requestId + this.signType + this.type + this.version + this.amount + this.bankAbbr + this.currency + this.orderDate + this.orderId + this.merAcDate + this.period + this.periodUnit + this.merchantAbbr + this.productDesc + this.productId + this.productName + this.productNum + this.reserved1 + this.reserved2 + this.userToken + this.showUrl + this.couponsFlag), this.Key); string data = "characterSet=" + this.characterSet + "&callbackUrl=" + this.callbackUrl + "¬ifyUrl=" + this.notifyUrl + "&ipAddress=" + this.ipAddress + "&merchantId=" + this.MerchantAcctId + "&requestId=" + this.requestId + "&signType=" + this.signType + "&type=" + this.type + "&version=" + this.version + "&amount=" + this.amount + "&bankAbbr=" + this.bankAbbr + "¤cy=" + this.currency + "&orderDate=" + this.orderDate + "&orderId=" + this.orderId + "&merAcDate=" + this.merAcDate + "&period=" + this.period + "&periodUnit=" + this.periodUnit + "&merchantAbbr=" + this.merchantAbbr + "&productDesc=" + this.productDesc + "&productId=" + this.productId + "&productName=" + this.productName + "&productNum=" + this.productNum + "&reserved1=" + this.reserved1 + "&reserved2=" + this.reserved2 + "&userToken=" + this.userToken + "&showUrl=" + this.showUrl + "&couponsFlag=" + this.couponsFlag + "&hmac=" + str3; Hashtable hashtable = IPosMUtil.parseStringToMap(IPosMUtil.httpRequest("https://ipos.10086.cn/ips/cmpayService", data)); string hmac = (string)hashtable["hmac"]; string str7 = (string)hashtable["returnCode"]; string str8 = (string)hashtable["message"]; if ("000000".Equals(str7) && SignUtil.verifySign(((string)hashtable["merchantId"]) + ((string)hashtable["requestId"]) + ((string)hashtable["signType"]) + ((string)hashtable["type"]) + ((string)hashtable["version"]) + str7 + str8 + ((string)hashtable["payUrl"]), this.Key, hmac)) { string payUrl = (string)hashtable["payUrl"]; HttpContext.Current.Response.Redirect(IPosMUtil.getRedirectUrl(payUrl)); } }
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 override void VerifyNotify(int timeout, string configXml) { Hashtable hashtable = IPosMUtil.parseStringToMap(IPosMUtil.keyValueToString(this.parameters)); XmlDocument document = new XmlDocument(); document.LoadXml(configXml); string innerText = document.FirstChild.SelectSingleNode("Key").InnerText; string str3 = (string)hashtable["merchantId"]; string str4 = (string)hashtable["payNo"]; string str5 = (string)hashtable["returnCode"]; string str6 = (string)hashtable["message"]; string str7 = (string)hashtable["signType"]; string str8 = (string)hashtable["type"]; string str9 = (string)hashtable["version"]; string str10 = (string)hashtable["amount"]; string str11 = (string)hashtable["amtItem"]; string str12 = (string)hashtable["bankAbbr"]; string str13 = (string)hashtable["mobile"]; string str14 = (string)hashtable["orderId"]; string str15 = (string)hashtable["payDate"]; string str16 = (string)hashtable["accountDate"]; string str17 = (string)hashtable["reserved1"]; string str18 = (string)hashtable["reserved2"]; string str19 = (string)hashtable["status"]; string str20 = (string)hashtable["orderDate"]; string str21 = (string)hashtable["fee"]; string hmac = (string)hashtable["hmac"]; string source = str3 + str4 + str5 + str6 + str7 + str8 + str9 + str10 + str11 + str12 + str13 + str14 + str15 + str16 + str17 + str18 + str19 + str20 + str21; if (!"000000".Equals(str5)) { this.OnNotifyVerifyFaild(); } else if ("MD5".Equals(GlobalParam.getInstance().signType) && !SignUtil.verifySign(source, innerText, hmac)) { this.OnNotifyVerifyFaild(); } else { this.OnFinished(false); } }
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 override string GetOrderId() { return((string)IPosMUtil.parseStringToMap(IPosMUtil.keyValueToString(this.parameters))["orderId"]); }
public override decimal GetOrderAmount() { string s = (string)IPosMUtil.parseStringToMap(IPosMUtil.keyValueToString(this.parameters))["amount"]; return(decimal.Parse(s) / 100M); }
private void Page_Load(object sender, System.EventArgs e) { Request.ContentEncoding = Encoding.GetEncoding("GBK"); //后台接收支付结果通知 NameValueCollection param = Context.Request.Form; try { PerrMsg.Text = ""; String reqData = IPosMUtil.keyValueToString(param); log.Info("reqData = " + reqData); Hashtable ht = IPosMUtil.parseStringToMap(reqData); // 取得singKey值 String signKey = GlobalParam.getInstance().signKey; //支付结果通知 String merchantId = (String)ht["merchantId"]; String payNo = (String)ht["payNo"]; String returnCode = (String)ht["returnCode"]; String message = (String)ht["message"]; String signType = (String)ht["signType"]; String type = (String)ht["type"]; String version = (String)ht["version"]; String amount = (String)ht["amount"]; String amtItem = (String)ht["amtItem"]; String bankAbbr = (String)ht["bankAbbr"]; String mobile = (String)ht["mobile"]; String orderId = (String)ht["orderId"]; String payDate = (String)ht["payDate"]; String accountDate = (String)ht["accountDate"]; String reserved1 = (String)ht["reserved1"]; String reserved2 = (String)ht["reserved2"]; String status = (String)ht["status"]; String orderDate = (String)ht["orderDate"]; String fee = (String)ht["fee"]; String hmac = (String)ht["hmac"]; //进行验签的原文 String signData = merchantId + payNo + returnCode + message + signType + type + version + amount + amtItem + bankAbbr + mobile + orderId + payDate + accountDate + reserved1 + reserved2 + status + orderDate + fee; if ("000000".Equals(returnCode)) { if ("MD5".Equals(GlobalParam.getInstance().signType)) { if (SignUtil.verifySign(signData, signKey, hmac)) { Pamount.Text = amount; PamtItem.Text = amtItem; PbankAbbr.Text = bankAbbr; Pmobile.Text = mobile; PorderId.Text = orderId; PpayDate.Text = payDate; Preserved1.Text = HttpUtility.UrlDecode(reserved1, Encoding.UTF8); Preserved2.Text = HttpUtility.UrlDecode(reserved2, Encoding.UTF8); Pstatus.Text = status; PorderDate.Text = orderDate; Pfee.Text = fee; } else { PerrMsg.Text = "签约失败"; PreturnCode.Text = returnCode; Pmessage.Text = HttpUtility.UrlDecode(message, Encoding.UTF8); } } } else { PerrMsg.Text = "页面通知失败"; PreturnCode.Text = returnCode; Pmessage.Text = HttpUtility.UrlDecode(message, Encoding.UTF8); } } catch (Exception el) { log.Error("Received Notify failed:" + el.Message); PerrMsg.Text = HttpUtility.UrlDecode(el.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 = "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); }