Weapp.php 2.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293
  1. <?php
  2. // +----------------------------------------------------------------------
  3. // | Niucloud-admin 企业快速开发的saas管理平台
  4. // +----------------------------------------------------------------------
  5. // | 官方网址:https://www.niucloud.com
  6. // +----------------------------------------------------------------------
  7. // | niucloud团队 版权所有 开源版本可自由商用
  8. // +----------------------------------------------------------------------
  9. // | Author: Niucloud Team
  10. // +----------------------------------------------------------------------
  11. namespace core\template;
  12. use app\service\core\weapp\CoreWeappService;
  13. use EasyWeChat\Kernel\Exceptions\InvalidArgumentException;
  14. use EasyWeChat\Kernel\Exceptions\InvalidConfigException;
  15. use EasyWeChat\Kernel\Support\Collection;
  16. use GuzzleHttp\Exception\GuzzleException;
  17. use Psr\Http\Message\ResponseInterface;
  18. class Weapp extends BaseTemplate
  19. {
  20. /**
  21. * @param array $config
  22. * @return void
  23. */
  24. protected function initialize(array $config = [])
  25. {
  26. parent::initialize($config);
  27. }
  28. /**
  29. * 消息发送
  30. * @param array $data
  31. * @return array|Collection|object|ResponseInterface|string
  32. * @throws GuzzleException
  33. * @throws InvalidArgumentException
  34. * @throws InvalidConfigException
  35. */
  36. public function send(array $data)
  37. {
  38. $api = CoreWeappService::appApiClient();
  39. $api->postJson('cgi-bin/message/subscribe/send', [
  40. 'template_id' => $data['template_id'], // 所需下发的订阅模板id
  41. 'touser' => $data['openid'], // 接收者(用户)的 openid
  42. 'page' => $data['page'], // 点击模板卡片后的跳转页面,仅限本小程序内的页面。支持带参数,(示例index?foo=bar)。该字段不填则模板无跳转。
  43. 'data' => $data['data'],
  44. ]);
  45. }
  46. /**
  47. * 添加模板消息
  48. * @param array $data
  49. * @return array|Collection|object|ResponseInterface|string
  50. * @throws GuzzleException
  51. * @throws InvalidConfigException
  52. */
  53. public function addTemplate(array $data)
  54. {
  55. $api = CoreWeappService::appApiClient();
  56. return $api->postJson('wxaapi/newtmpl/addtemplate', [
  57. 'tid' => $data['tid'],
  58. 'kidList' => $data['kid_list'],
  59. 'sceneDesc' => $data['scene_desc'],
  60. ]);
  61. }
  62. /**
  63. * 删除
  64. * @param array $data
  65. * @return array|Collection|object|ResponseInterface|string
  66. * @throws GuzzleException
  67. * @throws InvalidConfigException
  68. */
  69. public function delete(array $data)
  70. {
  71. $api = CoreWeappService::appApiClient();
  72. return $api->postJson('wxaapi/newtmpl/deltemplate', [
  73. 'priTmplId' => $data['template_id'],
  74. ]);
  75. }
  76. /**
  77. * 获取
  78. * @return void
  79. */
  80. public function get()
  81. {
  82. }
  83. }