Search in sources :

Example 1 with SignatureHeaders

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;
}
Also used : BusinessException(top.longmarch.lmcore.exception.BusinessException) AppProductApi(top.longmarch.sign.entity.AppProductApi) ArrayList(java.util.ArrayList) SignatureHeaders(top.longmarch.sign.util.SignatureHeaders) AppProduct(top.longmarch.sign.entity.AppProduct) AppApiInfo(top.longmarch.sign.entity.AppApiInfo)

Aggregations

ArrayList (java.util.ArrayList)1 BusinessException (top.longmarch.lmcore.exception.BusinessException)1 AppApiInfo (top.longmarch.sign.entity.AppApiInfo)1 AppProduct (top.longmarch.sign.entity.AppProduct)1 AppProductApi (top.longmarch.sign.entity.AppProductApi)1 SignatureHeaders (top.longmarch.sign.util.SignatureHeaders)1