예제 #1
0
        protected void Page_Load(object sender, EventArgs e)
        {
            Lebi_OnlinePay pay = B_Lebi_OnlinePay.GetModel("Code='weixinpay'");

            if (pay == null)
            {
                Log.Add("在线支付接口 weixinpay 配置错误");
                return;
            }
            Lebi_Currency currendy = B_Lebi_Currency.GetModel(pay.Currency_id);
            int           order_id = RequestTool.RequestInt("order_id", 0);
            Lebi_Order    order    = B_Lebi_Order.GetModel(order_id);

            if (order == null)
            {
                Response.Write("订单错误");
                Response.End();
                return;
            }
            TenpayUtil tu        = new TenpayUtil();
            string     sp_billno = order.Code;
            //当前时间 yyyyMMdd
            string date = DateTime.Now.ToString("yyyyMMdd");

            //if (null == sp_billno)
            //{
            //    //生成订单10位序列号,此处用时间和随机数生成,商户根据自己调整,保证唯一
            //    sp_billno = DateTime.Now.ToString("HHmmss") + TenpayUtil.BuildRandomStr(4);
            //}
            //else
            //{
            //    sp_billno = Request["order_no"].ToString();
            //}

            sp_billno = TenpayUtil.partner + sp_billno;


            RequestHandler outParams = new RequestHandler(Context);

            outParams.init();
            string productid = sp_billno;
            string timeStamp = TenpayUtil.getTimestamp();
            string nonceStr  = TenpayUtil.getNoncestr();

            RequestHandler Params = new RequestHandler(Context);

            Params.setParameter("appid", TenpayUtil.appid);
            Params.setParameter("appkey", TenpayUtil.appkey);
            Params.setParameter("noncestr", nonceStr);
            Params.setParameter("timestamp", timeStamp);
            Params.setParameter("productid", productid);
            string sign = Params.createSHA1Sign();

            Params.setParameter("sign", sign);


            parm = "weixin://wxpay/bizpayurl?sign=" + sign + "&appid=" + TenpayUtil.appid + "&productid=" + productid + "&timeStamp=" + timeStamp + "&nonceStr=" + nonceStr;
            Response.Write(parm);
            parm = QRfromGoogle(parm);
        }
예제 #2
0
        //获取package带参数的签名包
        public string getRequestURL()
        {
            this.createSign();
            StringBuilder sb    = new StringBuilder();
            ArrayList     akeys = new ArrayList(parameters.Keys);

            akeys.Sort();
            foreach (string k in akeys)
            {
                string v = (string)parameters[k];
                if (null != v && "key".CompareTo(k) != 0)
                {
                    sb.Append(k + "=" + TenpayUtil.UrlEncode(v, getCharset()) + "&");
                }
            }

            //去掉最后一个&
            if (sb.Length > 0)
            {
                sb.Remove(sb.Length - 1, 1);
            }


            return(sb.ToString());
        }
예제 #3
0
        /**
         * 生成扫描支付模式一URL
         * @param productId 商品ID
         * @return 模式一URL
         */
        public static string GetPrePayUrl(string productId)
        {
            Lebi_Order order = B_Lebi_Order.GetModel("id = lbsql{" + productId + "}");

            if (order == null)
            {
                throw new WxPayException("订单不存在!");
                SystemLog.Add("weixinpay-NativePay" + "productId : " + productId);
            }
            WxPayConfig conf = new WxPayConfig(order);
            WxPayData   data = new WxPayData();

            data.SetValue("appid", conf.APPID);                     //公众帐号id
            data.SetValue("mch_id", conf.MCHID);                    //商户号
            data.SetValue("time_stamp", TenpayUtil.getTimestamp()); //时间戳
            data.SetValue("nonce_str", TenpayUtil.getNoncestr());   //随机字符串
            data.SetValue("product_id", productId);                 //商品ID
            data.SetValue("sign", data.MakeSign(order));            //签名
            string str = ToUrlParams(data.GetValues());             //转换为URL串
            string url = "weixin://wxpay/bizpayurl?" + str;

            return(url);
        }
예제 #4
0
        public static string package  = "";                          //进行支付需要的包

        protected void Page_Load(object sender, EventArgs e)
        {
            Lebi_OnlinePay pay = B_Lebi_OnlinePay.GetModel("Code='weixinpay'");

            if (pay == null)
            {
                Log.Add("在线支付接口 weixinpay 配置错误");
                return;
            }
            Shop.Bussiness.Site site    = new Shop.Bussiness.Site();
            B_BaseConfig        bconfig = new B_BaseConfig();
            BaseConfig          SYS     = bconfig.LoadConfig();

            partnerid  = pay.UserName;
            partnerkey = pay.UserKey;
            appid      = SYS.platform_weixin_id;
            appsecret  = SYS.platform_weixin_secret;
            appkey     = "";
            notify_url = "http://" + RequestTool.GetRequestDomain() + site.WebPath + "/onlinepay/weixinpay.aspx";

            Lebi_Currency currendy = B_Lebi_Currency.GetModel(pay.Currency_id);
            int           order_id = RequestTool.RequestInt("order_id", 0);
            Lebi_Order    order    = B_Lebi_Order.GetModel(order_id);

            if (order == null)
            {
                Response.Write("订单错误");
                Response.End();
                return;
            }

            string order_price = (order.Money_Pay * currendy.ExchangeRate * 100).ToString();
            string sp_billno   = order.Code;

            Lebi_User user = B_Lebi_User.GetModel(order.User_id);

            if (user == null)
            {
                Response.Write("订单错误");
                Response.End();
                return;
            }
            ///////////////////////////////////////////////////////////////////////////////////////////////
            //当前时间 yyyyMMdd
            string date = DateTime.Now.ToString("yyyyMMdd");

            if (null == sp_billno)
            {
                //生成订单10位序列号,此处用时间和随机数生成,商户根据自己调整,保证唯一
                sp_billno = DateTime.Now.ToString("HHmmss") + TenpayUtil.BuildRandomStr(4);
            }
            else
            {
                sp_billno = Request["order_no"];
            }

            sp_billno = partnerid + sp_billno;


            //创建支付应答对象
            var packageReqHandler = new RequestHandler(Context);

            //初始化
            packageReqHandler.init();

            timeStamp = TenpayUtil.getTimestamp();
            nonceStr  = TenpayUtil.getNoncestr();


            //设置package订单参数

            packageReqHandler.setParameter("body", "test"); //商品信息 127字符
            packageReqHandler.setParameter("appid", user.bind_weixin_id);
            packageReqHandler.setParameter("mch_id", mchid);
            packageReqHandler.setParameter("nonce_str", nonceStr.ToLower());
            packageReqHandler.setParameter("notify_url", notify_url);
            packageReqHandler.setParameter("openid", "openid");
            packageReqHandler.setParameter("out_trade_no", sp_billno);                        //商家订单号
            packageReqHandler.setParameter("spbill_create_ip", Page.Request.UserHostAddress); //用户的公网ip,不是商户服务器IP
            packageReqHandler.setParameter("total_fee", "1");                                 //商品金额,以分为单位(money * 100).ToString()
            packageReqHandler.setParameter("trade_type", "JSAPI");

            //获取package包
            sign = packageReqHandler.CreateMd5Sign("key", appkey);
            WriteFile(Server.MapPath("") + "\\Log.txt", sign);
            packageReqHandler.setParameter("sign", sign);

            string data = packageReqHandler.parseXML();

            WriteFile(Server.MapPath("") + "\\Log.txt", data);

            string prepayXml = HttpUtil.Send(data, "https://api.mch.weixin.qq.com/pay/unifiedorder");

            WriteFile(Server.MapPath("") + "\\Log.txt", prepayXml);

            //获取预支付ID
            var xdoc = new XmlDocument();

            xdoc.LoadXml(prepayXml);
            XmlNode     xn  = xdoc.SelectSingleNode("xml");
            XmlNodeList xnl = xn.ChildNodes;

            if (xnl.Count > 7)
            {
                prepayId = xnl[7].InnerText;
                package  = string.Format("prepay_id={0}", prepayId);
                WriteFile(Server.MapPath("") + "\\Log.txt", package);
            }

            //设置支付参数
            var paySignReqHandler = new RequestHandler(Context);

            paySignReqHandler.setParameter("appId", appId);
            paySignReqHandler.setParameter("timeStamp", timeStamp);
            paySignReqHandler.setParameter("nonceStr", nonceStr);
            paySignReqHandler.setParameter("package", package);
            paySignReqHandler.setParameter("signType", "MD5");
            paySign = paySignReqHandler.CreateMd5Sign("key", appkey);


            WriteFile(Server.MapPath("") + "\\Log.txt", paySign);
        }
예제 #5
0
        protected void Page_Load(object sender, EventArgs e)
        {
            //创建ResponseHandler实例
            ResponseHandler resHandler = new ResponseHandler(Context);

            //判断签名
            try
            {
                //string return_code = RequestTool.RequestString("return_code");//SUCCESS/FAIL此字段是通信标识,非交易标识,交易是否成功需要查看 result_code 来判断
                //string return_msg = RequestTool.RequestString("return_msg");//返回信息,如非空,为错误原因/签名失败/参数格式校验错误
                //string appid = RequestTool.RequestString("appid");
                //string mch_id = RequestTool.RequestString("mch_id");
                //string nonce_str = RequestTool.RequestString("nonce_str");
                //string sign = RequestTool.RequestString("sign");
                //string result_code = RequestTool.RequestString("result_code");//业务结果SUCCESS/FAIL
                //string error_code = RequestTool.RequestString("error_code");
                //string error_code_des = RequestTool.RequestString("error_code_des");
                //string openid = RequestTool.RequestString("openid");
                //string trade_type = RequestTool.RequestString("trade_type");//交易类型
                //string bank_type = RequestTool.RequestString("bank_type");//out_trade_no
                //string total_fee = RequestTool.RequestString("total_fee");
                //string out_trade_no = RequestTool.RequestString("out_trade_no");
                //string attach = RequestTool.RequestString("attach");//商家数据包,原样返回
                //string time_end = RequestTool.RequestString("time_end");
                //string transaction_id = RequestTool.RequestString("transaction_id");//微信支付单号
                #region 协议参数=====================================
                //--------------协议参数--------------------------------------------------------
                //SUCCESS/FAIL此字段是通信标识,非交易标识,交易是否成功需要查
                string return_code = resHandler.getParameter("return_code");
                //返回信息,如非空,为错误原因签名失败参数格式校验错误
                string return_msg = resHandler.getParameter("return_msg");
                //微信分配的公众账号 ID
                string appid = resHandler.getParameter("appid");

                //以下字段在 return_code 为 SUCCESS 的时候有返回--------------------------------
                //微信支付分配的商户号
                string mch_id = resHandler.getParameter("mch_id");
                //微信支付分配的终端设备号
                string device_info = resHandler.getParameter("device_info");
                //微信分配的公众账号 ID
                string nonce_str = resHandler.getParameter("nonce_str");
                //业务结果 SUCCESS/FAIL
                string result_code = resHandler.getParameter("result_code");
                //错误代码
                string err_code = resHandler.getParameter("err_code");
                //结果信息描述
                string err_code_des = resHandler.getParameter("err_code_des");

                //以下字段在 return_code 和 result_code 都为 SUCCESS 的时候有返回---------------
                //-------------业务参数---------------------------------------------------------
                //用户在商户 appid 下的唯一标识
                string openid = resHandler.getParameter("openid");
                //用户是否关注公众账号,Y-关注,N-未关注,仅在公众账号类型支付有效
                string is_subscribe = resHandler.getParameter("is_subscribe");
                //JSAPI、NATIVE、MICROPAY、APP
                string trade_type = resHandler.getParameter("trade_type");
                //银行类型,采用字符串类型的银行标识
                string bank_type = resHandler.getParameter("bank_type");
                //订单总金额,单位为分
                string total_fee = resHandler.getParameter("total_fee");
                //货币类型,符合 ISO 4217 标准的三位字母代码,默认人民币:CNY
                string fee_type = resHandler.getParameter("fee_type");
                //微信支付订单号
                string transaction_id = resHandler.getParameter("transaction_id");
                //商户系统的订单号,与请求一致。
                string out_trade_no = resHandler.getParameter("out_trade_no");
                //商家数据包,原样返回
                string attach = resHandler.getParameter("attach");
                //支 付 完 成 时 间 , 格 式 为yyyyMMddhhmmss,如 2009 年12 月27日 9点 10分 10 秒表示为 20091227091010。时区为 GMT+8 beijing。该时间取自微信支付服务器
                string time_end = resHandler.getParameter("time_end");
                #endregion
                SystemLog.Add("JSAPI微信支付回调payNotifyUrl");
                Lebi_Order order = B_Lebi_Order.GetModel("Code=lbsql{'" + out_trade_no + "'}");
                if (order == null)
                {
                    Response.Write("系统错误");
                    SystemLog.Add("JSAPI微信支付-订单号" + out_trade_no + "不存在");
                    Response.End();
                    return;
                }
                TenpayUtil tu = new TenpayUtil(order);
                //SystemLog.Add(return_code + "|||" + result_code + "|||" + openid + "|||" + mch_id + "|||" + out_trade_no);

                if (return_code == "SUCCESS" && result_code == "SUCCESS")
                {
                    Lebi_User      user = B_Lebi_User.GetModel(order.User_id);
                    Lebi_OnlinePay pay  = B_Lebi_OnlinePay.GetModel("Code='weixinpay' and ','+Language_ids+',' like '%," + order.Language_id + ",%'");
                    if (pay == null)
                    {
                        Log.Add("在线支付接口 weixinpay 配置错误");
                        SystemLog.Add("JSAPI微信支付-接口配置错误");
                        return;
                    }
                    //if (user.bind_weixin_id == openid && pay.UserName == mch_id)
                    //{
                    Order.OnlinePaySuccess(out_trade_no, transaction_id, false);
                    Response.Write(paysuccess());
                    return;
                    //}
                }
                SystemLog.Add("JSAPI微信支付-签名失败");
                Response.Write(payerror("签名失败"));
            }
            catch (Exception ex)
            {
                SystemLog.Add("JSAPI微信支付-参数格式校验错误[" + ex.ToString() + "]");
                Response.Write(payerror("参数格式校验错误"));
            }
        }
예제 #6
0
        protected void Page_Load(object sender, EventArgs e)
        {
            int order_id = RequestTool.RequestInt("order_id", 0);

            order = B_Lebi_Order.GetModel(order_id);
            if (order == null)
            {
                Response.Write("ERROR");
                Response.End();
                return;
            }
            Lebi_Language language = B_Lebi_Language.GetModel(order.Language_id);

            if (order.IsPaid == 1)
            {
                Response.Write(Language.Tag("已付款", language.Code));
                Response.End();
                return;
            }
            order.Site_id_pay = CurrentSite.id;
            order.Language_id = CurrentLanguage.id;
            Lebi_OnlinePay pay = B_Lebi_OnlinePay.GetModel("id = " + order.OnlinePay_id + "");

            if (pay == null)
            {
                Log.Add("在线支付接口 weixinpay 配置错误");
                return;
            }
            if (pay.FreeFeeRate == 1)
            {
                pay.FeeRate = 0;
            }
            Lebi_Currency currendy = B_Lebi_Currency.GetModel(pay.Currency_id);

            if (order.IsPaid == 0)
            {
                if (pay.FeeRate > 0)
                {
                    order.Money_OnlinepayFee = order.Money_Pay * pay.FeeRate / 100;
                }
                if (order.OnlinePay_id != pay.id)
                {
                    order.OnlinePay_id   = pay.id;
                    order.OnlinePay_Code = pay.Code;
                    order.OnlinePay      = pay.Name;
                }
                B_Lebi_Order.Update(order);
            }
            Lebi_User user = B_Lebi_User.GetModel(order.User_id);

            if (user == null)
            {
                Response.Write("订单错误");
                Response.End();
                return;
            }
            returnurl = URL("P_UserOrderDetails", order.id);
            TenpayUtil tu = new TenpayUtil(order);

            appId     = tu.appid;
            timeStamp = TenpayUtil.getTimestamp();
            nonceStr  = TenpayUtil.getNoncestr();
            string order_price = (order.Money_Pay * currendy.ExchangeRate * 100 * (1 + (pay.FeeRate / 100))).ToString("0");
            string sp_billno   = order.Code;

            shopname = Lang(CurrentSite.Name);
            string prepayId = order.weixin_prepay_id;

            if (prepayId == "" || prepayId == "INVALID_REQUEST")
            {
                //创建支付应答对象
                RequestHandler packageReqHandler = new RequestHandler(Context);
                //初始化
                packageReqHandler.init();
                //设置package订单参数
                packageReqHandler.setParameter("body", order.Code); //商品信息 127字符
                packageReqHandler.setParameter("appid", tu.appid);
                packageReqHandler.setParameter("mch_id", tu.mch_id);
                packageReqHandler.setParameter("nonce_str", nonceStr);
                packageReqHandler.setParameter("openid", user.bind_weixin_id);
                packageReqHandler.setParameter("out_trade_no", sp_billno);                     //商家订单号
                packageReqHandler.setParameter("spbill_create_ip", RequestTool.GetClientIP()); //Page.Request.UserHostAddress); //用户的公网ip,不是商户服务器IP
                packageReqHandler.setParameter("total_fee", order_price);                      //商品金额,以分为单位(money * 100).ToString()
                packageReqHandler.setParameter("trade_type", "JSAPI");
                //packageReqHandler.setParameter("notify_url", HttpUtility.UrlEncode(tu.tenpay_notify));
                packageReqHandler.setParameter("notify_url", tu.tenpay_notify);
                //Response.Write("body:" + order.Code + ",appid:" + tu.appid + ",mch_id:" + tu.mch_id + ",nonce_str:" + nonceStr + ",notify_url:" + HttpUtility.UrlEncode(tu.tenpay_notify) + ",openid:" + user.bind_weixin_id + ",out_trade_no:" + sp_billno + ",spbill_create_ip:" + RequestTool.GetClientIP() + ",total_fee:" + order_price + ",key:" + tu.key + "");
                string sign = packageReqHandler.createMd5Sign("key", tu.key);
                packageReqHandler.setParameter("sign", sign);
                string data      = packageReqHandler.parseXML();
                string prepayXml = HttpUtil.Send(data, "https://api.mch.weixin.qq.com/pay/unifiedorder");

                //获取预支付ID
                var xdoc = new XmlDocument();
                xdoc.LoadXml(prepayXml);
                XmlNode     xn  = xdoc.SelectSingleNode("xml");
                XmlNodeList xnl = xn.ChildNodes;
                //Response.Write("<br/>xml:" + xnl[0].InnerText + "|" + xnl[1].InnerText + "|" + xnl[2].InnerText + "|" + xnl[3].InnerText + "|" + xnl[4].InnerText + "|" + xnl[5].InnerText + "|" + xnl[6].InnerText + "|" + xnl[7].InnerText + "|" + xnl[8].InnerText + "");
                if (xnl.Count > 7)
                {
                    prepayId = xnl[7].InnerText;
                    order.weixin_prepay_id = prepayId;
                    B_Lebi_Order.Update(order);
                }
            }
            //Response.Write("prepayId:" + prepayId + "");
            packageValue = string.Format("prepay_id={0}", prepayId);
            var paySignReqHandler = new RequestHandler(Context);

            paySignReqHandler.setParameter("appId", appId);
            paySignReqHandler.setParameter("timeStamp", timeStamp);
            paySignReqHandler.setParameter("nonceStr", nonceStr);
            paySignReqHandler.setParameter("package", packageValue);
            paySignReqHandler.setParameter("signType", "MD5");
            paySign = paySignReqHandler.createMd5Sign("key", tu.key);

            //获取debug信息,建议把请求和debug信息写入日志,方便定位问题
            //string pakcageDebuginfo = packageReqHandler.getDebugInfo();
            //Response.Write("<br/>pakcageDebuginfo:" + pakcageDebuginfo + "<br/>");
            //string paySignDebuginfo = paySignReqHandler.getDebugInfo();
            //Response.Write("<br/>paySignDebuginfo:" + paySignDebuginfo + "<br/>");
        }
예제 #7
0
        protected void Page_Load(object sender, EventArgs e)
        {
            string sp_billno = Request["order_no"];
            //当前时间 yyyyMMdd
            string date = DateTime.Now.ToString("yyyyMMdd");
            //订单号,此处用时间和随机数生成,商户根据自己调整,保证唯一
            string out_trade_no = "" + DateTime.Now.ToString("HHmmss") + TenpayUtil.BuildRandomStr(4);

            if (null == sp_billno)
            {
                //生成订单10位序列号,此处用时间和随机数生成,商户根据自己调整,保证唯一
                sp_billno = DateTime.Now.ToString("HHmmss") + TenpayUtil.BuildRandomStr(4);
            }
            else
            {
                sp_billno = Request["order_no"].ToString();
            }

            sp_billno = TenpayUtil.partner + sp_billno;



            //创建RequestHandler实例
            RequestHandler packageReqHandler = new RequestHandler(Context);

            //初始化
            packageReqHandler.init();
            packageReqHandler.setKey(TenpayUtil.key);

            //设置package订单参数
            packageReqHandler.setParameter("partner", TenpayUtil.partner);                    //商户号
            packageReqHandler.setParameter("bank_type", "WX");                                //银行类型
            packageReqHandler.setParameter("fee_type", "1");                                  //币种,1人民币
            packageReqHandler.setParameter("input_charset", "GBK");
            packageReqHandler.setParameter("out_trade_no", sp_billno);                        //商家订单号
            packageReqHandler.setParameter("total_fee", "1");                                 //商品金额,以分为单位(money * 100).ToString()
            packageReqHandler.setParameter("notify_url", TenpayUtil.tenpay_notify);           //接收财付通通知的URL
            packageReqHandler.setParameter("body", "nativecall");                             //商品描述
            packageReqHandler.setParameter("spbill_create_ip", Page.Request.UserHostAddress); //用户的公网ip,不是商户服务器IP

            //获取package包
            string packageValue = packageReqHandler.getRequestURL();

            //调起微信支付签名
            string timeStamp = TenpayUtil.getTimestamp();
            string nonceStr  = TenpayUtil.getNoncestr();

            //设置支付参数
            RequestHandler payHandler = new RequestHandler(Context);

            payHandler.setParameter("appid", TenpayUtil.appid);
            payHandler.setParameter("noncestr", nonceStr);
            payHandler.setParameter("timestamp", timeStamp);
            payHandler.setParameter("package", packageValue);
            payHandler.setParameter("RetCode", "0");
            payHandler.setParameter("RetErrMsg", "成功");
            string paySign = payHandler.createSHA1Sign();

            payHandler.setParameter("app_signature", paySign);
            payHandler.setParameter("sign_method", "SHA1");


            Response.ContentType = "text/xml";
            Response.Clear();
            Response.Write(payHandler.parseXML());
        }