![](/images/smiles/icon_arrow.gif)
We recommend the WeChat public platform test link here:
http://mp.weixin.qq.com/debug/cgi-bin/sandbox?t=sandbox/login
![](http://dl2.iteye.com/upload/attachment/0126/3997/fe081531-d30b-3fe1-852a-6089267083aa.png)
![](http://dl2.iteye.com/upload/attachment/0126/3999/4abf9282-dfae-362c-bb18-8716d015073a.png)
1. Get the code
in the frontend get method, or in the background
https:// open.weixin.qq.com/connect/oauth2/authorize?appid=wx87a416348df09713&redirect_uri=http%3A%2F%2F10.88.75.139%3A8082%2Fcheckout%2Fguest&response_type=code&scope=snsapi_base&state=1#wechat_redirect
Here redirect_uri must be urlencode
2. Get openId according to appid, secret, code and get it
in the foreground:
https://api.weixin.qq.com/sns/oauth2/access_token?appid=wx87********f09713&secret=85327124638****** **963b5a50c&code=031mBHO10Uya2C1wPzM104zIO10mBHOm&grant_type=authorization_code
or in the background:
WechatQueryCommand queryCommand = prepareWechatQueryCommand(variableMap); if(WechatQueryCommand.QUERY_METHOD_GET.equals(queryCommand.getQueryMethod())) { return URLConnectionUtil.getResponseBodyAsString(prepareWechatQueryCommand(variableMap).toQueryString()); } else { return WechatUtil.post(queryCommand.getQueryUri(), queryCommand.toQueryString()); }
Token is also included in the above return
![](http://dl2.iteye.com/upload/attachment/0126/4007/36220ddb-c8a5-3f7c-a91d-75346f68fe27.png)
parameters
response.setContentType("text/html; charset=UTF-8"); PrintWriter out = response.getWriter(); out.print(html); out.flush(); out.close();
There will be problems
![](http://dl2.iteye.com/upload/attachment/0126/3995/af99015e-5993-3eae-9a54-de4441914b67.png)
4. Use js-sdk to evoke WeChat payment service