Explorar el Código

完善微信授权接口返回数据

sunxiaobiao hace 1 año
padre
commit
100ecbfdf4

+ 8 - 0
userCenter_service/src/main/java/com/bjtdba/userCenter/service/impl/WechatLogOnServiceImpl.java

@@ -37,11 +37,19 @@ public class WechatLogOnServiceImpl implements WechatLogOnService {
37 37
         System.out.println("微信返回数据"+a);
38 38
         String openid =(String)JSONObject.parseObject(a).get("openid");
39 39
         String unionid =(String)JSONObject.parseObject(a).get("unionid");
40
+        String access_token =(String)JSONObject.parseObject(a).get("access_token");
41
+        String url2 = SystemConfig.WECHAT_USER_INFO_URL.replace("ACCESS_TOKEN", access_token).replace("OPENID", openid);
42
+        String b = HttpURLConnectionUtils.doGet(url2);
43
+        System.out.println("微信返回数据"+b);
44
+        String nickname =(String)JSONObject.parseObject(b).get("nickname");
45
+        String headimgurl =(String)JSONObject.parseObject(b).get("headimgurl");
40 46
         /**
41 47
          * 拿openid 查询数据库   判断用户是否绑定    绑定成功直接登录进入系统,绑定不成功返回标示 提示用户进行绑定
42 48
          */
43 49
 //        User user = userDao.selectUserByOpenid(openid);
44 50
         User user = userDao.selectUserByOpenid(unionid);
51
+        data.put("nickname",nickname);
52
+        data.put("headimgurl",headimgurl);
45 53
         data.put("openid",openid);
46 54
         data.put("unionid",unionid);
47 55
         if(user==null){

+ 2 - 0
userCenter_service/src/main/java/com/bjtdba/userCenter/system/SystemConfig.java

@@ -8,6 +8,8 @@ public class SystemConfig {
8 8
      */
9 9
      public static final String WECHAT_URL = "https://api.weixin.qq.com/sns/oauth2/access_token?appid=APPID&secret=SECRET&code=CODE&grant_type=authorization_code";
10 10
 
11
+     public static final String WECHAT_USER_INFO_URL = "https://api.weixin.qq.com/sns/userinfo?access_token=ACCESS_TOKEN&openid=OPENID&lang=zh_CN";
12
+
11 13
 //     public static final String WECHAT_APPID = "wxbf753066ac8686ba";
12 14
      public static final String WECHAT_APPID = "wxdb6da871310a1379";
13 15