require "openssl"
require "base64"
require "time"
require "json"
class YHSDMultipass
attr_accessor :cipher_key
attr_accessor :cipher_iv
def initialize(key)
@cipher_key = key[0, 16]
@cipher_iv = key[16, 16]
end
def aes_encrypt(data)
cipher = OpenSSL::Cipher::Cipher.new("aes-128-cbc")
cipher.encrypt
cipher.key = @cipher_key
cipher.iv = @cipher_iv
ciphertext = cipher.update(data) + cipher.final
ciphertext.to_s
end
end
# 用户信息JSON
customer_data = {
"uid" => "test@youhaosuda.com",
"type" => "email",
"name" => "test"
}
# 接入密钥
secret_key = '095AE461E2554EED8D12F19F9662247E'
# 店铺主域名
shop_domain = 'youhaosuda.com'
encrypt_data = YHSDMultipass.new(secret_key).aes_encrypt(customer_data.to_json)
redirect_url = "http://" + shop_domain + "/account/multipass/login/#{encrypt_data}"
puts "customer_data:" + customer_data.to_json
puts "encrypt_data:" + encrypt_data
puts "redirect_url:" + redirect_url
cmVxdWlyZSAib3BlbnNzbCIKcmVxdWlyZSAiYmFzZTY0IgpyZXF1aXJlICJ0aW1lIgpyZXF1aXJlICJqc29uIgoKY2xhc3MgWUhTRE11bHRpcGFzcyAKCiAgYXR0cl9hY2Nlc3NvciA6Y2lwaGVyX2tleQogIGF0dHJfYWNjZXNzb3IgOmNpcGhlcl9pdiAKCiAgZGVmIGluaXRpYWxpemUoa2V5KQogICAgQGNpcGhlcl9rZXkgPSBrZXlbMCwgMTZdCiAgICBAY2lwaGVyX2l2ID0ga2V5WzE2LCAxNl0KICBlbmQKCiAgZGVmIGFlc19lbmNyeXB0KGRhdGEpCiAgICBjaXBoZXIgPSBPcGVuU1NMOjpDaXBoZXI6OkNpcGhlci5uZXcoImFlcy0xMjgtY2JjIikKICAgIGNpcGhlci5lbmNyeXB0CiAgICBjaXBoZXIua2V5ID0gQGNpcGhlcl9rZXkgCiAgICBjaXBoZXIuaXYgPSBAY2lwaGVyX2l2IAogICAgY2lwaGVydGV4dCA9IGNpcGhlci51cGRhdGUoZGF0YSkgKyBjaXBoZXIuZmlu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