pay-redpack-create.php 1.9 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455
  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 "./config.php";
  20. // 3. 创建接口实例
  21. // $wechat = new \WePay\Redpack($config);
  22. // $wechat = \We::WePayRedpack($config);
  23. $wechat = \WePay\Redpack::instance($config);
  24. // 4. 组装参数,可以参考官方商户文档
  25. $options = [
  26. 'mch_billno' => time(),
  27. 're_openid' => 'o38gps3vNdCqaggFfrBRCRikwlWY',
  28. 'send_name' => '商户名称😍',
  29. 'act_name' => '活动名称',
  30. 'total_amount' => '100',
  31. 'total_num' => '1',
  32. 'wishing' => '感谢您参加猜灯谜活动,祝您元宵节快乐!',
  33. 'remark' => '猜越多得越多,快来抢!',
  34. 'client_ip' => '127.0.0.1',
  35. ];
  36. // 发送红包记录
  37. $result = $wechat->create($options);
  38. echo '<pre>';
  39. var_export($result);
  40. // 查询红包记录
  41. $result = $wechat->query($options['mch_billno']);
  42. var_export($result);
  43. } catch (Exception $e) {
  44. // 出错啦,处理下吧
  45. echo $e->getMessage() . PHP_EOL;
  46. }