pay-v3-order-native.php 2.7 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182
  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. $order = (string)time();
  24. $result = $payment->create('native', [
  25. 'appid' => $config['appid'],
  26. 'mchid' => $config['mch_id'],
  27. 'description' => '商品描述',
  28. 'out_trade_no' => $order,
  29. 'notify_url' => 'https://thinkadmin.top',
  30. 'amount' => ['total' => 2, 'currency' => 'CNY'],
  31. ]);
  32. echo '<pre>';
  33. echo "\n--- 创建支付参数 ---\n";
  34. var_export($result);
  35. // array('code_url' => 'weixin://wxpay/bizpayurl?pr=cdJXOVDzz');
  36. echo "\n\n--- 查询支付参数 ---\n";
  37. $result = $payment->query($order);
  38. var_export($result);
  39. // array(
  40. // 'amount' => array('payer_currency' => 'CNY', 'total' => 2),
  41. // 'appid' => 'wx60a43dd8161666d4',
  42. // 'mchid' => '1332187001',
  43. // 'out_trade_no' => '1669027871',
  44. // 'promotion_detail' => array(),
  45. // 'scene_info' => array('device_id' => ''),
  46. // 'trade_state' => 'NOTPAY',
  47. // 'trade_state_desc' => '订单未支付',
  48. // );
  49. // 创建退款
  50. $out_refund_no = strval(time());
  51. $result = $payment->createRefund([
  52. 'out_trade_no' => $order,
  53. 'out_refund_no' => $out_refund_no,
  54. 'amount' => [
  55. 'refund' => 2,
  56. 'total' => 2,
  57. 'currency' => 'CNY'
  58. ]
  59. ]);
  60. echo "\n--- 创建退款订单2 ---\n";
  61. var_export($result);
  62. $result = $payment->queryRefund($out_refund_no);
  63. echo "\n--- 查询退款订单2 ---\n";
  64. var_export($result);
  65. } catch (\Exception $exception) {
  66. // 出错啦,处理下吧
  67. echo $exception->getMessage() . PHP_EOL;
  68. }