Skip to content

Commit

Permalink
Merge pull request #288 from overtrue/develop
Browse files Browse the repository at this point in the history
Merge Develop
  • Loading branch information
overtrue committed Feb 17, 2016
2 parents 3bbe722 + c83c671 commit a1f8d53
Show file tree
Hide file tree
Showing 27 changed files with 609 additions and 33 deletions.
2 changes: 1 addition & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -4,5 +4,5 @@ sftp-config.json
composer.lock
/*.php
/.idea
/examples
/coverage
/.split
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
2 changes: 2 additions & 0 deletions phpunit.xml.dist
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,8 @@
<exclude>
<directory suffix="ServiceProvider.php">src/</directory>
<directory suffix="Exception.php">src/</directory>
<directory>src/Encryption</directory>
<directory>src/Support</directory>
</exclude>
</whitelist>
</filter>
Expand Down
24 changes: 15 additions & 9 deletions src/Core/AbstractAPI.php
Original file line number Diff line number Diff line change
Expand Up @@ -60,8 +60,6 @@ abstract class AbstractAPI
public function __construct(AccessToken $accessToken)
{
$this->setAccessToken($accessToken);

$this->registerHttpMiddleware();
}

/**
Expand All @@ -71,7 +69,15 @@ public function __construct(AccessToken $accessToken)
*/
public function getHttp()
{
return $this->http ?: $this->http = new Http();
if (is_null($this->http)) {
$this->http = new Http();
}

if (count($this->http->getMiddlewares()) === 0) {
$this->registerHttpMiddlewares();
}

return $this->http;
}

/**
Expand Down Expand Up @@ -134,22 +140,22 @@ public function parseJSON($method, array $args)
/**
* Set request access_token query.
*/
protected function registerHttpMiddleware()
protected function registerHttpMiddlewares()
{
// access token
$this->getHttp()->addMiddleware($this->accessTokenMiddleware());
$this->http->addMiddleware($this->accessTokenMiddleware());
// log
$this->getHttp()->addMiddleware($this->logMiddleware());
$this->http->addMiddleware($this->logMiddleware());
// retry
$this->getHttp()->addMiddleware($this->retryMiddleware());
$this->http->addMiddleware($this->retryMiddleware());
}

/**
* Attache access token to request query.
*
* @return \Closure
*/
public function accessTokenMiddleware()
protected function accessTokenMiddleware()
{
return function (callable $handler) {
return function (RequestInterface $request, array $options) use ($handler) {
Expand All @@ -172,7 +178,7 @@ public function accessTokenMiddleware()
*
* @return \Closure
*/
public function logMiddleware()
protected function logMiddleware()
{
return Middleware::tap(function (RequestInterface $request) {
Log::debug("Request: {$request->getMethod()} {$request->getUri()}");
Expand Down
2 changes: 1 addition & 1 deletion src/Core/AccessToken.php
Original file line number Diff line number Diff line change
Expand Up @@ -207,7 +207,7 @@ public function getTokenFromServer()
$token = $http->parseJSON($http->get(self::API_TOKEN_GET, $params));

if (empty($token['access_token'])) {
throw new HttpException('Request AccessToken fail.'.json_encode($token, JSON_UNESCAPED_UNICODE));
throw new HttpException('Request AccessToken fail. response: '.json_encode($token, JSON_UNESCAPED_UNICODE));
}

return $token;
Expand Down
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']);
};
}
}
10 changes: 6 additions & 4 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 All @@ -83,7 +85,7 @@ public function add(array $buttons, array $matchRule = [])
public function destroy($menuId = null)
{
if ($menuId !== null) {
return $this->parseJSON('post', [self::API_CONDITIONAL_DELETE, ['menuid' => $menuId]]);
return $this->parseJSON('json', [self::API_CONDITIONAL_DELETE, ['menuid' => $menuId]]);
}

return $this->parseJSON('get', [self::API_DELETE]);
Expand All @@ -98,6 +100,6 @@ public function destroy($menuId = null)
*/
public function test($userId)
{
return $this->parseJSON('post', [self::API_CONDITIONAL_TEST, ['user_id' => $userId]]);
return $this->parseJSON('json', [self::API_CONDITIONAL_TEST, ['user_id' => $userId]]);
}
}
11 changes: 0 additions & 11 deletions src/Message/AbstractMessage.php
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,6 @@
*/
namespace EasyWeChat\Message;

use EasyWeChat\Support\Arr;
use EasyWeChat\Support\Attribute;

/**
Expand Down Expand Up @@ -63,16 +62,6 @@ abstract class AbstractMessage extends Attribute
*/
protected $properties = [];

/**
* Constructor.
*
* @param array $attributes
*/
public function __construct(array $attributes = [])
{
parent::__construct(Arr::only($attributes, $this->properties));
}

/**
* Return type name message.
*
Expand Down
13 changes: 13 additions & 0 deletions src/Payment/API.php
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,7 @@ class API extends AbstractAPI
const API_DOWNLOAD_BILL = 'https://api.mch.weixin.qq.com/pay/downloadbill';
const API_REPORT = 'https://api.mch.weixin.qq.com/payitil/report';
const API_URL_SHORTEN = 'https://api.mch.weixin.qq.com/tools/shorturl';
const API_AUTH_CODE_TO_OPENID = 'https://api.mch.weixin.qq.com/tools/authcodetoopenid';

// order id types.
const TRANSCATION_ID = 'transcation_id';
Expand Down Expand Up @@ -324,6 +325,18 @@ public function report($api, $timeConsuming, $resultCode, $returnCode, array $ot
return $this->request(self::API_REPORT, $params);
}

/**
* Get openid by auth code.
*
* @param string $authCode
*
* @return \EasyWeChat\Support\Collection
*/
public function authCodeToOpenId($authCode)
{
return $this->request(self::API_AUTH_CODE_TO_OPENID, ['auth_code' => $authCode]);
}

/**
* Merchant setter.
*
Expand Down
9 changes: 7 additions & 2 deletions src/Payment/Payment.php
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
*/
namespace EasyWeChat\Payment;

use EasyWeChat\Core\AccessToken;
use EasyWeChat\Core\Exceptions\FaultException;
use EasyWeChat\Support\Url as UrlHelper;
use EasyWeChat\Support\XML;
Expand Down Expand Up @@ -140,13 +141,17 @@ public function configForPayment($prepayId, $json = true)
/**
* Generate js config for share user address.
*
* @param string $accessToken
* @param bool $json
* @param string|accessToken $accessToken
* @param bool $json
*
* @return string|array
*/
public function configForShareAddress($accessToken, $json = true)
{
if ($accessToken instanceof AccessToken) {
$accessToken = $accessToken->getToken();
}

$params = [
'appId' => $this->merchant->app_id,
'scope' => 'jsapi_address',
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 自动回复模块
41 changes: 41 additions & 0 deletions src/Reply/Reply.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
<?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 EasyWeChat\Core\AbstractAPI;

/**
* 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"
}
}
6 changes: 4 additions & 2 deletions src/Support/Attribute.php
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,9 @@ abstract class Attribute extends Collection
*/
public function __construct($attributes = [])
{
parent::__construct($attributes);
foreach ($attributes as $key => $value) {
$this->set($key, $value);
}
}

/**
Expand All @@ -68,7 +70,7 @@ public function __construct($attributes = [])
*/
public function setAttribute($attribute, $value)
{
$this->add($attribute, $value);
$this->set($attribute, $value);

return $this;
}
Expand Down
Loading

0 comments on commit a1f8d53

Please sign in to comment.