barCharge.php 1.5 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950
  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' => '0.01', // 微信沙箱模式,需要金额固定为0.01
  21. 'return_param' => '123',
  22. 'client_ip' => isset($_SERVER['REMOTE_ADDR']) ? $_SERVER['REMOTE_ADDR'] : '127.0.0.1', // 客户地址
  23. 'terminal_id' => 'web', // 终端设备号(门店号或收银设备ID) 默认值 web
  24. 'auth_code' => '1231212232323123123',
  25. // 如果是服务商,请提供以下参数
  26. 'sub_appid' => '', //微信分配的子商户公众账号ID
  27. 'sub_mch_id' => '', // 微信支付分配的子商户号
  28. ];
  29. // 使用
  30. try {
  31. $client = new \Payment\Client(\Payment\Client::WECHAT, $wxConfig);
  32. $res = $client->pay(\Payment\Client::WX_CHANNEL_BAR, $payData);
  33. } catch (InvalidArgumentException $e) {
  34. echo $e->getMessage();
  35. exit;
  36. } catch (\Payment\Exceptions\GatewayException $e) {
  37. echo $e->getMessage();
  38. exit;
  39. } catch (\Payment\Exceptions\ClassNotFoundException $e) {
  40. echo $e->getMessage();
  41. exit;
  42. }
  43. var_dump($res);