appCharge.php 1.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051
  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 qr pay',
  17. 'subject' => '测试支付宝APP支付',
  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. ];
  26. // 使用
  27. try {
  28. $client = new \Payment\Client(\Payment\Client::ALIPAY, $aliConfig);
  29. $res = $client->pay(\Payment\Client::ALI_CHANNEL_APP, $payData);
  30. } catch (InvalidArgumentException $e) {
  31. echo $e->getMessage();
  32. exit;
  33. } catch (\Payment\Exceptions\GatewayException $e) {
  34. echo $e->getMessage();
  35. var_dump($e->getRaw());
  36. exit;
  37. } catch (\Payment\Exceptions\ClassNotFoundException $e) {
  38. echo $e->getMessage();
  39. exit;
  40. } catch (Exception $e) {
  41. echo $e->getMessage();
  42. exit;
  43. }
  44. echo $res;// 这里如果直接输出到页面,&not 会被转义,请注意