forked from w7corp/easywechat
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge branch 'develop' into corp_server
* develop: Apply fixes from StyleCI (w7corp#706) Fix w7corp#601 (w7corp#705) Fix CS. add defaultColor Add docblocks. Fix (w7corp#702) Add api. (w7corp#700)
- Loading branch information
Showing
7 changed files
with
184 additions
and
2 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
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
43 changes: 43 additions & 0 deletions
43
src/Foundation/ServiceProviders/FundamentalServiceProvider.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,43 @@ | ||
<?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. | ||
*/ | ||
|
||
/** | ||
* FundamentalServiceProvider.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\Fundamental\API; | ||
use Pimple\Container; | ||
use Pimple\ServiceProviderInterface; | ||
|
||
/** | ||
* Class FundamentalServiceProvider. | ||
*/ | ||
class FundamentalServiceProvider implements ServiceProviderInterface | ||
{ | ||
/** | ||
* {@inheritdoc}. | ||
*/ | ||
public function register(Container $pimple) | ||
{ | ||
$pimple['fundamental.api'] = function ($pimple) { | ||
return new API($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,52 @@ | ||
<?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. | ||
*/ | ||
|
||
/** | ||
* Fundamental API. | ||
* | ||
* @author mingyoung <[email protected]> | ||
* @copyright 2017 | ||
* | ||
* @see https://github.com/overtrue | ||
* @see http://overtrue.me | ||
*/ | ||
|
||
namespace EasyWeChat\Fundamental; | ||
|
||
use EasyWeChat\Core\AbstractAPI; | ||
|
||
class API extends AbstractAPI | ||
{ | ||
const API_CLEAR_QUOTA = 'https://api.weixin.qq.com/cgi-bin/clear_quota'; | ||
const API_CALLBACK_IP = 'https://api.weixin.qq.com/cgi-bin/getcallbackip'; | ||
|
||
/** | ||
* Clear quota. | ||
* | ||
* @return \EasyWeChat\Support\Collection | ||
*/ | ||
public function clearQuota() | ||
{ | ||
$appid = $this->getAccessToken()->getAppId(); | ||
|
||
return $this->parseJSON('json', [self::API_CLEAR_QUOTA, compact('appid')]); | ||
} | ||
|
||
/** | ||
* Get wechat callback ip. | ||
* | ||
* @return \EasyWeChat\Support\Collection | ||
*/ | ||
public function getCallbackIp() | ||
{ | ||
return $this->parseJSON('get', [self::API_CALLBACK_IP]); | ||
} | ||
} |
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
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
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,54 @@ | ||
<?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\Fundamental\API; | ||
use EasyWeChat\Tests\TestCase; | ||
|
||
class FundamentalAPITest extends TestCase | ||
{ | ||
/** | ||
* Test clearQuota(). | ||
*/ | ||
public function testClearQuota() | ||
{ | ||
$result = $this->make()->clearQuota(); | ||
|
||
$this->assertEquals('https://api.weixin.qq.com/cgi-bin/clear_quota', $result['api']); | ||
$this->assertSame(['appid' => 'i-am-app-id'], $result['params']); | ||
} | ||
|
||
/** | ||
* Test getCallbackIp(). | ||
*/ | ||
public function testGetCallbackIp() | ||
{ | ||
$result = $this->make()->getCallbackIp(); | ||
|
||
$this->assertEquals('https://api.weixin.qq.com/cgi-bin/getcallbackip', $result['api']); | ||
} | ||
|
||
private function make() | ||
{ | ||
$accessToken = \Mockery::mock('EasyWeChat\Core\AccessToken', function ($mock) { | ||
$mock->shouldReceive('getAppId')->andReturn('i-am-app-id'); | ||
}); | ||
$api = \Mockery::mock('EasyWeChat\Fundamental\API[parseJSON]', [$accessToken]); | ||
$api->shouldReceive('parseJSON')->andReturnUsing(function ($api, $params) { | ||
if (isset($params[1])) { | ||
return ['api' => $params[0], 'params' => $params[1]]; | ||
} | ||
|
||
return ['api' => $params[0]]; | ||
}); | ||
|
||
return $api; | ||
} | ||
} |