wapCharge.php 1.6 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152
  1. <?php
  2. /*
  3. * The file is part of the payment lib.
  4. *
  5. * (c) Leo <dayugog@gmail.com>
  6. *
  7. * This source file is subject to the MIT license that is bundled
  8. * with this source code in the file LICENSE.
  9. */
  10. require_once __DIR__ . '/../../vendor/autoload.php';
  11. date_default_timezone_set('Asia/Shanghai');
  12. $wxConfig = require_once __DIR__ . '/../wxconfig.php';
  13. $tradeNo = time() . rand(1000, 9999);
  14. // 订单信息
  15. $payData = [
  16. 'body' => 'test body',
  17. 'subject' => 'test subject',
  18. 'trade_no' => $tradeNo,
  19. 'time_expire' => time() + 600, // 表示必须 600s 内付款
  20. 'amount' => '3.01', // 微信沙箱模式,需要金额固定为3.01
  21. 'return_param' => '123',
  22. 'client_ip' => isset($_SERVER['REMOTE_ADDR']) ? $_SERVER['REMOTE_ADDR'] : '127.0.0.1', // 客户地址
  23. //{"h5_info": {"type":"Wap","wap_url": "https://pay.qq.com","wap_name": "腾讯充值"}}
  24. 'scene_info' => [
  25. 'type' => 'Wap', // IOS Android Wap 腾讯建议 IOS ANDROID 采用app支付
  26. 'wap_url' => 'https://Leo112g.github.io/', //自己的 wap 地址
  27. 'wap_name' => '测试充值',
  28. ],
  29. ];
  30. // 使用
  31. try {
  32. $client = new \Payment\Client(\Payment\Client::WECHAT, $wxConfig);
  33. $res = $client->pay(\Payment\Client::WX_CHANNEL_WAP, $payData);
  34. } catch (InvalidArgumentException $e) {
  35. echo $e->getMessage();
  36. exit;
  37. } catch (\Payment\Exceptions\GatewayException $e) {
  38. echo $e->getMessage();
  39. exit;
  40. } catch (\Payment\Exceptions\ClassNotFoundException $e) {
  41. echo $e->getMessage();
  42. exit;
  43. }
  44. var_dump($res);