fork(2) download
  1. <?php
  2.  
  3. function getPayload($app_secret_key, $data) {
  4. // Get the encryption key (16 first bytes of the app's client_secret key)
  5. $encryption_key = substr($app_secret_key, 0, 16);
  6.  
  7. // Decrypt payload
  8. $json_data = aes_128_decrypt($encryption_key, $data);
  9.  
  10. // Decode json
  11. $json_decoded = json_decode($json_data, true);
  12. return $json_data;
  13. }
  14.  
  15. function aes_128_decrypt($key, $data) {
  16. // Ecwid sends data in url-safe base64. Convert the raw data to the original base64 first
  17. $base64_original = str_replace(array('-', '_'), array('+', '/'), $data);
  18.  
  19. // Get binary data
  20. $decoded = base64_decode($base64_original);
  21.  
  22. // Initialization vector is the first 16 bytes of the received data
  23. $iv = substr($decoded, 0, 16);
  24.  
  25. // The payload itself is is the rest of the received data
  26. $payload = substr($decoded, 16);
  27.  
  28. // Decrypt raw binary payload
  29. $json = openssl_decrypt($payload, "aes-128-cbc", $key, OPENSSL_RAW_DATA, $iv);
  30. //$json = mcrypt_decrypt(MCRYPT_RIJNDAEL_128, $key, $payload, MCRYPT_MODE_CBC, $iv); // You can use this instead of openssl_decrupt, if mcrypt is enabled in your system
  31.  
  32. return $json;
  33. }
  34.  
  35. // Get payload from the GET and process it
  36. $ecwid_payload = "ng7W9c9jLhkX7ATMpafNAd5Vt_skEaFAqnQaw0Ing1iwYQOwB0Q_CuCS8yQeHeorTdCpZWDTNrzhcq_umX7IaAFUPPgs0zyddY7Er1tA0aze5kWGHUV54fJHoVEJHMmVEi-G5g8ZnNopIFu0YQgQqLpCq8TP2zFJunSTA7VXHTmqHNAD2JXaUb-VylcJWzgV0vaCoGyHqaPbsNNw6HSWkAzhh8dLmsYB0uzsZ_zl3wVXubCL4p2N53PmNPBLCgoC";
  37. $client_secret = "zcKf1Zt0UsO43S46Un3pxIgs91R1xMGs";
  38.  
  39. $result = getPayload($client_secret, $ecwid_payload);
  40.  
  41. print($result);
  42.  
Success #stdin #stdout 0.02s 24524KB
stdin
Standard input is empty
stdout
{"store_id":20553036,"access_token":"secret_a9TmTJfRt3gyvxjJ9UwYjs9VQip3F7rp","public_token":"public_QQ99gUwVGdvKuZbLLyNZzDsvXF5iF3gh","view_mode":"PAGE","lang":"ru"}