意外 url 如果 woocommerce api 的签名基础字符串通过 okhttp 客户端

Unexpected url in case of signature base string of woocommerce api through okhttp client

生成签名的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=----

问题是这个url通过okhttp客户端生成签名时,日志显示"unexpected url"错误。

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

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

得到解决方案。

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

oauthConsumerSecretKeyStringValue 变量具有消费者密钥。

签名基础字符串是包含所有oauth参数的字符串,oauth_signature.This字符串用于生成签名。

现在 "GET&" 字符在签名时是强制性的 generation.But 当数据被 posted 时它应该 post 在 url 没有这 "GET&" 个字符。

感谢大家抽出宝贵时间。