WechatOfficialTemplate.php 1.5 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758
  1. <?php
  2. namespace app\common\library\easywechatPlus;
  3. use app\common\facade\HttpClient;
  4. /**
  5. * 补充 公众号行业模板
  6. */
  7. class WechatOfficialTemplate extends EasywechatPlus
  8. {
  9. /**
  10. * 添加公众号模板
  11. *
  12. * @param string $shortId 模板 id
  13. * @param array $keywordList 模板关键字
  14. * @return void
  15. */
  16. public function addTemplate($shortId, $keywordList)
  17. {
  18. $params = ['template_id_short' => $shortId];
  19. if ($keywordList) {
  20. $params['keyword_name_list'] = $keywordList;
  21. }
  22. $access_token = $this->getAccessToken();
  23. $add_template_url = "https://api.weixin.qq.com/cgi-bin/template/api_add_template";
  24. $result = HttpClient::request('post', $add_template_url, [
  25. 'body' => json_encode($params, JSON_UNESCAPED_UNICODE),
  26. 'query' => ["access_token" => $access_token['access_token']],
  27. 'headers' => ['Content-Type' => 'application/json']
  28. ]);
  29. $result = $result->getBody()->getContents();
  30. return json_decode($result, true);
  31. }
  32. /**
  33. * 方法转发到 easywechat
  34. *
  35. * @param string $funcname
  36. * @param array $arguments
  37. * @return void
  38. */
  39. public function __call($funcname, $arguments)
  40. {
  41. if ($funcname == 'deletePrivateTemplate') {
  42. return $this->app->template_message->{$funcname}(...$arguments);
  43. }
  44. return $this->app->{$funcname}(...$arguments);
  45. }
  46. }