-
-
Notifications
You must be signed in to change notification settings - Fork 2.4k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
开放平台大幅重构并且添加测试 #606
开放平台大幅重构并且添加测试 #606
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
NB,不过建议容器名称那里在同一类东西时使用 .
分割
}; | ||
|
||
// Authorization events handlers. | ||
$pimple['open_platform_handle_component_verify_ticket'] = function($pimple) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
其实可以考虑使用 .
:比如:open_platform.handles.component_verify_ticket
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
那就统一所有 open platform 的类都这样咯:
open_platform
open_platform.access_token
open_platform.handlers.component_verify_ticket
if (is_array($message)) { | ||
$message = new Collection($message); | ||
} | ||
$handler = $this->getDefaultHandler($message->get('InfoType')); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
这里的 InfoType 会不会是 MsgType? @tsunamilx
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
OpenPlatform 相关的消息类型是 InfoType
@tsunamilx 实例化 Application($config) 的时候是不是先要把 component_access_token 加到 $config 配置里?不然获取不了 $app->oauth->user() |
第三方平台的 OAuth 倒是没有考虑过,等我研究研究先。 |
@jeftom 构思:
方案一 方案二 $pimple['oauth'] = function ($pimple) {
$socialite = new Socialite(...);
if ( is open platform ) {
$socialite->drive(open platform auth);
} else {
$socialite->drive(wechat);
}
} 我个人认为方案二比较适合。@overtrue, @mingyoung 意下如何? |
同样觉得方案二比较适合。😜 |
重构的原因是因为不好用。。。
原来的只是封装了 API 的调用,缓存了
component_verify_ticket
,但对于授权和授权方的信息没有做任何处理,尤其是authorizer_access_token
和authorizer_refresh_token
的缓存。因为第三方平台须要使用
authorizer_access_token
来调用各 API,authorizer_access_token
又须要authorizer_refresh_token
来刷新,authorizer_refresh_token
又要通过授权才能获得,要进行授权又要先有component_verify_ticket
和component_access_token
... 说多了都是泪 ...此重构的主要目的就是想封装掉
authorizer_access_token
和authorizer_refresh_token
的获取和缓存。主要重构内容:
Container
来获取实例而不是直接new
,主要修改在OpenPlatformServiceProvider
和OpenPlatform\Guard
两个类上。easywechat.open_platform.*
。EventHandler
,分别处理授权成功,授权更新,授权取消和 verify ticket。AuthorizerToken
用来替换原AccessToken
来调用 API。中英文文档随后会另外提交。