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

关于API_TOKEN_REFRESH #20

Closed
zsj1029 opened this issue May 16, 2015 · 4 comments
Closed

关于API_TOKEN_REFRESH #20

zsj1029 opened this issue May 16, 2015 · 4 comments
Milestone

Comments

@zsj1029
Copy link

zsj1029 commented May 16, 2015

通过refresh_token重新获取用户access_token,auth.php没做实现吗?

有一种业务场景:
1、用户一个月前网页授权过了,我这也存了用户的性别、昵称等等
2、用户最近更改了微信昵称,他发现我的网站个人信息页面昵称还是以前的
这种情况我想重新获取用户信息,按照auth逻辑,是不是要重新让用户跳转授权页面确认
而不是通过refresh_token重新获取用户access_token,然后自动获取最新的用户信息

@overtrue
Copy link
Collaborator

@zsj1029 这块确实没实现,现在有这么一个问题:

一个 openid 对应一组:access_token + refresh_token,所以如果缓存的话,这套逻辑没想到怎么一个比较优雅的实现。

目前有这么一个想法不知道你们觉得怎么样?

  1. 用户没有授权过(在你的数据库里没有这个openid或者没有他的access_token)
$user = $auth->authorize();

此时你把user信息写入到你的数组库中,同时获取 $auth->access_token$auth->refresh_token 也写入到他的数据库记录中。

下次进来的时候,因为已经授权过嘛,你可以从数据库取出 access_token:

$res = $auth->refresh($refreshToken); // $refreshToken 为该用户的$refreshToken
$user = $auth->getUser($openId, $res['access_token']); // 使用刷新后的access_token得到用户信息

$res 包含以下信息:

{
   "access_token":"ACCESS_TOKEN",
   "expires_in":7200,
   "refresh_token":"REFRESH_TOKEN",
   "openid":"OPENID",
   "scope":"SCOPE",
   "unionid": "o6_bmasdasdsad6_2sgVt7hMZOPfL"
}

刷新后把 $res->access_token$res->refresh_token 存起来用于下次刷新用

不知道上面的这样是否能接受?如果OK的话我就提交代码。

@zsj1029
Copy link
Author

zsj1029 commented May 17, 2015

我记得微信有个 检验授权凭证(access_token)是否有效
如果有效期,就继续使用,过期了refresh_token重新请求access_token

@zsj1029
Copy link
Author

zsj1029 commented May 17, 2015

我建议,你把基础方法都写好,逻辑让开发自己处理
感觉你把业务也写进去了,开发再处理就比较麻烦了

overtrue added a commit that referenced this issue May 17, 2015
@overtrue
Copy link
Collaborator

@zsj1029 已经提交到master分支,你可以修改你的 composer.json 更新一个 master 下来看看:

composer require "overtrue/wechat:dev-master" 

然后参考文档:网页授权

试用一下,如果没问题我就发版

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

No branches or pull requests

2 participants