|
- <?php
- header("Content-type:text/html;charset=utf-8");
- ini_set('date.timezone', 'Asia/Shanghai');
- //error_reporting(E_ERROR);
- require_once "../lib/WxPay.Api.php";
- require_once "WxPay.JsApiPay.php";
- require_once 'log.php';
- require_once '../../Common/Function.php';
-
- //初始化日志
- $logHandler = new CLogFileHandler("../logs/" . date('Y-m-d') . '.log');
- $log = Log::Init($logHandler, 15);
-
- //打印输出数组信息
- function printf_info($data)
- {
- foreach ($data as $key => $value) {
- echo "<font color='#00ff55;'>$key</font> : $value <br/>";
- }
- }
-
- //①、获取用户openid
- $tools = new JsApiPay();
- $openId = $tools->GetOpenid();
- /*if(isset($_GET['weiyixi'])){
- return( array('a'=>$openId));
- die;
- }*/
- //var_dump($_GET['orderid']);exit();
- if (!empty($_GET['orderid']) && $_GET['orderid'] !== 'false') {
- $orderno = $_GET['orderid'];
- } else {
- echo "<script>alert('订单号有误')</script>";
- exit;
- }
- if (isset($_GET['disney']) && $_GET['disney'] == 1) { //微信 1.0 迪士尼微信支付 现不再使用
- $url = "http://xmwxc.zhizhuchuxing.cn/php_include/order_details.php?order_id=" . $orderno;
- $result = http_request($url);
- wlog("disney::" . $openId . "--" . $orderno . "--" . $url . "--" . $result);
- $orderDetail = json_decode($result, true);
- $money = $orderDetail['order_price'] * 100;
- //$money=1;
- if ($money == 0) {
- $successurl = "http://xmwxc.zhizhuchuxing.cn/php_include/order_details.php?order_id=" . $orderno . "&disney=1";
- Header("Location: $successurl");
- exit;
- }
- $limit_time = date("Y-m-d H:i:s", strtotime("-10 minutes"));
- if ($orderDetail['create_time'] <= $limit_time) {
- $overtime_url = "http://xmwxc.zhizhuchuxing.cn/disneydetial2/over_time.php";
- Header("Location: $overtime_url");
- exit;
- }
- $name = $orderDetail['prod_name'];
- //$name='迪士尼';
- $reurl = "http://" . $_SERVER['HTTP_HOST'] . "/php_include/disney_pay_callback.php";
- wlog("disney::" . $reurl);
- } else if (isset($_GET['istest'])) { //测试代码
- print_r($_GET);
- $orderno = 'test123454321';
- if ($_GET['istest'] == 1) {
- $money = 1;
- $name = '测试一分钱';
- } else if ($_GET['istest'] == 2) {
- $money = 201;
- $name = '测试两元';
- } else if ($_GET['istest'] == 3) {
- $money = 501;
- $name = '测试五元';
- }
- $reurl = "http://xmwxc.zhizhuchuxing.cn/wechat/WxPay/realpay/istest.php";
-
- } else if (isset($_GET['fx'])) { //分销平台支付(微信商城,定制巴士)
-
- if (isset($_GET['ifdisney']) && $_GET['ifdisney'] == 1) { //分销迪士尼
- $url = "http://xmwxc.zhizhuchuxing.cn/fx/order_detail.php?ifdisney=1&orderno=" . $orderno;
- $result = http_request($url);
-
- //wlog($openId."--".$orderno."--".$url."--".$result);
- $orderDetail = json_decode($result, true);
- // die;
- if ($orderDetail['order_status'] == 146) {
- $successurl = "http://xmwxc.zhizhuchuxing.cn/fx/order_detail.php?ifdisney=1&orderno=" . $orderno;
- Header("Location: $successurl");
- exit;
- }
-
- $money = (int)$orderDetail['order_price'] * 100;
-
- //var_dump($money);die;
- if ($money == 0) {
- $successurl = "http://xmwxc.zhizhuchuxing.cn/fx/order_detail.php?ifdisney=1&orderno=" . $orderno;
- Header("Location: $successurl");
- exit;
- }
- $name = $orderDetail['prod_name'];
- //echo $name;die;
-
- $reurl = "http://xmwxc.zhizhuchuxing.cn/wechat/WxPay/realpay/success_notify_fx_disney.php";
- } else {
- $url = "http://xmwxc.zhizhuchuxing.cn/fx/order_detail.php?orderno=" . $orderno;
- $result = http_request($url);
-
- //wlog($openId."--".$orderno."--".$url."--".$result);
- $orderDetail = json_decode($result, true);
- // die;
- if ($orderDetail['order_status'] != 145) {
- $successurl = "http://xmwxc.zhizhuchuxing.cn/bookingHomePage/payFailure.html?orderno=" . $orderno;
- Header("Location: $successurl");
- exit;
- }
-
- $money = (int)($orderDetail['order_price'] * 100);
-
- //var_dump($money);die;
- if ($money == 0) {
- $successurl = "http://xmwxc.zhizhuchuxing.cn/fx/order_detail.php?orderno=" . $orderno;
- Header("Location: $successurl");
- exit;
- }
- $name = $orderDetail['prod_name'];
- //echo $name;die;
-
- $reurl = "http://xmwxc.zhizhuchuxing.cn/wechat/WxPay/realpay/success_notify_fx.php";
-
-
- }
-
- $time_cut = time() - strtotime($orderDetail['create_time']);
- if ($time_cut > 600) {
-
- $successurl = "http://xmwxc.zhizhuchuxing.cn/fx/out_time_drop_order.php?orderno=" . $orderno;
- Header("Location: $successurl");
- exit;
-
- }
-
-
- } else {
- $url = "http://xmwxc.zhizhuchuxing.cn/core/order_detail.asp?orderno=" . $orderno;
- $result = http_request($url);
- wlog($openId . "--" . $orderno . "--" . $url . "--" . $result);
- $orderDetail = json_decode($result, true);
- $money = $orderDetail['price'] * 100;
- if ($money == 0) {
- $successurl = "http://xmwxc.zhizhuchuxing.cn/core/order_confirm1.asp?orderno=" . $orderno;
- Header("Location: $successurl");
- exit;
- }
- $name = $orderDetail['prod_name'];
- $reurl = dirname("http://" . $_SERVER['HTTP_HOST'] . $_SERVER['REQUEST_URI']) . "/success_notify.php";
-
- }
- //$openId='oCVcbv1udkL4iZm-t1h8YMrMDSyU';
- //②、统一下单
- $input = new WxPayUnifiedOrder();
- $SetBody = $name . ": " . $orderno;
-
- $input->SetBody($SetBody);
- //$input->SetOut_trade_no(WxPayConfig::MCHID.date("YmdHis"));
- $SetOut_trade_no = $orderno . "-" . date("ymdHis"); //支付串号(商户单号)
- $input->SetOut_trade_no($SetOut_trade_no);
- $input->SetTotal_fee($money);
- $SetTime_start = date("YmdHis");
- $input->SetTime_start($SetTime_start);
-
- $SetTime_expire = date("YmdHis", time() + 600);
-
- $input->SetTime_expire($SetTime_expire);
- $SetGoods_tag = "代金券";
-
- $input->SetGoods_tag($SetGoods_tag);
- wlog($reurl);
- $input->SetNotify_url($reurl); //回掉地址
- $SetTrade_type = "JSAPI";
- $input->SetTrade_type($SetTrade_type);
- $input->SetOpenid($openId);
- wlog($SetBody . "^" . $SetOut_trade_no . "^" . $money . "^" . $SetTime_start . "^" . $SetTime_expire . "^" . $SetGoods_tag . "^" . $reurl . "^" . $SetTrade_type . "^" . $openId);
- $order = WxPayApi::unifiedOrder($input, 15);
- //echo '<font color="#f00"><b>统一下单支付单信息qwwww</b></font><br/>';
- //printf_info($order);
- $jsApiParameters = $tools->GetJsApiParameters($order);
- //print_r($jsApiParameters);
- //获取共享收货地址js函数参数
- $editAddress = $tools->GetEditAddressParameters();
- wlog(json_encode($jsApiParameters));
- //③、在支持成功回调通知中处理成功之后的事宜,见 notify.php
- /**
- * 注意:
- * 1、当你的回调地址不可访问的时候,回调通知会失败,可以通过查询订单来确认支付是否成功
- * 2、jsapi支付时需要填入用户openid,WxPay.JsApiPay.php中有获取openid流程 (文档可以参考微信公众平台“网页授权接口”,
- * 参考http://mp.weixin.qq.com/wiki/17/c0f37d5704f0b64713d5d2c37b468d75.html)
- */
- function wlog($result)
- {
- $dir = __DIR__ . '/Log/';
- if (!is_dir($dir)) {
- mkdir($dir);
- }
- $filename = $dir . date("Y-m-d") . ".log";
- file_put_contents($filename, date("Y-m-d H:i:s") . " " . $result . PHP_EOL, FILE_APPEND);//订单详细日志
- }
-
- ?>
-
- <script type="text/javascript">
- window.onload = function () {
- if (typeof WeixinJSBridge == "undefined") {
- if (document.addEventListener) {
- document.addEventListener('WeixinJSBridgeReady', jsApiCall, false);
- } else if (document.attachEvent) {
- document.attachEvent('WeixinJSBridgeReady', jsApiCall);
- document.attachEvent('onWeixinJSBridgeReady', jsApiCall);
- }
- } else {
- jsApiCall();
- }
- };
- //调用微信JS api 支付
- function jsApiCall() {
- WeixinJSBridge.invoke(
- 'getBrandWCPayRequest',
- <?php echo $jsApiParameters; ?>,
- function (res) {
- WeixinJSBridge.log(res.err_msg);
- if (res.err_msg == 'get_brand_wcpay_request:ok') {
-
-
- var orderno =<?php echo $orderno;?>;
- alert('支付成功');
- <?php if (isset($_GET['disney']) && $_GET['disney'] == 1){?>
-
- var goods_tid =<?php echo $orderDetail['good_type'];wlog(json_encode($orderDetail) . "---order_id:" . $_GET['orderid']);?>;
- window.location.href = 'http://xmwxc.zhizhuchuxing.cn/disneydetial2/paysuccess.php?orderno=' +<?php echo $orderDetail['order_serial_no'];?> +'&pt=1';
-
- <?php }else{?>
- <?php if (isset($_GET['fx'])) {?>
-
- <?php if (isset($_GET['code2'])) { //非分销
- if ($_GET['code2'] == 'wxsc') {?> //微信商城支付成功跳转页面
- location.href = 'http://xmwxc.zhizhuchuxing.cn/weixin2/pay_success.html';
- <?php }else{?>
- <?php if($_GET['code2'] == 'dzbs'){?> //定制巴士支付成功跳转页面
- location.href = 'http://xmwxc.zhizhuchuxing.cn/ZZDZ2/pay_success.html';
- <?php }else{?> //其他
- location.href = 'http://xmwxc.zhizhuchuxing.cn/bookingHomePage/paySuccess_1.html';
- <?php }?>
-
-
- <?php }
- }else{?> //分销支付成功
- location.href = 'http://sfx.zhizhuchuxing.com/wchat_fx/back_info.html';
- <?php }?>
- <?php }else{?>
- location.href = 'http://xmwxc.zhizhuchuxing.cn/core/order_confirm1.asp?orderno=' + orderno;
- <?php }}?>
- } else if (res.err_msg == 'get_brand_wcpay_request:cancel') {
- var orderno =<?php echo $orderno;?>;
- alert('取消支付');
- <?php if (isset($_GET['disney']) && $_GET['disney'] == 1){?>
- var goods_tid =<?php echo $orderDetail['good_type'];?>;
- window.location.href = 'http://xmwxc.zhizhuchuxing.cn/disneydetial2/pay.php?orderno=' +<?php echo $_GET['orderid'];?> +'&pt=1';
-
-
- <?php }else{?>
- <?php if (isset($_GET['fx'])) {?>
-
- <?php if (isset($_GET['code2'])) {?>
- <?php if($_GET['code2'] == 'wxsc'){?>
- location.href = 'http://xmwxc.zhizhuchuxing.cn/weixin2/order_detail.html?order_id=' +<?php echo $_GET['orderid'];?>;
- <?php }else{ ?>
- <?php if($_GET['code2'] == 'dzbs'){?>
- location.href = 'http://xmwxc.zhizhuchuxing.cn/ZZDZ2/order_detail.html?order_id=' +<?php echo $_GET['orderid'];?>;
- <?php }else{ ?>
- location.href = 'http://xmwxc.zhizhuchuxing.cn/bookingHomePage/payFailure.html';
- <?php } ?>
-
- <?php }?>
- // location.href='http://xmwxc.zhizhuchuxing.cn/bookingHomePage/payFailure.html';
-
- <?php }else{?>
- location.href = 'http://sfx.zhizhuchuxing.com/wchat_fx/order_detail.html';
- <?php }?>
- <?php }else{?>
-
- window.location.href = 'http://xmwxc.zhizhuchuxing.cn/bookingHomePage/onlinePay.html?orderno=' + orderno;
- <?php }}?>
- //window.history.go(-1);
- } else {
- var orderno =<?php echo $orderno;?>;
- alert('支付失败');
- <?php if (isset($_GET['disney']) && $_GET['disney'] == 1){?>
- var goods_tid =<?php echo $orderDetail['good_type'];?>;
- window.location.href = 'http://xmwxc.zhizhuchuxing.cn/disneydetial2/pay.php?orderno=' +<?php echo $_GET['orderid'];?> +'&pt=1';
-
-
-
- <?php }else{?>
- <?php if (isset($_GET['fx'])) {?>
- <?php if (isset($_GET['code2'])) {?>
- <?php if ($_GET['code2'] == 'wxsc') {?>
- location.href = 'http://xmwxc.zhizhuchuxing.cn/weixin2/order_detail.html?order_id=' +<?php echo $_GET['orderid'];?>;
- <?php }else{?>
-
- <?php if($_GET['code2'] == 'dzbs'){?>
- location.href = 'http://xmwxc.zhizhuchuxing.cn/ZZDZ2/order_detail.html?order_id=' +<?php echo $_GET['orderid'];?>;
- <?php }else{ ?>
- location.href = 'http://xmwxc.zhizhuchuxing.cn/bookingHomePage/payFailure.html';
- <?php } ?>
- <?php }?>
- <?php }else{?>
- location.href = 'http://sfx.zhizhuchuxing.com/wchat_fx/order_detail.html';
- <?php }?>
- <?php }else{?>
- window.location.href = 'http://xmwxc.zhizhuchuxing.cn/bookingHomePage/onlinePay.html?orderno=' + orderno;
- <?php }}?>
-
- }
- }
- );
- }
-
- function callpay() {
- if (typeof WeixinJSBridge == "undefined") {
- if (document.addEventListener) {
- document.addEventListener('WeixinJSBridgeReady', jsApiCall, false);
- } else if (document.attachEvent) {
- document.attachEvent('WeixinJSBridgeReady', jsApiCall);
- document.attachEvent('onWeixinJSBridgeReady', jsApiCall);
- }
- } else {
- jsApiCall();
- }
- }
- </script>
-
|