You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 
 
 
 

337 lines
14 KiB

  1. <?php
  2. header("Content-type:text/html;charset=utf-8");
  3. ini_set('date.timezone', 'Asia/Shanghai');
  4. //error_reporting(E_ERROR);
  5. require_once "../lib/WxPay.Api.php";
  6. require_once "WxPay.JsApiPay.php";
  7. require_once 'log.php';
  8. require_once '../../Common/Function.php';
  9. //初始化日志
  10. $logHandler = new CLogFileHandler("../logs/" . date('Y-m-d') . '.log');
  11. $log = Log::Init($logHandler, 15);
  12. //打印输出数组信息
  13. function printf_info($data)
  14. {
  15. foreach ($data as $key => $value) {
  16. echo "<font color='#00ff55;'>$key</font> : $value <br/>";
  17. }
  18. }
  19. //①、获取用户openid
  20. $tools = new JsApiPay();
  21. $openId = $tools->GetOpenid();
  22. /*if(isset($_GET['weiyixi'])){
  23. return( array('a'=>$openId));
  24. die;
  25. }*/
  26. //var_dump($_GET['orderid']);exit();
  27. if (!empty($_GET['orderid']) && $_GET['orderid'] !== 'false') {
  28. $orderno = $_GET['orderid'];
  29. } else {
  30. echo "<script>alert('订单号有误')</script>";
  31. exit;
  32. }
  33. if (isset($_GET['disney']) && $_GET['disney'] == 1) { //微信 1.0 迪士尼微信支付 现不再使用
  34. $url = "http://wx.zhizhuchuxing.com/php_include/order_details.php?order_id=" . $orderno;
  35. $result = http_request($url);
  36. wlog("disney::" . $openId . "--" . $orderno . "--" . $url . "--" . $result);
  37. $orderDetail = json_decode($result, true);
  38. $money = $orderDetail['order_price'] * 100;
  39. //$money=1;
  40. if ($money == 0) {
  41. $successurl = "http://wx.zhizhuchuxing.com/php_include/order_details.php?order_id=" . $orderno . "&disney=1";
  42. Header("Location: $successurl");
  43. exit;
  44. }
  45. $limit_time = date("Y-m-d H:i:s", strtotime("-10 minutes"));
  46. if ($orderDetail['create_time'] <= $limit_time) {
  47. $overtime_url = "http://wx.zhizhuchuxing.com/disneydetial2/over_time.php";
  48. Header("Location: $overtime_url");
  49. exit;
  50. }
  51. $name = $orderDetail['prod_name'];
  52. //$name='迪士尼';
  53. $reurl = "http://" . $_SERVER['HTTP_HOST'] . "/php_include/disney_pay_callback.php";
  54. wlog("disney::" . $reurl);
  55. } else if (isset($_GET['istest'])) { //测试代码
  56. print_r($_GET);
  57. $orderno = 'test123454321';
  58. if ($_GET['istest'] == 1) {
  59. $money = 1;
  60. $name = '测试一分钱';
  61. } else if ($_GET['istest'] == 2) {
  62. $money = 201;
  63. $name = '测试两元';
  64. } else if ($_GET['istest'] == 3) {
  65. $money = 501;
  66. $name = '测试五元';
  67. }
  68. $reurl = "http://wx.zhizhuchuxing.com/wechat/WxPay/realpay/istest.php";
  69. } else if (isset($_GET['fx'])) { //分销平台支付(微信商城,定制巴士)
  70. if (isset($_GET['ifdisney']) && $_GET['ifdisney'] == 1) { //分销迪士尼
  71. $url = "http://wx.zhizhuchuxing.com/fx/order_detail.php?ifdisney=1&orderno=" . $orderno;
  72. $result = http_request($url);
  73. //wlog($openId."--".$orderno."--".$url."--".$result);
  74. $orderDetail = json_decode($result, true);
  75. // die;
  76. if ($orderDetail['order_status'] == 146) {
  77. $successurl = "http://wx.zhizhuchuxing.com/fx/order_detail.php?ifdisney=1&orderno=" . $orderno;
  78. Header("Location: $successurl");
  79. exit;
  80. }
  81. $money = (int)$orderDetail['order_price'] * 100;
  82. //var_dump($money);die;
  83. if ($money == 0) {
  84. $successurl = "http://wx.zhizhuchuxing.com/fx/order_detail.php?ifdisney=1&orderno=" . $orderno;
  85. Header("Location: $successurl");
  86. exit;
  87. }
  88. $name = $orderDetail['prod_name'];
  89. //echo $name;die;
  90. $reurl = "http://wx.zhizhuchuxing.com/wechat/WxPay/realpay/success_notify_fx_disney.php";
  91. } else {
  92. $url = "http://wx.zhizhuchuxing.com/fx/order_detail.php?orderno=" . $orderno;
  93. $result = http_request($url);
  94. //wlog($openId."--".$orderno."--".$url."--".$result);
  95. $orderDetail = json_decode($result, true);
  96. // die;
  97. if ($orderDetail['order_status'] != 145) {
  98. $successurl = "http://wx.zhizhuchuxing.com/bookingHomePage/payFailure.html?orderno=" . $orderno;
  99. Header("Location: $successurl");
  100. exit;
  101. }
  102. $money = (int)($orderDetail['order_price'] * 100);
  103. //var_dump($money);die;
  104. if ($money == 0) {
  105. $successurl = "http://wx.zhizhuchuxing.com/fx/order_detail.php?orderno=" . $orderno;
  106. Header("Location: $successurl");
  107. exit;
  108. }
  109. $name = $orderDetail['prod_name'];
  110. //echo $name;die;
  111. $reurl = "http://wx.zhizhuchuxing.com/wechat/WxPay/realpay/success_notify_fx.php";
  112. }
  113. $time_cut = time() - strtotime($orderDetail['create_time']);
  114. if ($time_cut > 600) {
  115. $successurl = "http://wx.zhizhuchuxing.com/fx/out_time_drop_order.php?orderno=" . $orderno;
  116. Header("Location: $successurl");
  117. exit;
  118. }
  119. } else {
  120. $url = "http://wx.zhizhuchuxing.com/core/order_detail.asp?orderno=" . $orderno;
  121. $result = http_request($url);
  122. wlog($openId . "--" . $orderno . "--" . $url . "--" . $result);
  123. $orderDetail = json_decode($result, true);
  124. $money = $orderDetail['price'] * 100;
  125. if ($money == 0) {
  126. $successurl = "http://wx.zhizhuchuxing.com/core/order_confirm1.asp?orderno=" . $orderno;
  127. Header("Location: $successurl");
  128. exit;
  129. }
  130. $name = $orderDetail['prod_name'];
  131. $reurl = dirname("http://" . $_SERVER['HTTP_HOST'] . $_SERVER['REQUEST_URI']) . "/success_notify.php";
  132. }
  133. //$openId='oCVcbv1udkL4iZm-t1h8YMrMDSyU';
  134. //②、统一下单
  135. $input = new WxPayUnifiedOrder();
  136. $SetBody = $name . ": " . $orderno;
  137. $input->SetBody($SetBody);
  138. //$input->SetOut_trade_no(WxPayConfig::MCHID.date("YmdHis"));
  139. $SetOut_trade_no = $orderno . "-" . date("ymdHis"); //支付串号(商户单号)
  140. $input->SetOut_trade_no($SetOut_trade_no);
  141. $input->SetTotal_fee($money);
  142. $SetTime_start = date("YmdHis");
  143. $input->SetTime_start($SetTime_start);
  144. $SetTime_expire = date("YmdHis", time() + 600);
  145. $input->SetTime_expire($SetTime_expire);
  146. $SetGoods_tag = "代金券";
  147. $input->SetGoods_tag($SetGoods_tag);
  148. wlog($reurl);
  149. $input->SetNotify_url($reurl); //回掉地址
  150. $SetTrade_type = "JSAPI";
  151. $input->SetTrade_type($SetTrade_type);
  152. $input->SetOpenid($openId);
  153. wlog($SetBody . "^" . $SetOut_trade_no . "^" . $money . "^" . $SetTime_start . "^" . $SetTime_expire . "^" . $SetGoods_tag . "^" . $reurl . "^" . $SetTrade_type . "^" . $openId);
  154. $order = WxPayApi::unifiedOrder($input, 15);
  155. //echo '<font color="#f00"><b>统一下单支付单信息qwwww</b></font><br/>';
  156. //printf_info($order);
  157. $jsApiParameters = $tools->GetJsApiParameters($order);
  158. //print_r($jsApiParameters);
  159. //获取共享收货地址js函数参数
  160. $editAddress = $tools->GetEditAddressParameters();
  161. wlog(json_encode($jsApiParameters));
  162. //③、在支持成功回调通知中处理成功之后的事宜,见 notify.php
  163. /**
  164. * 注意:
  165. * 1、当你的回调地址不可访问的时候,回调通知会失败,可以通过查询订单来确认支付是否成功
  166. * 2、jsapi支付时需要填入用户openid,WxPay.JsApiPay.php中有获取openid流程 (文档可以参考微信公众平台“网页授权接口”,
  167. * 参考http://mp.weixin.qq.com/wiki/17/c0f37d5704f0b64713d5d2c37b468d75.html)
  168. */
  169. function wlog($result)
  170. {
  171. $dir = __DIR__ . '/Log/';
  172. if (!is_dir($dir)) {
  173. mkdir($dir);
  174. }
  175. $filename = $dir . date("Y-m-d") . ".log";
  176. file_put_contents($filename, date("Y-m-d H:i:s") . " " . $result . PHP_EOL, FILE_APPEND);//订单详细日志
  177. }
  178. ?>
  179. <script type="text/javascript">
  180. window.onload = function () {
  181. if (typeof WeixinJSBridge == "undefined") {
  182. if (document.addEventListener) {
  183. document.addEventListener('WeixinJSBridgeReady', jsApiCall, false);
  184. } else if (document.attachEvent) {
  185. document.attachEvent('WeixinJSBridgeReady', jsApiCall);
  186. document.attachEvent('onWeixinJSBridgeReady', jsApiCall);
  187. }
  188. } else {
  189. jsApiCall();
  190. }
  191. };
  192. //调用微信JS api 支付
  193. function jsApiCall() {
  194. WeixinJSBridge.invoke(
  195. 'getBrandWCPayRequest',
  196. <?php echo $jsApiParameters; ?>,
  197. function (res) {
  198. WeixinJSBridge.log(res.err_msg);
  199. if (res.err_msg == 'get_brand_wcpay_request:ok') {
  200. var orderno =<?php echo $orderno;?>;
  201. alert('支付成功');
  202. <?php if (isset($_GET['disney']) && $_GET['disney'] == 1){?>
  203. var goods_tid =<?php echo $orderDetail['good_type'];wlog(json_encode($orderDetail) . "---order_id:" . $_GET['orderid']);?>;
  204. window.location.href = 'http://wx.zhizhuchuxing.com/disneydetial2/paysuccess.php?orderno=' +<?php echo $orderDetail['order_serial_no'];?> +'&pt=1';
  205. <?php }else{?>
  206. <?php if (isset($_GET['fx'])) {?>
  207. <?php if (isset($_GET['code2'])) { //非分销
  208. if ($_GET['code2'] == 'wxsc') {?> //微信商城支付成功跳转页面
  209. location.href = 'http://wx.zhizhuchuxing.com/weixin2/pay_success.html';
  210. <?php }else{?>
  211. <?php if($_GET['code2'] == 'dzbs'){?> //定制巴士支付成功跳转页面
  212. location.href = 'http://wx.zhizhuchuxing.com/ZZDZ2/pay_success.html';
  213. <?php }else{?> //其他
  214. location.href = 'http://wx.zhizhuchuxing.com/bookingHomePage/paySuccess_1.html';
  215. <?php }?>
  216. <?php }
  217. }else{?> //分销支付成功
  218. location.href = 'http://sfx.zhizhuchuxing.com/wchat_fx/back_info.html';
  219. <?php }?>
  220. <?php }else{?>
  221. location.href = 'http://wx.zhizhuchuxing.com/core/order_confirm1.asp?orderno=' + orderno;
  222. <?php }}?>
  223. } else if (res.err_msg == 'get_brand_wcpay_request:cancel') {
  224. var orderno =<?php echo $orderno;?>;
  225. alert('取消支付');
  226. <?php if (isset($_GET['disney']) && $_GET['disney'] == 1){?>
  227. var goods_tid =<?php echo $orderDetail['good_type'];?>;
  228. window.location.href = 'http://wx.zhizhuchuxing.com/disneydetial2/pay.php?orderno=' +<?php echo $_GET['orderid'];?> +'&pt=1';
  229. <?php }else{?>
  230. <?php if (isset($_GET['fx'])) {?>
  231. <?php if (isset($_GET['code2'])) {?>
  232. <?php if($_GET['code2'] == 'wxsc'){?>
  233. location.href = 'http://wx.zhizhuchuxing.com/weixin2/order_detail.html?order_id=' +<?php echo $_GET['orderid'];?>;
  234. <?php }else{ ?>
  235. <?php if($_GET['code2'] == 'dzbs'){?>
  236. location.href = 'http://wx.zhizhuchuxing.com/ZZDZ2/order_detail.html?order_id=' +<?php echo $_GET['orderid'];?>;
  237. <?php }else{ ?>
  238. location.href = 'http://wx.zhizhuchuxing.com/bookingHomePage/payFailure.html';
  239. <?php } ?>
  240. <?php }?>
  241. // location.href='http://wx.zhizhuchuxing.com/bookingHomePage/payFailure.html';
  242. <?php }else{?>
  243. location.href = 'http://sfx.zhizhuchuxing.com/wchat_fx/order_detail.html';
  244. <?php }?>
  245. <?php }else{?>
  246. window.location.href = 'http://wx.zhizhuchuxing.com/bookingHomePage/onlinePay.html?orderno=' + orderno;
  247. <?php }}?>
  248. //window.history.go(-1);
  249. } else {
  250. var orderno =<?php echo $orderno;?>;
  251. alert('支付失败');
  252. <?php if (isset($_GET['disney']) && $_GET['disney'] == 1){?>
  253. var goods_tid =<?php echo $orderDetail['good_type'];?>;
  254. window.location.href = 'http://wx.zhizhuchuxing.com/disneydetial2/pay.php?orderno=' +<?php echo $_GET['orderid'];?> +'&pt=1';
  255. <?php }else{?>
  256. <?php if (isset($_GET['fx'])) {?>
  257. <?php if (isset($_GET['code2'])) {?>
  258. <?php if ($_GET['code2'] == 'wxsc') {?>
  259. location.href = 'http://wx.zhizhuchuxing.com/weixin2/order_detail.html?order_id=' +<?php echo $_GET['orderid'];?>;
  260. <?php }else{?>
  261. <?php if($_GET['code2'] == 'dzbs'){?>
  262. location.href = 'http://wx.zhizhuchuxing.com/ZZDZ2/order_detail.html?order_id=' +<?php echo $_GET['orderid'];?>;
  263. <?php }else{ ?>
  264. location.href = 'http://wx.zhizhuchuxing.com/bookingHomePage/payFailure.html';
  265. <?php } ?>
  266. <?php }?>
  267. <?php }else{?>
  268. location.href = 'http://sfx.zhizhuchuxing.com/wchat_fx/order_detail.html';
  269. <?php }?>
  270. <?php }else{?>
  271. window.location.href = 'http://wx.zhizhuchuxing.com/bookingHomePage/onlinePay.html?orderno=' + orderno;
  272. <?php }}?>
  273. }
  274. }
  275. );
  276. }
  277. function callpay() {
  278. if (typeof WeixinJSBridge == "undefined") {
  279. if (document.addEventListener) {
  280. document.addEventListener('WeixinJSBridgeReady', jsApiCall, false);
  281. } else if (document.attachEvent) {
  282. document.attachEvent('WeixinJSBridgeReady', jsApiCall);
  283. document.attachEvent('onWeixinJSBridgeReady', jsApiCall);
  284. }
  285. } else {
  286. jsApiCall();
  287. }
  288. }
  289. </script>