|
|
|
@ -24,14 +24,6 @@ class Wechat::Weapp
|
|
|
|
|
def decrypt(session_key, encrypted_data, iv)
|
|
|
|
|
session_key = Base64.decode64(session_key)
|
|
|
|
|
encrypted_data = Base64.decode64(encrypted_data)
|
|
|
|
|
cd = CharDet.detect(encrypted_data)
|
|
|
|
|
encrypted_data =
|
|
|
|
|
if cd["encoding"] == 'GB18030' && cd['confidence'] > 0.8
|
|
|
|
|
encrypted_data.encode('UTF-8', 'GBK', {:invalid => :replace, :undef => :replace, :replace => ' '})
|
|
|
|
|
else
|
|
|
|
|
encrypted_data.force_encoding('UTF-8')
|
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
iv = Base64.decode64(iv)
|
|
|
|
|
|
|
|
|
|
cipher = OpenSSL::Cipher::AES.new(128, :CBC)
|
|
|
|
|