155 lines
3.6 KiB
PHP
155 lines
3.6 KiB
PHP
<?php
|
|
|
|
|
|
namespace wchat\officialaccount;
|
|
|
|
|
|
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
|
|
* @return mixed
|
|
* @throws \Exception
|
|
*/
|
|
public function generate($tagName)
|
|
{
|
|
$params['tag[name]'] = $tagName;
|
|
|
|
$config = $this->config->getAccessToken();
|
|
|
|
$this->request->setErrorField('errcode');
|
|
$this->request->setErrorMsgField('errmsg');
|
|
|
|
return $this->request->post($this->generate_url . $config, $params);
|
|
}
|
|
|
|
/**
|
|
* @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();
|
|
|
|
|
|
$this->request->setErrorField('errcode');
|
|
$this->request->setErrorMsgField('errmsg');
|
|
|
|
return $this->request->post($this->tag_edit . $config, $url);
|
|
}
|
|
|
|
|
|
/**
|
|
* @param $id
|
|
* @param $tagName
|
|
* @return mixed
|
|
* @throws \Exception
|
|
*/
|
|
public function tag_delete($id)
|
|
{
|
|
$url['tag[id]'] = $id;
|
|
|
|
$config = $this->config->getAccessToken();
|
|
$this->request->setErrorField('errcode');
|
|
$this->request->setErrorMsgField('errmsg');
|
|
return $this->request->post($this->tag_delete . $config, $url);
|
|
}
|
|
|
|
|
|
/**
|
|
* @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();
|
|
|
|
$this->request->setErrorField('errcode');
|
|
$this->request->setErrorMsgField('errmsg');
|
|
return $this->request->post($this->user_batch_add_tag . $config, $url);
|
|
}
|
|
|
|
|
|
/**
|
|
* @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();
|
|
|
|
$this->request->setErrorField('errcode');
|
|
$this->request->setErrorMsgField('errmsg');
|
|
return $this->request->post($this->user_batch_remove_tag . $config, $url);
|
|
}
|
|
|
|
|
|
/**
|
|
* @return mixed
|
|
* @throws \Exception
|
|
*/
|
|
public function tagList()
|
|
{
|
|
$config = $this->config->getAccessToken();
|
|
|
|
$this->request->setErrorField('errcode');
|
|
$this->request->setErrorMsgField('errmsg');
|
|
return $this->request->get($this->tag_lists . $config);
|
|
}
|
|
|
|
|
|
/**
|
|
* @return mixed
|
|
* @throws \Exception
|
|
*/
|
|
public function tag_fans_list()
|
|
{
|
|
$config = $this->config->getAccessToken();
|
|
$this->request->setErrorField('errcode');
|
|
$this->request->setErrorMsgField('errmsg');
|
|
return $this->request->get($this->tag_fans_list . $config);
|
|
}
|
|
|
|
|
|
/**
|
|
* @param $openid
|
|
* @return mixed
|
|
* @throws \Exception
|
|
*/
|
|
public function user_tag($openid)
|
|
{
|
|
$config = $this->config->getAccessToken();
|
|
$this->request->setErrorField('errcode');
|
|
$this->request->setErrorMsgField('errmsg');
|
|
return $this->request->post($this->user_tag . $config, [
|
|
'openid' => $openid
|
|
]);
|
|
}
|
|
|
|
}
|