예제 #1
0
 public function buildRequest($req)
 {
     //获取prepay_id============
     $unifiedOrder = new UnifiedOrder_pub($this->wxConfig);
     //设置统一支付接口参数
     $unifiedOrder->setParameter("openid", "{$req['openId']}");
     //商品描述
     $unifiedOrder->setParameter("body", "{$req['body']}");
     //商品描述
     $unifiedOrder->setParameter("out_trade_no", "{$req['order_sn']}");
     //商户订单号
     $amount = $req['order_paied'] * 100;
     $unifiedOrder->setParameter("total_fee", "{$amount}");
     //总金额
     $unifiedOrder->setParameter("notify_url", $this->wxConfig['notify_url']);
     //通知地址
     $unifiedOrder->setParameter("trade_type", "JSAPI");
     //交易类型
     //非必填参数,商户可根据实际情况选填
     //$unifiedOrder->setParameter("sub_mch_id","XXXX");//子商户号
     //$unifiedOrder->setParameter("device_info","XXXX");//设备号
     //$unifiedOrder->setParameter("attach","XXXX");//附加数据
     //$unifiedOrder->setParameter("time_start","XXXX");//交易起始时间
     //$unifiedOrder->setParameter("time_expire","XXXX");//交易结束时间
     //$unifiedOrder->setParameter("goods_tag","XXXX");//商品标记
     //$unifiedOrder->setParameter("openid","XXXX");//用户标识
     //$unifiedOrder->setParameter("product_id","XXXX");//商品ID
     $prepay_id = $unifiedOrder->getPrepayId();
     //使用jsapi调起支付============
     $this->jsApi->setPrepayId($prepay_id);
     $this->jsApi = $this->jsApi->getParameters();
     return "<script>\n        function jsApiCall(){\n            WeixinJSBridge.invoke(\n                'getBrandWCPayRequest',\n                {$this->jsApi},\n                function(res){\n                    //支付成功\n                    if(res.err_msg == 'get_brand_wcpay_request:ok')\n                        window.location = '/ng/#/order';\n                    //用户取消\n                    else if(res.err_msg == 'get_brand_wcpay_request:cancel'){\n                        window.location = '/ng/#/order';\n                    }\n                    //支付失败\n                    else{\n                        alert('支付失败,请重试下');\n                        window.location = '/ng/#/order';\n                    }\n                }\n            );\n        }\n        ;(function(){\n            if (typeof WeixinJSBridge == 'undefined'){\n                if( document.addEventListener ){\n                    document.addEventListener('WeixinJSBridgeReady', jsApiCall, false);\n                }else if (document.attachEvent){\n                    document.attachEvent('WeixinJSBridgeReady', jsApiCall);\n                    document.attachEvent('onWeixinJSBridgeReady', jsApiCall);\n                }\n            }else{\n                jsApiCall();\n            }\n            //监控关闭窗口\n            WeixinJSBridge.invoke('closeWindow',{},function(res){\n                window.location.href = '/ng/#/order';\n            });\n        })()</script>";
 }
예제 #2
0
 public function pay()
 {
     if (empty($this->pay_config['pay_weixin_appid']) || empty($this->pay_config['pay_weixin_mchid']) || empty($this->pay_config['pay_weixin_key'])) {
         return array('err_code' => 1, 'err_msg' => '微信支付缺少配置信息!请联系管理员处理或选择其他支付方式。');
     }
     if (empty($this->openid)) {
         return array('err_code' => 1, 'err_msg' => '没有获取到用户的微信资料,无法使用微信支付');
     }
     import('source.class.pay.Weixinnewpay.WxPayPubHelper');
     $jsApi = new JsApi_pub($this->pay_config['pay_weixin_appid'], $this->pay_config['pay_weixin_mchid'], $this->pay_config['pay_weixin_key']);
     $unifiedOrder = new UnifiedOrder_pub($this->pay_config['pay_weixin_appid'], $this->pay_config['pay_weixin_mchid'], $this->pay_config['pay_weixin_key']);
     $unifiedOrder->setParameter('openid', $this->openid);
     $unifiedOrder->setParameter('body', $this->order_info['order_no_txt']);
     $unifiedOrder->setParameter('out_trade_no', $this->order_info['trade_no']);
     $unifiedOrder->setParameter('total_fee', floatval($this->order_info['total'] * 100));
     $unifiedOrder->setParameter('notify_url', option('config.wap_site_url') . '/paynotice.php');
     $unifiedOrder->setParameter('trade_type', 'JSAPI');
     $unifiedOrder->setParameter('attach', 'weixin');
     $prepay_result = $unifiedOrder->getPrepayId();
     if ($prepay_result['return_code'] == 'FAIL') {
         return array('err_code' => 1, 'err_msg' => '没有获取微信支付的预支付ID,请重新发起支付!<br/><br/>微信支付错误返回:' . $prepay_result['return_msg']);
     }
     if ($prepay_result['err_code']) {
         return array('err_code' => 1, 'err_msg' => '没有获取微信支付的预支付ID,请重新发起支付!<br/><br/>微信支付错误返回:' . $prepay_result['err_code_des']);
     }
     $jsApi->setPrepayId($prepay_result['prepay_id']);
     return array('err_code' => 0, 'pay_data' => $jsApi->getParameters());
 }
예제 #3
0
 public function mobile_pay()
 {
     import('@.ORG.pay.Weixinnewpay.WxPayPubHelper');
     //使用jsapi接口
     $jsApi = new JsApi_pub($this->pay_config['pay_weixin_appid'], $this->pay_config['pay_weixin_mchid'], $this->pay_config['pay_weixin_key'], $this->pay_config['pay_weixin_appsecret']);
     //使用统一支付接口
     $unifiedOrder = new UnifiedOrder_pub($this->pay_config['pay_weixin_appid'], $this->pay_config['pay_weixin_mchid'], $this->pay_config['pay_weixin_key'], $this->pay_config['pay_weixin_appsecret']);
     $unifiedOrder->setParameter("openid", $_SESSION['openid']);
     //用户微信唯一标识
     $unifiedOrder->setParameter("body", $this->order_info['order_name'] . '_' . $this->order_info['order_num']);
     //商品描述
     //自定义订单号,此处仅作举例
     $unifiedOrder->setParameter("out_trade_no", $this->order_info['order_type'] . '_' . $this->order_info['order_id']);
     //商户订单号
     $unifiedOrder->setParameter("total_fee", floatval($this->pay_money * 100));
     //总金额
     $unifiedOrder->setParameter("notify_url", C('config.site_url') . '/source/wap_weixin_notice.php');
     //通知地址
     $unifiedOrder->setParameter("trade_type", "JSAPI");
     //交易类型
     $unifiedOrder->setParameter("attach", 'weixin');
     //附加数据
     $prepay_result = $unifiedOrder->getPrepayId();
     if ($prepay_result['return_code'] == 'FAIL') {
         return array('error' => 1, 'msg' => '没有获取微信支付的预支付ID,请重新发起支付!微信支付错误返回:' . $prepay_result['return_msg']);
     }
     if ($prepay_result['err_code']) {
         return array('error' => 1, 'msg' => '没有获取微信支付的预支付ID,请重新发起支付!<br/><br/>微信支付错误返回:' . $prepay_result['err_code_des']);
     }
     //=========步骤3:使用jsapi调起支付============
     $jsApi->setPrepayId($prepay_result['prepay_id']);
     return array('error' => 0, 'weixin_param' => $jsApi->getParameters());
 }
예제 #4
0
 public function config($config = null)
 {
     if (empty($_SERVER['HTTP_USER_AGENT']) || strpos($_SERVER['HTTP_USER_AGENT'], 'MicroMessenger') === false && strpos($_SERVER['HTTP_USER_AGENT'], 'Windows Phone') === false) {
         header('Location: ' . WEB_PATH . '/pay/wxpay_web_url/payinfo/nowechat');
         die;
     }
     include_once dirname(__FILE__) . "/wxpay/WxPayPubHelper.php";
     if (empty($config['pay_type_data'])) {
         $this->db = System::load_sys_class('model');
         $pay = $this->db->GetOne("SELECT * from `@#_pay` where `pay_class` = 'wxpay_web'");
         $config['pay_type_data'] = unserialize($pay['pay_key']);
     }
     WxPayConf_pub::$APPID = $config['pay_type_data']['APPID']['val'];
     WxPayConf_pub::$MCHID = $config['pay_type_data']['MCHID']['val'];
     WxPayConf_pub::$KEY = $config['pay_type_data']['KEY']['val'];
     WxPayConf_pub::$APPSECRET = $config['pay_type_data']['APPSECRET']['val'];
     $jsApi = new JsApi_pub();
     if (!isset($_GET['code'])) {
         $url = G_WEB_PATH . '/index.php/pay/wxpay_web_url/?money=' . $config['money'] . '&out_trade_no=' . $config['code'];
         $url = $jsApi->createOauthUrlForCode(urlencode($url));
         header("Location: {$url}");
         die;
     } else {
         $jsApi->setCode($_GET['code']);
         $openid = $jsApi->getOpenId();
     }
     //		var_dump($_GET);
     //		echo $openid;die;
     WxPayConf_pub::$SSLCERT_PATH = dirname(__FILE__) . '/cacert/apiclient_cert.pem';
     WxPayConf_pub::$SSLKEY_PATH = dirname(__FILE__) . '/cacert/apiclient_key.pem';
     //=========步骤2:使用统一支付接口,获取prepay_id============
     //使用统一支付接口
     $unifiedOrder = new UnifiedOrder_pub();
     //设置统一支付接口参数
     //设置必填参数
     //appid已填,商户无需重复填写
     //mch_id已填,商户无需重复填写
     //noncestr已填,商户无需重复填写
     //spbill_create_ip已填,商户无需重复填写
     //sign已填,商户无需重复填写
     $unifiedOrder->setParameter("openid", $openid);
     $unifiedOrder->setParameter("body", "购买商品");
     //商品描述
     $unifiedOrder->setParameter("out_trade_no", $config['code']);
     //商户订单号
     $unifiedOrder->setParameter("total_fee", $config['money'] * 100);
     //总金额
     $unifiedOrder->setParameter("notify_url", $config['NotifyUrl']);
     //通知地址
     $unifiedOrder->setParameter("trade_type", "JSAPI");
     //交易类型
     $prepay_id = $unifiedOrder->getPrepayId();
     //=========步骤3:使用jsapi调起支付============
     $jsApi->setPrepayId($prepay_id);
     $jsApiParameters = $jsApi->getParameters();
     include 'wxpay_web.html.php';
 }
예제 #5
0
 public function new_pay()
 {
     import('@.ORG.Weixinnewpay.WxPayPubHelper');
     //使用jsapi接口
     $jsApi = new JsApi_pub($this->payConfig['new_appid'], $this->payConfig['mchid'], $this->payConfig['key'], $this->payConfig['appsecret']);
     //获取订单信息
     $orderid = $_GET['single_orderid'];
     $payHandel = new payHandle($this->token, $_GET['from'], 'weixin');
     $orderInfo = $payHandel->beforePay($orderid);
     $price = $orderInfo['price'];
     //判断是否已经支付过
     if ($orderInfo['paid']) {
         exit('您已经支付过此次订单!');
     }
     //=========步骤2:使用统一支付接口,获取prepay_id============
     //使用统一支付接口
     $unifiedOrder = new UnifiedOrder_pub($this->payConfig['new_appid'], $this->payConfig['mchid'], $this->payConfig['key'], $this->payConfig['appsecret']);
     $unifiedOrder->setParameter("openid", $_GET['wecha_id']);
     //商品描述
     $unifiedOrder->setParameter("body", $orderid);
     //商品描述
     //自定义订单号,此处仅作举例
     $unifiedOrder->setParameter("out_trade_no", $orderid);
     //商户订单号
     $unifiedOrder->setParameter("total_fee", $price * 100);
     //总金额
     if (strpos(CONF_PATH, 'DataPig')) {
         $noticeFileName = 'notice_datapig.php';
     } elseif (strpos(CONF_PATH, 'weimidata')) {
         $noticeFileName = 'notice_weimidata.php';
     } else {
         $noticeFileName = 'notice.php';
     }
     $unifiedOrder->setParameter("notify_url", C('site_url') . '/wxpay/' . $noticeFileName);
     //通知地址
     $unifiedOrder->setParameter("trade_type", "JSAPI");
     //交易类型
     $unifiedOrder->setParameter("attach", 'token=' . $_GET['token'] . '&wecha_id=' . $_GET['wecha_id'] . '&from=' . $_GET['from']);
     //附加数据
     $prepay_id = $unifiedOrder->getPrepayId();
     if (empty($prepay_id)) {
         $this->error('没有获取到微信支付预支付ID,请管理员检查微信支付配置项!');
     }
     //=========步骤3:使用jsapi调起支付============
     $jsApi->setPrepayId($prepay_id);
     $jsApiParameters = $jsApi->getParameters();
     $this->assign('jsApiParameters', $jsApiParameters);
     $from = $_GET['from'];
     $from = $from ? $from : 'Groupon';
     $from = $from != 'groupon' ? $from : 'Groupon';
     $returnUrl = $this->siteUrl . '/index.php?g=Wap&m=' . $from . '&a=payReturn&nohandle=1&token=' . $_GET['token'] . '&wecha_id=' . $_GET['wecha_id'] . '&orderid=' . $orderid;
     $this->assign('returnUrl', $returnUrl);
     //$this->display();
     echo '<html><head><meta http-equiv="Content-Type" content="text/html; charset=UTF-8" /><meta name="viewport" content="width=device-width,height=device-height,inital-scale=1.0,maximum-scale=1.0,user-scalable=no;" /><meta name="apple-mobile-web-app-capable" content="yes" /><meta name="apple-mobile-web-app-status-bar-style" content="black" /><meta name="format-detection" content="telephone=no" /><link href="/tpl/Wap/default/common/css/style/css/hotels.css" rel="stylesheet" type="text/css" /><title>微信支付</title><script language="javascript">function callpay(){WeixinJSBridge.invoke("getBrandWCPayRequest",' . $jsApiParameters . ',function(res){WeixinJSBridge.log(res.err_msg);if(res.err_msg=="get_brand_wcpay_request:ok"){document.getElementById("payDom").style.display="none";document.getElementById("successDom").style.display="";setTimeout("window.location.href = \'' . $returnUrl . '\'",2000);}else{if(res.err_msg == "get_brand_wcpay_request:cancel"){var err_msg = "您取消了支付";}else if(res.err_msg == "get_brand_wcpay_request:fail"){var err_msg = "支付失败<br/>错误信息:"+res.err_desc;}else{var err_msg = res.err_msg +"<br/>"+res.err_desc;}document.getElementById("payDom").style.display="none";document.getElementById("failDom").style.display="";document.getElementById("failRt").innerHTML=err_msg;}});}</script></head><body style="padding-top:20px;"><style>.deploy_ctype_tip{z-index:1001;width:100%;text-align:center;position:fixed;top:50%;margin-top:-23px;left:0;}.deploy_ctype_tip p{display:inline-block;padding:13px 24px;border:solid #d6d482 1px;background:#f5f4c5;font-size:16px;color:#8f772f;line-height:18px;border-radius:3px;}</style><div id="payDom" class="cardexplain"><ul class="round"><li class="title mb"><span class="none">支付信息</span></li><li class="nob"><table width="100%" border="0" cellspacing="0" cellpadding="0" class="kuang"><tr><th>金额</th><td>' . floatval($_GET['price']) . '元</td></tr></table></li></ul><div class="footReturn" style="text-align:center"><input type="button" style="margin:0 auto 20px auto;width:100%"  onclick="callpay()"  class="submit" value="点击进行微信支付" /></div></div><div id="failDom" style="display:none" class="cardexplain"><ul class="round"><li class="title mb"><span class="none">支付结果</span></li><li class="nob"><table width="100%" border="0" cellspacing="0" cellpadding="0" class="kuang"><tr><th>支付失败</th><td><div id="failRt"></div></td></tr></table></li></ul><div class="footReturn" style="text-align:center"><input type="button" style="margin:0 auto 20px auto;width:100%"  onclick="callpay()"  class="submit" value="重新进行支付" /></div></div><div id="successDom" style="display:none" class="cardexplain"><ul class="round"><li class="title mb"><span class="none">支付成功</span></li><li class="nob"><table width="100%" border="0" cellspacing="0" cellpadding="0" class="kuang"><tr><td>您已支付成功,页面正在跳转...</td></tr></table><div id="failRt"></div></li></ul></div></body></html>';
 }
예제 #6
0
 public function index()
 {
     $this->isUserLogin();
     vendor('Weixinpay.WxPayPubHelper');
     //使用jsapi接口
     $jsApi = new \JsApi_pub();
     //=========步骤1:网页授权获取用户openid============
     //通过code获得openid
     $code = $_GET['code'];
     $jsApi->setCode($code);
     $openid = session('WST_USER')['wxId'];
     $pkey = session('WST_USER')["userId"] . "@" . $_SESSION["orderIds"];
     $time = time();
     $res = array('order_sn' => $time, 'order_amount' => $_SESSION['needPay']);
     //=========步骤2:使用统一支付接口,获取prepay_id============
     //使用统一支付接口
     $unifiedOrder = new \UnifiedOrder_pub();
     $total_fee = $res['order_amount'] * 100;
     //$total_fee = 1;
     $body = "订单支付{$res['order_sn']}";
     $unifiedOrder->setParameter("openid", "{$openid}");
     //用户标识
     $unifiedOrder->setParameter("body", $body);
     //商品描述
     //自定义订单号,此处仅作举例
     $out_trade_no = $res['order_sn'];
     $unifiedOrder->setParameter("out_trade_no", "{$out_trade_no}");
     //商户订单号
     $unifiedOrder->setParameter("total_fee", $total_fee);
     //总金额
     $unifiedOrder->setParameter("attach", "{$pkey}");
     //附加数据
     $unifiedOrder->setParameter("notify_url", C('WxPayConf_pub.NOTIFY_URL'));
     //通知地址
     $unifiedOrder->setParameter("trade_type", "JSAPI");
     //交易类型
     $unifiedOrder->SetParameter("input_charset", "UTF-8");
     //非必填参数,商户可根据实际情况选填
     $prepay_id = $unifiedOrder->getPrepayId();
     //=========步骤3:使用jsapi调起支付============
     $jsApi->setPrepayId($prepay_id);
     $jsApiParameters = $jsApi->getParameters();
     $wxconf = json_decode($jsApiParameters, true);
     if ($wxconf['package'] == 'prepay_id=') {
         $this->error('当前订单存在异常,不能使用支付');
     }
     $this->assign('res', $res);
     $this->assign('jsApiParameters', $jsApiParameters);
     $this->display('default/payment/wxjsapi/wxpay');
 }
예제 #7
0
 function get_payform($order_info)
 {
     if (!defined('WXAPPID')) {
         $_SESSION['order_info'] = $order_info;
         define("WXAPPID", $this->_config['appid']);
         define("WXMCHID", $this->_config['mchid']);
         define("WXKEY", $this->_config['key']);
         define("WXAPPSECRET", $this->_config['appsecret']);
         define("WXCURL_TIMEOUT", 30);
         define('WXNOTIFY_URL', $this->_create_notify_url($order_info["order_id"], $order_info['payment_code']));
         define('WXJS_API_CALL_URL', $this->_create_notify_url($order_info["order_id"], $order_info['payment_code']));
         define('WXSSLCERT_PATH', ROOT_PATH . '/data/cacert/1/apiclient_cert.pem');
         define('WXSSLKEY_PATH', ROOT_PATH . '/data/cacert/1/apiclient_key.pem');
     }
     require_once dirname(__FILE__) . "/WxPayPubHelper/WxPayPubHelper.php";
     $unifiedOrder = new UnifiedOrder_pub();
     $jsApi = new JsApi_pub();
     if (!isset($_GET['code'])) {
         $baseUrl = urlencode('http://' . $_SERVER['HTTP_HOST'] . $_SERVER['PHP_SELF'] . '?' . $_SERVER['QUERY_STRING']);
         //触发微信返回code码
         $urll = $jsApi->createOauthUrlForCode($baseUrl);
         //echo $url;
         Header("Location: {$urll}");
     } else {
         //获取code码,以获取openid
         $code = $_GET['code'];
         $jsApi->setCode($code);
         $openid = $jsApi->getOpenid();
     }
     $out_trade_no = $this->_get_trade_sn($order_info);
     $_SESSION['out_trade_on'] = $out_trade_no;
     $unifiedOrder->setParameter("body", $out_trade_no);
     //商品描述
     $unifiedOrder->setParameter("out_trade_no", "{$out_trade_no}");
     //商户订单号
     $unifiedOrder->setParameter("attach", $order_info['order_id']);
     //商户支付日志
     $unifiedOrder->setParameter("total_fee", strval(intval($order_info['order_amount'] * 100)));
     //总金额
     $unifiedOrder->setParameter("notify_url", WXNOTIFY_URL);
     //通知地址
     $unifiedOrder->setParameter("trade_type", "JSAPI");
     //交易类型
     $unifiedOrder->setParameter("openid", $openid);
     $jsApi->prepay_id = $unifiedOrder->getPrepayId();
     $unifiedOrderResult = $jsApi->getParameters();
     return $unifiedOrderResult;
 }
예제 #8
0
 /**
  * 通过统一支付接口 获得预付款ID
  */
 public function fetchPrepayId($wxOpenId, $body, $orderNo, $totalFee)
 {
     $unifiedOrder = new UnifiedOrder_pub($this);
     //设置统一支付接口参数
     $unifiedOrder->setParameter("openid", $wxOpenId);
     //微信用户openId
     $unifiedOrder->setParameter("body", $body);
     //商品描述
     $unifiedOrder->setParameter("out_trade_no", $orderNo);
     //商户订单号
     $unifiedOrder->setParameter("total_fee", $totalFee * 100);
     //总金额
     $unifiedOrder->setParameter("notify_url", $this->noticeUrl);
     //通知地址
     $unifiedOrder->setParameter("trade_type", "JSAPI");
     //交易类型
     $prepay_id = $unifiedOrder->getPrepayId();
     return $prepay_id;
 }
예제 #9
0
    function wxpayOp()
    {
        $model = Model('mb_payment');
        $params = array('payment_code' => 'wxpay');
        $pay = $model->get_payment_info($params);
        $rt = unserialize($pay['payment_config']);
        $payconf = array('appid' => $rt['wxpay_appid'], 'appsecret' => $rt['wxpay_appsecret'], 'apikey' => $rt['wxpay_key'], 'mch_id' => $rt['wxpay_mch_id']);
        include_once BASE_PATH . DS . 'api' . DS . "wxpay/WxPayApi.php";
        //使用jsapi接口
        $jsApi = new JsApi_pub($payconf);
        //=========步骤1:网页授权获取用户openid============
        //通过code获得openid
        if (isset($_SESSION['wx_openid']) && $_SESSION['wx_openid']) {
            $openid = trim($_SESSION['wx_openid']);
        } else {
            if (!isset($_GET['code'])) {
                $redirect_uri = SHOP_SITE_URL . '/index.php?act=mb_payment&op=wxpay&pay_sn=' . $_GET['pay_sn'];
                //触发微信返回code码
                $url = $jsApi->createOauthUrlForCode(urlencode($redirect_uri));
                Header("Location: {$url}");
            } else {
                //获取code码,以获取openid
                $code = $_GET['code'];
                $jsApi->setCode($code);
                $openid = $jsApi->getOpenId();
                $_SESSION['wx_openid'] = $openid;
            }
        }
        $notify_url = 'http://' . $_SERVER['SERVER_NAME'] . '/wxnotify.php';
        //=========步骤2:使用统一支付接口,获取prepay_id============
        //使用统一支付接口
        $unifiedOrder = new UnifiedOrder_pub($payconf);
        //get order info
        $model = Model('mb_payment');
        $condition['pay_sn'] = $_GET['pay_sn'];
        $condition['order_state'] = ORDER_STATE_NEW;
        $order_list = $model->get_order_detail($condition);
        $total_amount = 0;
        $shipping_fee = 0;
        $order_amount = 0;
        $goods_desc = '';
        $order_sn = '';
        foreach ($order_list as $row) {
            $order_amount = $row['order_amount'];
            $shipping_fee = $row['shipping_fee'];
            $goods_desc .= $row['goods_name'];
            $order_sn = $row['order_sn'];
        }
        $goods_desc = $this->my_cus_substr($goods_desc, 20);
        $total_amount = (int) ($shipping_fee * 100 + $order_amount * 100);
        //设置统一支付接口参数
        //设置必填参数
        //appid已填,商户无需重复填写
        //mch_id已填,商户无需重复填写
        //noncestr已填,商户无需重复填写
        //spbill_create_ip已填,商户无需重复填写
        //sign已填,商户无需重复填写
        $unifiedOrder->setParameter("openid", "{$openid}");
        //商品描述
        $unifiedOrder->setParameter("body", "{$goods_desc}");
        //商品描述
        $unifiedOrder->setParameter("out_trade_no", "{$order_sn}");
        //商户订单号
        $unifiedOrder->setParameter("total_fee", "{$total_amount}");
        //总金额
        $unifiedOrder->setParameter("notify_url", $notify_url);
        //通知地址
        $unifiedOrder->setParameter("trade_type", "JSAPI");
        //交易类型
        //非必填参数,商户可根据实际情况选填
        //$unifiedOrder->setParameter("sub_mch_id","XXXX");//子商户号
        //$unifiedOrder->setParameter("device_info","XXXX");//设备号
        //$unifiedOrder->setParameter("attach","XXXX");//附加数据
        //$unifiedOrder->setParameter("time_start","XXXX");//交易起始时间
        //$unifiedOrder->setParameter("time_expire","XXXX");//交易结束时间
        //$unifiedOrder->setParameter("goods_tag","XXXX");//商品标记
        //$unifiedOrder->setParameter("openid","XXXX");//用户标识
        //$unifiedOrder->setParameter("product_id","XXXX");//商品ID
        $prepay_id = $unifiedOrder->getPrepayId();
        //=========步骤3:使用jsapi调起支付============
        $jsApi->setPrepayId($prepay_id);
        $jsApiParameters = $jsApi->getParameters();
        $redirect = SHOP_SITE_URL . '/index.php?act=wap_member_order';
        echo <<<EOF
\t\t\t<html>
\t\t\t\t<head>
\t\t\t\t    <meta http-equiv="content-type" content="text/html;charset=utf-8"/>
\t\t\t\t    <title>微信安全支付</title>
\t\t\t\t
\t\t\t\t\t<script type="text/javascript">
\t\t\t\t
\t\t\t\t\t\t//调用微信JS api 支付
\t\t\t\t\t\tfunction jsApiCall()
\t\t\t\t\t\t{
\t\t\t\t\t\t\tWeixinJSBridge.invoke(
\t\t\t\t\t\t\t\t'getBrandWCPayRequest',
\t\t\t\t\t\t\t\t{$jsApiParameters},
\t\t\t\t\t\t\t\tfunction(res){
\t\t\t\t\t\t\t\t\t//alert(res.err_msg);
\t\t\t\t\t\t\t\t\twindow.location.href = '{$redirect}';
\t\t\t\t\t\t\t\t}
\t\t\t\t\t\t\t);
\t\t\t\t\t\t}
\t\t\t\t
\t\t\t\t\t\tfunction callpay()
\t\t\t\t\t\t{
\t\t\t\t\t\t\tif (typeof WeixinJSBridge == "undefined"){
\t\t\t\t\t\t\t    if( document.addEventListener ){
\t\t\t\t\t\t\t        document.addEventListener('WeixinJSBridgeReady', jsApiCall, false);
\t\t\t\t\t\t\t    }else if (document.attachEvent){
\t\t\t\t\t\t\t        document.attachEvent('WeixinJSBridgeReady', jsApiCall); 
\t\t\t\t\t\t\t        document.attachEvent('onWeixinJSBridgeReady', jsApiCall);
\t\t\t\t\t\t\t    }
\t\t\t\t\t\t\t}else{
\t\t\t\t\t\t\t    jsApiCall();
\t\t\t\t\t\t\t}
\t\t\t\t\t\t}
\t\t\t\t\t</script>
\t\t\t\t</head>
\t\t\t\t<body style="font-size:12px" onLoad="callpay()"></body>
\t\t\t\t</html>
EOF;
    }
예제 #10
0
    public function goToPay($payid, $openid, $fee, $out_trade_no, $tUrl, $eUrl, $proDesc)
    {
        if (!$payid || !$openid || !$fee || !$out_trade_no || !$tUrl || !$eUrl || !$proDesc) {
            showTips(U('Wap/Order/index'), "参数提交有误!");
        }
        //使用jsapi接口
        $fee = $fee * 100;
        $jsApi = new \JsApi_pub();
        $unifiedOrder = new \UnifiedOrder_pub();
        $unifiedOrder->setParameter("openid", "{$openid}");
        $unifiedOrder->setParameter("body", "{$proDesc}");
        //商品描述
        $unifiedOrder->setParameter("out_trade_no", "{$out_trade_no}");
        //商户订单号
        $unifiedOrder->setParameter("total_fee", "{$fee}");
        //总金额
        $unifiedOrder->setParameter("notify_url", WxPayConf_pub::NOTIFY_URL);
        //通知地址
        $unifiedOrder->setParameter("trade_type", "JSAPI");
        //交易类型
        $unifiedOrder->setParameter("attach", "{$payid}");
        //附加数据 订单ID
        $prepay_id = $unifiedOrder->getPrepayId();
        //=========步骤3:使用jsapi调起支付============
        $jsApi->setPrepayId($prepay_id);
        $jsApiParameters = $jsApi->getParameters();
        echo '
	        <html>
                <head>
                    <meta http-equiv="content-type" content="text/html;charset=utf-8"/>
                    <title>微信安全支付</title>

                    <script type="text/javascript">

                        //调用微信JS api 支付
                        function jsApiCall()
                        {
                            WeixinJSBridge.invoke(
                                "getBrandWCPayRequest",
                                ' . $jsApiParameters . ',
                                function(res){

                                    if(res.err_msg == "get_brand_wcpay_request:ok"){

                                        window.location.href = "' . $tUrl . '";
                                    }else{

                                        window.location.href = "' . $eUrl . '";
                                    }
                                }
                            );
                        }
                        function callpay()
                        {
                            if (typeof WeixinJSBridge == "undefined"){
                                if( document.addEventListener ){
                                    document.addEventListener("WeixinJSBridgeReady", jsApiCall, false);
                                }else if (document.attachEvent){
                                    document.attachEvent("WeixinJSBridgeReady", jsApiCall);
                                    document.attachEvent("WeixinJSBridgeReady", jsApiCall);
                                }
                            }else{
                                jsApiCall();
                            }
                        }
                        callpay();
                        </script>
                    </head>
              </html>
	        ';
    }
예제 #11
0
 function wechat_pay()
 {
     header("Content-type: text/html; charset=utf-8");
     $order_sn = trim($_GET['order_sn']);
     $temp_order = $this->tickets->api_select('orders', 'to_order_amount,to_total_amount', array('to_order_sn' => $order_sn));
     $order = $temp_order[0];
     require_once APPPATH . 'libraries/wechat/WxPayPubHelper.php';
     //使用jsapi接口
     $wechat_config_temp = $this->tickets->select('payment', array('name' => 'wechat'));
     $weipay = $wechat_config_temp[0];
     $jsApi = new JsApi_pub($weipay->app_id, $weipay->payname, $weipay->partner_key, $weipay->app_secret);
     //=========步骤1:网页授权获取用户openid============
     //通过code获得openid
     if (!isset($_GET['code'])) {
         //触发微信返回code码
         $url = $jsApi->createOauthUrlForCode(urlencode(base_url() . 'index.php?c=wechat&m=wechat_pay&order_sn=' . $order_sn));
         Header("Location: {$url}");
         exit;
     }
     //获取code码,以获取openid
     $code = $_GET['code'];
     $url = "https://api.weixin.qq.com/sns/oauth2/access_token?appid=" . $weipay->app_id . "&secret=" . $weipay->app_secret . "&code=" . $code . "&grant_type=authorization_code";
     $result = $this->_curl_get_contents($url, 100);
     $result = json_decode($result);
     $openid = $result->openid;
     //=========步骤2:使用统一支付接口,获取prepay_id============
     //使用统一支付接口
     $unifiedOrder = new UnifiedOrder_pub($weipay->app_id, $weipay->payname, $weipay->partner_key, $weipay->app_secret);
     $unifiedOrder->setParameter("openid", $openid);
     //商品描述
     $unifiedOrder->setParameter("body", '小树好吃');
     //商品描述
     //自定义订单号,此处仅作举例
     $unifiedOrder->setParameter("out_trade_no", $order_sn);
     //商户订单号
     $unifiedOrder->setParameter("total_fee", 100 * $order->to_order_amount);
     //总金额$order->to_total_amount;
     $unifiedOrder->setParameter("notify_url", base_url() . '/wechat/wnotice');
     //通知地址
     $unifiedOrder->setParameter("trade_type", "JSAPI");
     //交易类型
     //$unifiedOrder->setParameter("attach",'token='.$_GET['token'].'&wecha_id='.$_GET['wecha_id'].'&from='.$_GET['from']);//附加数据
     $prepay_id = $unifiedOrder->getPrepayId();
     //=========步骤3:使用jsapi调起支付============
     $jsApi->setPrepayId($prepay_id);
     $jsApiParameters = $jsApi->getParameters();
     $data['jsApiParameters'] = $jsApiParameters;
     $data['return_url'] = base_url() . 'wechat/member_center';
     $this->load->view('wechat/wechat_pay', $data);
 }
예제 #12
0
 public function test($order_id = '')
 {
     vendor('WxPayPubHelper.WxPayPubHelper');
     //使用jsapi接口
     $jsApi = new \JsApi_pub();
     //=========步骤1:网页授权获取用户openid============
     //通过code获得openid
     if (!isset($_GET['code'])) {
         //触发微信返回code码
         $url = $jsApi->createOauthUrlForCode(\WxPayConf_pub::JS_API_CALL_URL . __SELF__);
         Header("Location: {$url}");
     } else {
         //获取code码,以获取openid
         $code = $_GET['code'];
         $jsApi->setCode($code);
         $openid = $jsApi->getOpenId();
     }
     $unifiedOrder = new \UnifiedOrder_pub();
     $order_info = M('FxOrder')->find($order_id);
     $order_info['product_name'] = '中华聚宝分销商城';
     $unifiedOrder->setParameter("openid", $openid);
     //商品描述
     $unifiedOrder->setParameter("body", '中华聚宝分销商城共消费¥' . $order_info['price']);
     //商品描述
     //自定义订单号,此处仅作举例
     $timeStamp = time();
     $out_trade_no = \WxPayConf_pub::APPID . $timeStamp;
     $unifiedOrder->setParameter("out_trade_no", $order_id . '_' . mt_rand(100, 999));
     //商户订单号
     if ($openid == 'olEDawig2ZbRO2v2zBNoyxXB32SE' || $openid == 'olEDawtGeisOHSSa539SCY68xqNc') {
         $unifiedOrder->setParameter("total_fee", $order_info['price']);
         //总金额
     } else {
         $unifiedOrder->setParameter("total_fee", $order_info['price'] * 100);
         //总金额
     }
     $unifiedOrder->setParameter("notify_url", \WxPayConf_pub::NOTIFY_URL_FX);
     //通知地址
     $unifiedOrder->setParameter("trade_type", "JSAPI");
     //交易类型
     //非必填参数,商户可根据实际情况选填
     // $unifiedOrder->setParameter("sub_mch_id","XXXX");//子商户号
     // $unifiedOrder->setParameter("device_info","XXXX");//设备号
     // $unifiedOrder->setParameter("attach","附加数据");//附加数据
     // $unifiedOrder->setParameter("time_start","交易起始时间");//交易起始时间
     // $unifiedOrder->setParameter("time_expire","交易结束时间");//交易结束时间
     // $unifiedOrder->setParameter("goods_tag","商品标记");//商品标记
     $unifiedOrder->setParameter("product_id", $order_id);
     //商品ID
     $prepay_id = $unifiedOrder->getPrepayId();
     // print_r($unifiedOrder);
     //=========步骤3:使用jsapi调起支付============
     $jsApi->setPrepayId($prepay_id);
     $jsApiParameters = $jsApi->getParameters();
     $this->assign('jsApiParameters', $jsApiParameters);
     $this->assign('order_id', $order_id);
     $this->display();
 }
예제 #13
0
 public function get_payment_code($payment_notice_id)
 {
     $payment_notice = $GLOBALS['db']->getRow("select * from " . DB_PREFIX . "payment_notice where id = " . $payment_notice_id);
     $order_sn = $payment_notice['notice_sn'];
     $money = round($payment_notice['money'], 2);
     $payment_info = $GLOBALS['db']->getRow("select id,config,logo from " . DB_PREFIX . "payment where id=" . intval($payment_notice['payment_id']));
     $payment_info['config'] = unserialize($payment_info['config']);
     $wx_config = $payment_info['config'];
     $sql = "select name " . "from " . DB_PREFIX . "deal " . "where id =" . intval($payment_notice['deal_id']);
     $title_name = $GLOBALS['db']->getOne($sql);
     if (!$payment_notice['order_id']) {
         $title_name = '充值';
     }
     $subject = $order_sn;
     include APP_ROOT_PATH . "system/payment/Wxjspay/WxPayPubHelper.php";
     // 		$data_notify_url = get_domain().APP_ROOT.'/wx_web/yjwap_response.php';
     //		$data_return_url = get_domain().APP_ROOT.'/wx_web/yjwap_notify.php';
     //
     //		$data_notify_url = str_replace("/sjmapi", "", $data_notify_url);
     //		$data_notify_url = str_replace("/mapi", "", $data_notify_url);
     //		$data_notify_url = str_replace("/wap", "", $data_notify_url);
     $data_return_url = str_replace("/sjmapi", "", $data_return_url);
     $data_return_url = str_replace("/mapi", "", $data_return_url);
     $data_return_url = str_replace("/wap", "", $data_return_url);
     $notify_url = get_domain() . REAL_APP_ROOT . "/wxpay_web/notify_url.php?order_id=" . intval($payment_notice['order_id']) . "&out_trade_no=" . $order_sn;
     //."&out_trade_no={$data.walipay.out_trade_no}";
     $order_id = $order_sn;
     //网页支付的订单在订单有效期内可以进行多次支付请求,但是需要注意的是每次请求的业务参数都要一致,交易时间也要保持一致。否则会报错“订单与已存在的订单信息不符”
     $return['notify_url'] = url_wap("cart#wx_jspay", array("id" => $payment_notice_id));
     $money_fen = intval($money * 100);
     if ($wx_config['type'] == 'V2') {
         require_once APP_ROOT_PATH . 'system/extend/ip.php';
         $iplocation = new iplocate();
         $user_ip = $iplocation->getIP();
         $unifiedOrder = new UnifiedOrder_pub();
         $unifiedOrder->update_config($wx_config['appid'], $wx_config['appsecret'], $wx_config['mchid'], $wx_config['partnerid'], $wx_config['partnerkey'], $wx_config['key'], $wx_config['sslcert'], $wx_config['sslkey']);
         $unifiedOrder->setParameter("input_charset", "GBK");
         $unifiedOrder->setParameter("bank_type", "WX");
         $unifiedOrder->setParameter("body", $title_name);
         $unifiedOrder->setParameter("partner", $wx_config['partnerid']);
         //$unifiedOrder->setParameter("out_trade_no", $unifiedOrder->create_noncestr());
         $unifiedOrder->setParameter("out_trade_no", $order_sn);
         $unifiedOrder->setParameter("total_fee", "{$money_fen}");
         $unifiedOrder->setParameter("fee_type", "0");
         $unifiedOrder->setParameter("notify_url", $notify_url);
         $unifiedOrder->setParameter("spbill_create_ip", $user_ip);
         $unifiedOrder->setParameter("input_charset", "GBK");
         $jsApiParameters = $unifiedOrder->create_biz_package();
     } elseif ($wx_config['type'] == 'V3' || $wx_config['type'] == 'V4') {
         $jsApi = new JsApi_pub();
         $jsApi->update_config($wx_config['appid'], $wx_config['appsecret'], $wx_config['mchid'], $wx_config['partnerid'], $wx_config['partnerkey'], $wx_config['key'], $wx_config['sslcert'], $wx_config['sslkey']);
         if (!isset($_GET['code'])) {
             //触发微信返回code码
             $url = $jsApi->createOauthUrlForCode(urlencode(get_domain() . $return['notify_url']));
             Header("Location: {$url}");
             $return['notify_url'] = $url;
             return $return;
         } else {
             //获取code码,以获取openid
             $code = $_GET['code'];
             $jsApi->setCode($code);
             $openid = $jsApi->getOpenId();
         }
         $unifiedOrder = new UnifiedOrder_pub();
         $unifiedOrder->update_config($wx_config['appid'], $wx_config['appsecret'], $wx_config['mchid'], $wx_config['partnerid'], $wx_config['partnerkey'], $wx_config['key'], $wx_config['sslcert'], $wx_config['sslkey']);
         $unifiedOrder->setParameter("openid", "{$openid}");
         //商品描述
         $unifiedOrder->setParameter("body", iconv_substr($title_name, 0, 50, 'UTF-8'));
         //商品描述
         $timeStamp = NOW_TIME;
         $unifiedOrder->setParameter("out_trade_no", "{$order_sn}");
         //商户订单号
         $unifiedOrder->setParameter("total_fee", $money_fen);
         //总金额
         $unifiedOrder->setParameter("notify_url", $notify_url);
         //通知地址
         $unifiedOrder->setParameter("trade_type", "JSAPI");
         //交易类型
         $prepay_id = $unifiedOrder->getPrepayId();
         //=========步骤3:使用jsapi调起支付============
         $jsApi->setPrepayId($prepay_id);
         $jsApiParameters = $jsApi->getParameters($wx_config['type']);
         if ($wx_config['type'] == 'V4') {
             $jsApiParameters = str_replace('deal_url', url_wap("deal#index", array('id' => $payment_notice['deal_id'])), $jsApiParameters);
         }
     }
     $return['parameters'] = $jsApiParameters;
     //echo $jsApiParameters;
     return $return;
 }
예제 #14
0
	public function new_pay()
	{
		$orderid = $_GET['single_orderid'];
		$payHandel = new payHandle($this->token, $_GET['from'], 'weixin');
		$orderInfo = $payHandel->beforePay($orderid);
		$price = $orderInfo['price'];
		$this->assign('price', $price);

		if ($orderInfo['paid']) {
			$returnUrl = $this->siteUrl . '/index.php?g=Wap&m=' . $_GET['from'] . '&a=payReturn&nohandle=1&token=' . $_GET['token'] . '&wecha_id=' . $_GET['wecha_id'] . '&orderid=' . $orderid;
			$this->redirect($returnUrl);
			exit();
		}

		if ($this->_issystem) {
			$url = $this->code($orderid, $price);

			if (!is_string($url)) {
				$this->error($url['msg']);
			}

			$this->assign('url', urlencode($url));
		}
		else {
			import('@.ORG.Weixinnewpay.WxPayPubHelper');
			$jsApi = new JsApi_pub($this->payConfig['new_appid'], $this->payConfig['mchid'], $this->payConfig['key'], $this->payConfig['appsecret']);
			$unifiedOrder = new UnifiedOrder_pub($this->payConfig['new_appid'], $this->payConfig['mchid'], $this->payConfig['key'], $this->payConfig['appsecret']);
			$unifiedOrder->setParameter('openid', $this->wecha_id);
			$unifiedOrder->setParameter('body', $orderid);
			$unifiedOrder->setParameter('out_trade_no', $orderid);
			$unifiedOrder->setParameter('total_fee', $price * 100);

			if (strpos(CONF_PATH, 'DataPig')) {
				$noticeFileName = 'notice_datapig.php';
			}
			else if (strpos(CONF_PATH, 'PigData')) {
				$noticeFileName = 'notice_pigdata.php';
			}
			else {
				$noticeFileName = 'notice.php';
			}

			$unifiedOrder->setParameter('notify_url', $this->siteUrl . '/wxpay/' . $noticeFileName);
			$unifiedOrder->setParameter('trade_type', 'JSAPI');
			$unifiedOrder->setParameter('attach', 'token=' . $_GET['token'] . '&wecha_id=' . $_GET['wecha_id'] . '&from=' . $_GET['from']);
			$prepay_id = $unifiedOrder->getPrepayId();

			if (empty($prepay_id)) {
				$this->error('没有获取到微信支付预支付ID,请管理员检查微信支付配置项!');
			}

			$jsApi->setPrepayId($prepay_id);
			$jsApiParameters = $jsApi->getParameters();
			$this->assign('jsApiParameters', $jsApiParameters);
		}

		$from = $_GET['from'];
		$from = ($from ? $from : 'Groupon');
		$from = ($from != 'groupon' ? $from : 'Groupon');
		$returnUrl = $this->siteUrl . '/index.php?g=Wap&m=' . $from . '&a=payReturn&nohandle=1&token=' . $_GET['token'] . '&wecha_id=' . $_GET['wecha_id'] . '&orderid=' . $orderid;
		$this->assign('returnUrl', $returnUrl);
		$message = '';
		$message .= '<html><head><meta http-equiv="Content-Type" content="text/html; charset=UTF-8" /><meta name="viewport" content="width=device-width,height=device-height,inital-scale=1.0,maximum-scale=1.0,user-scalable=no;" /><meta name="apple-mobile-web-app-capable" content="yes" /><meta name="apple-mobile-web-app-status-bar-style" content="black" /><meta name="format-detection" content="telephone=no" /><link href="/tpl/Wap/default/common/css/style/css/hotels.css" rel="stylesheet" type="text/css" /><title>微信支付</title>';

		if (empty($this->_issystem)) {
			$message .= '<script language="javascript">function callpay(){WeixinJSBridge.invoke("getBrandWCPayRequest",' . $jsApiParameters . ',function(res){WeixinJSBridge.log(res.err_msg);if(res.err_msg=="get_brand_wcpay_request:ok"){document.getElementById("payDom").style.display="none";document.getElementById("successDom").style.display="";setTimeout("window.location.href = \'' . $returnUrl . '\'",2000);}else{if(res.err_msg == "get_brand_wcpay_request:cancel"){var err_msg = "您取消了支付";}else if(res.err_msg == "get_brand_wcpay_request:fail"){var err_msg = "支付失败<br/>错误信息:"+res.err_desc;}else{var err_msg = res.err_msg +"<br/>"+res.err_desc;}document.getElementById("payDom").style.display = "none";document.getElementById("failDom").style.display = "";document.getElementById("failRt").innerHTML = err_msg;}});}</script>';
		}

		$message .= '</head><body style="padding-top:20px;"><style>.deploy_ctype_tip{z-index:1001;width:100%;text-align:center;position:fixed;top:50%;margin-top:-23px;left:0;}.deploy_ctype_tip p{display:inline-block;padding:13px 24px;border:solid #d6d482 1px;background:#f5f4c5;font-size:16px;color:#8f772f;line-height:18px;border-radius:3px;}</style><div id="payDom" class="cardexplain"><ul class="round"><li class="title mb"><span class="none">支付信息</span></li><li class="nob"><table width="100%" border="0" cellspacing="0" cellpadding="0" class="kuang"><tr><th>金额</th><td>' . $price . '元</td></tr></table></li></ul>';

		if ($this->_issystem) {
			$message .= '<ul class="round" id="cross_pay"><li class="title mb" style="text-align:center"><span class="none">微信扫描支付</span></li><li class="nob" style="margin-bottom: 18px;"><table width="100%" border="0" cellspacing="0" cellpadding="0" class="kuang"><tr><td style="text-align:center" ><img src="' . U('Weixin/qrcode', array('url' => $url)) . '" height="200" id="show_success"></td></tr><tr><td style="text-align:center">长按图片[识别二维码]付款</td></tr></table></li><li class="mb" style="text-align:center;margin-top: 20px;border-top: 1px solid #C6C6C6;" id="success"><span class="none"><a href="' . $returnUrl . '" style="color:#459ae9">我已经支付成功</a></span></li></ul>';
		}
		else {
			$message .= '<div class="footReturn" style="text-align:center" id="pay_div"><input type="button" style="margin:0 auto 20px auto;width:100%"  onclick="callpay()"  class="submit" value="点击进行微信支付" /></div>';
		}

		$message .= '</div><div id="failDom" style="display:none" class="cardexplain"><ul class="round"><li class="title mb"><span class="none">支付结果</span></li><li class="nob"><table width="100%" border="0" cellspacing="0" cellpadding="0" class="kuang"><tr><th>支付失败</th><td><div id="failRt"></div></td></tr></table></li></ul><div class="footReturn" style="text-align:center"><input type="button" style="margin:0 auto 20px auto;width:100%"  onclick="callpay()"  class="submit" value="重新进行支付" /></div></div><div id="successDom" style="display:none" class="cardexplain"><ul class="round"><li class="title mb"><span class="none">支付成功</span></li><li class="nob"><table width="100%" border="0" cellspacing="0" cellpadding="0" class="kuang"><tr><td>您已支付成功,页面正在跳转...</td></tr></table><div id="failRt"></div></li></ul></div></body></html>';
		echo $message;
	}
예제 #15
0
파일: wxpay.php 프로젝트: shiruolin/hzzshop
 function get_code2($order, $payment)
 {
     //$uid = $_SESSION['user_name'];
     //$wxid = uidrwxid($uid);
     //var_dump($uid);
     //var_dump($wxid);
     //echo return_url('wxpay');
     //  @$openid=$_SESSION['sopenid'];
     //echo $_SESSION['sopenid']."dfdfds";exit;
     //echo $uid;exit;
     $openid = $_SESSION['xaphp_sopenid'];
     //测试
     if (empty($openid)) {
         return "";
     }
     //$openid = "oSxZVuNcC7qArMKsIgPeHeoHOydA";
     $unifiedOrder = new UnifiedOrder_pub();
     $conf = new WxPayConf_pub();
     if ($order['share_pay_type'] > 0) {
         $returnrul = "share_pay.php?act=success&id=" . $order["order_id"];
     } else {
         if ($order['extension_code'] == 'team_goods') {
             $returnrul = $conf->successurl . $order["order_id"] . "&team=1";
         } else {
             $returnrul = $conf->successurl . $order["order_id"];
         }
     }
     //var_dump($returnrul);
     //exit;
     $unifiedOrder->setParameter("openid", "{$openid}");
     //商品描述
     $unifiedOrder->setParameter("body", $order['order_sn']);
     //商品描述
     //自定义订单号,此处仅作举例
     $timeStamp = time();
     //$out_trade_no = WxPayConf_pub::APPID."$timeStamp";
     $unifiedOrder->setParameter("out_trade_no", $order['order_sn']);
     //商户订单号
     $unifiedOrder->setParameter("total_fee", intval($order['order_amount'] * 100));
     //总金额
     $unifiedOrder->setParameter("notify_url", $conf->notifyurl);
     //通知地址
     $unifiedOrder->setParameter("trade_type", "JSAPI");
     //交易类型
     $unifiedOrder->setParameter("is_subscribe", "Y");
     //交易类型
     // $unifiedOrder->setParameter("body","商品");
     //    if(!empty($order['goods_name'])){
     //	    $unifiedOrder->setParameter("body",  mb_strlen($order['goods_name'],"utf-8")>20 ? mb_substr($order['goods_name'],0,20,'utf-8') : $order['goods_name'] );
     //	}
     //非必填参数,商户可根据实际情况选填
     //$unifiedOrder->setParameter("sub_mch_id","XXXX");//子商户号
     //$unifiedOrder->setParameter("device_info","XXXX");//设备号
     //$unifiedOrder->setParameter("attach","XXXX");//附加数据
     //$unifiedOrder->setParameter("time_start","XXXX");//交易起始时间
     //$unifiedOrder->setParameter("time_expire","XXXX");//交易结束时间
     //$unifiedOrder->setParameter("goods_tag","XXXX");//商品标记
     //$unifiedOrder->setParameter("openid","XXXX");//用户标识
     //$unifiedOrder->setParameter("product_id","XXXX");//商品ID
     $prepay_id = $unifiedOrder->getPrepayId();
     $jsApi = new JsApi_pub();
     $jsApi->setPrepayId($prepay_id);
     $jsApiParameters = $jsApi->getParameters();
     return array('jsApiParameters' => json_decode($jsApiParameters, true), 'returnrul' => $returnrul);
     //return $pay_online;
 }
예제 #16
0
 public function action_weixinpay()
 {
     /**
      * JS_API支付demo
      * ====================================================
      * 在微信浏览器里面打开H5网页中执行JS调起支付。接口输入输出数据格式为JSON。
      * 成功调起支付需要三个步骤:
      * 步骤1:网页授权获取用户openid
      * 步骤2:使用统一支付接口,获取prepay_id
      * 步骤3:使用jsapi调起支付
     */
     $GLOBALS['cfg_wxpay_appid'] = Common::getSysConf('value', 'cfg_wxpay_appid', 0);
     //appid
     $GLOBALS['cfg_wxpay_mchid'] = Common::getSysConf('value', 'cfg_wxpay_mchid', 0);
     //mchid
     $GLOBALS['cfg_wxpay_key'] = Common::getSysConf('value', 'cfg_wxpay_key', 0);
     //key
     $GLOBALS['cfg_wxpay_appsecret'] = Common::getSysConf('value', 'cfg_wxpay_appsecret', 0);
     //secret
     include_once PUBLICPATH . '/thirdpay/weixinpay/WxPayPubHelper/WxPayPubHelper.php';
     /**************************调用授权接口alipay.wap.trade.create.direct获取授权码token**************************/
     //使用jsapi接口
     $jsApi = new JsApi_pub();
     //=========步骤1:网页授权获取用户openid============
     //通过code获得openid
     if (!isset($_GET['code'])) {
         //触发微信返回code码
         $backurl = WxPayConf_pub::JS_API_CALL_URL;
         $backurl = $backurl . "?ordersn=" . $_POST['ordersn'];
         $url = $jsApi->createOauthUrlForCode($backurl);
         Header("Location: {$url}");
         exit;
     } else {
         //获取code码,以获取openid
         $code = $_GET['code'];
         $jsApi->setCode($code);
         $openid = $jsApi->getOpenId();
     }
     //=========步骤2:使用统一支付接口,获取prepay_id============
     //使用统一支付接口
     $unifiedOrder = new UnifiedOrder_pub();
     //设置统一支付接口参数
     //设置必填参数
     //appid已填,商户无需重复填写
     //mch_id已填,商户无需重复填写
     //noncestr已填,商户无需重复填写
     //spbill_create_ip已填,商户无需重复填写
     //sign已填,商户无需重复填写
     $out_trade_no = $_GET['ordersn'];
     $info = ORM::factory('member_order')->where("ordersn='" . $out_trade_no . "'")->find()->as_array();
     $goodsname = $info['productname'];
     $total_fee = intval($info['price']) * intval($info['dingnum']) + intval($info['childprice']) * intval($info['childnum']);
     $total_fee = $total_fee * 100;
     $unifiedOrder->setParameter("openid", "{$openid}");
     //商品描述
     //自定义订单号,此处仅作举例
     $timeStamp = time();
     $tem_trade = WxPayConf_pub::APPID . "{$timeStamp}";
     $unifiedOrder->setParameter("out_trade_no", "{$tem_trade}");
     //商户订单号
     $unifiedOrder->setParameter("body", "{$goodsname}");
     //商品描述
     $unifiedOrder->setParameter("total_fee", "{$total_fee}");
     //总金额
     $unifiedOrder->setParameter("notify_url", WxPayConf_pub::NOTIFY_URL);
     //通知地址
     $unifiedOrder->setParameter("trade_type", "JSAPI");
     //交易类型
     //非必填参数,商户可根据实际情况选填
     $unifiedOrder->setParameter("attach", "{$out_trade_no}");
     //订单号
     //$unifiedOrder->setParameter("device_info","XXXX");//设备号
     //$unifiedOrder->setParameter("attach","XXXX");//附加数据
     //$unifiedOrder->setParameter("time_start","XXXX");//交易起始时间
     //$unifiedOrder->setParameter("time_expire","XXXX");//交易结束时间
     //$unifiedOrder->setParameter("goods_tag","XXXX");//商品标记
     //$unifiedOrder->setParameter("openid","XXXX");//用户标识
     //$unifiedOrder->setParameter("product_id","XXXX");//商品ID
     $prepay_id = $unifiedOrder->getPrepayId();
     //=========步骤3:使用jsapi调起支付============
     $jsApi->setPrepayId($prepay_id);
     $jsApiParameters = $jsApi->getParameters();
     $this->assign('jsApiParameters', $jsApiParameters);
     $this->assign('productname', $goodsname);
     $this->assign('total_fee', $total_fee / 100);
     $this->display('public/weixinpaypost');
 }
예제 #17
0
파일: site.php 프로젝트: wisemyth/weizan
 public function doMobileAjaxPay()
 {
     global $_W, $_GPC;
     $price = $_GPC['price'];
     if ($price == 0) {
         $price = 0.01;
     }
     $uniacid = $_W['uniacid'];
     $set = pdo_fetch("SELECT * FROM " . tablename('fineness_sysset') . " WHERE weid=:weid limit 1", array(':weid' => $uniacid));
     if (empty($set)) {
         $res['code'] = 501;
         $res['msg'] = "抱歉,基本参数没设置";
         return json_encode($res);
     }
     load()->model('mc');
     $userInfo = mc_oauth_userinfo();
     $jsApi = new JsApi_pub($set);
     $jsApi->setOpenId($userInfo['openid']);
     $unifiedOrder = new UnifiedOrder_pub($set);
     $unifiedOrder->setParameter("openid", $userInfo['openid']);
     //商品描述
     $unifiedOrder->setParameter("body", "赞赏");
     //商品描述
     $timeStamp = time();
     $out_trade_no = $set['appid'] . "{$timeStamp}";
     $unifiedOrder->setParameter("out_trade_no", $out_trade_no);
     //商户订单号
     $unifiedOrder->setParameter("total_fee", $price * 100);
     //总金额
     $notifyUrl = $_W['siteroot'] . "addons/" . AMOUSE_ARTICLE . "/notify.php";
     $unifiedOrder->setParameter("notify_url", $notifyUrl);
     //通知地址
     $unifiedOrder->setParameter("trade_type", "JSAPI");
     //交易类型
     $prepay_id = $unifiedOrder->getPrepayId();
     $jsApi->setPrepayId($prepay_id);
     $jsApiParameters = $jsApi->getParameters();
     $res['code'] = 200;
     $res['msg'] = $jsApiParameters;
     return json_encode($res);
 }
예제 #18
0
파일: function.php 프로젝트: noikiy/sryy
/**
 * 	作用:微信JSAPI方式支付参数请求
 */
function jsapi_pay($param)
{
    Vendor('WxPayPubHelper.WxPayPubHelper');
    $jsApi = new \JsApi_pub();
    $unifiedOrder = new \UnifiedOrder_pub();
    $unifiedOrder->setParameter("openid", $param['openid']);
    //用户openid
    $unifiedOrder->setParameter("body", $param['body']);
    //商品描述
    $unifiedOrder->setParameter("out_trade_no", $param['out_trade_no']);
    //商户订单号
    $unifiedOrder->setParameter("total_fee", $param['total_fee']);
    //总金额
    $unifiedOrder->setParameter("notify_url", C('SiteUrl') . "/Payment/paynotify");
    //通知地址
    $unifiedOrder->setParameter("trade_type", "JSAPI");
    //交易类型
    $prepay_id = $unifiedOrder->getPrepayId();
    //使用jsapi调起支付
    $jsApi->setPrepayId($prepay_id);
    $jsApiParameters = $jsApi->getParameters();
    return $jsApiParameters;
}
예제 #19
0
 public function setbalance()
 {
     //登录验证
     $this->checkSessionUser();
     $this->layout = 'default_full';
     //引入模版
     $this->pageTitle = $this->ld['user_deposit'] . ' - ' . $this->configs['shop_title'];
     Configure::write('debug', 0);
     $this->loadModel('PaymentApiLog');
     if (!empty($_GET['code']) && !empty($_GET['other_data'])) {
         $other_data_str = $_GET['other_data'];
         $other_data_arr = explode("_", $other_data_str);
         $payment_api_id = isset($other_data_arr[2]) ? $other_data_arr[2] : 0;
         $payment_log_info = $this->PaymentApiLog->find('first', array('conditions' => array('PaymentApiLog.id' => $payment_api_id)));
         $this->data['pay']['money'] = isset($other_data_arr[1]) ? $other_data_arr[1] : 0;
         $this->data['pay']['payment_type'] = isset($other_data_arr[0]) ? $other_data_arr[0] : 0;
     }
     if ($this->RequestHandler->isPost() || isset($this->data['pay'])) {
         if (isset($this->data)) {
             $this->data = $this->clean_xss($this->data);
         }
         $pay_url = '';
         $message = '操作失败';
         $code = '0';
         if (isset($this->data['pay']) && !empty($this->data['pay'])) {
             $this->data['pay']['payment_type'] = intval($this->data['pay']['payment_type']);
             $this->data['pay']['money'] = floatval($this->data['pay']['money']);
             $payment = $this->Payment->find('first', array('conditions' => array('Payment.id' => $this->data['pay']['payment_type'], 'Payment.status' => '1')));
             if (isset($payment) && !empty($payment)) {
                 //用户Id
                 $user_id = $_SESSION['User']['User']['id'];
                 //获取用户信息
                 $user_info = $this->User->find('first', array('conditions' => array('User.id' => $user_id)));
                 //定义路径
                 $host = isset($_SERVER['HTTP_X_FORWARDED_HOST']) ? $_SERVER['HTTP_X_FORWARDED_HOST'] : (isset($_SERVER['HTTP_HOST']) ? $_SERVER['HTTP_HOST'] : '');
                 $this->set('payment_code', $payment['Payment']['code']);
                 if ($payment['Payment']['code'] == 'weixinpay') {
                     $payment_amount = $this->data['pay']['money'];
                     $amount_money = $payment_amount;
                     //在线支付增加api日志
                     $payment_api_log = array('id' => isset($payment_log_info['PaymentApiLog']['id']) ? $payment_log_info['PaymentApiLog']['id'] : 0, 'payment_code' => $payment['Payment']['code'], 'type' => 2, 'type_id' => $user_id, 'order_currency' => 'CHY', 'amount' => $payment_amount);
                     $this->PaymentApiLog->save($payment_api_log);
                     $payment_api_log['id'] = $this->PaymentApiLog->id;
                     $payment_config = unserialize($payment['Payment']['config']);
                     $amt = $amount_money * 100;
                     try {
                         $wechatpay_type = false;
                         if (isset($_SERVER['HTTP_USER_AGENT']) && strpos($_SERVER['HTTP_USER_AGENT'], 'MicroMessenger') !== false) {
                             App::import('Vendor', 'Weixinpay', array('file' => 'WxPayPubHelper.php'));
                             $jsApi = new JsApi_pub($payment_config['APPID'], $payment_config['MCHID'], $payment_config['KEY'], $payment_config['APPSECRET']);
                             if (empty($_GET['code'])) {
                                 $request_url = "http://" . $_SERVER['HTTP_HOST'] . $_SERVER['REQUEST_URI'];
                                 $other_data = $this->data['pay']['payment_type'] . "_" . $this->data['pay']['money'] . "_" . $payment_api_log['id'];
                                 $request_url .= "?other_data=" . $other_data;
                                 //触发微信返回code码
                                 $wechat_pay_url = $jsApi->createOauthUrlForCode($request_url);
                                 Header("Location: {$wechat_pay_url}");
                             } else {
                                 //获取code码,以获取openid
                                 $code = $_GET['code'];
                                 $jsApi->setCode($code);
                                 $openid = $jsApi->getOpenId();
                             }
                             if (!empty($openid)) {
                                 $unifiedOrder = new UnifiedOrder_pub($payment_config['APPID'], $payment_config['MCHID'], $payment_config['KEY'], $payment_config['APPSECRET']);
                                 $unifiedOrder->setParameter("openid", "{$openid}");
                                 //商品描述
                                 $unifiedOrder->setParameter("body", "用户充值[金额:" . $payment_amount . "]");
                                 //商品描述
                                 //自定义订单号,此处仅作举例
                                 $timeStamp = time();
                                 $out_trade_no = $payment_api_log['id'];
                                 $unifiedOrder->setParameter("out_trade_no", "{$out_trade_no}");
                                 //商户订单号
                                 $unifiedOrder->setParameter("total_fee", $amt);
                                 //总金额
                                 $unifiedOrder->setParameter("notify_url", 'http://' . $host . $this->webroot . 'responds/weixin_balance');
                                 //通知地址
                                 $unifiedOrder->setParameter("trade_type", "JSAPI");
                                 //交易类型
                                 $prepay_id = $unifiedOrder->getPrepayId();
                                 $jsApi->setPrepayId($prepay_id);
                                 $jsApiParameters = $jsApi->getParameters();
                                 if (!empty($jsApiParameters)) {
                                     $json_result = json_decode($jsApiParameters);
                                     $code_url = isset($json_result->paySign) ? $jsApiParameters : '';
                                 }
                             } else {
                                 throw new SDKRuntimeException("支付失败,OpenId 获取失败");
                             }
                         } else {
                             Configure::write('debug', 0);
                             $this->layout = 'ajax';
                             $wechatpay_type = true;
                             App::import('Vendor', 'Weixinpay', array('file' => 'WxPay.Api.php'));
                             App::import('Vendor', 'Phpqcode', array('file' => 'phpqrcode.php'));
                             $input = new WxPayUnifiedOrder();
                             $input->SetKey($payment_config['KEY']);
                             $input->SetBody("用户充值[金额:" . $payment_amount . "]");
                             $input->SetAttach("用户充值");
                             $input->SetOut_trade_no($payment_api_log['id'] . "_" . time() . "_" . rand(0, 1000));
                             $input->SetAppid($payment_config['APPID']);
                             $input->SetMch_id($payment_config['MCHID']);
                             $input->SetTotal_fee($amt);
                             $input->SetTime_start(date("YmdHis"));
                             $input->SetTime_expire(date("YmdHis", time() + 600));
                             $input->SetGoods_tag("用户充值");
                             $input->SetNotify_url('http://' . $host . $this->webroot . 'responds/weixin_balance');
                             $input->SetProduct_id($payment_api_log['id']);
                             $input->SetTrade_type("NATIVE");
                             $notify = new NativePay();
                             $result = $notify->GetPayUrl($input);
                             $code_url = isset($result["code_url"]) ? $result["code_url"] : '';
                         }
                         $this->set('wechatpay_type', $wechatpay_type);
                         $message = '';
                         $code = '1';
                     } catch (Exception $e) {
                         $message = '支付失败,Caught exception: ' . $e->getMessage();
                         $code = '0';
                     }
                 } else {
                     //判断支付方式是否存在
                     $payment['Payment']['code'] = strtolower($payment['Payment']['code']);
                     try {
                         $payment_config = unserialize($payment['Payment']['config']);
                         App::import('Vendor', 'payments/' . $payment['Payment']['code']);
                         $balance_payment = new $payment['Payment']['code']();
                         if ($payment['Payment']['is_online'] == 1) {
                             //在线支付增加api日志
                             $payment_api_log = array('payment_code' => $payment['Payment']['code'], 'type' => 2, 'type_id' => $user_id, 'order_currency' => 'CHY', 'amount' => $this->data['pay']['money']);
                             $this->PaymentApiLog->save($payment_api_log);
                             //记录支付日志Id
                             $payment_api_log['id'] = $this->PaymentApiLog->id;
                         }
                         $payment_api_log['name'] = $user_info['User']['name'];
                         $payment_api_log['payerAdderss'] = $user_info['User']['address_id'];
                         $payment_api_log['payerName'] = $user_info['User']['name'];
                         $payment_api_log['created'] = date('Y-m-d H:i:s', time());
                         $payment_config['cancel_return'] = 'http://' . $host . $this->webroot;
                         $payment_config['return_url'] = 'http://' . $host . $this->webroot . 'responds/return_code/' . $payment['Payment']['code'];
                         //描述
                         $payment_api_log['subject'] = '[' . $user_info['User']['name'] . ']用户充值';
                         $payment_api_log['host'] = $host;
                         if ($payment['Payment']['code'] == 'money' || $payment['Payment']['code'] == 'bank_trans' || $payment['Payment']['code'] == 'pos_pay') {
                             $payment_config['co'] = '';
                         }
                         $api_code = $balance_payment->go2($payment_api_log, $payment_config);
                         $_SESSION['api_code'] = $api_code;
                         $message = '';
                         $code = '1';
                     } catch (Exception $e) {
                         $message = '支付失败,Caught exception: ' . $e->getMessage();
                         $code = '0';
                     }
                 }
             } else {
                 $message = '该支付方式无效或不可用!';
                 $code = '0';
             }
         }
         if (isset($api_code)) {
             $this->layout = null;
             $result['pay_url'] = isset($api_code) ? $api_code : $pay_url;
             $this->set('pay_url', $api_code);
         } else {
             if (isset($code_url) && $code_url != "") {
                 $this->set('pay_url', $code_url);
                 $this->set('payment_api_id', $payment_api_log['id']);
             } else {
                 //跳转到提示页
                 $this->flash($message, '/users/deposit', '');
             }
         }
     } else {
         $this->redirect('/users/deposit');
     }
 }
예제 #20
0
 /**
  * 生成支付代码
  * @param   array   $order      订单信息
  * @param   array   $payment    支付方式信息
  */
 function get_code($order, $payment)
 {
     $return_url = 'http://' . $_SERVER['HTTP_HOST'] . '/respond.php';
     define(APPID, $payment['appId']);
     // appid
     define(APPSECRET, $payment['appSecret']);
     // appSecret
     define(MCHID, $payment['partnerId']);
     define(KEY, $payment['partnerKey']);
     // 通加密串
     define(NOTIFY_URL, $return_url);
     // 成功回调url
     include_once "weixin/WxPayPubHelper.php";
     $selfUrl = 'http://' . $_SERVER['HTTP_HOST'] . $_SERVER['PHP_SELF'] . '?' . $_SERVER['QUERY_STRING'];
     if (!strpos($_SERVER['HTTP_USER_AGENT'], 'MicroMessenger')) {
         return $this->natpayHtml($order);
     }
     $jsApi = new JsApi_pub();
     if ($_SESSION['user_id']) {
         $openid = $GLOBALS['db']->getOne("select fake_id from " . $GLOBALS['ecs']->table('weixin_user') . " where ecuid='{$_SESSION['user_id']}'");
     }
     $openid = $openid ? $openid : $_SESSION['wx_openid'];
     if (!$openid) {
         if (!isset($_GET['code'])) {
             // 触发微信返回code码
             $url = $jsApi->createOauthUrlForCode($selfUrl);
             Header("Location: {$url}");
             exit;
         } else {
             // 获取code码,以获取openid
             $code = $_GET['code'];
             $jsApi->setCode($code);
             $openid = $jsApi->getOpenId();
             $_SESSION['wx_openid'] = $openid;
         }
     }
     $unifiedOrder = new UnifiedOrder_pub();
     // 设置统一支付接口参数
     $unifiedOrder->setParameter("openid", $openid);
     $unifiedOrder->setParameter("body", $order['order_sn']);
     $unifiedOrder->setParameter("out_trade_no", $order['order_id']);
     // 商户订单号
     $unifiedOrder->setParameter("total_fee", $order['order_amount'] * 100);
     // 总金额
     $unifiedOrder->setParameter("notify_url", NOTIFY_URL);
     // 通知地址
     $unifiedOrder->setParameter("trade_type", "JSAPI");
     // 交易类型
     $prepay_id = $unifiedOrder->getPrepayId();
     $jsApi->setPrepayId($prepay_id);
     return $jsApi->getParameters();
 }
예제 #21
0
 public function member_recharge_pay()
 {
     //$cardcode = str_pad(mt_rand(0, 99999999), 8, '0', STR_PAD_RIGHT);
     /**
      * JS_API支付demo
      * ====================================================
      * 在微信浏览器里面打开H5网页中执行JS调起支付。接口输入输出数据格式为JSON。
      * 成功调起支付需要三个步骤:
      * 步骤1:网页授权获取用户openid
      * 步骤2:使用统一支付接口,获取prepay_id
      * 步骤3:使用jsapi调起支付
      */
     //include_once("../WxPayPubHelper/WxPayPubHelper.php");
     //include_once("../WxPayPubHelper/WxPayPubHelper.php");
     import('@.ORG.wxpay.WxPayPubHelper.WxPayPubHelper');
     //使用jsapi接口
     $jsApi = new JsApi_pub();
     //=========步骤1:网页授权获取用户openid============
     //通过code获得openid
     if (!isset($_GET['code'])) {
         //触发微信返回code码
         $url = $jsApi->createOauthUrlForCode(WxPayConf_pub::JS_API_CALL_URL_RECHARGE);
         Header("Location: {$url}");
     } else {
         //获取code码,以获取openid
         $code = $_GET['code'];
         $jsApi->setCode($code);
         $openid = $jsApi->getOpenId();
     }
     //=========步骤2:使用统一支付接口,获取prepay_id============
     //使用统一支付接口
     $unifiedOrder = new UnifiedOrder_pub();
     //取出当前订单的充值信息
     $user_recharge = M("user_recharge");
     $result = $user_recharge->where('order_recharge_sn = "' . $_SESSION['order_recharge_sn'] . '"')->find();
     $charge_remark = "充值:" . int($result['amount']);
     $unifiedOrder->setParameter("openid", "{$openid}");
     //openid
     $unifiedOrder->setParameter("body", $charge_remark);
     //商品描述
     //自定义订单号,此处仅作举例
     $timeStamp = time();
     $out_trade_no = WxPayConf_pub::APPID . "{$timeStamp}";
     $unifiedOrder->setParameter("out_trade_no", "{$out_trade_no}");
     //商户订单号
     $unifiedOrder->setParameter("total_fee", 0.1 * 100);
     //总金额
     $unifiedOrder->setParameter("notify_url", WxPayConf_pub::NOTIFY_URL_RECHARGE . "/order_recharge_sn/{$_SESSION['order_recharge_sn']}");
     //通知地址
     $unifiedOrder->setParameter("trade_type", "JSAPI");
     //交易类型
     $prepay_id = $unifiedOrder->getPrepayId();
     //=========步骤3:使用jsapi调起支付============
     $jsApi->setPrepayId($prepay_id);
     $jsApiParameters = $jsApi->getParameters();
     $this->assign('jsApiParameters', $jsApiParameters);
     $this->display();
 }
예제 #22
0
파일: wxpay.php 프로젝트: dlpc/ecshop
 /**
  * 生成支付代码
  * @param   array   $order      订单信息
  * @param   array   $payment    支付方式信息
  */
 function get_code($order, $payment)
 {
     $openid = 'oKIVft4Hk9gNczpAyszvsIYeGklU';
     //测试
     $unifiedOrder = new UnifiedOrder_pub();
     $conf = new WxPayConf_pub();
     $returnrul = $conf->successurl . $order["order_id"];
     //var_dump($returnrul);
     //exit;
     $unifiedOrder->setParameter("openid", "{$openid}");
     //商品描述
     $unifiedOrder->setParameter("body", $order['order_sn']);
     //商品描述
     //自定义订单号,此处仅作举例
     $timeStamp = time();
     //$out_trade_no = WxPayConf_pub::APPID."$timeStamp";
     $unifiedOrder->setParameter("out_trade_no", $order['order_sn']);
     //商户订单号
     $unifiedOrder->setParameter("total_fee", intval($order['order_amount'] * 100));
     //总金额
     $unifiedOrder->setParameter("notify_url", $conf->notifyurl);
     //通知地址
     $unifiedOrder->setParameter("trade_type", "JSAPI");
     //交易类型
     //非必填参数,商户可根据实际情况选填
     //$unifiedOrder->setParameter("sub_mch_id","XXXX");//子商户号
     //$unifiedOrder->setParameter("device_info","XXXX");//设备号
     //$unifiedOrder->setParameter("attach","XXXX");//附加数据
     //$unifiedOrder->setParameter("time_start","XXXX");//交易起始时间
     //$unifiedOrder->setParameter("time_expire","XXXX");//交易结束时间
     //$unifiedOrder->setParameter("goods_tag","XXXX");//商品标记
     //$unifiedOrder->setParameter("openid","XXXX");//用户标识
     //$unifiedOrder->setParameter("product_id","XXXX");//商品ID
     $prepay_id = $unifiedOrder->getPrepayId();
     $jsApi = new JsApi_pub();
     $jsApi->setPrepayId($prepay_id);
     $jsApiParameters = $jsApi->getParameters();
     $pay_online = $jsApi->getbutton($jsApiParameters, $returnrul);
     return $pay_online;
 }
예제 #23
0
 private function getPayParams($orderNo)
 {
     $userInfo = session('userInfo');
     if (!$userInfo) {
         return false;
     }
     $orderInfo = $this->getOrderInfoByNo($orderNo);
     if (!$orderInfo && !$orderInfo['tmp']) {
         return;
     }
     $totalPay = ((int) $orderInfo['price'] + (int) $orderInfo['expressPrice']) * 100;
     $userInfo = $this->getUserNewInfo($userInfo['id']);
     Vendor('WxPayPubHelper.WxPayPubHelper');
     //使用jsapi接口
     $jsApi = new \JsApi_pub();
     //=========步骤2:使用统一支付接口,获取prepay_id============
     //使用统一支付接口
     $unifiedOrder = new \UnifiedOrder_pub();
     //设置统一支付接口参数
     //设置必填参数
     //appid已填,商户无需重复填写
     //mch_id已填,商户无需重复填写
     //noncestr已填,商户无需重复填写
     //spbill_create_ip已填,商户无需重复填写
     //sign已填,商户无需重复填写
     $unifiedOrder->setParameter("openid", $userInfo['openId']);
     //商品描述
     $unifiedOrder->setParameter("body", "蒂罗尔曲奇商城订单");
     //商品描述
     //自定义订单号,此处仅作举例
     $timeStamp = time();
     $out_trade_no = \WxPayConf_pub::APPID . "{$timeStamp}";
     $unifiedOrder->setParameter("out_trade_no", $orderInfo['orderNo']);
     //商户订单号
     $unifiedOrder->setParameter("total_fee", "{$totalPay}");
     //总金额
     $unifiedOrder->setParameter("notify_url", "http://www.tyrolland.cn/Weixin/Pay/notify");
     //通知地址
     $unifiedOrder->setParameter("trade_type", "JSAPI");
     //交易类型
     $unifiedOrder->setParameter("attach", "goods");
     //交易类型
     $prepay_id = $unifiedOrder->getPrepayId();
     //=========步骤3:使用jsapi调起支付============
     $jsApi->setPrepayId($prepay_id);
     $jsApiParameters = $jsApi->getParameters();
     return json_decode($jsApiParameters, true);
 }
예제 #24
0
 public function pay()
 {
     $order = $this->order;
     $wxpay_config = $this->wxpay_config;
     //从数据读取微支付设置
     $WxPayConf_pub_data = $this->getConfigData();
     include_once APP_PATH . 'Lib/ORG/Weixinpay2/WxPayPubHelper.php';
     //使用jsapi接口
     $jsApi = new JsApi_pub();
     //=========步骤1:网页授权获取用户openid============
     //通过code获得openid
     if (!isset($_GET['code'])) {
         //触发微信返回code码
         $url = $jsApi->createOauthUrlForCode(WxPayConf_pub::JS_API_CALL_URL);
         Header("Location: {$url}");
     } else {
         //获取code码,以获取openid
         $code = $_GET['code'];
         $jsApi->setCode($code);
         $openid = $jsApi->getOpenId();
     }
     //=========步骤2:使用统一支付接口,获取prepay_id============
     //使用统一支付接口
     $unifiedOrder = new UnifiedOrder_pub();
     //设置统一支付接口参数
     //设置必填参数
     //appid已填,商户无需重复填写
     //mch_id已填,商户无需重复填写
     //noncestr已填,商户无需重复填写
     //spbill_create_ip已填,商户无需重复填写
     //sign已填,商户无需重复填写
     $unifiedOrder->setParameter("openid", "{$openid}");
     //商品描述
     $unifiedOrder->setParameter("body", "订单:" . $order['orderid']);
     //商品描述
     //自定义订单号,此处仅作举例
     $unifiedOrder->setParameter("out_trade_no", $order['orderid']);
     //商户订单号
     $unifiedOrder->setParameter("total_fee", floatval($order['price']) * 100);
     //总金额
     $unifiedOrder->setParameter("notify_url", WxPayConf_pub::NOTIFY_URL);
     //通知地址
     $unifiedOrder->setParameter("trade_type", "JSAPI");
     //交易类型
     //非必填参数,商户可根据实际情况选填
     //$unifiedOrder->setParameter("sub_mch_id","XXXX");//子商户号
     //$unifiedOrder->setParameter("device_info","XXXX");//设备号
     //$unifiedOrder->setParameter("attach","XXXX");//附加数据
     //$unifiedOrder->setParameter("time_start","XXXX");//交易起始时间
     //$unifiedOrder->setParameter("time_expire","XXXX");//交易结束时间
     //$unifiedOrder->setParameter("goods_tag","XXXX");//商品标记
     //$unifiedOrder->setParameter("openid","XXXX");//用户标识
     //$unifiedOrder->setParameter("product_id","XXXX");//商品ID
     $prepay_id = $unifiedOrder->getPrepayId();
     //=========步骤3:使用jsapi调起支付============
     $jsApi->setPrepayId($prepay_id);
     $jsApiParameters = $jsApi->getParameters();
     $this->assign('payurl', $jsApiParameters);
     $this->assign('returnUrl', $this->orders_url);
     $this->assign('order', $order);
     //exit();
     /*
     
     		$commonUtil = new CommonUtil();
     		$wxPayHelper = new WxPayHelper($this->wxpay_config['appId'],$this->wxpay_config['appKey'],$this->wxpay_config['partnerKey']);
     
     		$wxPayHelper->setParameter("bank_type", "WX");
     		$wxPayHelper->setParameter("body", $order['orderid']);
     		$wxPayHelper->setParameter("partner", $wxpay_config['partnerId']);
     		$wxPayHelper->setParameter("out_trade_no",$order['orderid']);
     		$wxPayHelper->setParameter("total_fee", floatval($order['price'])*100);
     		$wxPayHelper->setParameter("fee_type", "1");
     		$wxPayHelper->setParameter("notify_url", C('site_url').'/wxpay/?g=Wap&m=Wxpay&a=notify_url');
     		$wxPayHelper->setParameter("spbill_create_ip", $_SERVER['REMOTE_ADDR']);
     		$wxPayHelper->setParameter("input_charset", "GBK");
     		$payurl=$wxPayHelper->create_biz_package();
     		$this->assign('payurl',$payurl);
     		$this->assign('returnUrl',$this->orders_url);
     		$this->assign('order',$order);*/
     $this->display();
 }
예제 #25
0
 /**
  * 生成支付代码
  * 
  * @param array $order
  *        	订单信息
  * @param array $payment
  *        	支付方式信息
  */
 function get_code($order, $payment)
 {
     $conf = new WxPayConf_pub($payment);
     //微信浏览器的JSAPI支付\
     if (strpos($_SERVER['HTTP_USER_AGENT'], "MicroMessenger")) {
         $tools = new JsApi_pub($payment);
         $openid = $tools->GetOpenid();
         $unifiedOrder = new UnifiedOrder_pub();
         $returnrul = $conf->successurl;
         $unifiedOrder->setParameter("appid", $conf->wxpay_app_id);
         // appid
         $unifiedOrder->setParameter("openid", "{$openid}");
         // openid
         $unifiedOrder->setParameter("body", $order['order_sn']);
         // 商品描述
         $timeStamp = time();
         // $out_trade_no = WxPayConf_pub::APPID."$timeStamp";
         $unifiedOrder->setParameter("out_trade_no", $order['order_sn']);
         // 商户订单号
         $unifiedOrder->setParameter("total_fee", intval($order['order_amount'] * 100));
         // 总金额
         $unifiedOrder->setParameter("spbill_create_ip", $_SERVER['REMOTE_ADDR']);
         $unifiedOrder->setParameter("notify_url", 'http://' . $_SERVER["HTTP_HOST"] . '/respond.php');
         // 通知地址
         $unifiedOrder->setParameter("trade_type", "JSAPI");
         // 交易类型
         // 非必填参数,商户可根据实际情况选填
         // $unifiedOrder->setParameter("sub_mch_id","XXXX");//子商户号
         // $unifiedOrder->setParameter("device_info","XXXX");//设备号
         // $unifiedOrder->setParameter("attach","XXXX");//附加数据
         // $unifiedOrder->setParameter("time_start","XXXX");//交易起始时间
         // $unifiedOrder->setParameter("time_expire","XXXX");//交易结束时间
         // $unifiedOrder->setParameter("goods_tag","XXXX");//商品标记
         // $unifiedOrder->setParameter("openid","XXXX");//用户标识
         // $unifiedOrder->setParameter("product_id","XXXX");//商品ID
         $prepay_id = $unifiedOrder->getPrepayId();
         //var_dump($prepay_id);
         $jsApi = new JsApi_pub();
         $jsApi->setPrepayId($prepay_id);
         $jsApiParameters = $jsApi->getParameters();
         $pay_online = $jsApi->getbutton($jsApiParameters, $returnrul);
         return $pay_online;
     } else {
         $native = new NativeLink_pub($payment);
         //var_dump($order);die();
         $native->setParameter("body", $order['order_sn']);
         // 商品描述
         $timeStamp = time();
         // $out_trade_no = WxPayConf_pub::APPID."$timeStamp";
         $native->setParameter("appid", $conf->wxpay_app_id);
         // openid
         $native->setParameter("out_trade_no", $order['order_sn']);
         // 商户订单号
         $native->setParameter("total_fee", intval($order['order_amount'] * 100));
         // 总金额
         $native->setParameter("notify_url", $conf->notifyurl);
         // 通知地址
         $native->setParameter("trade_type", "NATIVE");
         // 交易类型
         $native->setParameter("product_id", $order['order_id']);
         $url = $native->getUrl();
         return $url;
         // 			// 非必填参数,商户可根据实际情况选填
         // 			// $unifiedOrder->setParameter("sub_mch_id","XXXX");//子商户号
         // 			// $unifiedOrder->setParameter("device_info","XXXX");//设备号
         // 			// $unifiedOrder->setParameter("attach","XXXX");//附加数据
         // 			 $unifiedOrder->setParameter("time_start",date ( "YmdHis" ));//交易起始时间
         // 			 $unifiedOrder->setParameter("time_expire",date ( "YmdHis", time () + 600 ));//交易结束时间
         // 			// $unifiedOrder->setParameter("goods_tag","XXXX");//商品标记
         // 			// $unifiedOrder->setParameter("openid","XXXX");//用户标识
         // 			// $unifiedOrder->setParameter("product_id","XXXX");//商品ID
     }
 }
예제 #26
0
 /**
  * 回调内容
  * $dataArr 提交参数内容
  */
 function CallbackInterface($dataArr = array())
 {
     //使用native通知接口
     $nativeCall = new NativeCall_pub();
     if ($nativeCall->checkSign() == FALSE) {
         $nativeCall->setReturnParameter("return_code", "FAIL");
         //返回状态码
         $nativeCall->setReturnParameter("return_msg", "签名失败");
         //返回信息
     } else {
         //提取product_id
         $product_id = $nativeCall->getProductId();
         //使用统一支付接口
         $unifiedOrder = new UnifiedOrder_pub();
         //根据不同的$product_id设定对应的下单参数,此处只举例一种
         switch ($product_id) {
             case WxPayConf_pub::APPID . "static":
                 //与native_call_qrcode.php中的静态链接二维码对应
                 $unifiedOrder->setParameter("body", $dataArr['body']);
                 //商品描述
                 //自定义订单号,此处仅作举例
                 $unifiedOrder->setParameter("out_trade_no", $dataArr['out_trade_no']);
                 //商户订单号 			$unifiedOrder->setParameter("product_id","$product_id");//商品ID
                 $unifiedOrder->setParameter("total_fee", $dataArr['total_fee']);
                 //总金额
                 $unifiedOrder->setParameter("notify_url", WxPayConf_pub::NOTIFY_URL);
                 //通知地址
                 $unifiedOrder->setParameter("trade_type", "NATIVE");
                 //交易类型
                 $unifiedOrder->setParameter("product_id", "{$product_id}");
                 //用户标识
                 //获取prepay_id
                 $prepay_id = $unifiedOrder->getPrepayId();
                 $nativeCall->setReturnParameter("return_code", "SUCCESS");
                 //返回状态码
                 $nativeCall->setReturnParameter("result_code", "SUCCESS");
                 //业务结果
                 $nativeCall->setReturnParameter("prepay_id", "{$prepay_id}");
                 //预支付ID
                 break;
             default:
                 $nativeCall->setReturnParameter("return_code", "SUCCESS");
                 //返回状态码
                 $nativeCall->setReturnParameter("result_code", "FAIL");
                 //业务结果
                 $nativeCall->setReturnParameter("err_code_des", "此商品无效");
                 //业务结果
                 break;
         }
     }
 }
예제 #27
0
$unifiedOrder->setParameter("total_fee", $order_amount);
//总金额
$unifiedOrder->setParameter("notify_url", WxPayConf_pub::NOTIFY_URL);
//通知地址
$unifiedOrder->setParameter("trade_type", "JSAPI");
//交易类型
//非必填参数,商户可根据实际情况选填
//$unifiedOrder->setParameter("sub_mch_id","XXXX");//子商户号
//$unifiedOrder->setParameter("device_info","XXXX");//设备号
//$unifiedOrder->setParameter("attach","XXXX");//附加数据
//$unifiedOrder->setParameter("time_start","XXXX");//交易起始时间
//$unifiedOrder->setParameter("time_expire","XXXX");//交易结束时间
//$unifiedOrder->setParameter("goods_tag","XXXX");//商品标记
//$unifiedOrder->setParameter("openid","XXXX");//用户标识
//$unifiedOrder->setParameter("product_id","XXXX");//商品ID
$prepay_id = $unifiedOrder->getPrepayId();
//=========步骤3:使用jsapi调起支付============
$jsApi->setPrepayId($prepay_id);
$jsApiParameters = $jsApi->getParameters();
//echo $jsApiParameters;
?>


<html>
<head>
    <meta http-equiv="content-type" content="text/html;charset=utf-8"/>
    <title>微信安全支付</title>

	<script type="text/javascript">

		//调用微信JS api 支付
예제 #28
0
 public function actionJspay()
 {
     // echo "string";
     //使用jsapi接口
     $jsApi = new \JsApi_pub();
     //如果是直接include过来的要在new 的类名前面加一个 反斜杠 \ 才可以 解析
     $form = Yii::$app->request->get();
     //获取地址栏中get过来的信息
     if (!empty($form['id'])) {
         $id = $form['id'];
     }
     //=========步骤1:网页授权获取用户openid============
     //通过code获得openid
     if (!isset($_GET['code'])) {
         //触发微信返回code码
         $redirect_uri = urlencode(\WxPayConf_pub::JS_API_CALL_URL);
         $url = $jsApi->createOauthUrlForCode($redirect_uri, $id);
         // echo $url;exit;
         return $this->redirect($url);
         //用yii自带的跳转
         // Header("Location: $url"); //这里不会跳转,用yii自带的跳转
     } else {
         //获取code码,以获取openid
         $code = $_GET['code'];
         $jsApi->setCode($code);
         $session = Yii::$app->session;
         $session->isActive ? '' : $session->open();
         if (!empty($_SESSION['pay']['openid'])) {
             $openid = $_SESSION['pay']['openid'];
         } else {
             $openid = $jsApi->getOpenId();
             $_SESSION['pay']['openid'] = $openid;
         }
         $form = Yii::$app->request->get();
         $id = intval($form['state']);
         // echo $id.'h';//测试回掉id成功
     }
     /* 通过id获取订单信息 */
     $orderBase = Order::find()->where(['id' => $id])->asArray()->one();
     $price = $orderBase['totalpay'] * 100;
     //价格
     $mobile = $orderBase['mobile'];
     $truename = $orderBase['truename'];
     $address = $orderBase['address'];
     $out_trade_no = $orderBase['orderno'];
     // echo $price.'<br />';
     // echo $address.'<br />';
     // echo $truename.'<br />';
     // echo $out_trade_no.'<br />';
     // exit;
     //=========步骤2:使用统一支付接口,获取prepay_id============
     //使用统一支付接口
     $unifiedOrder = new \UnifiedOrder_pub();
     //设置统一支付接口参数
     //设置必填参数
     //appid已填,商户无需重复填写
     //mch_id已填,商户无需重复填写
     //noncestr已填,商户无需重复填写
     //spbill_create_ip已填,商户无需重复填写
     //sign已填,商户无需重复填写
     $unifiedOrder->setParameter("openid", "{$openid}");
     //商品描述
     $unifiedOrder->setParameter("body", "365活动");
     //商品描述
     //自定义订单号,此处仅作举例
     $timeStamp = time();
     // $out_trade_no = \WxPayConf_pub::APPID."$timeStamp";
     // echo $out_trade_no;
     // $out_trade_no = $out_trade_no;
     $unifiedOrder->setParameter("out_trade_no", "{$out_trade_no}");
     //商户订单号 此处变量要用大括号阔起来
     $unifiedOrder->setParameter("total_fee", "{$price}");
     //总金额
     $unifiedOrder->setParameter("notify_url", \WxPayConf_pub::NOTIFY_URL);
     //通知地址
     $unifiedOrder->setParameter("trade_type", "JSAPI");
     //交易类型
     //非必填参数,商户可根据实际情况选填
     //$unifiedOrder->setParameter("sub_mch_id","XXXX");//子商户号
     //$unifiedOrder->setParameter("device_info","XXXX");//设备号
     //$unifiedOrder->setParameter("attach","XXXX");//附加数据
     $unifiedOrder->setParameter("time_start", date('YmdHis'));
     //交易起始时间
     $time_expire = date("YmdHis", strtotime("+7 day"));
     $unifiedOrder->setParameter("time_expire", "{$time_expire}");
     //交易结束时间
     // $unifiedOrder->setParameter("time_expire",date('YmdHis'));//交易结束时间
     $unifiedOrder->setParameter("goods_tag", "红叶");
     //商品标记
     //$unifiedOrder->setParameter("openid","XXXX");//用户标识
     $unifiedOrder->setParameter("product_id", "0008");
     //商品ID
     // ECHO $openid.'--P1';
     $prepay_id = $unifiedOrder->getPrepayId();
     //=========步骤3:使用jsapi调起支付============
     $jsApi->setPrepayId($prepay_id);
     $jsApiParameters = $jsApi->getParameters();
     $this->layout = false;
     //调用个人中心的布局
     return $this->render('pay', ['jsApiParameters' => $jsApiParameters, 'relprice' => $orderBase['totalpay'], 'mobile' => $mobile, 'truename' => $truename, 'address' => $address, 'out_trade_no' => $out_trade_no]);
     //显示页面,同时把$jsApiParameters 发送至页面
 }
예제 #29
0
파일: site.php 프로젝트: aspnmy/weizan
 /**
  * author: 微赞
  */
 public function doMobileOrderPay()
 {
     global $_W, $_GPC;
     $oid = $_GPC['oid'];
     $order = DBUtil::findById(DBUtil::$TABLE_ORDER_ORDER, $oid);
     MonUtil::emtpyMsg($order, "订单删除或不存在");
     $item = DBUtil::findById(DBUtil::$TABLE_ORDER_ITEM, $order['iid']);
     $form = DBUtil::findById(DBUtil::$TABLE_ORDER_FORM, $order['fid']);
     if ($order['status'] == $this::$STATUS_UNPAY && $order['pay_type'] == 1) {
         //立即支付
         $jsApi = new JsApi_pub($this->mOrderSetting);
         $jsApi->setOpenId($order['openid']);
         $unifiedOrder = new UnifiedOrder_pub($this->mOrderSetting);
         $unifiedOrder->setParameter("openid", $order['openid']);
         //商品描述
         $unifiedOrder->setParameter("body", "预约订单" . $item['iname']);
         //商品描述
         $out_trade_no = date("YmdHis", TIMESTAMP);
         $unifiedOrder->setParameter("out_trade_no", $out_trade_no);
         //商户订单号
         //$unifiedOrder->setParameter("total_fee", 1);//总金额
         $unifiedOrder->setParameter("total_fee", $order['zf_price'] * 100);
         //总金额
         $notifyUrl = $_W['siteroot'] . "addons/" . MON_ORDER . "/notify.php";
         $unifiedOrder->setParameter("notify_url", $notifyUrl);
         //通知地址
         $unifiedOrder->setParameter("trade_type", "JSAPI");
         //交易类型
         $prepay_id = $unifiedOrder->getPrepayId();
         $jsApi->setPrepayId($prepay_id);
         $jsApiParameters = $jsApi->getParameters();
         DBUtil::updateById(DBUtil::$TABLE_ORDER_ORDER, array('outno' => $out_trade_no), $oid);
     }
     include $this->template("orderPay");
 }
예제 #30
0
 function get_code($order, $payment)
 {
     $jsApi = new JsApi_pub();
     if (!isset($_GET['code'])) {
         $redirect = urlencode($GLOBALS['ecs']->url() . 'flow.php?step=ok&order_id=' . $order['order_sn']);
         $url = $jsApi->createOauthUrlForCode($redirect);
         Header("Location: {$url}");
     } else {
         $code = $_GET['code'];
         $jsApi->setCode($code);
         $openid = $jsApi->getOpenId();
     }
     if ($openid) {
         $unifiedOrder = new UnifiedOrder_pub();
         $unifiedOrder->setParameter("openid", "{$openid}");
         //商品描述
         $unifiedOrder->setParameter("body", $order['order_sn']);
         //商品描述
         $out_trade_no = $order['order_sn'];
         $unifiedOrder->setParameter("out_trade_no", "{$out_trade_no}");
         //商户订单号
         $unifiedOrder->setParameter("attach", strval($order['log_id']));
         //商户支付日志
         $unifiedOrder->setParameter("total_fee", strval(intval($order['order_amount'] * 100)));
         //总金额
         $unifiedOrder->setParameter("notify_url", WXNOTIFY_URL);
         //通知地址
         $unifiedOrder->setParameter("trade_type", "JSAPI");
         //交易类型
         $prepay_id = $unifiedOrder->getPrepayId();
         $jsApi->setPrepayId($prepay_id);
         $jsApiParameters = $jsApi->getParameters();
         $user_agent = $_SERVER['HTTP_USER_AGENT'];
         $allow_use_wxPay = true;
         if (strpos($user_agent, 'MicroMessenger') === false) {
             $allow_use_wxPay = false;
         } else {
             preg_match('/.*?(MicroMessenger\\/([0-9.]+))\\s*/', $user_agent, $matches);
             if ($matches[2] < 5.0) {
                 $allow_use_wxPay = false;
             }
         }
         $html .= '<script language="javascript">';
         if ($allow_use_wxPay) {
             $html .= "function jsApiCall(){";
             $html .= "WeixinJSBridge.invoke(";
             $html .= "'getBrandWCPayRequest',";
             $html .= $jsApiParameters . ",";
             $html .= "function(res){";
             $html .= "if(res.err_msg == 'get_brand_wcpay_request:ok'){window.location.href='" . $GLOBALS['ecs']->url() . "respond.php'}";
             //$html .= "WeixinJSBridge.log(res.err_msg);";
             $html .= "}";
             $html .= ");";
             $html .= "}";
             $html .= "function callpay(){";
             $html .= 'if (typeof WeixinJSBridge == "undefined"){';
             $html .= "if( document.addEventListener ){";
             $html .= "document.addEventListener('WeixinJSBridgeReady', jsApiCall, false);";
             $html .= "}else if (document.attachEvent){";
             $html .= "document.attachEvent('WeixinJSBridgeReady', jsApiCall); ";
             $html .= "document.attachEvent('onWeixinJSBridgeReady', jsApiCall);";
             $html .= "}";
             $html .= "}else{";
             $html .= "jsApiCall();";
             $html .= "}}";
         } else {
             $html .= 'function callpay(){';
             $html .= 'alert("您的微信不支持支付功能,请更新您的微信版本")';
             $html .= "}";
         }
         $html .= '</script>';
         $html .= '<button  class="c-btn4"  type="button" onclick="callpay()">微信支付</button>';
         return $html;
     } else {
         $html .= '<script language="javascript">';
         $html .= 'function callpay(){';
         $html .= 'alert("请在微信中使用微信支付")';
         $html .= "}";
         $html .= '</script>';
         $html .= '<button type="button" onclick="callpay()"       class="pay_bottom">微信支付</button>';
         return $html;
     }
 }