Search in sources :

Example 1 with AppProductApi

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

Example 2 with AppProductApi

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

Aggregations

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