$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); }