he2802 hace 2 años
padre
commit
b34d25b55e

+ 9 - 1
zhongzheng-api/src/main/java/com/zhongzheng/controller/wx/WxLoginController.java

@@ -86,7 +86,7 @@ public class WxLoginController
      * @param loginBody 登录信息
      * @return 结果
      */
-    @ApiOperation("小程序微信登录")
+    @ApiOperation("小程序通过手机授权微信登录")
     @PostMapping("/app/common/bindLogin")
     public AjaxResult bindLogin(@RequestBody WxLoginBody loginBody)
     {
@@ -94,6 +94,14 @@ public class WxLoginController
         return AjaxResult.success(map);
     }
 
+    @ApiOperation("小程序通过openid微信登录")
+    @PostMapping("/app/common/openIdLogin")
+    public AjaxResult openIdLogin(@RequestBody WxLoginBody loginBody)
+    {
+        Map<String,Object> map = wxLoginService.openIdLogin(loginBody);
+        return AjaxResult.success(map);
+    }
+
     @ApiOperation("获取用户小程序openid")
     @PostMapping("/wx/getOpenid")
     public AjaxResult<Void> getOpenid(@RequestBody WxLoginBody loginBody)

+ 32 - 0
zhongzheng-framework/src/main/java/com/zhongzheng/framework/web/service/WxLoginService.java

@@ -272,6 +272,38 @@ public class WxLoginService implements IWxLoginService {
         return map;
     }
 
+    @Transactional(rollbackFor = Exception.class)
+    public Map<String, Object> openIdLogin(WxLoginBody loginBody) {
+        if(Validator.isEmpty(loginBody.getOpenid())){
+            throw new CustomException("openid缺失");
+        }
+        User user = iUserService.getOne(new LambdaQueryWrapper<User>().eq(User::getOpenId, loginBody.getOpenid()).last("limit 1"));
+        if (ObjectUtils.isNull(user)&&Validator.isEmpty(loginBody.getUserId())) {
+            throw new CustomException("该openid暂无绑定!",666);
+        }
+        if (Validator.isNotEmpty(loginBody.getUserId())) {
+            user = iUserService.getOne(new LambdaQueryWrapper<User>().eq(User::getUserId, loginBody.getUserId()).last("limit 1"));
+            if(Validator.isNotEmpty(user.getOpenId())){
+                throw new CustomException("该用户已绑定过openid!",667);
+            }
+            user.setOpenId(loginBody.getOpenid());
+            iUserService.updateById(user);
+        }
+
+        //如果活动分销码变动
+        if (StringUtils.isNotBlank(loginBody.getShareActivityCode())){
+            user.setShareActivityCode(loginBody.getShareActivityCode());
+            iUserService.updateById(user);
+        }
+        ClientLoginUser loginUser = new ClientLoginUser();
+        loginUser.setUser(user);
+        Map<String, Object> map = new HashMap<>();
+        map.put(Constants.TOKEN, wxTokenService.createToken(loginUser));
+        map.put("user_account", loginUser.getUser().getUserAccount());
+        map.put("full_info", Validator.isEmpty(user.getIdCard()) ? false : true); //是否完善身份信息
+        return map;
+    }
+
 
     public Map<String, String> smallTel(WxLoginBody loginBody) {
         initData();

+ 3 - 0
zhongzheng-system/src/main/java/com/zhongzheng/modules/wx/bo/WxLoginBody.java

@@ -62,4 +62,7 @@ public class WxLoginBody {
 
     @ApiModelProperty("union_id")
     private String unionId;
+
+    @ApiModelProperty("小程序openid")
+    private String openid;
 }