GET
GET = 'get'
Class Tag.
$http : \EasyWeChat\Core\Http
Http instance.
$accessToken : \EasyWeChat\Core\AccessToken
The request token.
__construct(\EasyWeChat\Core\AccessToken $accessToken)
Constructor.
\EasyWeChat\Core\AccessToken | $accessToken |
getHttp() : \EasyWeChat\Core\Http
Return the http instance.
setHttp(\EasyWeChat\Core\Http $http) : $this
Set the http instance.
\EasyWeChat\Core\Http | $http |
getAccessToken() : \EasyWeChat\Core\AccessToken
Return the current accessToken.
setAccessToken(\EasyWeChat\Core\AccessToken $accessToken) : $this
Set the request token.
\EasyWeChat\Core\AccessToken | $accessToken |
parseJSON(string $method, array $args) : \EasyWeChat\Support\Collection
Parse JSON from response and check error.
string | $method | |
array | $args |
| null
create(string $name) : \EasyWeChat\Support\Collection
Create tag.
string | $name |
lists() : \EasyWeChat\Support\Collection
List all tags.
update(integer $tagId, string $name) : \EasyWeChat\Support\Collection
Update a tag name.
integer | $tagId | |
string | $name |
delete(integer $tagId) : \EasyWeChat\Support\Collection
Delete tag.
integer | $tagId |
userTags(string $openId) : \EasyWeChat\Support\Collection
Get user tags.
string | $openId |
usersOfTag(string $tagId, string $nextOpenId = '') : \EasyWeChat\Support\Collection
Get users from a tag.
string | $tagId | |
string | $nextOpenId |
batchTagUsers(array $openIds, integer $tagId) : \EasyWeChat\Support\Collection
Batch tag users.
array | $openIds | |
integer | $tagId |
batchUntagUsers(array $openIds, integer $tagId) : \EasyWeChat\Support\Collection
Untag users from a tag.
array | $openIds | |
integer | $tagId |
<?php
/*
* This file is part of the overtrue/wechat.
*
* (c) overtrue <i@overtrue.me>
*
* This source file is subject to the MIT license that is bundled
* with this source code in the file LICENSE.
*/
/**
* Group.php.
*
* @author overtrue <i@overtrue.me>
* @copyright 2015 overtrue <i@overtrue.me>
*
* @see https://github.com/overtrue
* @see http://overtrue.me
*/
namespace EasyWeChat\User;
use EasyWeChat\Core\AbstractAPI;
/**
* Class Tag.
*/
class Tag extends AbstractAPI
{
const API_GET = 'https://api.weixin.qq.com/cgi-bin/tags/get';
const API_CREATE = 'https://api.weixin.qq.com/cgi-bin/tags/create';
const API_UPDATE = 'https://api.weixin.qq.com/cgi-bin/tags/update';
const API_DELETE = 'https://api.weixin.qq.com/cgi-bin/tags/delete';
const API_USER_TAGS = 'https://api.weixin.qq.com/cgi-bin/tags/getidlist';
const API_MEMBER_BATCH_TAG = 'https://api.weixin.qq.com/cgi-bin/tags/members/batchtagging';
const API_MEMBER_BATCH_UNTAG = 'https://api.weixin.qq.com/cgi-bin/tags/members/batchuntagging';
const API_USERS_OF_TAG = 'https://api.weixin.qq.com/cgi-bin/user/tag/get';
/**
* Create tag.
*
* @param string $name
*
* @return \EasyWeChat\Support\Collection
*/
public function create($name)
{
$params = [
'tag' => ['name' => $name],
];
return $this->parseJSON('json', [self::API_CREATE, $params]);
}
/**
* List all tags.
*
* @return \EasyWeChat\Support\Collection
*/
public function lists()
{
return $this->parseJSON('get', [self::API_GET]);
}
/**
* Update a tag name.
*
* @param int $tagId
* @param string $name
*
* @return \EasyWeChat\Support\Collection
*/
public function update($tagId, $name)
{
$params = [
'tag' => [
'id' => $tagId,
'name' => $name,
],
];
return $this->parseJSON('json', [self::API_UPDATE, $params]);
}
/**
* Delete tag.
*
* @param int $tagId
*
* @return \EasyWeChat\Support\Collection
*/
public function delete($tagId)
{
$params = [
'tag' => ['id' => $tagId],
];
return $this->parseJSON('json', [self::API_DELETE, $params]);
}
/**
* Get user tags.
*
* @param string $openId
*
* @return \EasyWeChat\Support\Collection
*/
public function userTags($openId)
{
$params = ['openid' => $openId];
return $this->parseJSON('json', [self::API_USER_TAGS, $params]);
}
/**
* Get users from a tag.
*
* @param string $tagId
* @param string $nextOpenId
*
* @return \EasyWeChat\Support\Collection
*/
public function usersOfTag($tagId, $nextOpenId = '')
{
$params = ['tagid' => $tagId, 'next_openid' => $nextOpenId];
return $this->parseJSON('json', [self::API_USERS_OF_TAG, $params]);
}
/**
* Batch tag users.
*
* @param array $openIds
* @param int $tagId
*
* @return \EasyWeChat\Support\Collection
*/
public function batchTagUsers(array $openIds, $tagId)
{
$params = [
'openid_list' => $openIds,
'tagid' => $tagId,
];
return $this->parseJSON('json', [self::API_MEMBER_BATCH_TAG, $params]);
}
/**
* Untag users from a tag.
*
* @param array $openIds
* @param int $tagId
*
* @return \EasyWeChat\Support\Collection
*/
public function batchUntagUsers(array $openIds, $tagId)
{
$params = [
'openid_list' => $openIds,
'tagid' => $tagId,
];
return $this->parseJSON('json', [self::API_MEMBER_BATCH_UNTAG, $params]);
}
}