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.
 
 
 
 
 

287 lines
10 KiB

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