国内流行的内容管理系统(CMS)多端全媒体解决方案 https://www.dedebiz.com
Вы не можете выбрать более 25 тем Темы должны начинаться с буквы или цифры, могут содержать дефисы(-) и должны содержать не более 35 символов.

90 строки
3.2KB

  1. <?php
  2. namespace WeChat;
  3. if (!defined('DEDEINC')) exit('dedebiz');
  4. use WeChat\Contracts\BasicWeChat;
  5. /**
  6. * 模板消息
  7. * Class Template
  8. * @package WeChat
  9. */
  10. class Template extends BasicWeChat
  11. {
  12. /**
  13. * 设置所属行业
  14. * @param string $industry_id1 公众号模板消息所属行业编号
  15. * @param string $industry_id2 公众号模板消息所属行业编号
  16. * @return array
  17. * @throws Exceptions\InvalidResponseException
  18. * @throws Exceptions\LocalCacheException
  19. */
  20. public function setIndustry($industry_id1, $industry_id2)
  21. {
  22. $url = "https://api.weixin.qq.com/cgi-bin/template/api_set_industry?access_token=ACCESS_TOKEN";
  23. $this->registerApi($url, __FUNCTION__, func_get_args());
  24. return $this->httpPostForJson($url, ['industry_id1' => $industry_id1, 'industry_id2' => $industry_id2]);
  25. }
  26. /**
  27. * 获取设置的行业信息
  28. * @return array
  29. * @throws Exceptions\InvalidResponseException
  30. * @throws Exceptions\LocalCacheException
  31. */
  32. public function getIndustry()
  33. {
  34. $url = "https://api.weixin.qq.com/cgi-bin/template/get_industry?access_token=ACCESS_TOKEN";
  35. $this->registerApi($url, __FUNCTION__, func_get_args());
  36. return $this->httpGetForJson($url);
  37. }
  38. /**
  39. * 获得模板ID
  40. * @param string $tpl_id 板库中模板的编号,有“TM**”和“OPENTMTM**”等形式
  41. * @return array
  42. * @throws Exceptions\InvalidResponseException
  43. * @throws Exceptions\LocalCacheException
  44. */
  45. public function addTemplate($tpl_id)
  46. {
  47. $url = "https://api.weixin.qq.com/cgi-bin/template/api_add_template?access_token=ACCESS_TOKEN";
  48. $this->registerApi($url, __FUNCTION__, func_get_args());
  49. return $this->httpPostForJson($url, ['template_id_short' => $tpl_id]);
  50. }
  51. /**
  52. * 获取模板列表
  53. * @return array
  54. * @throws Exceptions\InvalidResponseException
  55. * @throws Exceptions\LocalCacheException
  56. */
  57. public function getAllPrivateTemplate()
  58. {
  59. $url = "https://api.weixin.qq.com/cgi-bin/template/get_all_private_template?access_token=ACCESS_TOKEN";
  60. $this->registerApi($url, __FUNCTION__, func_get_args());
  61. return $this->httpGetForJson($url);
  62. }
  63. /**
  64. * 删除模板ID
  65. * @param string $tpl_id 公众帐号下模板消息ID
  66. * @return array
  67. * @throws Exceptions\InvalidResponseException
  68. * @throws Exceptions\LocalCacheException
  69. */
  70. public function delPrivateTemplate($tpl_id)
  71. {
  72. $url = "https://api.weixin.qq.com/cgi-bin/template/del_private_template?access_token=ACCESS_TOKEN";
  73. $this->registerApi($url, __FUNCTION__, func_get_args());
  74. return $this->httpPostForJson($url, ['template_id' => $tpl_id]);
  75. }
  76. /**
  77. * 发送模板消息
  78. * @param array $data
  79. * @return array
  80. * @throws Exceptions\InvalidResponseException
  81. * @throws Exceptions\LocalCacheException
  82. */
  83. public function send(array $data)
  84. {
  85. $url = "https://api.weixin.qq.com/cgi-bin/message/template/send?access_token=ACCESS_TOKEN";
  86. $this->registerApi($url, __FUNCTION__, func_get_args());
  87. return $this->httpPostForJson($url, $data);
  88. }
  89. }
  90. ?>