Newtmpl.php 5.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151
  1. <?php
  2. // +----------------------------------------------------------------------
  3. // | WeChatDeveloper
  4. // +----------------------------------------------------------------------
  5. // | 版权所有 2014~2018 广州楚才信息科技有限公司 [ 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. $this->registerApi($url, __FUNCTION__, func_get_args());
  70. return $this->callPostApi($url, ['ids'=>$ids,'start' => '0', 'limit' => '30'], true);
  71. }
  72. /**
  73. * 获取模板标题下的关键词列表
  74. * @param string $tid 模板标题 id,可通过接口获取
  75. * @return array
  76. * @throws \WeChat\Exceptions\InvalidResponseException
  77. * @throws \WeChat\Exceptions\LocalCacheException
  78. */
  79. public function getPubTemplateKeyWordsById($tid)
  80. {
  81. $url = 'https://api.weixin.qq.com/wxaapi/newtmpl/getpubtemplatekeywords?access_token=ACCESS_TOKEN';
  82. $this->registerApi($url, __FUNCTION__, func_get_args());
  83. return $this->callPostApi($url, ['tid' => $tid], true);
  84. }
  85. /**
  86. * 组合模板并添加至帐号下的个人模板库
  87. * @param string $tid 模板标题 id,可通过接口获取,也可登录小程序后台查看获取
  88. * @param array $kidList 开发者自行组合好的模板关键词列表,关键词顺序可以自由搭配(例如 [3,5,4] 或 [4,5,3]),最多支持5个,最少2个关键词组合
  89. * @param string $sceneDesc 服务场景描述,15个字以内
  90. * @return array
  91. * @throws \WeChat\Exceptions\InvalidResponseException
  92. * @throws \WeChat\Exceptions\LocalCacheException
  93. */
  94. public function addTemplate($tid, array $kidList, $sceneDesc = '')
  95. {
  96. $url = 'https://api.weixin.qq.com/wxaapi/newtmpl/addtemplate?access_token=ACCESS_TOKEN';
  97. $this->registerApi($url, __FUNCTION__, func_get_args());
  98. return $this->callPostApi($url, ['tid' => $tid, 'kidList' => $kidList, 'sceneDesc' => $sceneDesc], false);
  99. }
  100. /**
  101. * 获取当前帐号下的个人模板列表
  102. * @return array
  103. * @throws \WeChat\Exceptions\InvalidResponseException
  104. * @throws \WeChat\Exceptions\LocalCacheException
  105. */
  106. public function getTemplateList()
  107. {
  108. $url = 'https://api.weixin.qq.com/wxaapi/newtmpl/gettemplate?access_token=ACCESS_TOKEN';
  109. $this->registerApi($url, __FUNCTION__, func_get_args());
  110. return $this->callPostApi($url, [], true);
  111. }
  112. /**
  113. * 删除帐号下的个人模板
  114. * @param string $priTmplId 要删除的模板id
  115. * @return array
  116. * @throws \WeChat\Exceptions\InvalidResponseException
  117. * @throws \WeChat\Exceptions\LocalCacheException
  118. */
  119. public function delTemplate($priTmplId)
  120. {
  121. $url = 'https://api.weixin.qq.com/wxaapi/newtmpl/deltemplate?access_token=ACCESS_TOKEN';
  122. $this->registerApi($url, __FUNCTION__, func_get_args());
  123. return $this->callPostApi($url, ['priTmplId' => $priTmplId], true);
  124. }
  125. /**
  126. * 发送订阅消息
  127. * @param array $data 发送的消息对象数组
  128. * @return array
  129. * @throws \WeChat\Exceptions\InvalidResponseException
  130. * @throws \WeChat\Exceptions\LocalCacheException
  131. */
  132. public function send(array $data)
  133. {
  134. $url = 'https://api.weixin.qq.com/cgi-bin/message/subscribe/send?access_token=ACCESS_TOKEN';
  135. $this->registerApi($url, __FUNCTION__, func_get_args());
  136. return $this->callPostApi($url, $data, true);
  137. }
  138. }