修改配置

This commit is contained in:
小久哥
2022-06-11 15:48:16 +08:00
parent f42644e836
commit cc0c7f374e
4 changed files with 73 additions and 11 deletions
@@ -0,0 +1,42 @@
package cn.iocoder.yudao.config;
import cn.binarywang.wx.miniapp.api.WxMaService;
import cn.binarywang.wx.miniapp.api.impl.WxMaServiceImpl;
import cn.binarywang.wx.miniapp.config.impl.WxMaDefaultConfigImpl;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.context.annotation.Scope;
import org.springframework.context.annotation.ScopedProxyMode;
/**
* Created by kellen on 2020/5/3. 微信小程序服务配置
*/
@Configuration
@Slf4j
public class WxMaConfiguration {
@Value("${wxma.app_id}")
private String appId;
@Value("${wxma.app_secret}")
private String appSecret;
@Bean
@Scope(value = "prototype", proxyMode = ScopedProxyMode.TARGET_CLASS)
public WxMaService wxMaService() {
WxMaDefaultConfigImpl wxMaDefaultConfig = new WxMaDefaultConfigImpl();
wxMaDefaultConfig.setAppid(appId);
wxMaDefaultConfig.setSecret(appSecret);
WxMaServiceImpl wxMaService = new WxMaServiceImpl();
wxMaService.setWxMaConfig(wxMaDefaultConfig);
return wxMaService;
}
}
@@ -1,2 +1,3 @@
org.springframework.boot.autoconfigure.EnableAutoConfiguration=\
cn.iocoder.yudao.config.WxCpConfigure
cn.iocoder.yudao.config.WxCpConfigure,\
cn.iocoder.yudao.config.WxMaConfiguration
@@ -1,5 +1,7 @@
package cn.iocoder.yudao.module.system.controller.admin.auth;
import cn.binarywang.wx.miniapp.api.WxMaService;
import cn.binarywang.wx.miniapp.bean.WxMaJscode2SessionResult;
import cn.hutool.core.util.ObjectUtil;
import cn.iocoder.yudao.framework.common.enums.CommonStatusEnum;
import cn.iocoder.yudao.framework.common.enums.UserTypeEnum;
@@ -69,7 +71,8 @@ public class AuthController {
private CpUserService cpUserService;
@Resource
private WxCpService wxCpService;
@Resource
private WxMaService wxMaService;
@Resource
private UserSessionService userSessionService;
@@ -94,9 +97,18 @@ public class AuthController {
if ("wxcp".equals(dto.getCode())){
cpuser = cpUserService.getByUserId("test");
}else{
if (dto.getPlatform().equalsIgnoreCase("WX")){
//普通微信
WxMaJscode2SessionResult result = wxMaService.jsCode2SessionInfo(dto.getCode());
log.info("微信登录信息,{}", result);
cpuser = cpUserService.getByUserId(result.getUnionid());
}else{
//企业微信
WxCpMaJsCode2SessionResult session = wxCpService.jsCode2Session(dto.getCode());
log.info("企业微信登录信息:{}", session);
cpuser = cpUserService.getByUserId(session.getUserId());
}
}
if (ObjectUtil.isEmpty(cpuser)){
cpuser = cpUserService.getByUserId("test");
@@ -106,12 +118,13 @@ public class AuthController {
if (ObjectUtil.isEmpty(user)){
CommonResult.error(ErrorCodeConstants.USER_NOT_EXISTS.getCode(),"未发现绑定的企业用户,暂时无法登录,请联系管理员");
}else {
if (dto.getPlatform().equalsIgnoreCase("WX")){
//暂时用微信小程序登录
}else{
user.setCpUserId(cpuser.getUserId());
userService.updateUser(UserConvert.INSTANCE.convertFromEntity(user));
}
LoginUser login1 = AuthConvert.INSTANCE.convert(user);
String token1 = userSessionService.createUserSession(login1, getClientIP(), getUserAgent());
}
AuthLoginReqVO login = AuthLoginReqVO.builder()
.username(cpuser.getUserId())
@@ -119,6 +132,7 @@ public class AuthController {
.platform("wxcp").build();
String token = authService.login(login, getClientIP(), getUserAgent());
log.info("TOKEN:::{}",token);
AuthLoginRespVO vo = AuthLoginRespVO.builder().token(token).user(cpuser).build();
return CommonResult.success(vo);
}
@@ -150,5 +150,10 @@ smms:
wxcp:
corpId: wwb9f9734e8e124761
farmAppid: 1000033
farmAppid: 1000036
farmSecret: UDSKsn0_LAPYqSwjH9E-AfY_X40lq0sormfe1yV_6Gc
#农场小程序
wxma:
app_id: wx4c3f7b2dd907f34e
app_secret: b2496a7a77483f819c6074841250119b