5 changed files with 159 additions and 18 deletions
@ -0,0 +1,50 @@ |
|||
<?php |
|||
|
|||
function get_Auth($groupId='TEST',$accountId='M0122',$password='90493119') |
|||
{ |
|||
$user_id = $accountId; |
|||
$user_password = $password; |
|||
$api_key = "A21181F1EE4966D3"; |
|||
$GroupId = $groupId; |
|||
|
|||
// 伺服器時間扣兩分鐘會比較穩定 |
|||
// $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); |
|||
} |
@ -0,0 +1,49 @@ |
|||
<?php |
|||
include "./header.php"; |
|||
include "T8_Authorization_curl.php"; |
|||
|
|||
$account_id = "M0122"; |
|||
$password = "90493119"; |
|||
$GroupId = 'TEST'; |
|||
$validation = get_Auth($GroupId,$account_id,$password); |
|||
// print_r(get_purchaseApply($conn, '123')); |
|||
$sql_purchaseApply = "SELECT * FROM purCharge"; |
|||
$result = get_purchaseApply($conn, $sql_purchaseApply); |
|||
print_r($result); |
|||
|
|||
function get_purchaseApply($conn){ |
|||
$sql_purchaseApply = "SELECT * FROM purCharge"; |
|||
$query_purchaseApply = $conn -> prepare($sql_purchaseApply); |
|||
$query_purchaseApply -> execute(); |
|||
$result = $query_purchaseApply -> fetchAll(); |
|||
return $result; |
|||
} |
|||
|
|||
|
|||
|
|||
|
|||
// print_r(get_purchase_apply($validation,$GroupId,"S230300001-14")); |
|||
//費用申請單API 不能用 |
|||
function get_purchase_apply($validation,$GroupId,$BillNo){ |
|||
$apiurl = "http://60.244.87.101:880//twWebAPI/V1/PURFEEAPPLY/GetERPData?pkValue=$BillNo"; |
|||
// echo $apiurl . "\n"; |
|||
$headerParam = [ |
|||
'CHI_Authorization: ' . $validation, |
|||
'GroupId:'.$GroupId |
|||
]; |
|||
$ch = curl_init(); |
|||
curl_setopt($ch, CURLOPT_URL, $apiurl); |
|||
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true); |
|||
curl_setopt($ch, CURLOPT_HTTPHEADER, $headerParam); |
|||
curl_setopt($ch, CURLOPT_CUSTOMREQUEST, "GET"); |
|||
|
|||
$response = curl_exec($ch); |
|||
if ($response === false) { |
|||
echo 'Curl error: ' . curl_error($ch); |
|||
} else { |
|||
$result = json_decode($response, true); |
|||
print_r($result); |
|||
} |
|||
|
|||
curl_close($ch); |
|||
} |
@ -0,0 +1,36 @@ |
|||
<?php |
|||
include "./header.php"; |
|||
include "T8_Authorization_curl.php"; |
|||
|
|||
$account_id = "M0122"; |
|||
$password = "90493119"; |
|||
$GroupId = 'TEST'; |
|||
$validation = get_Auth(); |
|||
|
|||
// print_r(get_purchase_apply($validation,$GroupId,"S230300001-14")); |
|||
|
|||
//費用申請單API 不能用 |
|||
function get_purchase_apply($validation,$GroupId,$BillNo){ |
|||
$apiurl = "http://60.244.87.101:880//twWebAPI/V1/PURFEEAPPLY/GetERPData?pkValue=$BillNo"; |
|||
// echo $apiurl . "\n"; |
|||
$headerParam = [ |
|||
'CHI_Authorization: ' . $validation, |
|||
'GroupId:'.$GroupId |
|||
]; |
|||
$ch = curl_init(); |
|||
curl_setopt($ch, CURLOPT_URL, $apiurl); |
|||
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true); |
|||
curl_setopt($ch, CURLOPT_HTTPHEADER, $headerParam); |
|||
curl_setopt($ch, CURLOPT_CUSTOMREQUEST, "GET"); |
|||
|
|||
$response = curl_exec($ch); |
|||
if ($response === false) { |
|||
echo 'Curl error: ' . curl_error($ch); |
|||
} else { |
|||
$result = json_decode($response, true); |
|||
print_r($result); |
|||
} |
|||
|
|||
curl_close($ch); |
|||
} |
|||
|
Loading…
Reference in new issue