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.
 
 
 
 
 

229 lines
7.8 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. $url="http://xmwx.zhizhuchuxing.cn/fx/order_detail.php?orderno=".$orderno;
  67. $result=http_request($url);
  68. wlog($openId."--".$orderno."--".$url."--".$result);
  69. $orderDetail=json_decode($result,true);
  70. if($orderDetail['order_status'] =146){
  71. $successurl="http://xmwx.zhizhuchuxing.cn/fx/order_detail.php?orderno=".$orderno;
  72. Header("Location: $successurl");
  73. exit;
  74. }
  75. $money=$orderDetail['price']*100;
  76. echo $money;die;
  77. if ($money == 0){
  78. $successurl="http://xmwx.zhizhuchuxing.cn/fx/order_detail.php?orderno=".$orderno;
  79. Header("Location: $successurl");
  80. exit;
  81. }
  82. $name=$orderDetail['prod_name'];
  83. $reurl=dirname("http://xmwx.zhizhuchuxing.cn/fx/success_notify.php");
  84. }else{
  85. $url="http://xmwx.zhizhuchuxing.cn/core/order_detail.asp?orderno=".$orderno;
  86. $result=http_request($url);
  87. wlog($openId."--".$orderno."--".$url."--".$result);
  88. $orderDetail=json_decode($result,true);
  89. $money=$orderDetail['price']*100;
  90. if ($money == 0){
  91. $successurl="http://xmwx.zhizhuchuxing.cn/core/order_confirm1.asp?orderno=".$orderno;
  92. Header("Location: $successurl");
  93. exit;
  94. }
  95. $name=$orderDetail['prod_name'];
  96. $reurl=dirname("http://".$_SERVER['HTTP_HOST'].$_SERVER['REQUEST_URI'])."/success_notify.php";
  97. }
  98. //$openId='oCVcbv1udkL4iZm-t1h8YMrMDSyU';
  99. //②、统一下单
  100. $input = new WxPayUnifiedOrder();
  101. $SetBody=$name.": ".$orderno;
  102. $input->SetBody($SetBody);
  103. //$input->SetOut_trade_no(WxPayConfig::MCHID.date("YmdHis"));
  104. $SetOut_trade_no=$orderno."-".date("ymdHis");
  105. $input->SetOut_trade_no($SetOut_trade_no);
  106. $input->SetTotal_fee($money);
  107. $SetTime_start=date("YmdHis");
  108. $input->SetTime_start($SetTime_start);
  109. $SetTime_expire=date("YmdHis", time() + 600);
  110. $input->SetTime_expire($SetTime_expire);
  111. $SetGoods_tag="代金券";
  112. $input->SetGoods_tag($SetGoods_tag);
  113. wlog($reurl);
  114. $input->SetNotify_url($reurl);
  115. $SetTrade_type="JSAPI";
  116. $input->SetTrade_type($SetTrade_type);
  117. $input->SetOpenid($openId);
  118. wlog($SetBody."^".$SetOut_trade_no."^".$money."^".$SetTime_start."^".$SetTime_expire."^".$SetGoods_tag."^".$reurl."^".$SetTrade_type."^".$openId);
  119. $order = WxPayApi::unifiedOrder($input,15);
  120. //echo '<font color="#f00"><b>统一下单支付单信息qwwww</b></font><br/>';
  121. //printf_info($order);
  122. $jsApiParameters = $tools->GetJsApiParameters($order);
  123. //print_r($jsApiParameters);
  124. //获取共享收货地址js函数参数
  125. $editAddress = $tools->GetEditAddressParameters();
  126. wlog(json_encode($jsApiParameters));
  127. //③、在支持成功回调通知中处理成功之后的事宜,见 notify.php
  128. /**
  129. * 注意:
  130. * 1、当你的回调地址不可访问的时候,回调通知会失败,可以通过查询订单来确认支付是否成功
  131. * 2、jsapi支付时需要填入用户openid,WxPay.JsApiPay.php中有获取openid流程 (文档可以参考微信公众平台“网页授权接口”,
  132. * 参考http://mp.weixin.qq.com/wiki/17/c0f37d5704f0b64713d5d2c37b468d75.html)
  133. */
  134. function wlog($result){
  135. $dir=__DIR__.'/Log/';
  136. if (!is_dir($dir)){
  137. mkdir($dir);
  138. }
  139. $filename=$dir.date("Y-m-d").".log";
  140. file_put_contents($filename, date("Y-m-d H:i:s")." ".$result.PHP_EOL,FILE_APPEND);//订单详细日志
  141. }
  142. ?>
  143. <script type="text/javascript">
  144. window.onload = function(){
  145. if (typeof WeixinJSBridge == "undefined"){
  146. if( document.addEventListener ){
  147. document.addEventListener('WeixinJSBridgeReady', jsApiCall, false);
  148. }else if (document.attachEvent){
  149. document.attachEvent('WeixinJSBridgeReady', jsApiCall);
  150. document.attachEvent('onWeixinJSBridgeReady', jsApiCall);
  151. }
  152. }else{
  153. jsApiCall();
  154. }
  155. };
  156. //调用微信JS api 支付
  157. function jsApiCall()
  158. {
  159. WeixinJSBridge.invoke(
  160. 'getBrandWCPayRequest',
  161. <?php echo $jsApiParameters; ?>,
  162. function(res){
  163. WeixinJSBridge.log(res.err_msg);
  164. if(res.err_msg =='get_brand_wcpay_request:ok'){
  165. var orderno=<?php echo $orderno ;?>;
  166. alert('支付成功');
  167. <?php if (isset($_GET['disney']) && $_GET['disney']==1){?>
  168. var goods_tid=<?php echo $orderDetail['good_type'] ;wlog(json_encode($orderDetail)."---order_id:".$_GET['orderid']);?>;
  169. window.location.href='http://xmwx.zhizhuchuxing.cn/disneydetial2/paysuccess.php?orderno='+<?php echo $orderDetail['order_serial_no'];?> + '&pt=1';
  170. <?php }else{?>
  171. location.href='http://xmwx.zhizhuchuxing.cn/core/order_confirm1.asp?orderno='+orderno;
  172. <?php }?>
  173. }else if(res.err_msg =='get_brand_wcpay_request:cancel'){
  174. var orderno=<?php echo $orderno ;?>;
  175. alert('取消支付');
  176. <?php if (isset($_GET['disney']) && $_GET['disney']==1){?>
  177. var goods_tid=<?php echo $orderDetail['good_type'] ;?>;
  178. window.location.href='http://xmwx.zhizhuchuxing.cn/disneydetial2/pay.php?orderno='+<?php echo $_GET['orderid'];?> + '&pt=1';
  179. <?php }else{?>
  180. window.location.href='http://xmwx.zhizhuchuxing.cn/bookingHomePage/onlinePay.html?orderno='+orderno;
  181. <?php }?>
  182. //window.history.go(-1);
  183. }else{
  184. var orderno=<?php echo $orderno ;?>;
  185. alert('支付失败');
  186. <?php if (isset($_GET['disney']) && $_GET['disney']==1){?>
  187. var goods_tid=<?php echo $orderDetail['good_type'] ;?>;
  188. window.location.href='http://xmwx.zhizhuchuxing.cn/disneydetial2/pay.php?orderno='+<?php echo $_GET['orderid'];?> + '&pt=1';
  189. <?php }else{?>
  190. window.location.href='http://xmwx.zhizhuchuxing.cn/bookingHomePage/onlinePay.html?orderno='+orderno;
  191. <?php }?>
  192. }
  193. }
  194. );
  195. }
  196. function callpay()
  197. {
  198. if (typeof WeixinJSBridge == "undefined"){
  199. if( document.addEventListener ){
  200. document.addEventListener('WeixinJSBridgeReady', jsApiCall, false);
  201. }else if (document.attachEvent){
  202. document.attachEvent('WeixinJSBridgeReady', jsApiCall);
  203. document.attachEvent('onWeixinJSBridgeReady', jsApiCall);
  204. }
  205. }else{
  206. jsApiCall();
  207. }
  208. }
  209. </script>