SubscribeMessage.php 2.1 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849
  1. <?php
  2. namespace wx\miniprogram\msg;
  3. use ErrorException;
  4. use wx\Base;
  5. /**
  6. * 小程序订阅消息
  7. *
  8. * @method json uniformMessage() static 统一服务消息
  9. * @method json send() static 发送订阅消息
  10. * @method json addTemplate() static 添加订阅消息模板
  11. * @method json deleteTemplate() static 删除订阅消息模板
  12. * @method json getCategory() static 获取小程序账号的类目
  13. * @method json getPubTemplateKeyWordsById() static 获取模板标题下的关键词列表
  14. * @method json getPubTemplateTitleList() static 获取帐号所属类目下的公共模板标题
  15. * @method json getTemplateList() static 获取当前帐号下的个人模板列表
  16. */
  17. class SubscribeMessage extends Base
  18. {
  19. private $requestUrl = [
  20. 'send' => 'https://api.weixin.qq.com/cgi-bin/message/subscribe/send?access_token=',
  21. 'addTemplate' => 'https://api.weixin.qq.com/wxaapi/newtmpl/addtemplate?access_token=',
  22. 'deleteTemplate' => 'https://api.weixin.qq.com/wxaapi/newtmpl/deltemplate?access_token=',
  23. 'getCategory' => 'https://api.weixin.qq.com/wxaapi/newtmpl/getcategory?access_token=',
  24. 'getPubTemplateKeyWordsById' => 'https://api.weixin.qq.com/wxaapi/newtmpl/getpubtemplatekeywords?access_token=',
  25. 'getPubTemplateTitleList' => 'https://api.weixin.qq.com/wxaapi/newtmpl/getpubtemplatetitles?access_token=',
  26. 'getTemplateList' => 'https://api.weixin.qq.com/wxaapi/newtmpl/gettemplate?access_token=',
  27. 'uniformMessage' => 'https://api.weixin.qq.com/cgi-bin/message/wxopen/template/uniform_send?access_token=',
  28. ];
  29. public function __call($method, $arguments)
  30. {
  31. if (!isset($this->requestUrl[$method])) {
  32. throw new ErrorException('Method ' . $method . ' not exists');
  33. }
  34. $num = count($arguments);
  35. if ($num != 2) {
  36. throw new ErrorException('Method ' . $method . ' needs two arguments. ' . $num . ' arguments given.');
  37. }
  38. $url = $this->requestUrl[$method] . $arguments[0];
  39. $data = $this->curl($url, json_encode($arguments[1]));
  40. return $data;
  41. }
  42. }