ByteDanceDecrypt.php 988 B

123456789101112131415161718192021222324252627282930313233343536373839404142
  1. <?php
  2. namespace app\service\byte_dance;
  3. use think\Cache;
  4. class ByteDanceDecrypt implements ByteDanceInterface {
  5. protected $session_key;
  6. protected $encryptedData;
  7. protected $iv;
  8. public function setSessionKey($sessionKey)
  9. {
  10. $this->session_key = $sessionKey;
  11. return $this;
  12. }
  13. /**
  14. * @param mixed $encryptedData
  15. */
  16. public function setEncryptedData($encryptedData): void
  17. {
  18. $this->encryptedData = $encryptedData;
  19. }
  20. /**
  21. * @param mixed $iv
  22. */
  23. public function setIv($iv): void
  24. {
  25. $this->iv = $iv;
  26. }
  27. public function get()
  28. {
  29. try {
  30. $decrypted=openssl_decrypt(base64_decode($this->encryptedData),'AES-128-CBC',base64_decode($this->session_key),OPENSSL_RAW_DATA,base64_decode($this->iv));
  31. return json_decode($decrypted,true);
  32. }catch (\Exception $e){
  33. ByteDance::throwIf(1,"数据解密失败({$e->getMessage()})");
  34. }
  35. }
  36. }