he2802 4 лет назад
Родитель
Сommit
33c5f3de51

+ 0 - 6
zhongzheng-admin/src/main/java/com/zhongzheng/ZhongZhengApplication.java

@@ -22,10 +22,4 @@ public class ZhongZhengApplication
         SpringApplication.run(ZhongZhengApplication.class, args);
         System.out.println("(♥◠‿◠)ノ゙  中正启动成功   ლ(´ڡ`ლ)゙");
     }
-
-    @Bean
-    @LoadBalanced
-    RestTemplate restTemplate(){
-        return new RestTemplate();
-    }
 }

+ 0 - 5
zhongzheng-api/src/main/java/com/zhongzheng/ZhongZhengApiApplication.java

@@ -20,9 +20,4 @@ public class ZhongZhengApiApplication {
         System.out.println("(♥◠‿◠)ノ゙  中正API启动成功   ლ(´ڡ`ლ)゙");
     }
 
-    @Bean
-    @LoadBalanced
-    RestTemplate restTemplate(){
-        return new RestTemplate();
-    }
 }

+ 21 - 4
zhongzheng-api/src/main/java/com/zhongzheng/controller/wx/WxLoginController.java

@@ -33,6 +33,24 @@ public class WxLoginController
 
     @Autowired
     private WxTokenService wxTokenService;
+
+    /**
+     * 登录方法
+     *
+     * @param loginBody 登录信息
+     * @return 结果
+     */
+    @ApiOperation("登录")
+    @PostMapping("/testLogin")
+    public AjaxResult testLogin(@RequestBody WxLoginBody loginBody)
+    {
+        ClientLoginUser loginUser = wxLoginService.test_login();
+        Map<String,Object> map = new HashMap<>();
+        map.put(Constants.TOKEN, loginUser.getToken());
+        map.put("union_id", loginUser.getUser().getUnionId());
+        return AjaxResult.success(map);
+    }
+
     /**
      * 登录方法
      *
@@ -43,11 +61,10 @@ public class WxLoginController
     @PostMapping("/login")
     public AjaxResult login(@RequestBody WxLoginBody loginBody)
     {
-        String union = "cba";
-        String token = wxLoginService.login(loginBody);
+        ClientLoginUser loginUser = wxLoginService.login(loginBody);
         Map<String,Object> map = new HashMap<>();
-        map.put(Constants.TOKEN, token);
-        map.put("union_id", union);
+        map.put(Constants.TOKEN, loginUser.getToken());
+        map.put("union_id", loginUser.getUser().getUnionId());
         return AjaxResult.success(map);
     }
 

+ 0 - 11
zhongzheng-common/src/main/java/com/zhongzheng/common/core/bo/WxLoginResultBo.java

@@ -1,11 +0,0 @@
-package com.zhongzheng.common.core.bo;
-
-import lombok.Data;
-
-@Data
-public class WxLoginResultBo {
-    private String openid;
-    private String session_key;
-    private String errcode;
-    private String errmsg;
-}

+ 1 - 1
zhongzheng-framework/src/main/java/com/zhongzheng/framework/config/SecurityConfig.java

@@ -101,7 +101,7 @@ public class SecurityConfig extends WebSecurityConfigurerAdapter
                 // 过滤请求
                 .authorizeRequests()
                 // 对于登录login 验证码captchaImage 允许匿名访问
-                .antMatchers("/login", "/captchaImage").anonymous()
+                .antMatchers("/login", "/captchaImage", "/testLogin").anonymous()
                 .antMatchers("/aliyun/oss/policy", "/aliyun/oss/callback").anonymous()
                 .antMatchers(
                         HttpMethod.GET,

+ 12 - 8
zhongzheng-framework/src/main/java/com/zhongzheng/framework/web/service/WxLoginService.java

@@ -3,7 +3,6 @@ package com.zhongzheng.framework.web.service;
 
 import com.alibaba.fastjson.JSON;
 import com.alibaba.fastjson.JSONObject;
-import com.zhongzheng.common.core.bo.WxLoginResultBo;
 import com.zhongzheng.common.exception.CustomException;
 
 import com.zhongzheng.common.utils.*;
@@ -20,7 +19,6 @@ import org.apache.commons.codec.binary.Base64;
 import org.springframework.beans.factory.annotation.Autowired;
 import org.springframework.beans.factory.annotation.Value;
 import org.springframework.stereotype.Component;
-import org.springframework.web.client.RestTemplate;
 
 import javax.annotation.Resource;
 
@@ -45,23 +43,30 @@ public class WxLoginService
 
     private String wxAuthParam = "appid=%s&secret=%s&js_code=%s&grant_type=authorization_code";
 
-    @Autowired
-    private RestTemplate restTemplate;
-
     @Autowired
     private IUserService iUserService;
 
     @Autowired
     private UserMapper userMapper;
 
-    public String login(WxLoginBody loginBody) {
+    public ClientLoginUser test_login() {
+        String unionId = "oQ2yp56PgQ-PfwN4vxTZhR5eTpzk";
+        User user = iUserService.queryByUnionId(unionId);
+        ClientLoginUser loginUser = new ClientLoginUser();
+        loginUser.setUser(user);
+        wxTokenService.createToken(loginUser);
+        return loginUser;
+    }
+
+    public ClientLoginUser login(WxLoginBody loginBody) {
         User user = getWxUnionIdUser(loginBody);
         if(user==null){
             throw new CustomException("登录错误");
         }
         ClientLoginUser loginUser = new ClientLoginUser();
         loginUser.setUser(user);
-        return wxTokenService.createToken(loginUser);
+        wxTokenService.createToken(loginUser);
+        return loginUser;
     }
 
     public String refreshToken(String unionId) {
@@ -110,7 +115,6 @@ public class WxLoginService
         String session_key = String.valueOf(jsonObject.get("session_key"));
         String openId = String.valueOf(jsonObject.get("openid"));
         String unionId = String.valueOf(jsonObject.get("unionid"));
-    //    WxLoginResultBo wxLoginResult = restTemplate.getForObject(url, WxLoginResultBo.class);
         String phoneNumber = obtainWxPhone(loginBody.getIv(),loginBody.getEncryptedData(),session_key);
         User user = iUserService.queryByUnionId(unionId);
         if(user==null){