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

Develop #410

Merged
merged 17 commits into from
May 4, 2016
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
2 changes: 1 addition & 1 deletion phpunit.xml.dist
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
<?xml version="1.0" encoding="UTF-8"?>
<phpunit backupGlobals="false"
backupStaticAttributes="false"
bootstrap="vendor/autoload.php"
bootstrap="tests/bootstrap.php"
colors="true"
convertErrorsToExceptions="true"
convertNoticesToExceptions="true"
Expand Down
8 changes: 8 additions & 0 deletions src/Foundation/ServiceProviders/UserServiceProvider.php
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@
namespace EasyWeChat\Foundation\ServiceProviders;

use EasyWeChat\User\Group;
use EasyWeChat\User\Tag;
use EasyWeChat\User\User;
use Pimple\Container;
use Pimple\ServiceProviderInterface;
Expand Down Expand Up @@ -53,7 +54,14 @@ public function register(Container $pimple)
return new Group($pimple['access_token']);
};

$tag = function ($pimple) {
return new Tag($pimple['access_token']);
};

$pimple['user_group'] = $group;
$pimple['user.group'] = $group;

$pimple['user_tag'] = $tag;
$pimple['user.tag'] = $tag;
}
}
164 changes: 164 additions & 0 deletions src/User/Tag.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,164 @@
<?php

/*
* This file is part of the overtrue/wechat.
*
* (c) overtrue <[email protected]>
*
* This source file is subject to the MIT license that is bundled
* with this source code in the file LICENSE.
*/

/**
* Group.php.
*
* @author overtrue <[email protected]>
* @copyright 2015 overtrue <[email protected]>
*
* @link https://github.com/overtrue
* @link 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 int
*/
public function create($name)
{
$params = [
'tag' => ['name' => $name],
];

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

/**
* List all tags.
*
* @return array
*/
public function lists()
{
return $this->parseJSON('get', [self::API_GET]);
}

/**
* Update a tag name.
*
* @param int $tagId
* @param string $name
*
* @return bool
*/
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 bool
*/
public function delete($tagId)
{
$params = [
'tag' => ['id' => $tagId],
];

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

/**
* Get user tags.
*
* @param string $openId
*
* @return int
*/
public function userTags($openId)
{
$params = ['openid' => $openId];

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

/**
* Get users from a tag.
*
* @param string $openId
*
* @return int
*/
public function usersOfTag($tagId)
{
$params = ['tagid' => $tagId];

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

/**
* Batch tag users.
*
* @param array $openIds
* @param int $tagid
*
* @return bool
*/
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 bool
*/
public function batchUntagUsers(array $openIds, $tagId)
{
$params = [
'openid_list' => $openIds,
'tagid' => $tagId,
];

return $this->parseJSON('json', [self::API_MEMBER_BATCH_UNTAG, $params]);
}
}
2 changes: 1 addition & 1 deletion tests/Broadcast/BroadcastBroadcastTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@

use EasyWeChat\Broadcast\Broadcast;

class BroadcastBroadcastTest extends PHPUnit_Framework_TestCase
class BroadcastBroadcastTest extends TestCase
{
public function getBroadcast()
{
Expand Down
2 changes: 1 addition & 1 deletion tests/Broadcast/BroadcastMessageBuilderTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
use EasyWeChat\Broadcast\Broadcast;
use EasyWeChat\Broadcast\MessageBuilder;

class BroadcastMessageBuilderTest extends PHPUnit_Framework_TestCase
class BroadcastMessageBuilderTest extends TestCase
{
/**
* Test msgType().
Expand Down
2 changes: 1 addition & 1 deletion tests/Broadcast/BroadcastTransformerTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@

use EasyWeChat\Broadcast\Transformer;

class BroadcastTransformerTest extends PHPUnit_Framework_TestCase
class BroadcastTransformerTest extends TestCase
{
/**
* Test transform().
Expand Down
2 changes: 1 addition & 1 deletion tests/Core/CoreAbstractAPITest.php
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ public function getHttpInstance()
}
}

class CoreAbstractAPITest extends PHPUnit_Framework_TestCase
class CoreAbstractAPITest extends TestCase
{
/**
* Test __construct.
Expand Down
2 changes: 1 addition & 1 deletion tests/Core/CoreAccessTokenTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
use EasyWeChat\Core\AccessToken;
use EasyWeChat\Core\Http;

class CoreAccessTokenTest extends PHPUnit_Framework_TestCase
class CoreAccessTokenTest extends TestCase
{
public function testGetToken()
{
Expand Down
2 changes: 1 addition & 1 deletion tests/Core/CoreHttpTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
use GuzzleHttp\Client;
use GuzzleHttp\Psr7\Response;

class CoreHttpTest extends PHPUnit_Framework_TestCase
class CoreHttpTest extends TestCase
{
public function testConstruct()
{
Expand Down
2 changes: 1 addition & 1 deletion tests/Encryption/EncryptionEncryptorTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
use EasyWeChat\Encryption\Encryptor;
use EasyWeChat\Support\XML;

class EncryptionEncryptorTest extends PHPUnit_Framework_TestCase
class EncryptionEncryptorTest extends TestCase
{
public function getEncryptor()
{
Expand Down
2 changes: 1 addition & 1 deletion tests/Foundation/ApplicationTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
use Pimple\ServiceProviderInterface;
use Symfony\Component\HttpFoundation\Request;

class ApplicationTest extends PHPUnit_Framework_TestCase
class ApplicationTest extends TestCase
{
/**
* Test __construct().
Expand Down
2 changes: 1 addition & 1 deletion tests/Js/JsJsTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
use EasyWeChat\Core\Http;
use EasyWeChat\Js\Js;

class JsJsTest extends PHPUnit_Framework_TestCase
class JsJsTest extends TestCase
{
public function getMockCache()
{
Expand Down
2 changes: 1 addition & 1 deletion tests/Material/MaterialMaterialTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
use EasyWeChat\Message\Article;
use GuzzleHttp\Psr7\Response;

class MaterialMaterialTest extends PHPUnit_Framework_TestCase
class MaterialMaterialTest extends TestCase
{
/**
* Return mock http.
Expand Down
2 changes: 1 addition & 1 deletion tests/Material/MaterialTemporaryTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
use EasyWeChat\Material\Temporary;
use Mockery\Mock;

class MaterialTemporaryTest extends PHPUnit_Framework_TestCase
class MaterialTemporaryTest extends TestCase
{
/**
* Return mock http.
Expand Down
2 changes: 1 addition & 1 deletion tests/Menu/MenuMenuTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@

use EasyWeChat\Menu\Menu;

class MenuMenuTest extends PHPUnit_Framework_TestCase
class MenuMenuTest extends TestCase
{
public function getMenu()
{
Expand Down
2 changes: 1 addition & 1 deletion tests/Message/MessageAbstractMessageTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ class FooMessage extends AbstractMessage
protected $properties = ['foo', 'bar'];
}

class MessageAbstractMessageTest extends PHPUnit_Framework_TestCase
class MessageAbstractMessageTest extends TestCase
{
/**
* Test __get().
Expand Down
2 changes: 1 addition & 1 deletion tests/Message/MessageArticleTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@

use EasyWeChat\Message\Article;

class MessageArticleTest extends PHPUnit_Framework_TestCase
class MessageArticleTest extends TestCase
{
/**
* Test get attributes.
Expand Down
2 changes: 1 addition & 1 deletion tests/Message/MessageImageTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@

use EasyWeChat\Message\Image;

class MessageImageTest extends PHPUnit_Framework_TestCase
class MessageImageTest extends TestCase
{
/**
* Test media().
Expand Down
2 changes: 1 addition & 1 deletion tests/Message/MessageMaterialTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@

use EasyWeChat\Message\Material;

class MessageMaterialTest extends PHPUnit_Framework_TestCase
class MessageMaterialTest extends TestCase
{
/**
* Test get attributes.
Expand Down
2 changes: 1 addition & 1 deletion tests/Message/MessageVideoTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@

use EasyWeChat\Message\Video;

class MessageVideoTest extends PHPUnit_Framework_TestCase
class MessageVideoTest extends TestCase
{
/**
* Test media().
Expand Down
2 changes: 1 addition & 1 deletion tests/Message/MessageVoiceTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@

use EasyWeChat\Message\Voice;

class MessageVoiceTest extends PHPUnit_Framework_TestCase
class MessageVoiceTest extends TestCase
{
/**
* Test media().
Expand Down
2 changes: 1 addition & 1 deletion tests/Notice/NoticeNoticeTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
use EasyWeChat\Core\Exceptions\InvalidArgumentException;
use EasyWeChat\Notice\Notice;

class NoticeNoticeTest extends PHPUnit_Framework_TestCase
class NoticeNoticeTest extends TestCase
{
public function getNotice($mockHttp = false)
{
Expand Down
2 changes: 1 addition & 1 deletion tests/POI/POIPOITest.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@

use EasyWeChat\POI\POI;

class POIPOITest extends PHPUnit_Framework_TestCase
class POIPOITest extends TestCase
{
public function getPOI()
{
Expand Down
2 changes: 1 addition & 1 deletion tests/Payment/PaymentAPITest.php
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
use EasyWeChat\Support\XML;
use Psr\Http\Message\ResponseInterface;

class PaymentAPITest extends PHPUnit_Framework_TestCase
class PaymentAPITest extends TestCase
{
/**
* Build API instance.
Expand Down
2 changes: 1 addition & 1 deletion tests/Payment/PaymentLuckyMoneyAPITest.php
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
use EasyWeChat\Payment\Merchant;
use EasyWeChat\Support\XML;

class PaymentLuckyMoneyAPITest extends PHPUnit_Framework_TestCase
class PaymentLuckyMoneyAPITest extends TestCase
{
public static function setUpBeforeClass()
{
Expand Down
Loading