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.
 
 
 
 
 

136 regels
4.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. //初始化日志
  8. $logHandler= new CLogFileHandler("../logs/".date('Y-m-d').'.log');
  9. $log = Log::Init($logHandler, 15);
  10. //打印输出数组信息
  11. function printf_info($data)
  12. {
  13. foreach($data as $key=>$value){
  14. echo "<font color='#00ff55;'>$key</font> : $value <br/>";
  15. }
  16. }
  17. //①、获取用户openid
  18. $tools = new JsApiPay();
  19. //$openId = $tools->GetOpenid();
  20. $openId='oCVcbv1udkL4iZm-t1h8YMrMDSyU';
  21. //②、统一下单
  22. $input = new WxPayUnifiedOrder();
  23. $input->SetBody("机票");
  24. $input->SetOut_trade_no(WxPayConfig::MCHID.date("YmdHis"));
  25. $input->SetTotal_fee("1");
  26. $input->SetTime_start(date("YmdHis"));
  27. $input->SetTime_expire(date("YmdHis", time() + 600));
  28. $input->SetGoods_tag("代金券");
  29. $input->SetNotify_url(dirname("http://".$_SERVER['HTTP_HOST'].$_SERVER['REQUEST_URI'])."/notify.php");
  30. $input->SetTrade_type("JSAPI");
  31. $input->SetOpenid($openId);
  32. $order = WxPayApi::unifiedOrder($input);
  33. echo '<font color="#f00"><b>统一下单支付单信息qwwww</b></font><br/>';
  34. printf_info($order);
  35. $jsApiParameters = $tools->GetJsApiParameters($order);
  36. print_r($jsApiParameters);
  37. //获取共享收货地址js函数参数
  38. $editAddress = $tools->GetEditAddressParameters();
  39. //③、在支持成功回调通知中处理成功之后的事宜,见 notify.php
  40. /**
  41. * 注意:
  42. * 1、当你的回调地址不可访问的时候,回调通知会失败,可以通过查询订单来确认支付是否成功
  43. * 2、jsapi支付时需要填入用户openid,WxPay.JsApiPay.php中有获取openid流程 (文档可以参考微信公众平台“网页授权接口”,
  44. * 参考http://mp.weixin.qq.com/wiki/17/c0f37d5704f0b64713d5d2c37b468d75.html)
  45. */
  46. ?>
  47. <html>
  48. <head>
  49. <meta http-equiv="content-type" content="text/html;charset=utf-8"/>
  50. <meta name="viewport" content="width=device-width, initial-scale=1"/>
  51. <title>微信支付样例-支付</title>
  52. <script type="text/javascript">
  53. //调用微信JS api 支付
  54. function jsApiCall()
  55. {
  56. WeixinJSBridge.invoke(
  57. 'getBrandWCPayRequest',
  58. <?php echo $jsApiParameters; ?>,
  59. function(res){
  60. WeixinJSBridge.log(res.err_msg);
  61. if(res.err_msg =='get_brand_wcpay_request:ok'){
  62. alert('支付成功');
  63. }else if(res.err_msg =='get_brand_wcpay_request:cancel'){
  64. alert(res.err_msg);
  65. alert('取消支付');
  66. }else{
  67. alert('支付失败');
  68. }
  69. }
  70. );
  71. }
  72. function callpay()
  73. {
  74. if (typeof WeixinJSBridge == "undefined"){
  75. if( document.addEventListener ){
  76. document.addEventListener('WeixinJSBridgeReady', jsApiCall, false);
  77. }else if (document.attachEvent){
  78. document.attachEvent('WeixinJSBridgeReady', jsApiCall);
  79. document.attachEvent('onWeixinJSBridgeReady', jsApiCall);
  80. }
  81. }else{
  82. jsApiCall();
  83. }
  84. }
  85. </script>
  86. <script type="text/javascript">
  87. //获取共享地址
  88. /*function editAddress()
  89. {
  90. WeixinJSBridge.invoke(
  91. 'editAddress',
  92. <?php echo $editAddress; ?>,
  93. function(res){
  94. var value1 = res.proviceFirstStageName;
  95. var value2 = res.addressCitySecondStageName;
  96. var value3 = res.addressCountiesThirdStageName;
  97. var value4 = res.addressDetailInfo;
  98. var tel = res.telNumber;
  99. alert(value1 + value2 + value3 + value4 + ":" + tel);
  100. }
  101. );
  102. }
  103. window.onload = function(){
  104. if (typeof WeixinJSBridge == "undefined"){
  105. if( document.addEventListener ){
  106. document.addEventListener('WeixinJSBridgeReady', editAddress, false);
  107. }else if (document.attachEvent){
  108. document.attachEvent('WeixinJSBridgeReady', editAddress);
  109. document.attachEvent('onWeixinJSBridgeReady', editAddress);
  110. }
  111. }else{
  112. editAddress();
  113. }
  114. };
  115. */
  116. </script>
  117. </head>
  118. <body>
  119. <br/>
  120. <font color="#9ACD32"><b>该笔订单支付金额为<span style="color:#f00;font-size:50px">1分</span>钱</b></font><br/><br/>
  121. <div align="center">
  122. <button style="width:210px; height:50px; border-radius: 15px;background-color:#FE6714; border:0px #FE6714 solid; cursor: pointer; color:white; font-size:16px;" type="button" onclick="callpay()" >立即支付</button>
  123. </div>
  124. </body>
  125. </html>