PHPでエンドポイントにアクセス

例「バーコードで物品管理」で作成した「バーコード指定でデータ取得」をするエンドポイントに対してPHPからアクセスします。

エンドポイントのページにサンプルコードがありますのでそれを使用します。

<?php
$ch = curl_init();                 <ここからテンプレートを使用>
curl_setopt_array($ch, array(
CURLOPT_URL => "https://dbaassandbox.matsuesoft.co.jp/matsue_yeivxx5azxpurhwb2bvbspss1yk3bm2j/proxyserver-AssetInfo-GetSpecificAssetByBarcode.php",
CURLOPT_POST => true,
CURLOPT_HTTPHEADER => array(
'Content-Type: application/json'
),
CURLOPT_POSTFIELDS => json_encode(array(
"TOKEN"=> "AvJJNtJWRvzhqFGB5FLcIQQga6JOzOV6",
"param_AssetInfo_Barcode_where"=> "9784845623556" ← 取得したいバーコードの値を設定
)),
CURLOPT_RETURNTRANSFER => true
));
$response = curl_exec($ch);
$http_code = curl_getinfo($ch, CURLINFO_HTTP_CODE);
if ($http_code != 200) {
// Error Occured
} else {
// Success
$json_response = json_decode($response);
if ($json_response->_status == "OK") { <ここまでテンプレートを使用>
↓ここを追加 if ($json_response->Result) {
print "Result - Item Name: " . $json_response->Result->ItemName . "\n"; ← 取得結果を表示
print "Result - Description: " . $json_response->Result->Description . "\n"; ← 取得結果を表示
print "Result - Barcode: " . $json_response->Result->Barcode . "\n"; ← 取得結果を表示
} else {
print "No Item matched\n";
}

↑ここまで追加 } else { <ここからテンプレートを使用>
print "Error! Result: " . $json_response->_status . " : " . $json_response->Message . "\n";
}
} <ここまでテンプレートを使用> ?>

実行しますと以下のように表示されます。

Result - Item Name: DEF Travel Book
Result - Description: This is DEF...
Result - Barcode: 9784845623556

※phpのCURLが必要です。 Windows版phpの場合はSSL関係で設定が必要な場合があります。

戻る

ログイン当サイトのユーザ名(ID)でログイン
クイックログイン:Facebookのアカウントで即時ログイン(ログイン情報保持オプション:ON) / 新規登録


お問い合わせ

© 2016-2024 Matsuesoft Corporation