注册用户推送id
This commit is contained in:
@ -17,6 +17,7 @@ import com.sczx.user.thirdpart.dto.WechatDecryptedPhoneInfo;
|
||||
import com.sczx.user.thirdpart.dto.WechatMiniProgramResponse;
|
||||
import com.sczx.user.thirdpart.integration.AlipayInteg;
|
||||
import com.sczx.user.thirdpart.integration.WeichatInteg;
|
||||
import com.sczx.user.util.DataPushApi;
|
||||
import com.sczx.user.util.JwtUtil;
|
||||
import com.sczx.user.util.RedisUtil;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
@ -56,6 +57,8 @@ public class UserServiceImpl implements IUserService {
|
||||
@Autowired
|
||||
private BaseUserReferralRepo baseUserReferralRepo;
|
||||
|
||||
@Autowired
|
||||
private DataPushApi dataPushApi;
|
||||
|
||||
@Override
|
||||
public String getWxOpenId(String code) {
|
||||
@ -185,7 +188,7 @@ public class UserServiceImpl implements IUserService {
|
||||
if(StringUtils.isBlank(phoneNumber)){
|
||||
throw new BizException("微信小程序注册失败,无法获取用户真实手机号");
|
||||
}
|
||||
|
||||
boolean isNewUser = false;
|
||||
LambdaQueryWrapper<BaseUserPO> queryWrapper = new LambdaQueryWrapper<>();
|
||||
queryWrapper.eq(BaseUserPO::getPhoneNumber, phoneNumber);
|
||||
baseUserPO = baseUserRepo.getOne(queryWrapper);
|
||||
@ -198,7 +201,7 @@ public class UserServiceImpl implements IUserService {
|
||||
|
||||
baseUserPO.setNickName(phoneNumber);
|
||||
baseUserPO.setRoleId(1);
|
||||
baseUserRepo.saveOrUpdate(baseUserPO);
|
||||
isNewUser = baseUserRepo.saveOrUpdate(baseUserPO);
|
||||
|
||||
if(Objects.nonNull(wxMiniProgramRegRequest.getReferralUserId())){
|
||||
LambdaQueryWrapper<BaseUserReferralPO> queryReferralWrapper = new LambdaQueryWrapper<>();
|
||||
@ -219,9 +222,13 @@ public class UserServiceImpl implements IUserService {
|
||||
}else {
|
||||
if(StringUtils.isBlank(baseUserPO.getWechatOpenid())){
|
||||
baseUserPO.setWechatOpenid(openid);
|
||||
baseUserRepo.saveOrUpdate(baseUserPO);
|
||||
isNewUser = baseUserRepo.saveOrUpdate(baseUserPO);
|
||||
}
|
||||
}
|
||||
// 推送用户ID
|
||||
if (isNewUser) {
|
||||
dataPushApi.sendAddUser(baseUserPO.getId());
|
||||
}
|
||||
return getLoginResponse(baseUserPO,MiniProgramTypeEnum.WECHAT);
|
||||
}catch (Exception e){
|
||||
log.error("微信小程序注册失败", e);
|
||||
@ -249,6 +256,7 @@ public class UserServiceImpl implements IUserService {
|
||||
queryWrapper.eq(BaseUserPO::getPhoneNumber, phoneNumber);
|
||||
BaseUserPO baseUserPO = baseUserRepo.getOne(queryWrapper);
|
||||
|
||||
boolean isNewUser = false;
|
||||
// 4. 创建或更新用户
|
||||
if (Objects.isNull(baseUserPO)) {
|
||||
baseUserPO =new BaseUserPO();
|
||||
@ -259,7 +267,7 @@ public class UserServiceImpl implements IUserService {
|
||||
baseUserPO.setNickName(phoneNumber);
|
||||
baseUserPO.setRoleId(1);
|
||||
baseUserPO.setAlipayOpenid(openId);
|
||||
baseUserRepo.saveOrUpdate(baseUserPO);
|
||||
isNewUser = baseUserRepo.saveOrUpdate(baseUserPO);
|
||||
|
||||
if(Objects.nonNull(alipayMiniProgramRegRequest.getReferralUserId())){
|
||||
LambdaQueryWrapper<BaseUserReferralPO> queryReferralWrapper = new LambdaQueryWrapper<>();
|
||||
@ -280,9 +288,13 @@ public class UserServiceImpl implements IUserService {
|
||||
}else {
|
||||
if(StringUtils.isBlank(baseUserPO.getAlipayOpenid())){
|
||||
baseUserPO.setAlipayOpenid(openId);
|
||||
baseUserRepo.saveOrUpdate(baseUserPO);
|
||||
isNewUser = baseUserRepo.saveOrUpdate(baseUserPO);
|
||||
}
|
||||
}
|
||||
// 推送用户ID
|
||||
if (isNewUser) {
|
||||
dataPushApi.sendAddUser(baseUserPO.getId());
|
||||
}
|
||||
// 5. 返回登录信息
|
||||
return getLoginResponse(baseUserPO,MiniProgramTypeEnum.ALIPAY);
|
||||
} catch (Exception e) {
|
||||
|
||||
75
src/main/java/com/sczx/user/util/DataPushApi.java
Normal file
75
src/main/java/com/sczx/user/util/DataPushApi.java
Normal file
@ -0,0 +1,75 @@
|
||||
package com.sczx.user.util;
|
||||
|
||||
import com.fasterxml.jackson.databind.ObjectMapper;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.beans.factory.annotation.Value;
|
||||
import org.springframework.http.*;
|
||||
import org.springframework.stereotype.Service;
|
||||
import org.springframework.web.client.RestTemplate;
|
||||
|
||||
import java.util.Map;
|
||||
|
||||
@Service
|
||||
public class DataPushApi {
|
||||
|
||||
private static final Logger logger = LoggerFactory.getLogger(DataPushApi.class);
|
||||
|
||||
@Autowired
|
||||
private ObjectMapper objectMapper;
|
||||
|
||||
@Value(value = "${dataPush.sendAddUserUrl}")
|
||||
private String sendAddUserUrl;
|
||||
|
||||
|
||||
/**
|
||||
* 发送添加用户信息
|
||||
* @param userId
|
||||
*/
|
||||
public boolean sendAddUser(Long userId) {
|
||||
return sendDataId(sendAddUserUrl, userId, "用户");
|
||||
}
|
||||
|
||||
|
||||
private boolean sendDataId(String url,Long id,String name) {
|
||||
try {
|
||||
// 发送HTTP请求调用添加接口
|
||||
RestTemplate restTemplate = new RestTemplate();
|
||||
ResponseEntity<String> response = restTemplate.getForEntity(url + id, String.class);
|
||||
|
||||
// 处理添加接口响应
|
||||
if (response.getStatusCode() == HttpStatus.OK) {
|
||||
// 解析响应内容,检查return_code是否为SUCCESS
|
||||
String responseBody = response.getBody();
|
||||
if (responseBody != null) {
|
||||
try {
|
||||
// 使用ObjectMapper解析JSON响应
|
||||
Map<String, Object> responseMap = objectMapper.readValue(responseBody, Map.class);
|
||||
Object returnCode = responseMap.get("code");
|
||||
if ("200".equals(returnCode)) {
|
||||
logger.info("推送{}ID成功,ID: {}", name, id);
|
||||
return true;
|
||||
} else {
|
||||
logger.error("推送{}ID失败,ID: {},响应: {}", name, id, responseBody);
|
||||
return false;
|
||||
}
|
||||
} catch (Exception jsonEx) {
|
||||
logger.error("推送{}ID接口响应异常,ID: {},响应: {}", name, id, responseBody, jsonEx);
|
||||
return false;
|
||||
}
|
||||
} else {
|
||||
logger.error("推送{}ID返回空响应,ID: {}", name, id);
|
||||
return false;
|
||||
}
|
||||
} else {
|
||||
logger.error("推送{}ID,ID: {},响应: {}", name, id, response.getBody());
|
||||
return false;
|
||||
}
|
||||
} catch (Exception e) {
|
||||
logger.error("推送门店ID异常,ID: " + name, id, e);
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
@ -84,4 +84,7 @@ alipay:
|
||||
format: JSON
|
||||
charset: UTF-8
|
||||
signType: RSA2
|
||||
encryptType: AES
|
||||
encryptType: AES
|
||||
|
||||
dataPush:
|
||||
sendAddUserUrl: http://115.190.8.52:8016/send/userinfo/
|
||||
Reference in New Issue
Block a user