public class GetOpenId
extends javax.servlet.http.HttpServlet
This servlet parses params from /wxpay.properties
and returns client's openid facing the appid
Here how it goes:
1. directly GET this url(which defined by your route file web.xml),
either an ajax call or redirect is ok, see instruction below.
2. due to Weixin's spec, client will be redirect to open.weixin.qq.com/blabla to obtain a code
3. we will translate the code into openid and output it
Response content-type in step #3 is alternative choice:
If it is a redirect request, a redir param is required in step #1,
we will append the openid as param and send a 302 response.
If it is a ajax request, nothing but directly GET this url is needed.
In such case, openid will be output as text/plain.
Since open.weixin.qq.com does not contains a cross-domain header, You must
A same client will reflect in different openids while it faces different WX service accounts.
So DO NOT use this servlet in a multi-instance environment,
due to this servlet use a static appid and secret read from the config file.
Retrieve current client's openid
GET /get-openid.api
Params
code :string , generated and passed by open.weixin.qq.com, need not manual handling.
redir :url , if you are doing an redirect and wish the openid returned as param k-v.
Response
if redir absent
Content-Type: text/plain; charset=utf-8
if redir provided
302 Found
Location: ${redir[@openid='$openid']}
,
序列化表格| 限定符和类型 | 字段和说明 |
|---|---|
protected static java.lang.String |
CODE |
protected java.util.Properties |
conf |
protected static java.lang.String |
KEY_APPID |
protected static java.lang.String |
KEY_OPENID |
protected static java.lang.String |
KEY_SECRET |
protected static java.lang.String |
REDIR |
| 构造器和说明 |
|---|
GetOpenId() |
| 限定符和类型 | 方法和说明 |
|---|---|
void |
doGet(javax.servlet.http.HttpServletRequest req,
javax.servlet.http.HttpServletResponse resp) |
void |
init() |
doDelete, doHead, doOptions, doPost, doPut, doTrace, getLastModified, service, serviceprotected static final java.lang.String KEY_APPID
protected static final java.lang.String KEY_SECRET
protected static final java.lang.String KEY_OPENID
protected static final java.lang.String CODE
protected static final java.lang.String REDIR
protected java.util.Properties conf
public void init()
init 在类中 javax.servlet.GenericServletpublic void doGet(javax.servlet.http.HttpServletRequest req,
javax.servlet.http.HttpServletResponse resp)
throws java.io.IOException,
javax.servlet.ServletException
doGet 在类中 javax.servlet.http.HttpServletjava.io.IOExceptionjavax.servlet.ServletException