use of top.longmarch.sign.entity.AppProductApi in project longmarch by yuyueqty.
the class AppProductServiceImpl method createSign.
@Override
public AppProductApi createSign(String appId, String apiId) {
AppProduct appProduct = this.getById(appId);
if (appProduct == null) {
throw new BusinessException(5000, "无效的appid");
}
AppApiInfo appApiInfo = appApiInfoService.getById(apiId);
if (appApiInfo == null) {
throw new BusinessException(5000, "无效的apiId");
}
AppProductApi productApi = appProductApiService.getOne(new LambdaQueryWrapper<AppProductApi>().eq(AppProductApi::getAppProductId, appId).eq(AppProductApi::getAppApiId, apiId));
if (productApi == null) {
throw new BusinessException(5000, "接口未授权");
}
// 初始化请求头信息
SignatureHeaders signatureHeaders = new SignatureHeaders();
signatureHeaders.setAppid(String.valueOf(appProduct.getAppId()));
signatureHeaders.setAppSecret(appProduct.getAppSecret());
signatureHeaders.setNonce(SignatureUtils.generateNonce());
signatureHeaders.setTimestamp(String.valueOf(System.currentTimeMillis()));
List<String> pathParams = new ArrayList<>();
pathParams.add(SignatureUtils.encode(appApiInfo.getUrl(), signatureHeaders.getAppSecret()));
signatureHeaders.setSignature(SignatureUtils.signature(signatureHeaders, pathParams, null, null));
productApi.setTimestamp(signatureHeaders.getTimestamp());
productApi.setNonce(signatureHeaders.getNonce());
productApi.setSignature(signatureHeaders.getSignature());
LambdaUpdateWrapper<AppProductApi> wrapper = Wrappers.lambdaUpdate();
wrapper.set(AppProductApi::getSignature, signatureHeaders.getSignature()).set(AppProductApi::getNonce, signatureHeaders.getNonce()).set(AppProductApi::getTimestamp, signatureHeaders.getTimestamp());
wrapper.eq(AppProductApi::getAppProductId, appId).eq(AppProductApi::getAppApiId, apiId);
appProductApiService.update(wrapper);
return productApi;
}
use of top.longmarch.sign.entity.AppProductApi in project longmarch by yuyueqty.
the class AppProductServiceImpl method getAppByAppId.
@Override
public AppDTO getAppByAppId(String appId, String uri, String method) {
AppProduct appProduct = this.getById(appId);
if (appProduct == null) {
throw new BusinessException(5000, "无效的appid");
}
List<AppApiInfo> appApiInfos = appApiInfoService.list(new LambdaQueryWrapper<AppApiInfo>().eq(AppApiInfo::getUrl, uri).eq(AppApiInfo::getMethod, method));
if (CollectionUtil.isEmpty(appApiInfos)) {
throw new BusinessException(5000, "无效的api接口");
}
AppApiInfo appApiInfo = appApiInfos.get(0);
AppProductApi productApi = appProductApiService.getOne(new LambdaQueryWrapper<AppProductApi>().eq(AppProductApi::getAppProductId, appProduct.getAppId()).eq(AppProductApi::getAppApiId, appApiInfo.getId()));
if (productApi == null) {
throw new BusinessException(5000, "接口未授权");
}
return new AppDTO(appProduct, appApiInfo, productApi);
}
Aggregations