-
-
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.
* 添加小程序支持 使用微信一致的命名 `mini_program`; 暂实现 session_key 和 access_token 的获取。 * fix styles
- Loading branch information
Showing
5 changed files
with
180 additions
and
1 deletion.
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
62 changes: 62 additions & 0 deletions
62
src/Foundation/ServiceProviders/MiniProgramServiceProvider.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,62 @@ | ||
<?php | ||
|
||
/* | ||
* This file is part of the overtrue/wechat. | ||
* | ||
* (c) overtrue <i@overtrue.me> | ||
* | ||
* This source file is subject to the MIT license that is bundled | ||
* with this source code in the file LICENSE. | ||
*/ | ||
|
||
/** | ||
* MiniProgramServiceProvider.php. | ||
* | ||
* This file is part of the wechat. | ||
* | ||
* (c) mingyoung <mingyoungcheung@gmail.com> | ||
* | ||
* 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\MiniProgram\AccessToken; | ||
use EasyWeChat\MiniProgram\MiniProgram; | ||
use Pimple\Container; | ||
use Pimple\ServiceProviderInterface; | ||
|
||
/** | ||
* Class MiniProgramServiceProvider. | ||
*/ | ||
class MiniProgramServiceProvider 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['mini_program_access_token'] = function ($pimple) { | ||
$config = $pimple['config']->get('mini_program'); | ||
|
||
return new AccessToken( | ||
$config['app_id'], | ||
$config['secret'], | ||
$pimple['cache'] | ||
); | ||
}; | ||
|
||
$pimple['mini_program'] = function ($pimple) { | ||
return new MiniProgram( | ||
$pimple['mini_program_access_token'], | ||
$pimple['config']->get('mini_program') | ||
); | ||
}; | ||
} | ||
} |
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,36 @@ | ||
<?php | ||
|
||
/* | ||
* This file is part of the overtrue/wechat. | ||
* | ||
* (c) overtrue <i@overtrue.me> | ||
* | ||
* This source file is subject to the MIT license that is bundled | ||
* with this source code in the file LICENSE. | ||
*/ | ||
|
||
/** | ||
* AccessToken.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 <mingyoungcheung@gmail.com> | ||
* @copyright 2016 | ||
* | ||
* @see https://github.com/overtrue | ||
* @see http://overtrue.me | ||
*/ | ||
|
||
namespace EasyWeChat\MiniProgram; | ||
|
||
use EasyWeChat\Core\AccessToken as CoreAccessToken; | ||
|
||
/** | ||
* Class AccessToken. | ||
*/ | ||
class AccessToken extends CoreAccessToken | ||
{ | ||
} |
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,79 @@ | ||
<?php | ||
|
||
/* | ||
* This file is part of the overtrue/wechat. | ||
* | ||
* (c) overtrue <i@overtrue.me> | ||
* | ||
* This source file is subject to the MIT license that is bundled | ||
* with this source code in the file LICENSE. | ||
*/ | ||
|
||
/** | ||
* MiniProgram.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 <mingyoungcheung@gmail.com> | ||
* @copyright 2016 | ||
* | ||
* @see https://github.com/overtrue | ||
* @see http://overtrue.me | ||
*/ | ||
|
||
namespace EasyWeChat\MiniProgram; | ||
|
||
use EasyWeChat\Core\AbstractAPI; | ||
|
||
/** | ||
* Class MiniProgram. | ||
*/ | ||
class MiniProgram extends AbstractAPI | ||
{ | ||
/** | ||
* Api. | ||
*/ | ||
const JSCODE_TO_SESSION = 'https://api.weixin.qq.com/sns/jscode2session'; | ||
|
||
/** | ||
* Mini program config. | ||
* | ||
* @var array | ||
*/ | ||
protected $config; | ||
|
||
/** | ||
* MiniProgram constructor. | ||
* | ||
* @param \EasyWeChat\MiniProgram\AccessToken $accessToken | ||
* @param array $config | ||
*/ | ||
public function __construct($accessToken, $config) | ||
{ | ||
parent::__construct($accessToken); | ||
|
||
$this->config = $config; | ||
} | ||
|
||
/** | ||
* JsCode 2 session key. | ||
* | ||
* @param string $jsCode | ||
* | ||
* @return \EasyWeChat\Support\Collection | ||
*/ | ||
public function getSessionKey($jsCode) | ||
{ | ||
$params = [ | ||
'appid' => $this->config['app_id'], | ||
'secret' => $this->config['secret'], | ||
'js_code' => $jsCode, | ||
'grant_type' => 'authorization_code', | ||
]; | ||
|
||
return $this->parseJSON('GET', [self::JSCODE_TO_SESSION, $params]); | ||
} | ||
} |