12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849 |
- <?php
- namespace wx\miniprogram\msg;
- use ErrorException;
- use wx\Base;
- /**
- * 小程序订阅消息
- *
- * @method json uniformMessage() static 统一服务消息
- * @method json send() static 发送订阅消息
- * @method json addTemplate() static 添加订阅消息模板
- * @method json deleteTemplate() static 删除订阅消息模板
- * @method json getCategory() static 获取小程序账号的类目
- * @method json getPubTemplateKeyWordsById() static 获取模板标题下的关键词列表
- * @method json getPubTemplateTitleList() static 获取帐号所属类目下的公共模板标题
- * @method json getTemplateList() static 获取当前帐号下的个人模板列表
- */
- class SubscribeMessage extends Base
- {
- private $requestUrl = [
- 'send' => 'https://api.weixin.qq.com/cgi-bin/message/subscribe/send?access_token=',
- 'addTemplate' => 'https://api.weixin.qq.com/wxaapi/newtmpl/addtemplate?access_token=',
- 'deleteTemplate' => 'https://api.weixin.qq.com/wxaapi/newtmpl/deltemplate?access_token=',
- 'getCategory' => 'https://api.weixin.qq.com/wxaapi/newtmpl/getcategory?access_token=',
- 'getPubTemplateKeyWordsById' => 'https://api.weixin.qq.com/wxaapi/newtmpl/getpubtemplatekeywords?access_token=',
- 'getPubTemplateTitleList' => 'https://api.weixin.qq.com/wxaapi/newtmpl/getpubtemplatetitles?access_token=',
- 'getTemplateList' => 'https://api.weixin.qq.com/wxaapi/newtmpl/gettemplate?access_token=',
- 'uniformMessage' => 'https://api.weixin.qq.com/cgi-bin/message/wxopen/template/uniform_send?access_token=',
- ];
- public function __call($method, $arguments)
- {
- if (!isset($this->requestUrl[$method])) {
- throw new ErrorException('Method ' . $method . ' not exists');
- }
- $num = count($arguments);
- if ($num != 2) {
- throw new ErrorException('Method ' . $method . ' needs two arguments. ' . $num . ' arguments given.');
- }
- $url = $this->requestUrl[$method] . $arguments[0];
- $data = $this->curl($url, json_encode($arguments[1]));
- return $data;
- }
- }
|