Skip to content

Commit

Permalink
✨ Blacklist. (#634)
Browse files Browse the repository at this point in the history
  • Loading branch information
mingyoung authored and overtrue committed Apr 5, 2017
1 parent a59297f commit f29d624
Show file tree
Hide file tree
Showing 2 changed files with 89 additions and 0 deletions.
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']);
}
}

0 comments on commit f29d624

Please sign in to comment.