Commit 64c48226 authored by muhong's avatar muhong

修改 登录接口和关注粉丝数量

parent 0d6e0272
...@@ -8,6 +8,7 @@ public class UserRequestDto implements Entity { ...@@ -8,6 +8,7 @@ public class UserRequestDto implements Entity {
private Long userId; private Long userId;
private String mobile; private String mobile;
private String code; private String code;
private String loginCode;
private String smsCode; private String smsCode;
private String avatarUrl; private String avatarUrl;
private Long shareUserId; private Long shareUserId;
...@@ -23,4 +24,5 @@ public class UserRequestDto implements Entity { ...@@ -23,4 +24,5 @@ public class UserRequestDto implements Entity {
private Integer type; private Integer type;
// 快捷登录方式(1、微信,2、支付宝,3、抖音) // 快捷登录方式(1、微信,2、支付宝,3、抖音)
private Integer loginType; private Integer loginType;
private String wxOpenId;
} }
package com.wwdz.ch.wx.impl; package com.wwdz.ch.wx.impl;
import com.wwdz.ch.core.type.Result;
import com.wwdz.ch.db.dao.*; import com.wwdz.ch.db.dao.*;
import com.wwdz.ch.db.domain.ItemsOfficialUsersRelation; import com.wwdz.ch.db.domain.ItemsOfficialUsersRelation;
import com.wwdz.ch.db.domain.User; import com.wwdz.ch.db.domain.User;
import com.wwdz.ch.db.domain.UserItemsRelation; import com.wwdz.ch.db.domain.UserItemsRelation;
import com.wwdz.ch.db.dto.request.FollowFansRecordRequestDto;
import com.wwdz.ch.wx.dao.UserInfo; import com.wwdz.ch.wx.dao.UserInfo;
import com.wwdz.ch.wx.entity.vo.ItemResponseVo; import com.wwdz.ch.wx.entity.vo.ItemResponseVo;
import com.wwdz.ch.wx.manager.UserTokenManager; import com.wwdz.ch.wx.manager.UserTokenManager;
import com.wwdz.ch.wx.service.FollowFansRecordService;
import com.wwdz.ch.wx.service.ItemCommonService; import com.wwdz.ch.wx.service.ItemCommonService;
import com.wwdz.ch.wx.util.StringUtil; import com.wwdz.ch.wx.util.StringUtil;
import org.apache.commons.collections.CollectionUtils; import org.apache.commons.collections.CollectionUtils;
...@@ -14,6 +17,7 @@ import org.springframework.beans.factory.annotation.Autowired; ...@@ -14,6 +17,7 @@ import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service; import org.springframework.stereotype.Service;
import java.util.List; import java.util.List;
import java.util.Map;
import java.util.Objects; import java.util.Objects;
import java.util.stream.Collectors; import java.util.stream.Collectors;
...@@ -34,6 +38,8 @@ public class ItemCommonServiceImpl implements ItemCommonService { ...@@ -34,6 +38,8 @@ public class ItemCommonServiceImpl implements ItemCommonService {
@Autowired @Autowired
private UserTokenManager userTokenManager; private UserTokenManager userTokenManager;
@Autowired
private FollowFansRecordService followFansRecordService;
@Override @Override
public void getNicknameAvatar(Long itemId, ItemResponseVo vo) { public void getNicknameAvatar(Long itemId, ItemResponseVo vo) {
...@@ -64,8 +70,16 @@ public class ItemCommonServiceImpl implements ItemCommonService { ...@@ -64,8 +70,16 @@ public class ItemCommonServiceImpl implements ItemCommonService {
long fansNumber = 0; long fansNumber = 0;
long collectionsNumber = 0; long collectionsNumber = 0;
long viewsNumber = 0; long viewsNumber = 0;
//TODO 关注和粉丝数量 // 关注和粉丝数量
FollowFansRecordRequestDto followFansRecordRequestDto = new FollowFansRecordRequestDto();
followFansRecordRequestDto.setSearchTargetId(userInfo.getUserId());
Result result = followFansRecordService.countFollowFans(followFansRecordRequestDto);
if (result.getSuccess()) {
Map<String, Object> map = (Map<String, Object>) result.getData();
followersNumber = (long) map.get("followerNum");
fansNumber = (long) map.get("fansNum");
}
// 收藏和浏览量
List<UserItemsRelation> userItemsRelations = userItemsRelationDao.listByUserIds(userInfo.getUserId(), null); List<UserItemsRelation> userItemsRelations = userItemsRelationDao.listByUserIds(userInfo.getUserId(), null);
if (CollectionUtils.isNotEmpty(userItemsRelations)) { if (CollectionUtils.isNotEmpty(userItemsRelations)) {
List<Long> itemIds = userItemsRelations.stream() List<Long> itemIds = userItemsRelations.stream()
......
...@@ -134,7 +134,7 @@ public class UserServiceImpl implements UserService { ...@@ -134,7 +134,7 @@ public class UserServiceImpl implements UserService {
return Result.failed("验证码不正确"); return Result.failed("验证码不正确");
} }
// 获取登录结果 // 获取登录结果
Map<String, Object> result = getLoginResult(dto.getMobile(), request); Map<String, Object> result = getLoginResult(dto, request);
Switch switchh = switchService.findOnly(); Switch switchh = switchService.findOnly();
boolean isOpen = Objects.nonNull(switchh) && switchh.getState() == 1; boolean isOpen = Objects.nonNull(switchh) && switchh.getState() == 1;
result.put("isInvited", inviteRecordService.isExisted(dto.getMobile()).getData()); result.put("isInvited", inviteRecordService.isExisted(dto.getMobile()).getData());
...@@ -172,6 +172,7 @@ public class UserServiceImpl implements UserService { ...@@ -172,6 +172,7 @@ public class UserServiceImpl implements UserService {
if (StringUtils.equals("decryptFalse", mobile)) { if (StringUtils.equals("decryptFalse", mobile)) {
return Result.failed(ResultCode.FAILED.getCode(), "用户信息解密失败"); return Result.failed(ResultCode.FAILED.getCode(), "用户信息解密失败");
} }
dto.setWxOpenId(wxLoginManager.getWxOpenId(dto.getLoginCode()));
} }
if (dto.getLoginType().equals(LoginTypeEnum.ALIPAY.getCode())) { if (dto.getLoginType().equals(LoginTypeEnum.ALIPAY.getCode())) {
mobile = alipayLoginManager.getPhone(dto.getEncryptedData()); mobile = alipayLoginManager.getPhone(dto.getEncryptedData());
...@@ -180,7 +181,7 @@ public class UserServiceImpl implements UserService { ...@@ -180,7 +181,7 @@ public class UserServiceImpl implements UserService {
} }
} }
if (dto.getLoginType().equals(LoginTypeEnum.TIKTOK.getCode())) { if (dto.getLoginType().equals(LoginTypeEnum.TIKTOK.getCode())) {
String sessionKey = tikTokLoginManager.getSessionKey(dto.getCode()); String sessionKey = tikTokLoginManager.getSessionKey(dto.getLoginCode());
if (StringUtils.isBlank(sessionKey)) { if (StringUtils.isBlank(sessionKey)) {
return Result.failed("获取sessionKey失败"); return Result.failed("获取sessionKey失败");
} }
...@@ -194,7 +195,7 @@ public class UserServiceImpl implements UserService { ...@@ -194,7 +195,7 @@ public class UserServiceImpl implements UserService {
return Result.failed("获取用户手机号失败"); return Result.failed("获取用户手机号失败");
} }
// 获取登录结果 // 获取登录结果
Map<String, Object> result = getLoginResult(mobile, request); Map<String, Object> result = getLoginResult(dto, request);
Switch switchh = switchService.findOnly(); Switch switchh = switchService.findOnly();
boolean isOpen = Objects.nonNull(switchh) && switchh.getState() == 1; boolean isOpen = Objects.nonNull(switchh) && switchh.getState() == 1;
result.put("isInvited", inviteRecordService.isExisted(mobile).getData()); result.put("isInvited", inviteRecordService.isExisted(mobile).getData());
...@@ -434,15 +435,15 @@ public class UserServiceImpl implements UserService { ...@@ -434,15 +435,15 @@ public class UserServiceImpl implements UserService {
/** /**
* 获取登录结果 * 获取登录结果
* *
* @param mobile * @param dto
* @param request * @param request
* @return * @return
*/ */
private Map<String, Object> getLoginResult(String mobile, HttpServletRequest request) { private Map<String, Object> getLoginResult(UserRequestDto dto, HttpServletRequest request) {
Map<String, Object> result = new HashMap<>(); Map<String, Object> result = new HashMap<>();
Date now = new Date(); Date now = new Date();
User user = userDao.queryByMobile(mobile); User user = userDao.queryByMobile(dto.getMobile());
if (Objects.isNull(user)) { if (Objects.isNull(user)) {
user = new User(); user = new User();
user.setUsername(UUID.randomUUID().toString().replace("-", "")); user.setUsername(UUID.randomUUID().toString().replace("-", ""));
...@@ -452,8 +453,11 @@ public class UserServiceImpl implements UserService { ...@@ -452,8 +453,11 @@ public class UserServiceImpl implements UserService {
user.setProfile(""); user.setProfile("");
user.setBackground(""); user.setBackground("");
user.setWechatId(""); user.setWechatId("");
user.setMobile(mobile); user.setMobile(dto.getMobile());
user.setAvatar(avatarUrl); user.setAvatar(avatarUrl);
if (StringUtils.isNotBlank(dto.getWxOpenId())) {
user.setWeixinOpenid(dto.getWxOpenId());
}
while (true) { while (true) {
String nickname = "收藏家" + StringUtil.generateRandomString(10); String nickname = "收藏家" + StringUtil.generateRandomString(10);
if (!userDao.isExistedByNickname(0L, nickname)) { if (!userDao.isExistedByNickname(0L, nickname)) {
...@@ -472,6 +476,9 @@ public class UserServiceImpl implements UserService { ...@@ -472,6 +476,9 @@ public class UserServiceImpl implements UserService {
user.setShareUserId(0L); user.setShareUserId(0L);
userDao.insert(user); userDao.insert(user);
} else { } else {
if (StringUtils.isNotBlank(dto.getWxOpenId())) {
user.setWeixinOpenid(dto.getWxOpenId());
}
user.setLastLoginTime(new Date()); user.setLastLoginTime(new Date());
user.setLastLoginIp(IpUtil.client(request)); user.setLastLoginIp(IpUtil.client(request));
if (userDao.updateById(user) == 0) { if (userDao.updateById(user) == 0) {
......
...@@ -50,10 +50,10 @@ public class TikTokLoginManager { ...@@ -50,10 +50,10 @@ public class TikTokLoginManager {
/** /**
* 获取用户登录后的session_key * 获取用户登录后的session_key
* *
* @param code * @param loginCode
* @return * @return
*/ */
public String getSessionKey(String code) { public String getSessionKey(String loginCode) {
try { try {
logger.info("开始获取抖音小程序的session_key"); logger.info("开始获取抖音小程序的session_key");
String activeProfile = applicationContext.getEnvironment().getActiveProfiles()[0]; String activeProfile = applicationContext.getEnvironment().getActiveProfiles()[0];
...@@ -64,7 +64,7 @@ public class TikTokLoginManager { ...@@ -64,7 +64,7 @@ public class TikTokLoginManager {
Map<String, Object> param = new HashMap<>(); Map<String, Object> param = new HashMap<>();
param.put("appid", appid); param.put("appid", appid);
param.put("secret", appSecret); param.put("secret", appSecret);
param.put("code", code); param.put("code", loginCode);
String result = OkHttpUtil.builder().url(url) String result = OkHttpUtil.builder().url(url)
.addParams(param) .addParams(param)
.post(true).sync(); .post(true).sync();
......
...@@ -26,8 +26,10 @@ public class WxLoginManager { ...@@ -26,8 +26,10 @@ public class WxLoginManager {
// 微信小程序appid // 微信小程序appid
private static final String appid = "wx5b4409448bf2c72b"; private static final String appid = "wx5b4409448bf2c72b";
// private static final String appid = "wxb2bc9d1be2d6345c";
// 微信小程序secret // 微信小程序secret
private static final String secret = "6fee0d7b2197845fed0a3fe8f5a9bd66"; private static final String secret = "6fee0d7b2197845fed0a3fe8f5a9bd66";
// private static final String secret = "fade0a145eea51cfc89a9e8808f28f04";
// 微信小程序获取access_token地址 // 微信小程序获取access_token地址
private static final String GET_ACCESS_TOKEN_URL = "https://api.weixin.qq.com/cgi-bin/token?grant_type=client_credential&appid=%s&secret=%s"; private static final String GET_ACCESS_TOKEN_URL = "https://api.weixin.qq.com/cgi-bin/token?grant_type=client_credential&appid=%s&secret=%s";
// 微信小程序获取用户手机号地址 // 微信小程序获取用户手机号地址
...@@ -40,6 +42,18 @@ public class WxLoginManager { ...@@ -40,6 +42,18 @@ public class WxLoginManager {
@Autowired @Autowired
private WxMaService wxMaService; private WxMaService wxMaService;
public String getWxOpenId(String loginCode) {
logger.info("开始获取openId-----------------------");
String openId = "";
try {
WxMaJscode2SessionResult result = this.wxMaService.getUserService().getSessionInfo(loginCode);
openId = result.getOpenid();
logger.info("获取openId成功");
} catch (Exception e) {
logger.error("获取微信登录用户的openId失败", e);
}
return openId;
}
public String getPhone(UserRequestDto dto) { public String getPhone(UserRequestDto dto) {
String phone = ""; String phone = "";
...@@ -66,7 +80,7 @@ public class WxLoginManager { ...@@ -66,7 +80,7 @@ public class WxLoginManager {
logger.info("开始获取sessionKey-----------------------"); logger.info("开始获取sessionKey-----------------------");
String sessionKey = ""; String sessionKey = "";
try { try {
WxMaJscode2SessionResult result = this.wxMaService.getUserService().getSessionInfo(dto.getCode()); WxMaJscode2SessionResult result = this.wxMaService.getUserService().getSessionInfo(dto.getLoginCode());
sessionKey = result.getSessionKey(); sessionKey = result.getSessionKey();
logger.info("获取sessionKey结果:" + JSON.toJSONString(result)); logger.info("获取sessionKey结果:" + JSON.toJSONString(result));
} catch (Exception e) { } catch (Exception e) {
...@@ -74,7 +88,7 @@ public class WxLoginManager { ...@@ -74,7 +88,7 @@ public class WxLoginManager {
return "sessionFalse"; return "sessionFalse";
} }
if (StringUtils.isBlank(sessionKey)) { if (StringUtils.isBlank(sessionKey)) {
logger.info("微信登录,调用官方接口失败:{}", dto.getCode()); logger.info("微信登录,调用官方接口失败:{}", dto.getLoginCode());
return "sessionFalse"; return "sessionFalse";
} }
......
...@@ -6,9 +6,26 @@ import com.wwdz.ch.wx.entity.vo.ItemResponseVo; ...@@ -6,9 +6,26 @@ import com.wwdz.ch.wx.entity.vo.ItemResponseVo;
import java.util.List; import java.util.List;
public interface ItemCommonService { public interface ItemCommonService {
/**
* 获取用户的昵称和头像
*
* @param itemId
* @param vo
*/
void getNicknameAvatar(Long itemId, ItemResponseVo vo); void getNicknameAvatar(Long itemId, ItemResponseVo vo);
/**
* 获取仅自己可见的用户发布的藏品
*
* @param token
* @return
*/
List<Long> getOnlyOneselfItemIds(String token); List<Long> getOnlyOneselfItemIds(String token);
/**
* 获取关注粉丝收藏和浏览量
*
* @param userInfo
*/
void getPageViews(UserInfo userInfo); void getPageViews(UserInfo userInfo);
} }
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment