Exemplo n.º 1
0
        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 + "&notifyUrl=" + 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 + "&currency=" + 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));
            }
        }
Exemplo n.º 2
0
        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 + "&notifyUrl=" + notifyUrl
                             + "&ipAddress=" + ipAddress + "&merchantId="
                             + merchantId + "&requestId=" + requestId + "&signType="
                             + signType + "&type=" + type + "&version=" + version
                             + "&amount=" + amount + "&bankAbbr=" + bankAbbr
                             + "&currency=" + 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));
            }
        }