Browse Source

用户微信授权关联此用户

tags/v1.0.0^2
chengwang 1 year ago
parent
commit
e13e3fba6f
4 changed files with 44 additions and 2 deletions
  1. +1
    -0
      tuoheng-service/tuoheng-miniprogram/src/main/java/com/tuoheng/miniprogram/controller/WxController.java
  2. +23
    -0
      tuoheng-service/tuoheng-miniprogram/src/main/java/com/tuoheng/miniprogram/enums/AuthorizeStatusEnum.java
  3. +1
    -1
      tuoheng-service/tuoheng-miniprogram/src/main/java/com/tuoheng/miniprogram/enums/UserAuthorizeEnum.java
  4. +19
    -1
      tuoheng-service/tuoheng-miniprogram/src/main/java/com/tuoheng/miniprogram/service/impl/WxServiceImpl.java

+ 1
- 0
tuoheng-service/tuoheng-miniprogram/src/main/java/com/tuoheng/miniprogram/controller/WxController.java View File

@@ -1,6 +1,7 @@
package com.tuoheng.miniprogram.controller;

import com.tuoheng.common.core.utils.JsonResult;
import com.tuoheng.miniprogram.dao.UserMapper;
import com.tuoheng.miniprogram.entity.wx.WxMessageRequest;
import com.tuoheng.miniprogram.service.IWxService;
import lombok.extern.slf4j.Slf4j;

+ 23
- 0
tuoheng-service/tuoheng-miniprogram/src/main/java/com/tuoheng/miniprogram/enums/AuthorizeStatusEnum.java View File

@@ -0,0 +1,23 @@
package com.tuoheng.miniprogram.enums;

import lombok.Getter;

/**
* 任务状态枚举
*/
public enum AuthorizeStatusEnum {
//1未授权 2授权
AUTHORIZE_DOWN(1,"未授权"),
AUTHORIZE_ON(2,"授权");

AuthorizeStatusEnum(int code, String description){
this.code = code;
this.description = description;
}

@Getter
private int code;

@Getter
private String description;
}

+ 1
- 1
tuoheng-service/tuoheng-miniprogram/src/main/java/com/tuoheng/miniprogram/enums/UserAuthorizeEnum.java View File

@@ -6,7 +6,7 @@ public enum UserAuthorizeEnum {
OPEN_ID_IS_NULL(10002, "openId为空");

/**
* 码
* 标识
*/
private Integer code;


+ 19
- 1
tuoheng-service/tuoheng-miniprogram/src/main/java/com/tuoheng/miniprogram/service/impl/WxServiceImpl.java View File

@@ -9,11 +9,15 @@ import com.tuoheng.common.core.utils.DateUtils;
import com.tuoheng.common.core.utils.JsonResult;
import com.tuoheng.common.core.utils.StringUtils;
import com.tuoheng.miniprogram.dao.UserAuthorizeMapper;
import com.tuoheng.miniprogram.dao.UserMapper;
import com.tuoheng.miniprogram.entity.User;
import com.tuoheng.miniprogram.entity.UserAuthorize;
import com.tuoheng.miniprogram.entity.dto.TemplateMinDto;
import com.tuoheng.miniprogram.entity.wx.WxMessageRequest;
import com.tuoheng.miniprogram.enums.AuthorizeStatusEnum;
import com.tuoheng.miniprogram.enums.MarkEnum;
import com.tuoheng.miniprogram.enums.UserAuthorizeEnum;
import com.tuoheng.miniprogram.enums.UserCodeEnum;
import com.tuoheng.miniprogram.param.WxSendMessageParam;
import com.tuoheng.miniprogram.service.IWxService;
import com.tuoheng.miniprogram.utils.CurrentUserUtil;
@@ -40,6 +44,9 @@ public class WxServiceImpl implements IWxService {
@Autowired
private UserAuthorizeMapper userAuthorizeMapper;

@Autowired
private UserMapper userMapper;

private static String accessToken;

private static long expiresTime;
@@ -79,7 +86,18 @@ public class WxServiceImpl implements IWxService {
return JsonResult.error("授权数据入库失败");
}
}

//关联登录用户,已经做过授权 修改授权标识
User user = CurrentUserUtil.getUserInfo();
if(ObjectUtil.isEmpty(user)){
return JsonResult.error(UserCodeEnum.USER_IS_NULL.getCode(),UserCodeEnum.USER_IS_NULL.getMsg());
}
user.setAuthorize(AuthorizeStatusEnum.AUTHORIZE_ON.getCode());
user.setUpdateTime(DateUtils.now());
user.setUpdateUser(userId);
int count = userMapper.updateById(user);
if(count <= 0){
return JsonResult.error("用户授权标识更新失败");
}
return JsonResult.success();
}


Loading…
Cancel
Save