123456789101112131415161718192021222324252627282930313233343536373839404142 |
- <?php
- namespace app\service\byte_dance;
- use think\Cache;
- class ByteDanceDecrypt implements ByteDanceInterface {
- protected $session_key;
- protected $encryptedData;
- protected $iv;
- public function setSessionKey($sessionKey)
- {
- $this->session_key = $sessionKey;
- return $this;
- }
- /**
- * @param mixed $encryptedData
- */
- public function setEncryptedData($encryptedData): void
- {
- $this->encryptedData = $encryptedData;
- }
- /**
- * @param mixed $iv
- */
- public function setIv($iv): void
- {
- $this->iv = $iv;
- }
- public function get()
- {
- try {
- $decrypted=openssl_decrypt(base64_decode($this->encryptedData),'AES-128-CBC',base64_decode($this->session_key),OPENSSL_RAW_DATA,base64_decode($this->iv));
- return json_decode($decrypted,true);
- }catch (\Exception $e){
- ByteDance::throwIf(1,"数据解密失败({$e->getMessage()})");
- }
- }
- }
|