We recommend the WeChat public platform test link here:
http://mp.weixin.qq.com/debug/cgi-bin/sandbox?t=sandbox/login
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
parameters
response.setContentType("text/html; charset=UTF-8"); PrintWriter out = response.getWriter(); out.print(html); out.flush(); out.close();
There will be problems
4. Use js-sdk to evoke WeChat payment service