修改配置
This commit is contained in:
+42
@@ -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;
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
+2
-1
@@ -1,2 +1,3 @@
|
|||||||
org.springframework.boot.autoconfigure.EnableAutoConfiguration=\
|
org.springframework.boot.autoconfigure.EnableAutoConfiguration=\
|
||||||
cn.iocoder.yudao.config.WxCpConfigure
|
cn.iocoder.yudao.config.WxCpConfigure,\
|
||||||
|
cn.iocoder.yudao.config.WxMaConfiguration
|
||||||
|
|||||||
+22
-8
@@ -1,5 +1,7 @@
|
|||||||
package cn.iocoder.yudao.module.system.controller.admin.auth;
|
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.hutool.core.util.ObjectUtil;
|
||||||
import cn.iocoder.yudao.framework.common.enums.CommonStatusEnum;
|
import cn.iocoder.yudao.framework.common.enums.CommonStatusEnum;
|
||||||
import cn.iocoder.yudao.framework.common.enums.UserTypeEnum;
|
import cn.iocoder.yudao.framework.common.enums.UserTypeEnum;
|
||||||
@@ -69,7 +71,8 @@ public class AuthController {
|
|||||||
private CpUserService cpUserService;
|
private CpUserService cpUserService;
|
||||||
@Resource
|
@Resource
|
||||||
private WxCpService wxCpService;
|
private WxCpService wxCpService;
|
||||||
|
@Resource
|
||||||
|
private WxMaService wxMaService;
|
||||||
@Resource
|
@Resource
|
||||||
private UserSessionService userSessionService;
|
private UserSessionService userSessionService;
|
||||||
|
|
||||||
@@ -94,8 +97,17 @@ public class AuthController {
|
|||||||
if ("wxcp".equals(dto.getCode())){
|
if ("wxcp".equals(dto.getCode())){
|
||||||
cpuser = cpUserService.getByUserId("test");
|
cpuser = cpUserService.getByUserId("test");
|
||||||
}else{
|
}else{
|
||||||
WxCpMaJsCode2SessionResult session = wxCpService.jsCode2Session(dto.getCode());
|
if (dto.getPlatform().equalsIgnoreCase("WX")){
|
||||||
cpuser = cpUserService.getByUserId(session.getUserId());
|
//普通微信
|
||||||
|
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)){
|
if (ObjectUtil.isEmpty(cpuser)){
|
||||||
@@ -106,19 +118,21 @@ public class AuthController {
|
|||||||
if (ObjectUtil.isEmpty(user)){
|
if (ObjectUtil.isEmpty(user)){
|
||||||
CommonResult.error(ErrorCodeConstants.USER_NOT_EXISTS.getCode(),"未发现绑定的企业用户,暂时无法登录,请联系管理员");
|
CommonResult.error(ErrorCodeConstants.USER_NOT_EXISTS.getCode(),"未发现绑定的企业用户,暂时无法登录,请联系管理员");
|
||||||
}else {
|
}else {
|
||||||
user.setCpUserId(cpuser.getUserId());
|
if (dto.getPlatform().equalsIgnoreCase("WX")){
|
||||||
userService.updateUser(UserConvert.INSTANCE.convertFromEntity(user));
|
//暂时用微信小程序登录
|
||||||
|
}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()
|
AuthLoginReqVO login = AuthLoginReqVO.builder()
|
||||||
.username(cpuser.getUserId())
|
.username(cpuser.getUserId())
|
||||||
.password("123456")
|
.password("123456")
|
||||||
.platform("wxcp").build();
|
.platform("wxcp").build();
|
||||||
String token = authService.login(login, getClientIP(), getUserAgent());
|
String token = authService.login(login, getClientIP(), getUserAgent());
|
||||||
|
|
||||||
|
log.info("TOKEN:::{}",token);
|
||||||
AuthLoginRespVO vo = AuthLoginRespVO.builder().token(token).user(cpuser).build();
|
AuthLoginRespVO vo = AuthLoginRespVO.builder().token(token).user(cpuser).build();
|
||||||
return CommonResult.success(vo);
|
return CommonResult.success(vo);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -150,5 +150,10 @@ smms:
|
|||||||
|
|
||||||
wxcp:
|
wxcp:
|
||||||
corpId: wwb9f9734e8e124761
|
corpId: wwb9f9734e8e124761
|
||||||
farmAppid: 1000033
|
farmAppid: 1000036
|
||||||
farmSecret: UDSKsn0_LAPYqSwjH9E-AfY_X40lq0sormfe1yV_6Gc
|
farmSecret: UDSKsn0_LAPYqSwjH9E-AfY_X40lq0sormfe1yV_6Gc
|
||||||
|
|
||||||
|
#农场小程序
|
||||||
|
wxma:
|
||||||
|
app_id: wx4c3f7b2dd907f34e
|
||||||
|
app_secret: b2496a7a77483f819c6074841250119b
|
||||||
|
|||||||
Reference in New Issue
Block a user