<?php
function aes_encode($key, $str)
{
$data = openssl_encrypt($str, 'AES-128-ECB', $key, OPENSSL_RAW_DATA);
$data = strtolower(bin2hex($data));
return $data;
}
$server = 'http://gvsoa.com:20883'; // 请替换为实际的服务器 URL
$postParams = array(
'grant_type' => 'password',
'client_id' => 'RNIHEHVSZAZZNHWJIVUIQCTSQMUGTRQS',
'client_secret' => aes_encode('891049691681066ac820978013714090', '891049691681066ac820978013714090'),
'username' => 'userName',
'password' => 'passWord'
);
$ch = curl_init($server . "/oauth2/token");
curl_setopt($ch, CURLOPT_TIMEOUT, 30);
curl_setopt($ch, CURLOPT_POST, 1);
curl_setopt($ch, CURLOPT_HEADER, false);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
curl_setopt($ch, CURLOPT_HTTPHEADER, array('Content-Type: application/x-www-form-urlencoded'));
curl_setopt($ch, CURLOPT_POSTFIELDS, http_build_query($postParams));
$response = curl_exec($ch);
if ($response === false) {
$error = curl_error($ch);
curl_close($ch);
echo "Curl request failed: $error";
} else {
$otoken = json_decode($response, true);
if ($otoken === null) {
echo "Failed to decode JSON response";
} else {
$otoken = $otoken['access_token']?? null;
if ($otoken === null) {
echo "Access token not found in response";
} else {
echo "Access Token: $otoken";
}
}
curl_close($ch);
}