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.
 
 
 
 
 
 

56 lines
1.7 KiB

<?php
// echo $validation = get_Auth($user_id, $user_password);
// function get_Auth($user_id = "ADMIN", $user_password = "chi")
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); ///測試區
// $sign = hash_hmac('SHA256', $data, '91EB2CB12C3F8211', false);
// echo $sign;
// $apiurl = 'https://erp.masada.com.tw:780/twWebAPI/GetAuth';
$apiurl = 'http://60.244.87.101:880//twWebAPI/GetAuth'; /// 測試區
// $apiurl = 'http://101.132.66.206: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"
// "GroupId:MASADA"
];
$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();
// exit();