loemkie 1 mês atrás
pai
commit
7ddc15d929

+ 13 - 0
src/main/java/com/qmrb/system/controller/UserController.java

@@ -64,6 +64,12 @@ public class UserController extends CommonController {
         return process(() -> wxLoginVO);
     }
 
+    @GetMapping("/getUserPhoneNumber")
+    public CommonResult<String> getUserPhoneNumber(String code){
+        String mobile = userService.getUserPhoneNumber(toolWxConfigService.findConf(),code);
+        return process(() -> mobile);
+    }
+
     /**
      * 获取当前默认用户信息以及toen信息
      * @param userParam
@@ -86,6 +92,11 @@ public class UserController extends CommonController {
         return process(() -> userInfo);
     }
 
+    /**
+     * 获取本系统的accesstoken
+     * @param authInfo
+     * @return
+     */
     private String getToken(UserAuthInfo authInfo){
         List<SimpleGrantedAuthority> roleList = authInfo.getRoles()
                 .stream().map(role -> new SimpleGrantedAuthority("ROLE_" + role)).toList();
@@ -98,6 +109,8 @@ public class UserController extends CommonController {
         return jwtTokenManager.createToken(authenticationToken);
     }
 
+
+
     /**
      * 微信小程序登录
      * @param loginParam

+ 4 - 0
src/main/java/com/qmrb/system/service/UserService.java

@@ -29,4 +29,8 @@ public interface UserService extends IService<Order> {
     public UserInfo getMyInfo(UserParam userParam);
 
     public UserInfo wxMpLogin(LoginParam loginParam);
+
+    public String getWxAccessToken(ToolWxConfig wxConfig, String code);
+
+    public String getUserPhoneNumber(ToolWxConfig wxConfig, String code);
 }

+ 26 - 0
src/main/java/com/qmrb/system/service/impl/UserServiceImpl.java

@@ -58,6 +58,32 @@ public class UserServiceImpl extends ServiceImpl<OrderMapper, Order> implements
         return result;
     }
 
+    public String getWxAccessToken(ToolWxConfig wxConfig, String code){
+        //获取当前的openid
+        Map hashMap = new HashMap();
+        hashMap.put("appid", wxConfig.getAppId());
+        hashMap.put("secret", wxConfig.getAppSecret());
+        hashMap.put("js_code", code);
+        hashMap.put("grant_type", "client_credential");
+        String json = HttpUtil.get(WxApiType.WX_LOGIN_URL.getValue(), hashMap);
+        JSONObject jsonObject = JSONUtil.parseObj(json);
+        log.info("json:{}",jsonObject);
+        String access_token = jsonObject.getStr("access_token");
+        return access_token;
+    }
+
+    public String getUserPhoneNumber(ToolWxConfig wxConfig, String code){
+        String token =  getWxAccessToken(wxConfig, code);
+        //获取当前的openid
+        Map hashMap = new HashMap();
+        hashMap.put("access_token", token);
+        String json = HttpUtil.post(WxApiType.WX_LOGIN_URL.getValue(), hashMap);
+        JSONObject jsonObject = JSONUtil.parseObj(json);
+        log.info("json:{}",jsonObject);
+        String access_token = jsonObject.getStr("access_token");
+        return access_token;
+    }
+
     public UserInfo getMyInfo(UserParam userParam){
         UserInfo userInfo = new UserInfo();
         userInfo.setId("1");