请问一般公众号开发如何做身份认证?

WBOY
Release: 2016-06-06 20:21:25
Original
1148 people have browsed it

公众号是可以通过oauth获取用户openid的,但是每次都请求吗?还是会采取session或者localstorage等方案?

回复内容:

公众号是可以通过oauth获取用户openid的,但是每次都请求吗?还是会采取session或者localstorage等方案?

第一次肯定是要做 oauth 的,获取到 openid 或者 unionid 保存到你的后台,然后返回给用户一个 sid(session id),一般这个 sid 由服务端置进客户端的 cookie 里,注意设置 cookie 在客户端的过期时间和 session 在服务端的过期时间一致。把 sid 存入 localStorage 当然也是可以的,但有点非主流不推荐。

授权获取后将openid存在你的session里,微信的session存储时间不是长久的,你需要在session里没有获取到openid时重新跳转到授权页面拉取用户信息,由于网页授权获取用户接口没有调用次数限制所有无须担心

https://github.com/thenbsp/wechat/blob/master/documentation/oauth.md

Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!