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.
80 lines
2.1 KiB
80 lines
2.1 KiB
<?php
|
|
// 202711
|
|
|
|
|
|
// $user_id = "M0000";
|
|
// $user_password = "M012290493119";
|
|
|
|
// 測試空間
|
|
$user_id = "M0117";
|
|
$user_password = "90493119";
|
|
$api_key = "A21181F1EE4966D3";
|
|
$GroupId = "TEST";
|
|
$apiurl = 'http://60.244.87.101:880//twWebAPI/GetAuth';
|
|
|
|
// 正式空間
|
|
// $user_id = "M0117";
|
|
// $user_password = "90493119";
|
|
// $api_key = "A21181F1EE4966D3";
|
|
// $GroupId = "MASADA";
|
|
// $apiurl = 'http://60.244.87.101:880//twWebAPI/GetAuth';
|
|
|
|
$data = array(
|
|
'user_id' => $user_id,
|
|
'user_password' => $user_password,
|
|
'api_key' => $api_key,
|
|
'GroupId' => $GroupId,
|
|
'apiurl' => $apiurl
|
|
);
|
|
echo $validation = get_Auth($data);
|
|
|
|
function get_Auth($data)
|
|
{
|
|
|
|
$user_id = $data['user_id'];
|
|
$user_password = $data['user_password'];
|
|
$api_key = $data['api_key'];
|
|
$GroupId = $data['GroupId'];
|
|
$apiurl = $data['apiurl'];
|
|
|
|
// 伺服器時間扣兩分鐘會比較穩定
|
|
// $now = gmdate("YmdHis");
|
|
$now = gmdate("YmdHis", strtotime("-2 minutes"));
|
|
|
|
$data = "$user_id." . $now;
|
|
$sign = hash_hmac('SHA256', $data, $api_key, false);
|
|
|
|
// 各種API連線網址
|
|
// $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';
|
|
|
|
$headerParam = [
|
|
"UserId: $user_id",
|
|
"Pwd: $user_password",
|
|
"TimestampUTC: $now",
|
|
"Sign: $sign",
|
|
"GroupId: $GroupId"
|
|
];
|
|
|
|
$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);
|
|
if ($response === false) {
|
|
echo 'Curl 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'];
|
|
|
|
print_r($result);
|
|
}
|
|
|
|
curl_close($ch);
|
|
}
|
|
|