Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

✨ Blacklist. #634

Merged
merged 1 commit into from
Apr 5, 2017
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
45 changes: 45 additions & 0 deletions src/User/User.php
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,9 @@ class User extends AbstractAPI
const API_GROUP = 'https://api.weixin.qq.com/cgi-bin/groups/getid';
const API_REMARK = 'https://api.weixin.qq.com/cgi-bin/user/info/updateremark';
const API_OAUTH_GET = 'https://api.weixin.qq.com/sns/userinfo';
const API_GET_BLACK_LIST = 'https://api.weixin.qq.com/cgi-bin/tags/members/getblacklist';
const API_BATCH_BLACK_LIST = 'https://api.weixin.qq.com/cgi-bin/tags/members/batchblacklist';
const API_BATCH_UNBLACK_LIST = 'https://api.weixin.qq.com/cgi-bin/tags/members/batchunblacklist';

/**
* Fetch a user by open id.
Expand Down Expand Up @@ -132,4 +135,46 @@ public function getGroup($openId)

return $this->parseJSON('json', [self::API_GROUP, $params]);
}

/**
* Get black list.
*
* @param string|null $beginOpenid
*
* @return \EasyWeChat\Support\Collection
*/
public function blacklist($beginOpenid = null)
{
$params = ['begin_openid' => $beginOpenid];

return $this->parseJSON('json', [self::API_GET_BLACK_LIST, $params]);
}

/**
* Batch block user.
*
* @param array $openidList
*
* @return \EasyWeChat\Support\Collection
*/
public function batchBlock(array $openidList)
{
$params = ['openid_list' => $openidList];

return $this->parseJSON('json', [self::API_BATCH_BLACK_LIST, $params]);
}

/**
* Batch unblock user.
*
* @param array $openidList
*
* @return \EasyWeChat\Support\Collection
*/
public function batchUnblock(array $openidList)
{
$params = ['openid_list' => $openidList];

return $this->parseJSON('json', [self::API_BATCH_UNBLACK_LIST, $params]);
}
}
44 changes: 44 additions & 0 deletions tests/User/UserUserTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -105,4 +105,48 @@ public function testGroup()
$result = $user->getGroup('openid2');
$this->assertEquals('openid2', $result['params']['openid']);
}

/**
* Test blacklist().
*/
public function testBlacklist()
{
$user = $this->getUser();
$result = $user->blacklist();

$this->assertNull($result['params']['begin_openid']);

$result = $user->blacklist('black-openid');
$this->assertEquals('black-openid', $result['params']['begin_openid']);
}

/**
* Test batchBlock().
*/
public function testBatchBlockUser()
{
$user = $this->getUser();

$result = $user->batchBlock(['openid1', 'openid2']);

$expected = ['openid1', 'openid2'];

$this->assertStringStartsWith(User::API_BATCH_BLACK_LIST, $result['api']);
$this->assertEquals($expected, $result['params']['openid_list']);
}

/**
* Test batchUnblock().
*/
public function testBatchUnblockUser()
{
$user = $this->getUser();

$result = $user->batchUnblock(['openid1', 'openid2']);

$expected = ['openid1', 'openid2'];

$this->assertStringStartsWith(User::API_BATCH_UNBLACK_LIST, $result['api']);
$this->assertEquals($expected, $result['params']['openid_list']);
}
}