1.小程序端调用wx.login(),获取到微信返回的code临时凭证.
2.小程序端调用我方的后台接口,Java后端调用微信的api,需要appId,appSecret,js_code,grant_type:authorization_code
代码如下:private JSONObject getUserWXLoginInfo(String wxCode) {String requestUrl = "https://api.weixin.qq.com/sns/jscode2session";MapString,String requestUrlParam = new HashMapString,String();requestUrlParam.put("appid", GameConstants.AppID);//开发者设置中的appIdrequestUrlParam.put("secret", GameConstants.AppSecret);//开发者设置中的appSecretrequestUrlParam.put("js_code", wxCode);//小程序调用wx.login返回的coderequestUrlParam.put("grant_type", "authorization_code");//默认参数//发送post请求读取调用微信 https://api.weixin.qq.com/sns/jscode2session 接口获取openid用户唯一标识JSONObject jsonObject = JSON.parseObject(UrlUtil.sendPost(requestUrl, requestUrlParam));return jsonObject;}public String login(String wxCode) throws ParseException {//请求微信api获取用户的openid和sessionKeyJSONObject jsonObject = getUserWXLogi