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.
 
 
 
 
 

128 lines
3.9 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. //②、统一下单
  21. $input = new WxPayUnifiedOrder();
  22. $input->SetBody("test");
  23. $input->SetAttach("test");
  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("test");
  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. //获取共享收货地址js函数参数
  37. $editAddress = $tools->GetEditAddressParameters();
  38. //③、在支持成功回调通知中处理成功之后的事宜,见 notify.php
  39. /**
  40. * 注意:
  41. * 1、当你的回调地址不可访问的时候,回调通知会失败,可以通过查询订单来确认支付是否成功
  42. * 2、jsapi支付时需要填入用户openid,WxPay.JsApiPay.php中有获取openid流程 (文档可以参考微信公众平台“网页授权接口”,
  43. * 参考http://mp.weixin.qq.com/wiki/17/c0f37d5704f0b64713d5d2c37b468d75.html)
  44. */
  45. ?>
  46. <html>
  47. <head>
  48. <meta http-equiv="content-type" content="text/html;charset=utf-8"/>
  49. <meta name="viewport" content="width=device-width, initial-scale=1"/>
  50. <title>微信支付样例-支付</title>
  51. <script type="text/javascript">
  52. //调用微信JS api 支付
  53. function jsApiCall()
  54. {
  55. WeixinJSBridge.invoke(
  56. 'getBrandWCPayRequest',
  57. <?php echo $jsApiParameters; ?>,
  58. function(res){
  59. WeixinJSBridge.log(res.err_msg);
  60. alert(res.err_code+res.err_desc+res.err_msg);
  61. }
  62. );
  63. }
  64. function callpay()
  65. {
  66. if (typeof WeixinJSBridge == "undefined"){
  67. if( document.addEventListener ){
  68. document.addEventListener('WeixinJSBridgeReady', jsApiCall, false);
  69. }else if (document.attachEvent){
  70. document.attachEvent('WeixinJSBridgeReady', jsApiCall);
  71. document.attachEvent('onWeixinJSBridgeReady', jsApiCall);
  72. }
  73. }else{
  74. jsApiCall();
  75. }
  76. }
  77. </script>
  78. <script type="text/javascript">
  79. //获取共享地址
  80. function editAddress()
  81. {
  82. WeixinJSBridge.invoke(
  83. 'editAddress',
  84. <?php echo $editAddress; ?>,
  85. function(res){
  86. var value1 = res.proviceFirstStageName;
  87. var value2 = res.addressCitySecondStageName;
  88. var value3 = res.addressCountiesThirdStageName;
  89. var value4 = res.addressDetailInfo;
  90. var tel = res.telNumber;
  91. alert(value1 + value2 + value3 + value4 + ":" + tel);
  92. }
  93. );
  94. }
  95. window.onload = function(){
  96. if (typeof WeixinJSBridge == "undefined"){
  97. if( document.addEventListener ){
  98. document.addEventListener('WeixinJSBridgeReady', editAddress, false);
  99. }else if (document.attachEvent){
  100. document.attachEvent('WeixinJSBridgeReady', editAddress);
  101. document.attachEvent('onWeixinJSBridgeReady', editAddress);
  102. }
  103. }else{
  104. editAddress();
  105. }
  106. };
  107. </script>
  108. </head>
  109. <body>
  110. <br/>
  111. <font color="#9ACD32"><b>该笔订单支付金额为<span style="color:#f00;font-size:50px">1分</span>钱</b></font><br/><br/>
  112. <div align="center">
  113. <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>
  114. </div>
  115. </body>
  116. </html>