Files
kiri-wchat/wchat/officialaccount/Tag.php
T
as2252258@163.com f7128047f4 add clear
2020-03-16 19:40:10 +08:00

157 lines
3.7 KiB
PHP

<?php
namespace wchat\officialaccount;
use wchat\common\Result;
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 Result
* @throws \Exception
*/
public function generate($tagName)
{
$params['tag'] = ['name' => $tagName];
$config = $this->config->getAccessToken();
$this->request->setErrorField('errcode');
$this->request->setErrorMsgField('errmsg');
$this->request->setData(json_encode($params));
return $this->request->post($this->generate_url . $config);
}
/**
* @param $id
* @param $tagName
* @return Result
* @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
* @return Result
* @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 Result
* @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 Result
* @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 Result
* @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 Result
* @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 Result
* @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
]);
}
}