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.
 
 
 
 
 

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