fix: 微信支付,登录接口。
This commit is contained in:
@@ -11,6 +11,7 @@ import com.intc.common.core.domain.R;
|
||||
import com.intc.common.core.domain.model.LoginBody;
|
||||
import com.intc.common.core.domain.model.RegisterBody;
|
||||
import com.intc.common.core.domain.model.SocialLoginBody;
|
||||
import com.intc.common.core.exception.ServiceException;
|
||||
import com.intc.common.core.utils.*;
|
||||
import com.intc.common.encrypt.annotation.ApiEncrypt;
|
||||
import com.intc.common.json.utils.JsonUtils;
|
||||
@@ -23,6 +24,7 @@ import com.intc.common.social.utils.SocialUtils;
|
||||
import com.intc.common.sse.dto.SseMessageDto;
|
||||
import com.intc.common.sse.utils.SseMessageUtils;
|
||||
import com.intc.common.tenant.helper.TenantHelper;
|
||||
import com.intc.fishery.domain.AquUser;
|
||||
import com.intc.system.domain.bo.SysTenantBo;
|
||||
import com.intc.system.domain.vo.SysClientVo;
|
||||
import com.intc.system.domain.vo.SysTenantVo;
|
||||
@@ -36,6 +38,8 @@ import com.intc.web.domain.vo.TenantListVo;
|
||||
import com.intc.web.service.IAuthStrategy;
|
||||
import com.intc.web.service.SysLoginService;
|
||||
import com.intc.web.service.SysRegisterService;
|
||||
import com.intc.weixin.domain.bo.ReqWxLogin;
|
||||
import com.intc.weixin.service.WxLoginService;
|
||||
import jakarta.servlet.http.HttpServletRequest;
|
||||
import lombok.RequiredArgsConstructor;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
@@ -43,6 +47,7 @@ import me.zhyd.oauth.model.AuthResponse;
|
||||
import me.zhyd.oauth.model.AuthUser;
|
||||
import me.zhyd.oauth.request.AuthRequest;
|
||||
import me.zhyd.oauth.utils.AuthStateUtils;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.validation.annotation.Validated;
|
||||
import org.springframework.web.bind.annotation.*;
|
||||
|
||||
@@ -75,6 +80,9 @@ public class AuthController {
|
||||
private final ISysClientService clientService;
|
||||
private final ScheduledExecutorService scheduledExecutorService;
|
||||
|
||||
@Autowired(required = false)
|
||||
private WxLoginService wxLoginService;
|
||||
|
||||
|
||||
/**
|
||||
* 登录方法
|
||||
@@ -239,4 +247,70 @@ public class AuthController {
|
||||
return R.ok(result);
|
||||
}
|
||||
|
||||
/**
|
||||
* 微信小程序登录
|
||||
*
|
||||
* @param request 微信登录请求
|
||||
* @return 结果
|
||||
*/
|
||||
@ApiEncrypt
|
||||
@PostMapping("/wechat_login")
|
||||
public R<AquUser> wechatLogin(@Validated @RequestBody ReqWxLogin request) {
|
||||
try {
|
||||
log.info("收到微信登录请求: clientId={}, tenantId={}", request.getClientId(), request.getTenantId());
|
||||
|
||||
// 1. 检查服务是否可用
|
||||
if (wxLoginService == null) {
|
||||
log.error("微信登录服务未启用,请检查配置: wx.miniapp.app-id");
|
||||
return R.fail("微信登录服务未启用,请联系管理员");
|
||||
}
|
||||
|
||||
// 2. 校验客户端
|
||||
SysClientVo client = clientService.queryByClientId(request.getClientId());
|
||||
if (ObjectUtil.isNull(client)) {
|
||||
log.error("客户端不存在: clientId={}", request.getClientId());
|
||||
return R.fail(MessageUtils.message("auth.grant.type.error"));
|
||||
}
|
||||
if (!SystemConstants.NORMAL.equals(client.getStatus())) {
|
||||
log.error("客户端已被禁用: clientId={}, status={}", request.getClientId(), client.getStatus());
|
||||
return R.fail(MessageUtils.message("auth.grant.type.blocked"));
|
||||
}
|
||||
|
||||
// 3. 校验租户
|
||||
if (StringUtils.isNotBlank(request.getTenantId())) {
|
||||
try {
|
||||
loginService.checkTenant(request.getTenantId());
|
||||
} catch (Exception e) {
|
||||
log.error("租户校验失败: tenantId={}", request.getTenantId(), e);
|
||||
return R.fail("租户校验失败: " + e.getMessage());
|
||||
}
|
||||
}
|
||||
|
||||
// 4. 执行微信登录
|
||||
AquUser aquUser = wxLoginService.loginByWeChat(
|
||||
request.getCode(),
|
||||
request.getJsCode(),
|
||||
request.getTenantId()
|
||||
);
|
||||
|
||||
if (aquUser == null) {
|
||||
log.error("微信登录失败,未返回用户信息");
|
||||
return R.fail("登录失败,请重试");
|
||||
}
|
||||
|
||||
// 5. 返回用户信息
|
||||
log.info("微信登录成功: userId={}, mobilePhone={}",
|
||||
aquUser.getId(), aquUser.getMobilePhone());
|
||||
|
||||
return R.ok(aquUser);
|
||||
|
||||
} catch (ServiceException e) {
|
||||
log.error("微信登录业务异常: {}", e.getMessage(), e);
|
||||
return R.fail(e.getMessage());
|
||||
} catch (Exception e) {
|
||||
log.error("微信登录系统异常", e);
|
||||
return R.fail("登录失败: " + e.getMessage());
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user