Skip to content
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

开放平台 APP 微信登录 #604

Closed
xlkit456852 opened this issue Mar 3, 2017 · 10 comments
Closed

开放平台 APP 微信登录 #604

xlkit456852 opened this issue Mar 3, 2017 · 10 comments

Comments

@xlkit456852
Copy link

xlkit456852 commented Mar 3, 2017

我用的环境

PHP 版本:5.6
overtrue/wechat 版本:3.0

问题及现象

在做APP的微信授权登录(不是网页授权登录,是跳转微信APP去授权),在文档里看到“开放平台”的模块。但并不知道怎么使用?
现在APP通过授权登录获得了code,我这边后台如何用这个模块配合利用这个code去获取微信用户的信息?

@mingyoung
Copy link
Collaborator

暂时只支持开放平台的第三方平台,app微信登录还没支持 :)

@mingyoung mingyoung changed the title 开放平台模块的使用流程? [4.0] 开放平台 APP 微信登录 Mar 3, 2017
@xlkit456852
Copy link
Author

那就是说我现在应该由后台去处理这个code还是由APP去处理?

@mingyoung mingyoung reopened this Mar 3, 2017
@mingyoung
Copy link
Collaborator

应该和网页授权的原理差不多吧?服务端处理

@mingyoung mingyoung added this to the 4.0 milestone Mar 3, 2017
@xlkit456852
Copy link
Author

话说4.0什么时候会出呢^_^

@xlkit456852
Copy link
Author

因为APP微信授权登录后,获取用户信息的流程基本和微信网页授权登录后差不多,只是APPID和APPSECRET不同,有没有方法在当前版本能复用微信网页授权后的那套获取用户信息的逻辑呢?

@mingyoung
Copy link
Collaborator

貌似和普通的授权一样的。那么直接用这个包就好了:overtrue/socialite
(已安装 overtrue/wechat 的话就不用再安装了)

use Overtrue\Socialite\SocialiteManager;

$config = [
    'wechat' => [
        'client_id'     => 'your-app-id',
        'client_secret' => 'your-app-secret',
        'redirect'      => null,
    ],
];

$socialite = new SocialiteManager($config);

// 获取code后获取用户信息
$user = $socialite->driver('wechat')->user();

代码自行测试 :)

@mingyoung mingyoung removed the Feature label Apr 5, 2017
@mingyoung mingyoung removed this from the 4.0 milestone Apr 5, 2017
@mingyoung mingyoung changed the title [4.0] 开放平台 APP 微信登录 开放平台 APP 微信登录 Apr 5, 2017
@overtrue
Copy link
Collaborator

overtrue commented Apr 5, 2017

👍

@mingyoung
Copy link
Collaborator

么么哒

@fengerwoo
Copy link

@overtrue 最后成功了吗?code怎么传的

@zacksleo
Copy link
Contributor

use Overtrue\Socialite\SocialiteManager;
$appCode = 'app中获取到的code';
$config = [
    'wechat' => [
        'client_id'     => 'your-app-id',
        'client_secret' => 'your-app-secret',
        'redirect'      => null,
    ],
];
$socialite = new SocialiteManager($config);
$wechat = $socialite->driver('wechat');
$accessToken = $wechat->getAccessToken($appCode);
$user = $wechat->user($accessToken);

亲测可以

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

5 participants