Beispiel #1
0
    protected void btnConsume_Click(object sender, EventArgs e)
    {
        ccWhere.Clear();
        ccWhere.AddComponent("JGCBM", LoginUser.BelongFactory, SearchComponent.Equals, SearchPad.NULL);
        JX_USERS jxUser = servComm.GetEntity <JX_USERS>(null, ccWhere);

        if (!String.IsNullOrEmpty(jxUser.PayNoCardMerId) && Request["paymethod"] == "1" || Request["paymethod"] != "1" && !String.IsNullOrEmpty(jxUser.PayB2CMerId))
        {
            //Dictionary<string, string> param = new Dictionary<string, string>();
            //// 随机构造一个订单号(演示用)
            Random rnd     = new Random();
            string orderID = DateTime.Now.ToString("yyyyMMddHHmmss") + ((rnd.Next(900) + 100).ToString() + "0").Substring(0, 2).Trim();

            ////填写参数

            //param["version"] = "5.0.0";//版本号
            //param["encoding"] = "UTF-8";//编码方式
            //param["certId"] = CertUtil.GetSignCertId();      //证书ID
            //param["txnType"] = "01";//交易类型
            //param["txnSubType"] = "01";//交易子类
            //param["bizType"] = "000201";//业务类型
            //param["frontUrl"] = "http://localhost:58826/BankPay/FrontRcvResponse.aspx?type=BankPay";    //前台通知地址
            //param["backUrl"] = "http://222.222.222.222:8080/demo/utf8/BackRcvResponse.aspx";  //后台通知地址,改自己的外网地址
            //param["signMethod"] = "01";//签名方法
            //param["channelType"] = "08";//渠道类型,07-PC,08-手机
            //param["accessType"] = "0";//接入类型
            //param["merId"] = "481601512173917";//商户号,请改成自己的商户号 481601512173917,777290058110097
            //param["orderId"] = orderID;//商户订单号,可任意修改
            //param["txnTime"] = DateTime.Now.ToString("yyyyMMddHHmmss");//订单发送时间
            //param["txnAmt"] = "1";//交易金额,单位分
            //param["currencyCode"] = "156";//交易币种
            ////param["orderDesc"] = "订单描述";//订单描述,暂时不会起作用
            //param["reqReserved"] = "透传信息";//请求方保留域,透传字段,查询、通知、对账文件中均会原样出现

            //SDKUtil.Sign(param, Encoding.UTF8);
            //// 将SDKUtil产生的Html文档写入页面,从而引导用户浏览器重定向
            //string html = SDKUtil.CreateAutoSubmitForm(SDKConfig.FrontTransUrl, param, Encoding.UTF8);
            //Response.ContentEncoding = Encoding.UTF8; // 指定输出编码
            //Response.Write(html);

            Hashtable myMap = new Hashtable();
            //无卡支付
            string payAmount = Request["actualAmount"];

            myMap.Add("MerOrderNo", orderID);
            myMap.Add("TranDate", DateTime.Now.ToString("yyyyMMdd"));
            myMap.Add("TranTime", DateTime.Now.ToString("hhmmss"));
            myMap.Add("OrderAmt", (int)(decimal.Parse(payAmount) * 100));
            //myMap.Add("OrderAmt", 1);
            myMap.Add("BusiType", "0001");
            myMap.Add("AccessType", "0");
            myMap.Add("AcqCode", "000000000000014");
            myMap.Add("MerPageUrl", Request.Url.GetLeftPart(UriPartial.Authority) + "/BankPay/FrontRcvResponse.aspx?type=BankPay");
            myMap.Add("MerBgUrl", Request.Url.GetLeftPart(UriPartial.Authority) + "/BankPay/BgRcvResponse.aspx?type=BankPay");
            myMap.Add("CurryNo", "CNY");

            //myMap.Add("SplitType", "");
            //myMap.Add("SplitMethod", "");
            //myMap.Add("MerSplitMsg", "");
            //myMap.Add("PayTimeOut", "145");
            myMap.Add("Version", "20140728");

            //myMap.Add("CommodityMsg", "ChinaPay测试-商品信息");
            //myMap.Add("MerResv", "ChinaPay测试-商户保留域");
            //myMap.Add("TranReserved", "{\"Referred\":\"www.chinapay.com\",\"BusiId\":\"0001\",\"TimeStamp\":\"1438915150976\",\"Remoteputr\":\"172.16.9.44\"}");
            myMap.Add("TranType", "0001");
            SecssUtil obj      = new SecssUtil();
            WNetPay   payModel = new WNetPay();


            //TODO 其他特殊用法请查看 pages/api_01_gateway/special_use_purchase.htm
            if (Request["paymethod"] == "1")
            {
                payModel.PayMethod = "0";
                myMap.Add("MerId", jxUser.PayNoCardMerId);
                obj.init(Request.PhysicalApplicationPath + "/ChinaPay/" + jxUser.PayNoCardMerId + "/security.properties"); //初始化安全控件:
            }
            else
            {
                payModel.PayMethod = "1";
                //B2C支付
                //myMap.Add("BankInstNo", "700000000000010");
                myMap.Add("MerId", jxUser.PayB2CMerId);
                obj.init(Request.PhysicalApplicationPath + "/ChinaPay/" + jxUser.PayB2CMerId + "/securityb2c.properties"); //初始化安全控件:
            }

            //bool ee =


            obj.sign(myMap);
            String chkValue = obj.getSign();
            myMap.Add("Signature", chkValue);
            //obj.verify(myMap);
            if ("00" != obj.getErrCode())
            {
            }



            payModel.OrderID        = orderID;
            payModel.UserID         = CurrentUserID;
            payModel.PayAmount      = decimal.Parse(payAmount);
            payModel.JGCBM          = LoginUser.BelongFactory;
            payModel.SubmitDateTime = DateTime.Now;

            payModel.PayStatus = "0";
            payModel.Remark    = "Remark";

            servComm.AddOrUpdate(payModel);



            //chkValue = DelegatePay(orderID);


            // SDKUtil.Sign(param, System.Text.Encoding.UTF8);
            myMap["Signature"] = chkValue;
            string html = SDKUtil.CreateAutoSubmitFormHash(SDKConfig.FrontTransUrl, myMap, System.Text.Encoding.UTF8); // 将SDKUtil产生的Html文档写入页面,从而引导用户浏览器重定向
            Response.ContentEncoding = Encoding.UTF8;                                                                  // 指定输出编码
            Response.Write(html);
            Response.End();
        }
        else
        {
            Response.Write("请配置支付参数");
            Response.End();
        }
    }