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.
 
 
 
 
 

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