pay-v3-order-h5.php 1.8 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950
  1. <?php
  2. // +----------------------------------------------------------------------
  3. // | WeChatDeveloper
  4. // +----------------------------------------------------------------------
  5. // | 版权所有 2014~2023 ThinkAdmin [ thinkadmin.top ]
  6. // +----------------------------------------------------------------------
  7. // | 官方网站: https://thinkadmin.top
  8. // +----------------------------------------------------------------------
  9. // | 开源协议 ( https://mit-license.org )
  10. // | 免责声明 ( https://thinkadmin.top/disclaimer )
  11. // +----------------------------------------------------------------------
  12. // | gitee 代码仓库:https://gitee.com/zoujingli/WeChatDeveloper
  13. // | github 代码仓库:https://github.com/zoujingli/WeChatDeveloper
  14. // +----------------------------------------------------------------------
  15. try {
  16. // 1. 手动加载入口文件
  17. include "../include.php";
  18. // 2. 准备公众号配置参数
  19. $config = include "./pay-v3-config.php";
  20. // 3. 创建接口实例
  21. $payment = \WePayV3\Order::instance($config);
  22. // 4. 组装支付参数
  23. $result = $payment->create('h5', [
  24. 'appid' => $config['appid'],
  25. 'mchid' => $config['mch_id'],
  26. 'description' => '商品描述',
  27. 'out_trade_no' => (string)time(),
  28. 'notify_url' => 'https://thinkadmin.top',
  29. 'amount' => ['total' => 2, 'currency' => 'CNY'],
  30. 'scene_info' => [
  31. 'h5_info' => [
  32. 'type' => 'Wap',
  33. ],
  34. 'payer_client_ip' => '14.23.150.211',
  35. ],
  36. ]);
  37. echo '<pre>';
  38. echo "\n--- 创建支付参数 ---\n";
  39. var_export($result);
  40. } catch (\Exception $exception) {
  41. // 出错啦,处理下吧
  42. echo $exception->getMessage() . PHP_EOL;
  43. }