-
-
Notifications
You must be signed in to change notification settings - Fork 2.4k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* Can manage mp comment. * protected method. * rename method. * comment module.
- Loading branch information
Showing
4 changed files
with
367 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,203 @@ | ||
<?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. | ||
*/ | ||
|
||
/** | ||
* Comment.php. | ||
* | ||
* Part of Overtrue\WeChat. | ||
* | ||
* For the full copyright and license information, please view the LICENSE | ||
* file that was distributed with this source code. | ||
* | ||
* @author mingyoung <[email protected]> | ||
* @copyright 2017 | ||
* | ||
* @see https://github.com/overtrue | ||
* @see http://overtrue.me | ||
*/ | ||
|
||
namespace EasyWeChat\Comment; | ||
|
||
use EasyWeChat\Core\AbstractAPI; | ||
|
||
class Comment extends AbstractAPI | ||
{ | ||
const API_OPEN_COMMENT = 'https://api.weixin.qq.com/cgi-bin/comment/open'; | ||
const API_CLOSE_COMMENT = 'https://api.weixin.qq.com/cgi-bin/comment/close'; | ||
const API_LIST_COMMENT = 'https://api.weixin.qq.com/cgi-bin/comment/list'; | ||
const API_MARK_ELECT = 'https://api.weixin.qq.com/cgi-bin/comment/markelect'; | ||
const API_UNMARK_ELECT = 'https://api.weixin.qq.com/cgi-bin/comment/unmarkelect'; | ||
const API_DELETE_COMMENT = 'https://api.weixin.qq.com/cgi-bin/comment/delete'; | ||
const API_REPLY_COMMENT = 'https://api.weixin.qq.com/cgi-bin/comment/reply/add'; | ||
const API_DELETE_REPLY = 'https://api.weixin.qq.com/cgi-bin/comment/reply/delete'; | ||
|
||
/** | ||
* Open article comment. | ||
* | ||
* @param int $dataId | ||
* @param int $index | ||
* | ||
* @return \EasyWeChat\Support\Collection | ||
*/ | ||
public function open($dataId, $index = null) | ||
{ | ||
$params = [ | ||
'msg_data_id' => $dataId, | ||
'index' => $index, | ||
]; | ||
|
||
return $this->parseJSON('post', [self::API_OPEN_COMMENT, $params]); | ||
} | ||
|
||
/** | ||
* Close comment. | ||
* | ||
* @param int $dataId | ||
* @param int $index | ||
* | ||
* @return \EasyWeChat\Support\Collection | ||
*/ | ||
public function close($dataId, $index = null) | ||
{ | ||
$params = [ | ||
'msg_data_id' => $dataId, | ||
'index' => $index, | ||
]; | ||
|
||
return $this->parseJSON('post', [self::API_CLOSE_COMMENT, $params]); | ||
} | ||
|
||
/** | ||
* Get article comments. | ||
* | ||
* @param int $dataId | ||
* @param int $index | ||
* @param int $begin | ||
* @param int $count | ||
* @param int $type | ||
* | ||
* @return \EasyWeChat\Support\Collection | ||
*/ | ||
public function lists($dataId, $index, $begin, $count, $type = 0) | ||
{ | ||
$params = [ | ||
'msg_data_id' => $dataId, | ||
'index' => $index, | ||
'begin' => $begin, | ||
'count' => $count, | ||
'type' => $type, | ||
]; | ||
|
||
return $this->parseJSON('post', [self::API_LIST_COMMENT, $params]); | ||
} | ||
|
||
/** | ||
* Mark elect comment. | ||
* | ||
* @param int $dataId | ||
* @param int $index | ||
* @param int $commentId | ||
* | ||
* @return \EasyWeChat\Support\Collection | ||
*/ | ||
public function markElect($dataId, $index, $commentId) | ||
{ | ||
$params = [ | ||
'msg_data_id' => $dataId, | ||
'index' => $index, | ||
'user_comment_id' => $commentId, | ||
]; | ||
|
||
return $this->parseJSON('post', [self::API_MARK_ELECT, $params]); | ||
} | ||
|
||
/** | ||
* Unmark elect comment. | ||
* | ||
* @param int $dataId | ||
* @param int $index | ||
* @param int $commentId | ||
* | ||
* @return \EasyWeChat\Support\Collection | ||
*/ | ||
public function unmarkElect($dataId, $index, $commentId) | ||
{ | ||
$params = [ | ||
'msg_data_id' => $dataId, | ||
'index' => $index, | ||
'user_comment_id' => $commentId, | ||
]; | ||
|
||
return $this->parseJSON('post', [self::API_UNMARK_ELECT, $params]); | ||
} | ||
|
||
/** | ||
* Delete comment. | ||
* | ||
* @param int $dataId | ||
* @param int $index | ||
* @param int $commentId | ||
* | ||
* @return \EasyWeChat\Support\Collection | ||
*/ | ||
public function delete($dataId, $index, $commentId) | ||
{ | ||
$params = [ | ||
'msg_data_id' => $dataId, | ||
'index' => $index, | ||
'user_comment_id' => $commentId, | ||
]; | ||
|
||
return $this->parseJSON('post', [self::API_DELETE_COMMENT, $params]); | ||
} | ||
|
||
/** | ||
* Reply to a comment. | ||
* | ||
* @param int $dataId | ||
* @param int $index | ||
* @param int $commentId | ||
* @param string $content | ||
* | ||
* @return \EasyWeChat\Support\Collection | ||
*/ | ||
public function reply($dataId, $index, $commentId, $content) | ||
{ | ||
$params = [ | ||
'msg_data_id' => $dataId, | ||
'index' => $index, | ||
'user_comment_id' => $commentId, | ||
'content' => $content, | ||
]; | ||
|
||
return $this->parseJSON('post', [self::API_REPLY_COMMENT, $params]); | ||
} | ||
|
||
/** | ||
* Delete a reply. | ||
* | ||
* @param int $dataId | ||
* @param int $index | ||
* @param int $commentId | ||
* | ||
* @return \EasyWeChat\Support\Collection | ||
*/ | ||
public function deleteReply($dataId, $index, $commentId) | ||
{ | ||
$params = [ | ||
'msg_data_id' => $dataId, | ||
'index' => $index, | ||
'user_comment_id' => $commentId, | ||
]; | ||
|
||
return $this->parseJSON('post', [self::API_DELETE_REPLY, $params]); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
40 changes: 40 additions & 0 deletions
40
src/Foundation/ServiceProviders/CommentServiceProvider.php
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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. | ||
*/ | ||
|
||
/** | ||
* CommentServiceProvider.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\Comment\Comment; | ||
use Pimple\Container; | ||
use Pimple\ServiceProviderInterface; | ||
|
||
class CommentServiceProvider implements ServiceProviderInterface | ||
{ | ||
/** | ||
* {@inheritdoc}. | ||
*/ | ||
public function register(Container $pimple) | ||
{ | ||
$pimple['comment'] = function ($pimple) { | ||
return new Comment($pimple['access_token']); | ||
}; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,122 @@ | ||
<?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. | ||
*/ | ||
|
||
namespace EasyWeChat\Tests\Comment; | ||
|
||
use EasyWeChat\Tests\TestCase; | ||
|
||
class CommentTest extends TestCase | ||
{ | ||
public function testOpenComment() | ||
{ | ||
$result = $this->getComment()->open('xxx123', 0); | ||
|
||
$this->assertEquals('https://api.weixin.qq.com/cgi-bin/comment/open', $result['api']); | ||
$this->assertSame(['msg_data_id' => 'xxx123', 'index' => 0], $result['params']); | ||
} | ||
|
||
public function testCloseComment() | ||
{ | ||
$result = $this->getComment()->close('xxx123', 0); | ||
|
||
$this->assertEquals('https://api.weixin.qq.com/cgi-bin/comment/close', $result['api']); | ||
$this->assertSame(['msg_data_id' => 'xxx123', 'index' => 0], $result['params']); | ||
} | ||
|
||
public function testListComment() | ||
{ | ||
$result = $this->getComment()->lists('xxx123', 0, 10, 20, 0); | ||
|
||
$this->assertEquals('https://api.weixin.qq.com/cgi-bin/comment/list', $result['api']); | ||
$this->assertSame([ | ||
'msg_data_id' => 'xxx123', | ||
'index' => 0, | ||
'begin' => 10, | ||
'count' => 20, | ||
'type' => 0, | ||
], $result['params']); | ||
} | ||
|
||
public function testMarkElect() | ||
{ | ||
$result = $this->getComment()->markElect('xxx123', 0, 'comment-id'); | ||
|
||
$this->assertEquals('https://api.weixin.qq.com/cgi-bin/comment/markelect', $result['api']); | ||
$this->assertSame([ | ||
'msg_data_id' => 'xxx123', | ||
'index' => 0, | ||
'user_comment_id' => 'comment-id', | ||
], $result['params']); | ||
} | ||
|
||
public function testUnmarkElect() | ||
{ | ||
$result = $this->getComment()->unmarkElect('xxx123', 0, 'comment-id'); | ||
|
||
$this->assertEquals('https://api.weixin.qq.com/cgi-bin/comment/unmarkelect', $result['api']); | ||
$this->assertSame([ | ||
'msg_data_id' => 'xxx123', | ||
'index' => 0, | ||
'user_comment_id' => 'comment-id', | ||
], $result['params']); | ||
} | ||
|
||
public function testDeleteComment() | ||
{ | ||
$result = $this->getComment()->delete('xxx123', 0, 'comment-id'); | ||
|
||
$this->assertEquals('https://api.weixin.qq.com/cgi-bin/comment/delete', $result['api']); | ||
$this->assertSame([ | ||
'msg_data_id' => 'xxx123', | ||
'index' => 0, | ||
'user_comment_id' => 'comment-id', | ||
], $result['params']); | ||
} | ||
|
||
public function testAddReply() | ||
{ | ||
$result = $this->getComment()->reply('xxx123', 0, 'comment-id', 'content...'); | ||
|
||
$this->assertEquals('https://api.weixin.qq.com/cgi-bin/comment/reply/add', $result['api']); | ||
$this->assertSame([ | ||
'msg_data_id' => 'xxx123', | ||
'index' => 0, | ||
'user_comment_id' => 'comment-id', | ||
'content' => 'content...', | ||
], $result['params']); | ||
} | ||
|
||
public function testDeleteReply() | ||
{ | ||
$result = $this->getComment()->deleteReply('xxx123', 0, 'comment-id'); | ||
|
||
$this->assertEquals('https://api.weixin.qq.com/cgi-bin/comment/reply/delete', $result['api']); | ||
$this->assertSame([ | ||
'msg_data_id' => 'xxx123', | ||
'index' => 0, | ||
'user_comment_id' => 'comment-id', | ||
], $result['params']); | ||
} | ||
|
||
private function getComment() | ||
{ | ||
$press = \Mockery::mock('EasyWeChat\Comment\Comment[parseJSON]', [\Mockery::mock('EasyWeChat\Core\AccessToken')]); | ||
$press->shouldReceive('parseJSON')->andReturnUsing(function ($method, $params) { | ||
return [ | ||
'api' => $params[0], | ||
'params' => empty($params[1]) ? null : $params[1], | ||
'quires' => empty($params[3]) ? null : $params[3], | ||
]; | ||
}); | ||
|
||
return $press; | ||
} | ||
} |