Browse Source

修改配置

zyh
小久哥 3 years ago
parent
commit
cc0c7f374e
  1. 42
      yudao-framework/yudao-spring-boot-starter-biz-weixin/src/main/java/cn/iocoder/yudao/config/WxMaConfiguration.java
  2. 3
      yudao-framework/yudao-spring-boot-starter-biz-weixin/src/main/resources/META-INF/spring.factories
  3. 30
      yudao-module-system/yudao-module-system-impl/src/main/java/cn/iocoder/yudao/module/system/controller/admin/auth/AuthController.java
  4. 9
      yudao-server/src/main/resources/application.yaml

42
yudao-framework/yudao-spring-boot-starter-biz-weixin/src/main/java/cn/iocoder/yudao/config/WxMaConfiguration.java

@ -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;
}
}

3
yudao-framework/yudao-spring-boot-starter-biz-weixin/src/main/resources/META-INF/spring.factories

@ -1,2 +1,3 @@
org.springframework.boot.autoconfigure.EnableAutoConfiguration=\
cn.iocoder.yudao.config.WxCpConfigure
cn.iocoder.yudao.config.WxCpConfigure,\
cn.iocoder.yudao.config.WxMaConfiguration

30
yudao-module-system/yudao-module-system-impl/src/main/java/cn/iocoder/yudao/module/system/controller/admin/auth/AuthController.java

@ -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,8 +97,17 @@ public class AuthController {
if ("wxcp".equals(dto.getCode())){
cpuser = cpUserService.getByUserId("test");
}else{
WxCpMaJsCode2SessionResult session = wxCpService.jsCode2Session(dto.getCode());
cpuser = cpUserService.getByUserId(session.getUserId());
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)){
@ -106,19 +118,21 @@ public class AuthController {
if (ObjectUtil.isEmpty(user)){
CommonResult.error(ErrorCodeConstants.USER_NOT_EXISTS.getCode(),"未发现绑定的企业用户,暂时无法登录,请联系管理员");
}else {
user.setCpUserId(cpuser.getUserId());
userService.updateUser(UserConvert.INSTANCE.convertFromEntity(user));
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())
.password("123456")
.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);
}

9
yudao-server/src/main/resources/application.yaml

@ -150,5 +150,10 @@ smms:
wxcp:
corpId: wwb9f9734e8e124761
farmAppid: 1000033
farmSecret: UDSKsn0_LAPYqSwjH9E-AfY_X40lq0sormfe1yV_6Gc
farmAppid: 1000036
farmSecret: UDSKsn0_LAPYqSwjH9E-AfY_X40lq0sormfe1yV_6Gc
#农场小程序
wxma:
app_id: wx4c3f7b2dd907f34e
app_secret: b2496a7a77483f819c6074841250119b

Loading…
Cancel
Save