Newtmpl.php 5.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153
  1. <?php
  2. // +----------------------------------------------------------------------
  3. // | WeChatDeveloper
  4. // +----------------------------------------------------------------------
  5. // | 版权所有 2014~2020 广州楚才信息科技有限公司 [ http://www.cuci.cc ]
  6. // +----------------------------------------------------------------------
  7. // | 官方网站: http://think.ctolog.com
  8. // +----------------------------------------------------------------------
  9. // | 开源协议 ( https://mit-license.org )
  10. // +----------------------------------------------------------------------
  11. // | github开源项目:https://github.com/zoujingli/WeChatDeveloper
  12. // +----------------------------------------------------------------------
  13. namespace WeMini;
  14. use WeChat\Contracts\BasicWeChat;
  15. /**
  16. * 公众号小程序订阅消息支持
  17. * Class Mini
  18. * @package WeChat
  19. */
  20. class Newtmpl extends BasicWeChat
  21. {
  22. /**
  23. * 获取小程序账号的类目
  24. * @param array $data 类目信息列表
  25. * @return array
  26. * @throws \WeChat\Exceptions\InvalidResponseException
  27. * @throws \WeChat\Exceptions\LocalCacheException
  28. */
  29. public function addCategory($data)
  30. {
  31. $url = 'https://api.weixin.qq.com/cgi-bin/wxopen/addcategory?access_token=ACCESS_TOKEN';
  32. $this->registerApi($url, __FUNCTION__, func_get_args());
  33. return $this->callPostApi($url, $data, true);
  34. }
  35. /**
  36. * 获取小程序账号的类目
  37. * @return array
  38. * @throws \WeChat\Exceptions\InvalidResponseException
  39. * @throws \WeChat\Exceptions\LocalCacheException
  40. */
  41. public function getCategory()
  42. {
  43. $url = 'https://api.weixin.qq.com/wxaapi/newtmpl/getcategory?access_token=ACCESS_TOKEN';
  44. $this->registerApi($url, __FUNCTION__, func_get_args());
  45. return $this->callGetApi($url);
  46. }
  47. /**
  48. * 获取小程序账号的类目
  49. * @return array
  50. * @throws \WeChat\Exceptions\InvalidResponseException
  51. * @throws \WeChat\Exceptions\LocalCacheException
  52. */
  53. public function deleteCategory()
  54. {
  55. $url = 'https://api.weixin.qq.com/cgi-bin/wxopen/deletecategory?access_token=TOKEN';
  56. $this->registerApi($url, __FUNCTION__, func_get_args());
  57. return $this->callPostApi($url, [], true);
  58. }
  59. /**
  60. * 获取帐号所属类目下的公共模板标题
  61. * @param string $ids 类目 id,多个用逗号隔开
  62. * @return array
  63. * @throws \WeChat\Exceptions\InvalidResponseException
  64. * @throws \WeChat\Exceptions\LocalCacheException
  65. */
  66. public function getPubTemplateTitleList($ids)
  67. {
  68. $url = 'https://api.weixin.qq.com/wxaapi/newtmpl/getpubtemplatetitles?access_token=ACCESS_TOKEN';
  69. $url .= '&' . http_build_query(['ids' => $ids, 'start' => '0', 'limit' => '30']);
  70. $this->registerApi($url, __FUNCTION__, func_get_args());
  71. return $this->callGetApi($url);
  72. }
  73. /**
  74. * 获取模板标题下的关键词列表
  75. * @param string $tid 模板标题 id,可通过接口获取
  76. * @return array
  77. * @throws \WeChat\Exceptions\InvalidResponseException
  78. * @throws \WeChat\Exceptions\LocalCacheException
  79. */
  80. public function getPubTemplateKeyWordsById($tid)
  81. {
  82. $url = 'https://api.weixin.qq.com/wxaapi/newtmpl/getpubtemplatekeywords?access_token=ACCESS_TOKEN';
  83. $url .= '&' . http_build_query(['tid' => $tid]);
  84. $this->registerApi($url, __FUNCTION__, func_get_args());
  85. return $this->callGetApi($url);
  86. }
  87. /**
  88. * 组合模板并添加至帐号下的个人模板库
  89. * @param string $tid 模板标题 id,可通过接口获取,也可登录小程序后台查看获取
  90. * @param array $kidList 开发者自行组合好的模板关键词列表,关键词顺序可以自由搭配(例如 [3,5,4] 或 [4,5,3]),最多支持5个,最少2个关键词组合
  91. * @param string $sceneDesc 服务场景描述,15个字以内
  92. * @return array
  93. * @throws \WeChat\Exceptions\InvalidResponseException
  94. * @throws \WeChat\Exceptions\LocalCacheException
  95. */
  96. public function addTemplate($tid, array $kidList, $sceneDesc = '')
  97. {
  98. $url = 'https://api.weixin.qq.com/wxaapi/newtmpl/addtemplate?access_token=ACCESS_TOKEN';
  99. $this->registerApi($url, __FUNCTION__, func_get_args());
  100. return $this->callPostApi($url, ['tid' => $tid, 'kidList' => $kidList, 'sceneDesc' => $sceneDesc], false);
  101. }
  102. /**
  103. * 获取当前帐号下的个人模板列表
  104. * @return array
  105. * @throws \WeChat\Exceptions\InvalidResponseException
  106. * @throws \WeChat\Exceptions\LocalCacheException
  107. */
  108. public function getTemplateList()
  109. {
  110. $url = 'https://api.weixin.qq.com/wxaapi/newtmpl/gettemplate?access_token=ACCESS_TOKEN';
  111. $this->registerApi($url, __FUNCTION__, func_get_args());
  112. return $this->callGetApi($url);
  113. }
  114. /**
  115. * 删除帐号下的个人模板
  116. * @param string $priTmplId 要删除的模板id
  117. * @return array
  118. * @throws \WeChat\Exceptions\InvalidResponseException
  119. * @throws \WeChat\Exceptions\LocalCacheException
  120. */
  121. public function delTemplate($priTmplId)
  122. {
  123. $url = 'https://api.weixin.qq.com/wxaapi/newtmpl/deltemplate?access_token=ACCESS_TOKEN';
  124. $this->registerApi($url, __FUNCTION__, func_get_args());
  125. return $this->callPostApi($url, ['priTmplId' => $priTmplId], true);
  126. }
  127. /**
  128. * 发送订阅消息
  129. * @param array $data 发送的消息对象数组
  130. * @return array
  131. * @throws \WeChat\Exceptions\InvalidResponseException
  132. * @throws \WeChat\Exceptions\LocalCacheException
  133. */
  134. public function send(array $data)
  135. {
  136. $url = 'https://api.weixin.qq.com/cgi-bin/message/subscribe/send?access_token=ACCESS_TOKEN';
  137. $this->registerApi($url, __FUNCTION__, func_get_args());
  138. return $this->callPostApi($url, $data, true);
  139. }
  140. }