use of com.chao.cloud.common.exception.BusinessException in project chao-cloud by chaojunzi.
the class SessionFormTokenProxy method around.
// 环绕拦截
@Around(value = "@annotation(com.chao.cloud.common.extra.token.annotation.FormToken)")
public Object around(ProceedingJoinPoint pdj) throws Exception {
Object obj = null;
HttpServletRequest request = getRequest();
log.info("[token]----start----------");
Method method = getMethod(pdj);
FormToken annotation = method.getAnnotation(FormToken.class);
String token = null;
if (annotation != null) {
boolean needSaveSession = annotation.save();
// 添加token
if (needSaveSession) {
request.getSession(true).setAttribute(FROM_TOKEN_KEY, IdUtil.fastUUID());
}
boolean needRemoveSession = annotation.remove();
// 删除token
if (needRemoveSession) {
boolean isRepeat = isRepeatSubmit(request);
// 获取token
token = (String) request.getSession(true).getAttribute(FROM_TOKEN_KEY);
request.getSession(true).removeAttribute(FROM_TOKEN_KEY);
if (isRepeat) {
log.warn("请不要重复提交,url:{}", request.getServletPath());
throw new BusinessException("请不要重复提交");
}
}
}
// 执行
try {
obj = pdj.proceed();
} catch (Throwable e) {
if (e instanceof ValidationException && StrUtil.isNotBlank(token) && annotation.remove()) {
// 参数校验回退
request.getSession(true).setAttribute(FROM_TOKEN_KEY, token);
}
throw new BusinessException(ExceptionUtil.getMessage(e));
}
log.info("[token]------end----------");
return obj;
}
use of com.chao.cloud.common.exception.BusinessException in project chao-cloud by chaojunzi.
the class TxSeataImportSelector method selectImports.
@Override
public String[] selectImports(AnnotationMetadata metadata) {
Class<Object> className = ClassUtil.loadClass(metadata.getClassName());
// 排除 DataSourceAutoConfiguration 自动注入
SpringBootApplication boot = AnnotationUtil.getAnnotation(className, SpringBootApplication.class);
// 修改值
Class<?>[] exclude = boot.exclude();
if (!ArrayUtil.contains(exclude, DataSourceAutoConfiguration.class)) {
Class<? extends Object>[] excludeClass = ArrayUtil.append(exclude, DataSourceAutoConfiguration.class);
EntityUtil.putAnnotationValue(boot, "exclude", excludeClass);
}
// 获取注解值
EnableTxSeata txSeata = AnnotationUtil.getAnnotation(className, EnableTxSeata.class);
// 加载相关配置
ConfigType type = txSeata.value();
switch(type) {
case // 0.7.1 只支持nacos
Nacos:
// 整合seata-nacos
Properties properties = this.getNacosProp();
// 获取配置资源
try {
ConfigService configService = NacosFactory.createConfigService(properties);
// NacosConfiguration
EntityUtil.setPrivateFinalField(NacosConfiguration.class, "configService", configService);
//
NacosConfiguration configuration = NacosConfiguration.getInstance();
// ConfigurationFactory
EntityUtil.setPrivateFinalField(ConfigurationFactory.class, "instance", configuration);
// 修改注册-nacos
// EntityUtil.setPrivateFinalField(ConfigurationFactory.class,
// "DEFAULT_FILE_INSTANCE", configuration);
EntityUtil.setPrivateFinalField(ConfigurationFactory.class, "CURRENT_FILE_INSTANCE", configuration);
// 修改服务发现
NamingService namingService = NamingFactory.createNamingService(properties);
EntityUtil.setPrivateFinalField(NacosRegistryServiceImpl.class, "naming", namingService);
} catch (Exception e) {
log.error("{}", e);
throw new BusinessException("Nacos-Seata 初始化失败");
}
return new String[] { TxSeataConfig.class.getName() };
default:
break;
}
return null;
}
use of com.chao.cloud.common.exception.BusinessException in project chao-cloud by chaojunzi.
the class WxAppUserInfoServiceImpl method getUserInfo.
@Override
public WxMaUserInfo getUserInfo(String encryptedData, String iv, String code) {
try {
// 获取session_key
log.info("[encryptedData={}]", encryptedData);
log.info("[iv={}]", iv);
WxMaJscode2SessionResult sessionInfo = wxMaUserService.getSessionInfo(code);
log.info("[sessionInfo={}]", sessionInfo);
// 获取用户信息
return wxMaUserService.getUserInfo(sessionInfo.getSessionKey(), getEncryptedData(encryptedData), iv);
} catch (WxErrorException e) {
WxError error = e.getError();
throw new BusinessException(error.getErrorMsg());
}
}
use of com.chao.cloud.common.exception.BusinessException in project chao-cloud by chaojunzi.
the class WxAppUserInfoServiceImpl method getPhoneNoInfo.
@Override
public WxMaPhoneNumberInfo getPhoneNoInfo(String encryptedData, String iv, String code) {
WxMaJscode2SessionResult sessionInfo = null;
try {
// 获取session_key
sessionInfo = wxMaUserService.getSessionInfo(code);
log.info("【获取手机号】[SessionKey={}]", sessionInfo.getSessionKey());
log.info("【获取手机号】[iv={}]", iv);
log.info("【获取手机号】[encryptedData={}]", encryptedData);
// 获取用户信息
return wxMaUserService.getPhoneNoInfo(sessionInfo.getSessionKey(), getEncryptedData(encryptedData), iv);
} catch (WxErrorException e) {
log.error("【获取手机号失败】[sessionInfo={}]", sessionInfo);
log.error("【获取手机号失败】[iv={}]", iv);
log.error("【获取手机号失败】[encryptedData={}]", encryptedData);
WxError error = e.getError();
throw new BusinessException(error.getErrorMsg());
}
}
Aggregations