Exemplo n.º 1
0
function getPayUrlForQRCode($paras = array())
{
    //使用统一支付接口
    $unifiedOrder = new UnifiedOrder_pub();
    //设置统一支付接口参数
    //设置必填参数
    //appid已填,商户无需重复填写
    //mch_id已填,商户无需重复填写
    //noncestr已填,商户无需重复填写
    //spbill_create_ip已填,商户无需重复填写
    //sign已填,商户无需重复填写
    $unifiedOrder->setParameter("openid", $paras['openid']);
    //用户标识
    $unifiedOrder->setParameter("body", $paras['p_title']);
    //商品描述
    //自定义订单号,此处仅作举例
    $timeStamp = time();
    $unifiedOrder->setParameter("out_trade_no", $paras['out_trade_no'] . rand(1, 10));
    //商户订单号
    $unifiedOrder->setParameter("total_fee", $paras['p_fee']);
    //总金额
    $unifiedOrder->setParameter("notify_url", WxPayConf_pub::NOTIFY_URL);
    //通知地址
    $unifiedOrder->setParameter("trade_type", "NATIVE");
    //交易类型
    $unifiedOrder->setParameter("attach", $paras['attach']);
    //附加数据
    //支付交易5分钟后关闭
    $time_expire = date('YmdHis', time() + 300);
    $unifiedOrder->setParameter("time_expire", "{$time_expire}");
    //交易结束时间
    //非必填参数,商户可根据实际情况选填
    //$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
    //获取统一支付接口结果
    $unifiedOrderResult = $unifiedOrder->getResult();
    $code_url = '';
    //商户根据实际情况设置相应的处理流程
    if ($unifiedOrderResult["return_code"] == "FAIL") {
        //商户自行增加处理流程
        //echo "通信出错:".$unifiedOrderResult['return_msg']."<br>";
    } elseif ($unifiedOrderResult["result_code"] == "FAIL") {
        //商户自行增加处理流程
        //echo "错误代码:".$unifiedOrderResult['err_code']."<br>";
        //echo "错误代码描述:".$unifiedOrderResult['err_code_des']."<br>";
    } elseif ($unifiedOrderResult["code_url"] != NULL) {
        //从统一支付接口获取到code_url
        $code_url = $unifiedOrderResult["code_url"];
        //商户自行增加处理流程
        //......
    }
    return $code_url;
}
Exemplo n.º 2
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();
 }
Exemplo n.º 3
0
 private function _unifiedOrder($order)
 {
     $config = $this->getConfig($order);
     $unifiedObj = new \UnifiedOrder_pub($config);
     $package = ['body' => str_replace(' ', '', $order['subject']), 'attach' => '', 'out_trade_no' => $order['mer_recharge_no'], 'total_fee' => $order['amount'], 'notify_url' => $order['notify_url'], 'trade_type' => $order['trade_type'], 'openid' => $order['open_id']];
     foreach ($package as $k => $v) {
         $unifiedObj->setParameter($k, $v);
     }
     return $unifiedObj;
 }
Exemplo n.º 4
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());
 }
Exemplo n.º 5
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());
 }
 public function createQrcode()
 {
     $pkey = base64_decode(I("pkey"));
     $pkeys = explode("@", $pkey);
     if (count($pkeys) != 2) {
         $this->assign('out_trade_no', "");
     } else {
         $morders = D('Home/Orders');
         $obj["orderIds"] = $pkeys[1];
         $data = $morders->getPayOrders($obj);
         $orders = $data["orders"];
         $needPay = $data["needPay"];
         $this->assign("orderIds", $orderIds);
         $this->assign("orders", $orders);
         $this->assign("needPay", $needPay);
         $this->assign("orderCnt", count($orders));
         // 使用统一支付接口
         $unifiedOrder = new \UnifiedOrder_pub();
         $unifiedOrder->setParameter("body", "支付订单費用");
         // 商品描述
         // 自定义订单号,此处仅作举例
         $timeStamp = time();
         $out_trade_no = "{$timeStamp}";
         // $out_trade_no = "1000001|1000002";
         $unifiedOrder->setParameter("out_trade_no", "{$out_trade_no}");
         // 商户订单号
         $unifiedOrder->setParameter("total_fee", $needPay * 100);
         // 总金额
         $unifiedOrder->setParameter("notify_url", C('WxPayConf_pub.NOTIFY_URL'));
         // 通知地址
         $unifiedOrder->setParameter("trade_type", "NATIVE");
         // 交易类型
         $unifiedOrder->setParameter("attach", "{$pkey}");
         // 附加数据
         // $unifiedOrder->setParameter ( "detail", "Ipad mini" );//附加数据
         $unifiedOrder->SetParameter("input_charset", "UTF-8");
         // 获取统一支付接口结果
         $unifiedOrderResult = $unifiedOrder->getResult();
         // 商户根据实际情况设置相应的处理流程
         if ($unifiedOrderResult["return_code"] == "FAIL") {
             // 商户自行增加处理流程
             echo "通信出错:" . $unifiedOrderResult['return_msg'] . "<br>";
         } elseif ($unifiedOrderResult["result_code"] == "FAIL") {
             // 商户自行增加处理流程
             echo "错误代码:" . $unifiedOrderResult['err_code'] . "<br>";
             echo "错误代码描述:" . $unifiedOrderResult['err_code_des'] . "<br>";
         } elseif ($unifiedOrderResult["code_url"] != NULL) {
             // 从统一支付接口获取到code_url
             $code_url = $unifiedOrderResult["code_url"];
             // 商户自行增加处理流程
         }
         $this->assign('out_trade_no', $obj["orderIds"]);
         $this->assign('code_url', $code_url);
         $this->assign('unifiedOrderResult', $unifiedOrderResult);
     }
     $this->display("default/payment/wxnative2/qrcode");
 }
Exemplo n.º 7
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>";
 }
 function get_code($order, $payment)
 {
     $unifiedOrder = new UnifiedOrder_pub();
     $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", "NATIVE");
     //交易类型
     $unifiedOrderResult = $unifiedOrder->getResult();
     $html = '<button type="button" onclick="javascript:alert(\'出错了\')">微信支付</button>';
     if ($unifiedOrderResult["code_url"] != NULL) {
         $code_url = $unifiedOrderResult["code_url"];
         $html = '<div class="wx_qrcode" style="text-align:center">';
         $html .= $this->getcode($code_url);
         $html .= "</div>";
         $html .= "<div style=\"text-align:center\">支付后点击<a href=\"user.php?act=order_list\">此处</a>查看我的订单</div>";
     }
     return $html;
 }
Exemplo n.º 9
0
 function get_code($order, $payment)
 {
     $unifiedOrder = new UnifiedOrder_pub();
     $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", "NATIVE");
     //交易类型
     $unifiedOrderResult = $unifiedOrder->getResult();
     $html = '<button type="button" onclick="javascript:alert(\'出错了\')">微信支付</button>';
     if ($unifiedOrderResult["code_url"] != NULL) {
         $code_url = $unifiedOrderResult["code_url"];
         $html = '<div class="wx_title">';
         $html .= '<span id="wxlogo"><img src="/themes/main/images/weixin/WePayLogo.jpg" width="148" height="40"/></span>';
         $html .= '<span id="tj"><img src="/themes/main/images/weixin/We_tj.jpg" width="47" height="20"/></span>';
         $html .= '<span id="desc">亿万用户的选择,更快更安全</span>';
         $html .= '<span id="price">支付:<font style="color:#ff6600">' . $order['order_amount'] . '</font> 元</span>';
         $html .= '</div>';
         $html .= '<div class="wx_qrcode" style="text-align:center">';
         $html .= $this->getcode($code_url);
         $html .= "</div>";
         $html .= "<div style=\"text-align:center\"><img src=\"/themes/main/images/weixin/wxfont.png\" width=\"186\" height=\"62\"></div>";
     }
     return $html;
 }
Exemplo n.º 10
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');
 }
Exemplo n.º 11
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>';
 }
Exemplo n.º 12
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);
 }
Exemplo n.º 13
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';
 }
Exemplo n.º 14
0
 public function buildRequest($req)
 {
     //使用统一支付接口
     $unifiedOrder = new UnifiedOrder_pub($this->wxConfig);
     $unifiedOrder->setParameter("body", $req['body']);
     //商品描述
     $unifiedOrder->setParameter("out_trade_no", $req['order_sn']);
     //商户订单号
     $unifiedOrder->setParameter("total_fee", $req['order_paied'] * 100);
     //总金额
     $unifiedOrder->setParameter("notify_url", $this->wxConfig['NOTIFY_URL']);
     //通知地址
     $unifiedOrder->setParameter("trade_type", "NATIVE");
     //交易类型
     //获取统一支付接口结果
     $unifiedOrderResult = $unifiedOrder->getResult();
     if ($unifiedOrderResult["return_code"] == "FAIL") {
         //echo "通信出错:".$unifiedOrderResult['return_msg']."<br>";
         return 0;
     } elseif ($unifiedOrderResult["result_code"] == "FAIL") {
         //echo "错误代码:".$unifiedOrderResult['err_code']."<br>";
         //echo "错误代码描述:".$unifiedOrderResult['err_code_des']."<br>";
         return 0;
     } elseif ($unifiedOrderResult["code_url"] != NULL) {
         //从统一支付接口获取到code_url
         $code_url = $unifiedOrderResult["code_url"];
         return $code_url;
     }
 }
Exemplo n.º 15
0
 private function config_jsdz()
 {
     $config = $this->config;
     $unifiedOrder = new UnifiedOrder_pub();
     //设置统一支付接口参数
     //设置必填参数
     //appid已填,商户无需重复填写
     //mch_id已填,商户无需重复填写
     //noncestr已填,商户无需重复填写
     //spbill_create_ip已填,商户无需重复填写
     //sign已填,商户无需重复填写
     $unifiedOrder->setParameter("body", "云购商品");
     //商品描述
     //自定义订单号,此处仅作举例
     $total_fee = $config['money'] * 100;
     $out_trade_no = $config['code'];
     //$total_fee=1;
     $unifiedOrder->setParameter("out_trade_no", "{$out_trade_no}");
     //商户订单号
     $unifiedOrder->setParameter("total_fee", $total_fee);
     //总金额
     $unifiedOrder->setParameter("notify_url", WxPayConf_pub::$NOTIFY_URL);
     //通知地址
     $unifiedOrder->setParameter("trade_type", "NATIVE");
     //交易类型
     //非必填参数,商户可根据实际情况选填
     //$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
     //获取统一支付接口结果
     $unifiedOrderResult = $unifiedOrder->getResult();
     //print_r($unifiedOrderResult);
     //exit;
     //商户根据实际情况设置相应的处理流程
     if ($unifiedOrderResult["return_code"] == "FAIL") {
         //商户自行增加处理流程
         echo "通信出错:" . $unifiedOrderResult['return_msg'] . "<br>";
     } elseif ($unifiedOrderResult["result_code"] == "FAIL") {
         //商户自行增加处理流程
         echo "错误代码:" . $unifiedOrderResult['err_code'] . "<br>";
         echo "错误代码描述:" . $unifiedOrderResult['err_code_des'] . "<br>";
     } elseif ($unifiedOrderResult["code_url"] != NULL) {
         //从统一支付接口获取到code_url
         $code_url = $unifiedOrderResult["code_url"];
         $this->url = $code_url;
         //echo 'xx';
         //header("location:".$code_url);
         //echo $code_url;
         // print_r($config);
         // print_r($unifiedOrderResult);exit;
         include 'native_dynamic_qrcode.php';
         //商户自行增加处理流程
         //......
     }
 }
Exemplo n.º 16
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;
 }
Exemplo n.º 17
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;
 }
Exemplo n.º 18
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();
     $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", "NATIVE");
     //交易类型
     $unifiedOrderResult = $unifiedOrder->getResult();
     $html = '<button type="button" onclick="javascript:alert(\'出错了\')">微信支付</button>';
     if ($unifiedOrderResult["code_url"] != NULL) {
         $code_url = $unifiedOrderResult["code_url"];
         $html = '<div class="wxnative" style="text-align:center">';
         $html .= $this->getcode($code_url, $order_info['order_id']);
         $html .= "</div>";
         $html .= "<div style=\"text-align:center;font-size:14px;\"><a href=\"index.php?app=buyer_order\" style=\"color:#ff0000;\">支付后点击此处</a>查看我的订单</div>";
     }
     return $html;
 }
Exemplo n.º 19
0
 public function dynamic_qrcode($payid, $fee, $out_trade_no, $tUrl, $eUrl, $proDesc)
 {
     //使用统一支付接口
     $unifiedOrder = new \UnifiedOrder_pub();
     if (!$payid || !$fee || !$out_trade_no || !$tUrl || !$eUrl || !$proDesc) {
         showTips('/index.php?s=/Pc/Centerall/my_order.html', "参数提交有误!");
     }
     //自定义订单号,此处仅作举例
     $fee = $fee * 100;
     $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", "NATIVE");
     //交易类型
     $unifiedOrder->setParameter("attach", "{$payid}");
     //附加数据 订单ID
     //获取统一支付接口结果
     $unifiedOrderResult = $unifiedOrder->getResult();
     //商户根据实际情况设置相应的处理流程
     if ($unifiedOrderResult["return_code"] == "FAIL") {
         //商户自行增加处理流程
         return "通信出错:" . $unifiedOrderResult['return_msg'] . "<br>";
     } elseif ($unifiedOrderResult["result_code"] == "FAIL") {
         //商户自行增加处理流程
         return "错误代码:" . $unifiedOrderResult['err_code'] . "<br>" . "错误代码描述:" . $unifiedOrderResult['err_code_des'] . "<br>";
     } elseif ($unifiedOrderResult["code_url"] != NULL) {
         //从统一支付接口获取到code_url
         $code_url = $unifiedOrderResult["code_url"];
         //商户自行增加处理流程
         //......
         return $code_url;
     }
 }
Exemplo n.º 20
0
<?php

/**
 * Native(原生)支付-模式二-demo
 * ====================================================
 * 商户生成订单,先调用统一支付接口获取到code_url,
 * 此URL直接生成二维码,用户扫码后调起支付。
 * 
*/
include_once "../WxPayPubHelper/WxPayPubHelper.php";
//使用统一支付接口
$unifiedOrder = new UnifiedOrder_pub();
//设置统一支付接口参数
//设置必填参数
//appid已填,商户无需重复填写
//mch_id已填,商户无需重复填写
//noncestr已填,商户无需重复填写
//spbill_create_ip已填,商户无需重复填写
//sign已填,商户无需重复填写
$unifiedOrder->setParameter("body", "贡献一分钱");
//商品描述
//自定义订单号,此处仅作举例
$timeStamp = time();
$out_trade_no = WxPayConf_pub::APPID . "{$timeStamp}";
$unifiedOrder->setParameter("out_trade_no", "{$out_trade_no}");
//商户订单号
$unifiedOrder->setParameter("total_fee", "1");
//总金额
$unifiedOrder->setParameter("notify_url", WxPayConf_pub::NOTIFY_URL);
//通知地址
$unifiedOrder->setParameter("trade_type", "NATIVE");
Exemplo n.º 21
0
 function wechat_qcode_pay()
 {
     require_once APPPATH . 'libraries/wechat/WxPayPubHelper.php';
     $out_trade_no = $this->uri->segment(3);
     $order_temp = $this->tickets->select('orders', array('to_order_sn' => $out_trade_no));
     $order = $order_temp[0];
     if ($order->to_status == ORDER_PAYED) {
         redirect('/member/order_list');
     }
     $wechat_config_temp = $this->tickets->select('payment', array('name' => 'wechat'));
     $weipay = $wechat_config_temp[0];
     //使用统一支付接口
     $unifiedOrder = new UnifiedOrder_pub($weipay->app_id, $weipay->payname, $weipay->partner_key, $weipay->app_secret);
     //设置统一支付接口参数
     //设置必填参数
     //appid已填,商户无需重复填写
     //mch_id已填,商户无需重复填写
     //noncestr已填,商户无需重复填写
     //spbill_create_ip已填,商户无需重复填写
     //sign已填,商户无需重复填写
     $unifiedOrder->setParameter("body", "小树好吃");
     //商品描述
     //自定义订单号,此处仅作举例
     $timeStamp = time();
     $notify_url = base_url() . '/wechat/wnotice';
     //$out_trade_no = $weipay->app_id."$timeStamp";
     $unifiedOrder->setParameter("out_trade_no", "{$out_trade_no}");
     //商户订单号
     $unifiedOrder->setParameter("total_fee", 100 * $order->to_order_amount);
     //总金额
     $unifiedOrder->setParameter("notify_url", $notify_url);
     //通知地址
     $unifiedOrder->setParameter("trade_type", "NATIVE");
     //交易类型
     //非必填参数,商户可根据实际情况选填
     //获取统一支付接口结果
     $unifiedOrderResult = $unifiedOrder->getResult();
     //商户根据实际情况设置相应的处理流程
     if ($unifiedOrderResult["return_code"] == "FAIL") {
         //商户自行增加处理流程
         echo "通信出错:" . $unifiedOrderResult['return_msg'] . "<br>";
     } elseif ($unifiedOrderResult["result_code"] == "FAIL") {
         //商户自行增加处理流程
         echo "错误代码:" . $unifiedOrderResult['err_code'] . "<br>";
         echo "错误代码描述:" . $unifiedOrderResult['err_code_des'] . "<br>";
     } elseif ($unifiedOrderResult["code_url"] != NULL) {
         //从统一支付接口获取到code_url
         $code_url = $unifiedOrderResult["code_url"];
         //商户自行增加处理流程
         //......
     }
     $data['out_trade_no'] = $out_trade_no;
     $data['code_url'] = $code_url;
     $data['unifiedOrderResult'] = $unifiedOrderResult;
     $this->load->view('/wechat/qcode', $data);
 }
Exemplo n.º 22
0
 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;
 }
Exemplo n.º 23
0
$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已填,商户无需重复填写
//ECHO $_SESSION['out_trade_no']."=====>dd";EXIT;
$out_trade_no = $_SESSION['out_trade_no'];
$goods_name = $_SESSION['goods_name'];
$order_amount = $_SESSION['order_amount'] * 100;
$unifiedOrder->setParameter("openid", "{$openid}");
//商品描述
$unifiedOrder->setParameter("body", "{$goods_name}");
//商品描述
Exemplo n.º 24
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;
	}
Exemplo n.º 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
     }
 }
Exemplo n.º 26
0
//使用native通知接口
$nativeCall = new NativeCall_pub();
//接收微信请求
$xml = $GLOBALS['HTTP_RAW_POST_DATA'];
$log_->log_result($log_name, "【接收到的native通知】:\n" . $xml . "\n");
$nativeCall->saveData($xml);
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中的静态链接二维码对应
            //设置统一支付接口参数
            //设置必填参数
            //appid已填,商户无需重复填写
            //mch_id已填,商户无需重复填写
            //noncestr已填,商户无需重复填写
            //spbill_create_ip已填,商户无需重复填写
            //sign已填,商户无需重复填写
            $unifiedOrder->setParameter("body", "贡献一分钱");
            //商品描述
            //自定义订单号,此处仅作举例
            $timeStamp = time();
Exemplo n.º 27
0
}
$payment = mysqld_select("SELECT * FROM " . table('payment') . " WHERE  enabled=1 and code='weixin' limit 1");
$configs = unserialize($payment['configs']);
$settings = globaSetting(array("weixin_appId", "weixin_appSecret"));
$_CMS['weixin_pay_appid'] = $settings['weixin_appId'];
//受理商ID,身份标识
$_CMS['weixin_pay_mchId'] = $configs['weixin_pay_mchId'];
//商户支付密钥Key。审核通过后,在微信发送的邮件中查看
$_CMS['weixin_pay_paySignKey'] = $configs['weixin_pay_paySignKey'];
//JSAPI接口中获取openid,审核后在公众平台开启开发模式后可查看
$_CMS['weixin_pay_appSecret'] = $settings['weixin_appSecret'];
include_once "WxPayPubHelper/WxPayPubHelper.php";
$weixin_openid = get_weixin_openid();
//=========步骤2:使用统一支付接口,获取prepay_id============
//使用统一支付接口
$unifiedOrder = new UnifiedOrder_pub();
//设置统一支付接口参数
//设置必填参数
//appid已填,商户无需重复填写
//mch_id已填,商户无需重复填写
//noncestr已填,商户无需重复填写
//spbill_create_ip已填,商户无需重复填写
//sign已填,商户无需重复填写
$unifiedOrder->setParameter("openid", $weixin_openid);
//商品描述
$unifiedOrder->setParameter("body", $goodtitle);
//商品描述
//自定义订单号,此处仅作举例
$timeStamp = time();
$unifiedOrder->setParameter("out_trade_no", $order['ordersn'] . '-' . $order['id']);
//商户订单号
Exemplo n.º 28
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;
    }
Exemplo n.º 29
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);
 }
Exemplo n.º 30
0
    public function send_pay()
    {
        //使用统一支付接口
        $unifiedOrder = new UnifiedOrder_pub();
        $amount = trim($this->config['money']) * 100;
        $notify_url = $this->config['NotifyUrl'];
        //通知URL
        //设置统一支付接口参数
        //设置必填参数
        //appid已填,商户无需重复填写
        //mch_id已填,商户无需重复填写
        //noncestr已填,商户无需重复填写
        //spbill_create_ip已填,商户无需重复填写
        //sign已填,商户无需重复填写
        //iconv("gb2312","utf-8//IGNORE",
        $unifiedOrder->setParameter("body", $this->config['title']);
        //商品描述
        //自定义订单号,此处仅作举例
        $out_trade_no = $this->config['code'];
        $unifiedOrder->setParameter("out_trade_no", $out_trade_no);
        //商户订单号
        $unifiedOrder->setParameter("total_fee", $amount);
        //总金额
        $unifiedOrder->setParameter("notify_url", $notify_url);
        //通知地址
        $unifiedOrder->setParameter("trade_type", "NATIVE");
        //交易类型
        //非必填参数,商户可根据实际情况选填
        //$unifiedOrder->setParameter("sub_mch_id","XXXX");//子商户号
        //$unifiedOrder->setParameter("device_info","XXXX");//设备号
        $unifiedOrder->setParameter("attach", "111");
        //附加数据
        //$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
        //获取统一支付接口结果
        $unifiedOrderResult = $unifiedOrder->getResult();
        //商户根据实际情况设置相应的处理流程
        if ($unifiedOrderResult["return_code"] == "FAIL") {
            //商户自行增加处理流程
            echo "通信出错:" . $unifiedOrderResult['return_msg'] . "<br>";
        } elseif ($unifiedOrderResult["result_code"] == "FAIL") {
            //商户自行增加处理流程
            echo iconv("utf-8", "gb2312//IGNORE", "错误代码:" . $unifiedOrderResult['err_code'] . "<br>");
            echo iconv("utf-8", "gb2312//IGNORE", "错误代码描述:" . $unifiedOrderResult['err_code_des'] . "<br>");
        } elseif ($unifiedOrderResult["code_url"] != NULL) {
            $qrcode = 'http://www.1ybye.com/system/modules/pay/lib/qrcode.js';
            //从统一支付接口获取到code_url
            $code_url = $unifiedOrderResult["code_url"];
            $saomiao = "微信安全支付,请扫我";
            //		//参数1表示图像大小,取值范围1-10;参数2表示质量,取值范围'L','M','Q','H'
            if ($unifiedOrderResult["code_url"] != NULL) {
                $hehe = '	var url = "' . $code_url . '";var qr = qrcode(10, "M");qr.addData(url);qr.make();var wording=document.createElement("p");wording.innerHTML = "' . $saomiao . '";	var code=document.createElement("DIV");	code.innerHTML = qr.createImgTag();var element=document.getElementById("qrcode");
					element.appendChild(wording);element.appendChild(code);';
            }
            $def_url = '<html><head></head><body><div align="center" id="qrcode">
		</div></body><script src="' . $qrcode . '"></script><script>' . $hehe . '</script></html>';
            echo $def_url;
            exit;
            //商户自行增加处理流程
            //......
        }
    }