wc-api-java 无法使用参数前后获得 woocommerce 订单

wc-api-java not able to get woocommerce orders using before and after param

我想获取特定日期的订单,但出现以下错误尝试了几种日期格式,但出现了相同的错误。这仅在我添加日期参数(之前和之后)时发生。此 api 适用于 per_page 或没有任何参数。

WooCommerce wooCommerce = new WooCommerceAPI(config, ApiVersionType.V3);
Map<String, String> params = new HashMap<>();
params.put("per_page","10");
params.put("after","2016-11-20T13:57:31.2311892-04:00");
params.put("before","2017-11-20T13:57:31.2311892-04:00");

List<Map<String, Object>>  orders = wooCommerce.getAll(EndpointBaseType.ORDERS.getValue(), params);

这段代码给我一个错误 线程“main”中的异常java.lang.RuntimeException:无法解析检索到的对象:{code=woocommerce_rest_authentication_error,消息=无效签名 - 提供的签名不匹配。,数据={status= 401}}

我得到了日期问题的解决方案,这里是解决方案。我们需要对日期进行编码。

params.put("after", percentEncode("01-01-2021T00:00:00"));

public String percentEncode(String s) {
        final String UTF_8 = "UTF-8";

        try {
            return URLEncoder.encode(s, UTF_8)
                    // OAuth encodes some characters differently:
                    .replace(SpecialSymbol.PLUS.getPlain(), SpecialSymbol.PLUS.getEncoded())
                    .replace(SpecialSymbol.STAR.getPlain(), SpecialSymbol.STAR.getEncoded())
                    .replace(SpecialSymbol.TILDE.getEncoded(), SpecialSymbol.TILDE.getPlain());
        } catch (UnsupportedEncodingException e) {
            throw new RuntimeException(e.getMessage(), e);
        }
    } 

对我来说,使用这种格式 2021-07-01T11:51:36 很有帮助。