You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
54 lines
1.5 KiB
54 lines
1.5 KiB
<?php
|
|
|
|
// $user_id = "M0000";
|
|
// $user_password = "M012290493119";
|
|
|
|
// echo $validation = get_Auth($user_id, $user_password);
|
|
|
|
function get_Auth($user_id = "M0000", $user_password = "M012290493119")
|
|
{
|
|
$currentTime = time();
|
|
$twoMinutesLater = $currentTime - (2 * 60);
|
|
|
|
// $now = gmdate("YmdHis");
|
|
$now = gmdate("YmdHis", strtotime("-2 minutes"));
|
|
$data = "$user_id." . $now;
|
|
$sign = hash_hmac('SHA256', $data, 'A21181F1EE4966D3', false);
|
|
|
|
// echo $sign;
|
|
|
|
// $apiurl = 'https://erp.masada.com.tw:780/twWebAPI/GetAuth';
|
|
$apiurl = 'http://60.244.87.101:880//twWebAPI/GetAuth';
|
|
// $apiurl = 'http://10.10.145.2:880//twWebAPI/GetAuth';
|
|
// $apiurl = 'https://erp.masada.com.tw:780/twWebAPI/GetAuth';
|
|
|
|
//GroupId : TEST測試區 ; MASADA正式區
|
|
$headerParam = [
|
|
"UserId: $user_id",
|
|
"Pwd: $user_password",
|
|
"TimestampUTC: $now",
|
|
"Sign: $sign",
|
|
"GroupId:TEST"
|
|
];
|
|
|
|
$ch = curl_init();
|
|
curl_setopt($ch, CURLOPT_URL, $apiurl);
|
|
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
|
|
curl_setopt($ch, CURLOPT_HTTPHEADER, $headerParam);
|
|
|
|
$response = curl_exec($ch);
|
|
echo $response;
|
|
if ($response === false) {
|
|
echo '123Curl error: ' . curl_error($ch);
|
|
} else {
|
|
$result = json_decode($response, true);
|
|
if ($result['Status'] == 'Success')
|
|
return $result['Data']['CHI_Authorization'];
|
|
if ($result['Status'] == 'Error')
|
|
return $result['ErrorMsg'];
|
|
}
|
|
|
|
curl_close($ch);
|
|
}
|
|
// $data = [];
|
|
// get_Auth();
|
|
|