use of top.longmarch.sign.util.SignatureHeaders 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;
}
Aggregations