liteCharge.php 1.3 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647
  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. 'openid' => 'ottkCuO1PW1Dnh6PWFffNk-2MPbY',
  24. 'product_id' => '123',
  25. ];
  26. // 使用
  27. try {
  28. $client = new \Payment\Client(\Payment\Client::WECHAT, $wxConfig);
  29. $res = $client->pay(\Payment\Client::WX_CHANNEL_LITE, $payData);
  30. } catch (InvalidArgumentException $e) {
  31. echo $e->getMessage();
  32. exit;
  33. } catch (\Payment\Exceptions\GatewayException $e) {
  34. echo $e->getMessage();
  35. exit;
  36. } catch (\Payment\Exceptions\ClassNotFoundException $e) {
  37. echo $e->getMessage();
  38. exit;
  39. }
  40. var_dump($res);