Skip to content

Commit

Permalink
Add reply. #108
Browse files Browse the repository at this point in the history
  • Loading branch information
overtrue committed Feb 17, 2016
1 parent 738b877 commit dc0d396
Show file tree
Hide file tree
Showing 10 changed files with 189 additions and 3 deletions.
1 change: 1 addition & 0 deletions build/easywechat-delete-branch.sh
Original file line number Diff line number Diff line change
Expand Up @@ -43,5 +43,6 @@ delete_branch support
delete_branch url
delete_branch user
delete_branch broadcast
delete_branch reply

rm -rf ./.tmp
3 changes: 2 additions & 1 deletion build/easywechat-split.sh
Original file line number Diff line number Diff line change
Expand Up @@ -53,4 +53,5 @@ split poi src/POI:[email protected]:easywechat/poi.git $TAGS
split support src/Support:[email protected]:easywechat/support.git $TAGS
split url src/Url:[email protected]:easywechat/url.git $TAGS
split user src/User:[email protected]:easywechat/user.git $TAGS
split broadcast src/User:[email protected]:easywechat/broadcast.git $TAGS
split broadcast src/User:[email protected]:easywechat/broadcast.git $TAGS
split reply src/User:[email protected]:easywechat/reply.git $TAGS
1 change: 1 addition & 0 deletions src/Foundation/Application.php
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,7 @@ class Application extends Container
ServiceProviders\StatsServiceProvider::class,
ServiceProviders\PaymentServiceProvider::class,
ServiceProviders\POIServiceProvider::class,
ServiceProviders\ReplyServiceProvider::class,
ServiceProviders\BroadcastServiceProvider::class,
];

Expand Down
47 changes: 47 additions & 0 deletions src/Foundation/ServiceProviders/ReplyServiceProvider.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
<?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.
*/

/**
* ReplyServiceProvider.php.
*
* This file is part of the 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.
*/
namespace EasyWeChat\Foundation\ServiceProviders;

use EasyWeChat\Reply\Reply;
use Pimple\Container;
use Pimple\ServiceProviderInterface;

/**
* Class ReplyServiceProvider.
*/
class ReplyServiceProvider implements ServiceProviderInterface
{
/**
* Registers services on the given container.
*
* This method should only be used to configure services and parameters.
* It should not get services.
*
* @param Container $pimple A container instance
*/
public function register(Container $pimple)
{
$pimple['reply'] = function ($pimple) {
return new Reply($pimple['access_token']);
};
}
}
6 changes: 4 additions & 2 deletions src/Menu/Menu.php
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ class Menu extends AbstractAPI
/**
* Get all menus.
*
* @return array
* @return \EasyWeChat\Support\Collection
*/
public function all()
{
Expand All @@ -48,7 +48,7 @@ public function all()
/**
* Get current menus.
*
* @return array
* @return \EasyWeChat\Support\Collection
*/
public function current()
{
Expand All @@ -60,6 +60,8 @@ public function current()
*
* @param array $buttons
* @param array $matchRule
*
* @return bool
*/
public function add(array $buttons, array $matchRule = [])
{
Expand Down
22 changes: 22 additions & 0 deletions src/Reply/LICENSE
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
The MIT License (MIT)

Copyright (c) 2015 Easy WeChat

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.

2 changes: 2 additions & 0 deletions src/Reply/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
# Reply
微信 SDK 自动回复模块
45 changes: 45 additions & 0 deletions src/Reply/Reply.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
<?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.
*/

/**
* Reply.php.
*
* @author overtrue <[email protected]>
* @copyright 2015 overtrue <[email protected]>
*
* @link https://github.com/overtrue
* @link http://overtrue.me
*/
namespace EasyWeChat\Reply;

use Doctrine\Common\Cache\Cache;
use Doctrine\Common\Cache\FilesystemCache;
use EasyWeChat\Core\AbstractAPI;
use EasyWeChat\Support\Str;
use EasyWeChat\Support\Url as UrlHelper;

/**
* Class Reply.
*/
class Reply extends AbstractAPI
{
const API_GET_CURRENT_SETTING = 'https://api.weixin.qq.com/cgi-bin/get_current_autoreply_info';

/**
* Get current auto reply settings.
*
* @return \EasyWeChat\Support\Collection
*/
public function current()
{
return $this->parseJSON('get', [self::API_GET_CURRENT_SETTING]);
}
}
25 changes: 25 additions & 0 deletions src/Reply/composer.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
{
"name": "easywechat/reply",
"description": "reply module for EasyWeChat SDK.",
"keywords": ["wechat", "weixin", "SDK", "easywechat"],
"license": "MIT",
"authors": [
{
"name": "overtrue",
"email": "[email protected]"
}
],
"autoload": {
"psr-4": {
"EasyWeChat\\Reply\\": "."
}
},
"minimum-stability":"dev",
"require-dev": {
"phpunit/phpunit": "4.8.*",
"mockery/mockery": "^1.0@dev"
},
"require": {
"easywechat/core" : "dev-master"
}
}
40 changes: 40 additions & 0 deletions tests/Reply/ReplyReplyTest.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
<?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.
*/

use EasyWeChat\Reply\Reply;

class ReplyReplyTest extends PHPUnit_Framework_TestCase
{
public function getReply()
{
$reply = Mockery::mock('EasyWeChat\Reply\Reply[parseJSON]', [Mockery::mock('EasyWeChat\Core\AccessToken')]);
$reply->shouldReceive('parseJSON')->andReturnUsing(function ($method, $params) {
return [
'api' => $params[0],
'params' => empty($params[1]) ? null : $params[1],
];
});

return $reply;
}

/**
* Test current().
*/
public function testCurrent()
{
$reply = $this->getReply();

$response = $reply->current();
$this->assertStringStartsWith(Reply::API_GET_CURRENT_SETTING, $response['api']);
$this->assertEmpty($response['params']);
}
}

0 comments on commit dc0d396

Please sign in to comment.