Client.php 1.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051
  1. <?php
  2. /**
  3. * 重庆赤晓店信息科技有限公司
  4. * https://www.chixiaodian.com
  5. * Copyright (c) 2023 赤店商城 All rights reserved.
  6. */
  7. /*
  8. * This file is part of the OtkurBiz/ByteDance.
  9. *
  10. * (c) alim <alim@bulutbazar.com>
  11. *
  12. * This source file is subject to the MIT license that is bundled
  13. * with this source code in the file LICENSE.
  14. */
  15. namespace ByteDance\MiniProgram\Message;
  16. use ByteDance\Kernel\BaseClient;
  17. /**
  18. * Class Client.
  19. *
  20. * @author alim <alim@bulutbazar.com>
  21. */
  22. class Client extends BaseClient
  23. {
  24. /**
  25. * 发送模版消息
  26. * 目前只有今日头条支持,抖音和 lite 接入中
  27. *
  28. * touser String 是 要发送给用户的 open id, open id 的获取请参考登录
  29. * template_id String 是 在开发者平台配置消息模版后获得的模版 id
  30. * page String 否 点击消息卡片之后打开的小程序页面地址,空则无跳转
  31. * form_id String 是 可以通过<form />组件获得 form_id, 获取方法
  32. * data dict<String, SubData> 是 模板中填充着的数据,key 必须是 keyword 为前缀
  33. *SubData
  34. *SubData 也是 dict,结构如下:
  35. *名称 类型 是否必填
  36. *value String 是
  37. * eg: {"access_token": "YOUR_ACCESS_TOKEN", "app_id": "YOUR_APP_ID", "data": {"keyword1": {"value": "v1"}, "keyword2": {"value": "v2"}}, "page": "pages/index", "form_id": "YOUR_FORM_ID", "touser": "USER_OPEN_ID", "template_id": "YOUR_TPL_ID"}
  38. *
  39. * @return \Psr\Http\Message\ResponseInterface|\EasyWeChat\Kernel\Support\Collection|array|object|string
  40. * @throws \ByteDance\Kernel\Exceptions\InvalidConfigException
  41. */
  42. public function create(string $touser, string $template_id, string $page, string $form_id, mixed $data)
  43. {
  44. return $this->httpPost('api/apps/game/template/send', ['touser'=>$touser, 'template_id' => $template_id, 'page'=>$page, 'form_id'=>$form_id, 'data'=>$data]);
  45. }
  46. }