public class SnsapiUserinfo
extends javax.servlet.http.HttpServlet
网页授权获取用户基本信息↗
需要在微信客户端上执行
直至微信6.0为止都无法使用 Ajax 调用此方法, 该尿性是由微信客户端造成的.
GET /snsapi-userinfo.api 取得 openid, 头像等 参数 code :string , 从 open.weixin.qq.com 跳转时带入, 无需客户端处理. redir :url , 可选, 允许带参数, 在 QueryString 中附加 openid=:openid 重定向. 请勿用作用户身份验证. 响应 当未附带redir
参数时: application/json openid :string , 当前用户的openid=:openid. nickname :string , 当前用户的名字 headimgurl :url-http , 当前用户的头像的 URL etc. 当附带redir
参数时: 302 Found Location: :redir?openid=:openid
限定符和类型 | 字段和说明 |
---|---|
protected java.lang.String |
appid |
protected static java.lang.String |
CODE |
protected static java.lang.String |
KEY_APPID |
protected static java.lang.String |
KEY_SECRET |
protected static java.lang.String |
OPENID |
protected static java.lang.String |
REDIR |
protected java.lang.String |
secret |
构造器和说明 |
---|
SnsapiUserinfo() |
限定符和类型 | 方法和说明 |
---|---|
void |
doGet(javax.servlet.http.HttpServletRequest req,
javax.servlet.http.HttpServletResponse resp) |
java.lang.String |
getAppid(javax.servlet.http.HttpServletRequest req)
提供 appid 参数
servlet 从此方法取得必需参数 appid, 覆盖此方法可以自定义 appid 的来源.
|
java.lang.String |
getSecret(java.lang.String appid)
提供 secret 参数
servlet 从此方法取得必需参数 secret, 覆盖此方法可以自定义 secret 的来源.
|
void |
init(javax.servlet.ServletConfig config)
读取配置文件
覆盖此方法可以删除对配置文件的访问.
|
void |
response(SnsUserinfoResponse snsUserinfoResp,
javax.servlet.http.HttpServletRequest req,
javax.servlet.http.HttpServletResponse resp)
构造响应
覆盖此方法可以自行构造响应
默认实现如文档所述
|
void |
trigger(SnsUserinfoResponse resp,
javax.servlet.http.HttpServletRequest req)
在取得 openid 后, 发送响应前的回调.
|
doDelete, doHead, doOptions, doPost, doPut, doTrace, getLastModified, service, service
protected static final java.lang.String KEY_APPID
protected static final java.lang.String KEY_SECRET
protected static final java.lang.String CODE
protected static final java.lang.String REDIR
protected static final java.lang.String OPENID
protected java.lang.String appid
protected java.lang.String secret
public java.lang.String getAppid(javax.servlet.http.HttpServletRequest req)
public java.lang.String getSecret(java.lang.String appid)
public void trigger(SnsUserinfoResponse resp, javax.servlet.http.HttpServletRequest req)
public void response(SnsUserinfoResponse snsUserinfoResp, javax.servlet.http.HttpServletRequest req, javax.servlet.http.HttpServletResponse resp) throws java.io.IOException
java.io.IOException
public void init(javax.servlet.ServletConfig config)
init
在接口中 javax.servlet.Servlet
init
在类中 javax.servlet.GenericServlet
public void doGet(javax.servlet.http.HttpServletRequest req, javax.servlet.http.HttpServletResponse resp) throws java.io.IOException, javax.servlet.ServletException
doGet
在类中 javax.servlet.http.HttpServlet
java.io.IOException
javax.servlet.ServletException