Browse Source

查询用户是否关注公众号

master
zy_Java 3 years ago
parent
commit
803c095eda
  1. 6
      ptos_tall/src/main/java/com/ccsens/ptos_tall/api/UserController.java
  2. 15
      ptos_tall/src/main/java/com/ccsens/ptos_tall/api/WxUserController.java
  3. 7
      ptos_tall/src/main/java/com/ccsens/ptos_tall/bean/dto/UserDto.java
  4. 9
      ptos_tall/src/main/java/com/ccsens/ptos_tall/bean/vo/UserVo.java
  5. 2
      ptos_tall/src/main/java/com/ccsens/ptos_tall/service/IUserService.java
  6. 9
      ptos_tall/src/main/java/com/ccsens/ptos_tall/service/IWxUserService.java
  7. 11
      ptos_tall/src/main/java/com/ccsens/ptos_tall/service/UserService.java
  8. 15
      ptos_tall/src/main/java/com/ccsens/ptos_tall/service/WxUserService.java

6
ptos_tall/src/main/java/com/ccsens/ptos_tall/api/UserController.java

@ -76,10 +76,10 @@ public class UserController {
@ApiImplicitParams({
})
@RequestMapping(value = "refreshToken",method = RequestMethod.GET,produces = {"application/json;charset=UTF-8"})
public JsonResponse getTokenByRefreshToken(@RequestParam(required = true) String refreshToken) throws Exception {
public JsonResponse<UserVo.TokenBean> getTokenByRefreshToken(@RequestParam(required = true) String refreshToken) throws Exception {
log.info("根据refreshToken重新获取token:{}",refreshToken);
String token = userService.getTokenByRefreshToken(refreshToken);
return JsonResponse.newInstance().ok(null,token,refreshToken);
UserVo.TokenBean tokenBean = userService.getTokenByRefreshToken(refreshToken);
return JsonResponse.newInstance().ok(tokenBean,tokenBean.getToken(),tokenBean.getRefreshToken());
}

15
ptos_tall/src/main/java/com/ccsens/ptos_tall/api/WxUserController.java

@ -2,16 +2,21 @@ package com.ccsens.ptos_tall.api;
import cn.hutool.core.util.ObjectUtil;
import com.alibaba.fastjson.JSONObject;
import com.ccsens.cloudutil.annotation.MustLogin;
import com.ccsens.ptos_tall.bean.dto.UserDto;
import com.ccsens.ptos_tall.bean.vo.UserVo;
import com.ccsens.ptos_tall.service.IWxUserService;
import com.ccsens.util.JacksonUtil;
import com.ccsens.util.JsonResponse;
import com.ccsens.util.bean.dto.QueryDto;
import com.ccsens.wechatutil.bean.dto.wxmini.NoticeDto;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParams;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import lombok.extern.slf4j.Slf4j;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RestController;
@ -21,6 +26,7 @@ import javax.servlet.http.HttpServletRequest;
import java.io.BufferedReader;
import java.io.IOException;
import java.security.NoSuchAlgorithmException;
import java.util.List;
/**
* @author
@ -88,4 +94,13 @@ public class WxUserController {
return JsonResponse.newInstance().ok(tokenBean,tokenBean.getToken(),tokenBean.getRefreshToken());
}
@MustLogin
@ApiOperation(value = "根据公众号id判断用户是否关注该公众号", notes = "")
@RequestMapping(value = "/officialId", method = RequestMethod.POST, produces = {"application/json;charset=UTF-8"})
public JsonResponse<UserVo.UserOfficial> getByOfficialId(@ApiParam @Validated @RequestBody QueryDto<UserDto.Official> params) {
log.info("根据公众号id判断用户是否关注该公众号:{}",params);
UserVo.UserOfficial userOfficial = wxUserService.getByOfficialId(params.getUserId(),params.getParam());
return JsonResponse.newInstance().ok(userOfficial);
}
}

7
ptos_tall/src/main/java/com/ccsens/ptos_tall/bean/dto/UserDto.java

@ -68,4 +68,11 @@ public class UserDto {
this.clientType = clientType;
}
}
@Data
@ApiModel("公众号的设备id")
public static class Official{
@ApiModelProperty("设备id")
private Long id;
}
}

9
ptos_tall/src/main/java/com/ccsens/ptos_tall/bean/vo/UserVo.java

@ -92,4 +92,13 @@ public class UserVo {
private String eventKey;
}
@Data
@ApiModel("用户是否关注公众号")
public static class UserOfficial{
@ApiModelProperty("用户id")
private Long userId;
@ApiModelProperty("是否关注公众号 0未关注 1已关注")
private byte status;
}
}

2
ptos_tall/src/main/java/com/ccsens/ptos_tall/service/IUserService.java

@ -57,7 +57,7 @@ public interface IUserService {
* @param refreshToken 刷新token
* @return 返回重新生成的token
*/
String getTokenByRefreshToken(String refreshToken);
UserVo.TokenBean getTokenByRefreshToken(String refreshToken);
/**
* 通过手机号获取userId

9
ptos_tall/src/main/java/com/ccsens/ptos_tall/service/IWxUserService.java

@ -1,5 +1,6 @@
package com.ccsens.ptos_tall.service;
import com.ccsens.ptos_tall.bean.dto.UserDto;
import com.ccsens.ptos_tall.bean.vo.UserVo;
import com.ccsens.wechatutil.bean.dto.wxmini.NoticeDto;
@ -29,5 +30,11 @@ public interface IWxUserService {
*/
UserVo.TokenBean getUserByEventKey(String eventKey);
/**
* 根据公众号id查找用户是否关注公众号
* @param userId userId
* @param param 公众号id
* @return 返回用户id和是否关注
*/
UserVo.UserOfficial getByOfficialId(Long userId, UserDto.Official param);
}

11
ptos_tall/src/main/java/com/ccsens/ptos_tall/service/UserService.java

@ -491,7 +491,7 @@ public class UserService implements IUserService {
}
@Override
public String getTokenByRefreshToken(String refreshToken) {
public UserVo.TokenBean getTokenByRefreshToken(String refreshToken) {
Claims claims;
try {
claims = JwtUtil.parseJWT(refreshToken, WebConstant.JWT_ACCESS_TOKEN_SECERT);
@ -520,7 +520,14 @@ public class UserService implements IUserService {
//生成token并缓存
String token = JwtUtil.createJWT(subject + "",payLoads, tokenExpired,WebConstant.JWT_ACCESS_TOKEN_SECERT);
redisUtil.set(RedisKeyManager.getTokenCachedKey(subject), token, tokenExpired / 1000);
return token;
UserVo.TokenBean tokenBean = new UserVo.TokenBean();
tokenBean.setToken(token);
tokenBean.setRefreshToken(refreshToken);
tokenBean.setId(sysUser.getId());
tokenBean.setAvatarUrl(sysUser.getAvatarUrl());
tokenBean.setPhone(sysAuthDao.getPhoneByUserId(sysUser.getId()));
return tokenBean;
}
@Override

15
ptos_tall/src/main/java/com/ccsens/ptos_tall/service/WxUserService.java

@ -4,6 +4,7 @@ import cn.hutool.core.collection.CollectionUtil;
import cn.hutool.core.lang.Snowflake;
import cn.hutool.core.util.ObjectUtil;
import cn.hutool.core.util.StrUtil;
import com.ccsens.ptos_tall.bean.dto.UserDto;
import com.ccsens.ptos_tall.bean.po.*;
import com.ccsens.ptos_tall.bean.vo.UserVo;
import com.ccsens.ptos_tall.persist.dao.SysAuthDao;
@ -159,6 +160,20 @@ public class WxUserService implements IWxUserService {
return tokenBean;
}
@Override
public UserVo.UserOfficial getByOfficialId(Long userId, UserDto.Official param) {
UserVo.UserOfficial userOfficial = new UserVo.UserOfficial();
//根据用户id和公众号id查询关联信息
WxOfficialUserExample wxOfficialUserExample = new WxOfficialUserExample();
wxOfficialUserExample.createCriteria().andUserIdEqualTo(userId).andOfficialIdEqualTo(param.getId());
List<WxOfficialUser> wxOfficialUsers = wxOfficialUserMapper.selectByExample(wxOfficialUserExample);
if(CollectionUtil.isNotEmpty(wxOfficialUsers)){
userOfficial.setUserId(wxOfficialUsers.get(0).getUserId());
userOfficial.setStatus(wxOfficialUsers.get(0).getRecStatus());
}
return userOfficial;
}
private void saveOfficialsUser(NoticeDto.Notice notice, UserVo.UserSign userSign) {
//查找公众号
WxOfficialExample wxOfficialExample = new WxOfficialExample();

Loading…
Cancel
Save