diff --git a/wchat/officialaccount/Tag.php b/wchat/officialaccount/Tag.php index 6f960bf..7e896c1 100644 --- a/wchat/officialaccount/Tag.php +++ b/wchat/officialaccount/Tag.php @@ -8,6 +8,13 @@ class Tag extends AfficialAccount { private $generate_url = 'https://api.weixin.qq.com/cgi-bin/tags/create?access_token='; + private $tag_lists = 'https://api.weixin.qq.com/cgi-bin/tags/get?access_token='; + private $tag_edit = 'https://api.weixin.qq.com/cgi-bin/tags/update?access_token='; + private $tag_delete = 'https://api.weixin.qq.com/cgi-bin/tags/delete?access_token='; + private $tag_fans_list = 'https://api.weixin.qq.com/cgi-bin/user/tag/get?access_token='; + private $user_batch_add_tag = 'https://api.weixin.qq.com/cgi-bin/tags/members/batchtagging?access_token='; + private $user_batch_remove_tag = 'https://api.weixin.qq.com/cgi-bin/tags/members/batchuntagging?access_token='; + private $user_tag = 'https://api.weixin.qq.com/cgi-bin/tags/getidlist?access_token='; /** * @param $tagName @@ -27,4 +34,135 @@ class Tag extends AfficialAccount return $result->getData(); } + /** + * @param $id + * @param $tagName + * @return mixed + * @throws \Exception + */ + public function tag_edit($id, $tagName) + { + $url['tag[id]'] = $id; + $url['tag[name]'] = $tagName; + + $config = $this->config->getAccessToken(); + + $result = $this->request->post($this->tag_edit . $config, $url); + if (!$result->isResultsOK()) { + throw new \Exception($result->getMessage()); + } + return $result->getData(); + } + + + /** + * @param $id + * @param $tagName + * @return mixed + * @throws \Exception + */ + public function tag_delete($id) + { + $url['tag[id]'] = $id; + + $config = $this->config->getAccessToken(); + + $result = $this->request->post($this->tag_delete . $config, $url); + if (!$result->isResultsOK()) { + throw new \Exception($result->getMessage()); + } + return $result->getData(); + } + + + /** + * @param $id + * @param string[] $openid_list + * @return mixed + * @throws \Exception + */ + public function user_batch_add_tag($id, array $openid_list) + { + $url['tagid'] = $id; + $url['openid_list'] = $openid_list; + + $config = $this->config->getAccessToken(); + + $result = $this->request->post($this->user_batch_add_tag . $config, $url); + if (!$result->isResultsOK()) { + throw new \Exception($result->getMessage()); + } + return $result->getData(); + } + + + /** + * @param $id + * @param string[] $openid_list + * @return mixed + * @throws \Exception + */ + public function user_batch_remove_tag($id, array $openid_list) + { + $url['tagid'] = $id; + $url['openid_list'] = $openid_list; + + $config = $this->config->getAccessToken(); + + $result = $this->request->post($this->user_batch_remove_tag . $config, $url); + if (!$result->isResultsOK()) { + throw new \Exception($result->getMessage()); + } + return $result->getData(); + } + + + /** + * @return mixed + * @throws \Exception + */ + public function tagList() + { + $config = $this->config->getAccessToken(); + + $result = $this->request->get($this->tag_lists . $config); + if (!$result->isResultsOK()) { + throw new \Exception($result->getMessage()); + } + return $result->getData(); + } + + + /** + * @return mixed + * @throws \Exception + */ + public function tag_fans_list() + { + $config = $this->config->getAccessToken(); + $result = $this->request->get($this->tag_fans_list . $config); + if (!$result->isResultsOK()) { + throw new \Exception($result->getMessage()); + } + return $result->getData(); + } + + + /** + * @param $openid + * @return mixed + * @throws \Exception + */ + public function user_tag($openid) + { + $config = $this->config->getAccessToken(); + $result = $this->request->post($this->user_tag . $config, [ + 'openid' => $openid + ]); + if (!$result->isResultsOK()) { + throw new \Exception($result->getMessage()); + } + return $result->getData(); + } + }