Skip to content

Commit

Permalink
Merge branch 'develop' into corp_server
Browse files Browse the repository at this point in the history
* 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
never615 committed May 22, 2017
2 parents 820b407 + 3de206d commit a4dfa80
Show file tree
Hide file tree
Showing 7 changed files with 184 additions and 2 deletions.
2 changes: 1 addition & 1 deletion composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@
"ext-openssl": "*",
"pimple/pimple": "~3.0",
"monolog/monolog": "^1.22",
"overtrue/socialite": ">=1.0.24",
"overtrue/socialite": ">=1.0.25",
"doctrine/cache": "~1.6",
"guzzlehttp/guzzle": "~6.2.1",
"symfony/http-foundation": "~2.6|~2.7|~2.8|~3.0",
Expand Down
19 changes: 19 additions & 0 deletions src/Foundation/Application.php
Original file line number Diff line number Diff line change
Expand Up @@ -296,4 +296,23 @@ private function initializeLogger()

Log::setLogger($logger);
}

/**
* Magic call.
*
* @param string $method
* @param array $args
*
* @return mixed
*
* @throws \Exception
*/
public function __call($method, $args)
{
if (is_callable([$this['fundamental.api'], $method])) {
return call_user_func_array([$this['fundamental.api'], $method], $args);
}

throw new \Exception("Call to undefined method {$method}()");
}
}
43 changes: 43 additions & 0 deletions src/Foundation/ServiceProviders/FundamentalServiceProvider.php
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']);
};
}
}
52 changes: 52 additions & 0 deletions src/Fundamental/API.php
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]);
}
}
14 changes: 14 additions & 0 deletions src/OfficialAccount/TemplateMessage/TemplateMessage.php
Original file line number Diff line number Diff line change
Expand Up @@ -82,6 +82,20 @@ public function __construct(AccessToken $accessToken)
$this->messageBackup = $this->message;
}

/**
* Set default color.
*
* @param string $color example: #0f0f0f
*
* @return $this
*/
public function defaultColor($color)
{
$this->defaultColor = $color;

return $this;
}

/**
* Set industry.
*
Expand Down
2 changes: 1 addition & 1 deletion src/Support/Log.php
Original file line number Diff line number Diff line change
Expand Up @@ -113,7 +113,7 @@ private static function createDefaultLogger()
{
$log = new Logger('EasyWeChat');

if (defined('PHPUNIT_RUNNING')) {
if (defined('PHPUNIT_RUNNING') || php_sapi_name() === 'cli') {
$log->pushHandler(new NullHandler());
} else {
$log->pushHandler(new ErrorLogHandler());
Expand Down
54 changes: 54 additions & 0 deletions tests/Fundamental/FundamentalAPITest.php
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;
}
}

0 comments on commit a4dfa80

Please sign in to comment.