如何在XxlJob中调用其他模块的方法

Blade 未结 3 1209
Jalena
Jalena 2021-06-21 15:36

一、该问题的重现步骤是什么?

在项目中使用XxlJob定时去执行一个方法,且这个方法是在一个新的模块中,且这个模块的方法受Blade权限管控。


如果在XxlJob中去调用这个方法,应当如何处理服务鉴权呢?


请问有例子吗?


目前打算使用`blade-starter-http`的HttpRequest来实现。


三、你正在使用的是什么产品,什么版本?在什么操作系统上?

BladeX 2.8.1


3条回答
  •  Jalena
    Jalena (楼主)
    2021-06-22 12:02

    我晕,编辑好的咋个成这样~


    配置:

        #动态签名认证配置
        sign:
          - method: ALL
            pattern: /dashboard/sign
            crypto: "sha1"
          - method: ALL
            pattern: /blade-business/taxrawdata/pull
            crypto: "sha1"


    代码

    // secure
    Map headers = new HashMap<>();
    long timestamp = DateUtil.now().getTime();
    String nonce = "223";
    String signature = DigestUtil.sha1Hex(timestamp + nonce);
    headers.put("nonce", nonce);
    headers.put("timestamp", String.valueOf(timestamp));
    headers.put("signature", signature);
    
    HttpRequest.get("http://localhost/blade-business/taxrawdata/pull")
            .log(LogLevel.BODY)
            .queryMap(queryMap)
            .cacheControl(CacheControl.FORCE_NETWORK)
            .addHeader(headers)
            .execute()
            .onResponse(responseSpec -> {
                if (responseSpec.isOk()) return ReturnT.SUCCESS;
                return new ReturnT(ReturnT.FAIL.getCode(), responseSpec.message());
            });


    日志:

    org.springblade.core.http.Slf4jLogger    : --> GET http://localhost/blade-business/taxrawdata/pull?endDate=20210622&startDate=20210619
    org.springblade.core.http.Slf4jLogger    : signature: 5e138fd57bd5f65faf01954d4740ef43ac3d0a5f
    org.springblade.core.http.Slf4jLogger    : nonce: 223
    org.springblade.core.http.Slf4jLogger    : timestamp: 1624332240162
    org.springblade.core.http.Slf4jLogger    : User-Agent: Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/74.0.3729.169 Safari/537.36
    org.springblade.core.http.Slf4jLogger    : --> END GET


    错误信息

    {"msg":"缺失令牌,鉴权失败","code":401,"data":null}


提交回复