PHP
Last updated
Last updated
<?php
class CryptographyHelper
{
const cipher = 'AES-256-CBC';
/**
* 加密 $text 需加密内容 $key Appid $v AppSecret
* @param string $text
* @param string $key
* @param string $iv
* @return string
*/
public static function EncryptAES256(string $text, string $key, string $iv): string
{
$encrypt = openssl_encrypt($text, self::cipher, $key, OPENSSL_RAW_DATA, $iv);
return base64_encode($encrypt);
}
/**
* 解密 $text 需解密内容 $key Appid $v AppSecret
* @param string $text
* @param string $key
* @param string $iv
* @return string
*/
public static function DecryptAES256(string $text, string $key, string $iv): string
{
$decodeText = base64_decode($text);
return openssl_decrypt($decodeText, self::cipher, $key, OPENSSL_RAW_DATA, $iv);
}
}
<?php
require_once "./vendor/autoload.php";
use GuzzleHttp\Client;
$time = 1648111171;
$key = '3b4db1e4202bde5a1b75dbd941defc38'; // app id
$iv = '20454ee618d4fb86'; // app secret
$b = [
'Account' => 'egg_test_ip_004',
];
$m = '1021202311031';
$t = $time;
echo "================= DES Example =================\n";
$postData = compact('b', 'm', 't');
echo 'Original Data ' . PHP_EOL;
print_r($postData);
$postData['b'] = CryptographyHelper::EncryptAES256(json_encode($postData['b']), $key, $iv);
echo 'After encrypted ' . PHP_EOL;
print_r($postData);
//$postData['b'] = CryptographyHelper::DecryptAES256($postData['b'], $key, $iv);
//$postData['b'] = json_decode($postData['b'], true);
//echo 'After decrypted ' . PHP_EOL;
//print_r($postData);
echo "================= END DES Example =================\n";
echo "\n\n\n";
echo "================= Send Request =================\n";
$params = [
'json' => $postData,
];
$config = [
'headers' => [
'Content-Type' => 'application/json',
'lang' => 'en-US',
],
];
$client = new Client($config);
//
$response = $client->post("http://qa1.h5_open_api.nqsf9emow.com:27799/v1/epoker/account/info", $params);
$data = \GuzzleHttp\json_decode($response->getBody()->getContents(), true);
print_r($data);
echo "================= End Send Request =================\n";