barCharge.php 1.6 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455
  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. $aliConfig = require_once __DIR__ . '/../aliconfig.php';
  13. // 交易信息
  14. $tradeNo = time() . rand(1000, 9999);
  15. $payData = [
  16. 'body' => 'ali bar pay',
  17. 'subject' => '测试支付宝条码支付',
  18. 'trade_no' => $tradeNo,
  19. 'time_expire' => time() + 600, // 表示必须 600s 内付款
  20. 'amount' => '0.01', // 单位为元 ,最小为0.01
  21. 'return_param' => '123123',
  22. // 'client_ip' => isset($_SERVER['REMOTE_ADDR']) ? $_SERVER['REMOTE_ADDR'] : '127.0.0.1',// 客户地址
  23. 'goods_type' => '1', // 0—虚拟类商品,1—实物类商品
  24. 'store_id' => '',
  25. 'operator_id' => '',
  26. 'terminal_id' => '', // 终端设备号(门店号或收银设备ID) 默认值 web
  27. 'scene' => 'bar_code', // 条码支付:bar_code 声波支付:wave_code
  28. 'auth_code' => '289580917433958393',
  29. ];
  30. // 使用
  31. try {
  32. $client = new \Payment\Client(\Payment\Client::ALIPAY, $aliConfig);
  33. $res = $client->pay(\Payment\Client::ALI_CHANNEL_BAR, $payData);
  34. } catch (InvalidArgumentException $e) {
  35. echo $e->getMessage();
  36. exit;
  37. } catch (\Payment\Exceptions\GatewayException $e) {
  38. echo $e->getMessage();
  39. var_dump($e->getRaw());
  40. exit;
  41. } catch (\Payment\Exceptions\ClassNotFoundException $e) {
  42. echo $e->getMessage();
  43. exit;
  44. } catch (Exception $e) {
  45. echo $e->getMessage();
  46. exit;
  47. }
  48. var_dump($res);