有 Java 编程相关的问题?

你可以在下面搜索框中键入要查询的问题!

通过okhttp客户端的woocommerce api的签名基字符串出现java意外url

要生成签名的url为

GET&http%3A%2F%2Fprojectrepo.net%2Fscoop%2Fwp-json%2Fwc%2Fv2%2Forders&oauth_consumer_key%3Dck_2f53925cb6d2c8f96407f09f67f5f118d01ed80e%26oauth_signature_method%3DHMAC-SHA1

未使用utf编码的字符串为

GET&http://----.net/----/wp-json/wc/v2/orders&oauth_consumer_key=----&oauth_signature_method=----

问题是,当通过okhttp客户端传递此url以生成签名时,日志上会显示“意外url”错误

Request request = new Request.Builder()
                    .url(signatureBaseString)
                    .build();
Response response = null;
response = client.newCall(request).execute();

怎么了?不能使用okhttp客户端生成签名,因为url是生成签名所需的utf编码的


共 (1) 个答案

  1. # 1 楼答案

    找到解决办法了

    android中生成签名的代码如下

    Mac mac = null;
    mac = Mac.getInstance("HMAC-SHA1");
    String secret = oauthConsumerSecretKeyStringValue+"&";
            mac.init(new SecretKeySpec(secret.getBytes("utf-8"), "HMAC-SHA1"));
    signature = Base64.encodeToString(mac.doFinal(signatureBaseString.getBytes("utf-8")), 0).trim();
    

    OAuthConsumerCretKeystringValue变量具有使用者密钥

    签名基字符串是除oauth_签名之外具有所有oauth参数的字符串。此字符串用于生成签名

    现在是“GET&在生成签名时,必须使用字符。但当数据发布时,它应该在没有“GET&角色

    谢谢大家抽出时间