double-break / spapi-php

Amazon Selling Partner API PHP Client
MIT License
56 stars 48 forks source link

The data returned by getreportDocument after downloading and decompression is garbled #11

Closed ykw090721 closed 3 years ago

ykw090721 commented 3 years ago

After I call ASECryptoStream::decrypt to decrypt the data, the returned data is garbled. I tried gzip decompression and conversion of the encoding type, but it can’t solve this problem. Have you encountered this problem?

lyubo-slavilov commented 3 years ago

@ykw090721, please provide example code which describes your use case at best. @MST1122 can you look at this?

ykw090721 commented 3 years ago

The problem is solved, I just call gzdecode after decrypting the data, but it didn’t work before

ykw090721 commented 3 years ago

问题解决了,我只是在解密数据后调用gzdecode,但是之前没有用

` public function downloadFeedProcessingReport($payload) { $encryptionDetails = $payload['encryptionDetails']; $feedDownloadUrl = $payload['url']; $key = $encryptionDetails['key']; $initializationVector = $encryptionDetails['initializationVector'];

    // base64 decode before using in encryption
    $initializationVector = base64_decode($initializationVector, true);
    $key = base64_decode($key, true);
    $decryptedFile = ASECryptoStream::decrypt(file_get_contents($feedDownloadUrl), $key, $initializationVector);
    if($payload['compressionAlgorithm']=='GZIP') {
        $decryptedFile=gzdecode($decryptedFile);
    }
    $decryptedFile = preg_replace('/\s+/S', " ", $decryptedFile);
    $xml = simplexml_load_string($decryptedFile);
    $json = json_encode($xml);
    return json_decode($json, TRUE);
}`

Should be this