相关疑难解决方法(0)

Auth 1.0 oauth_signature 创建Android for magento API

我使用以下身份验证作为标题调用 Magento API,

auth = "OAuth oauth_consumer_key=**********************,oauth_consumer_secret=****************,oauth_token=************,oauth_token_secret=**************,oauth_signature_method=HMAC-SHA1,oauth_timestamp=" + ConstantFunctions.GetTimeStamp() + ",oauth_nonce=" + ConstantFunctions.GetNonce() + ",oauth_signature=*******************) ;
Run Code Online (Sandbox Code Playgroud)

当我调用 API 时,获取错误oauth_problem=signature_invalid。所有其他参数验证成功但签名中出现错误,我尝试使用以下代码生成签名,

     public static String GETHMACSHA1(String value, String key)
            throws UnsupportedEncodingException, NoSuchAlgorithmException,
            InvalidKeyException {
        String type = "HmacSHA1";
        SecretKeySpec secret = new SecretKeySpec(key.getBytes(), type);
        Mac mac = Mac.getInstance(type);
        mac.init(secret);
        byte[] bytes = mac.doFinal(value.getBytes());
        return bytesToHex(bytes);
    }

    private final static char[] hexArray = "0123456789abcdef".toCharArray();

    private static String bytesToHex(byte[] bytes) {
        char[] hexChars = new char[bytes.length * 2];
        int v;
        for (int j …
Run Code Online (Sandbox Code Playgroud)

rest android authorization retrofit magento-1.9

3
推荐指数
1
解决办法
2004
查看次数

标签 统计

android ×1

authorization ×1

magento-1.9 ×1

rest ×1

retrofit ×1