liteCharge.php 1.0 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344
  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. $cmbConfig = require_once __DIR__ . '/../cmbconfig.php';
  13. $tradeNo = time() . rand(1000, 9999);
  14. $data = [
  15. 'date' => time(),
  16. 'trade_no' => $tradeNo,
  17. 'amount' => 1.00,
  18. 'time_expire' => time() + 1000,
  19. ];
  20. // 使用
  21. try {
  22. $client = new \Payment\Client(\Payment\Client::CMB, $cmbConfig);
  23. $res = $client->pay(\Payment\Client::CMB_CHANNEL_APP, $data);
  24. } catch (InvalidArgumentException $e) {
  25. echo $e->getMessage();
  26. exit;
  27. } catch (\Payment\Exceptions\GatewayException $e) {
  28. echo $e->getMessage();
  29. exit;
  30. } catch (\Payment\Exceptions\ClassNotFoundException $e) {
  31. echo $e->getMessage();
  32. exit;
  33. } catch (Exception $e) {
  34. echo $e->getMessage();
  35. exit;
  36. }
  37. var_dump($res);