1

FoxyCart の Order Desk から POST を受信するスクリプトを作成しようとしています。requestb.in で一時的なリクエスト ビンをセットアップします。そこに POST を指定すると、新しい順序の JSON が正常に取得されます。このコードを使用して、スクリプトの JSON 文字列をコピーして貼り付けたところ、JSON を解析でき、データベースに変数を正常に追加できました。

$string = "{"id":"1191583","email":"office@burntimpressions.com","shipping_method":"","quantity_total":1,"weight_total":0,"product_total":0,"shipping_total":0,"handling_total":0,"tax_total":0,"discount_total":0,"order_total":0,"cc_number_masked":"","cc_exp":"","processor_response":"","payment_type":"","payment_status":"Approved","processor_balance":0,"customer_id":"","email_count":"1","ip_address":"71.161.83.59","tag_color":"","source_name":"Order Desk","source_id":"1191583","fulfillment_name":"","fulfillment_id":"","tag_name":"","folder_id":6814,"date_added":"2015-06-14 16:53:54","date_updated":"2015-06-14 16:54:27","shipping":{"first_name":"Galen","last_name":"Dively","company":"Vermont Novelty Toaster Corporation","address1":"136 Bay Street","address2":"Ste 2","address3":"","address4":"","city":"Saint Johnsbury","state":"Vermont","postal_code":"05819","country":"US","phone":"(916) 448-5517"},"customer":{"first_name":"Galen","last_name":"Dively","company":"Vermont Novelty Toaster Corporation","address1":"136 Bay Street","address2":"Ste 2","city":"Saint Johnsbury","state":"Vermont","postal_code":"05819","country":"US","phone":"(916) 448-5517"},"checkout_data":[],"order_metadata":[],"discount_list":[],"order_notes":[],"order_items":[{"id":"2090400","name":"selfie test","price":0,"quantity":1,"weight":0,"code":"selfie","delivery_type":"ship","category_code":"","variation_list":[],"metadata":[]}],"order_shipments":[]}";
$order = json_decode($string, true);
$transactionId = $order [id];
$firstName = $order[customer][first_name];
foreach($order [order_items] as $p)
{
$cid = $p[id];
$productName = $p[name];
$code = $p[code];
$quantity = $p[quantity];
}

Order Desk のドキュメントには、これで POST を取得するように記載されています。

$order = json_decode($_POST['order'], 1);

私は何も得ていません。考えられることはほぼすべて試しました。このフォーラムを調べたところ、JSON を解析できるものは何も見つかりませんでした。Order Desk の管理パネルからエラーが表示されないので、POST が成功したと思います。

オーダー デスクには、セキュリティ上の目的でこのコードがあります。POSTはそれらすべてを通過したようです。

<?php
//Check For Order
if (!isset($_POST['order'])) {
    header(':', true, 400);
    die('No Data Found');
}

//Cbeck Store ID
//Be sure to set your store ID. Ask Order Desk support if you aren't sure    what it is.
if (!isset($_SERVER['HTTP_X_ORDER_DESK_STORE_ID']) ||   $_SERVER['HTTP_X_ORDER_DESK_STORE_ID'] != "YOUR-STORE-ID") {
    header(':', true, 403);
    die('Unauthorized Request');
}

//Check the Hash (optional)
//The API Key can be found in the Advanced Settings section. Order Desk Pro only
if (!isset($_SERVER['HTTP_X_ORDER_DESK_HASH']) || hash_hmac('sha256', rawurldecode($_POST['order']), 'YOUR_API_KEY') != $_SERVER['HTTP_X_ORDER_DESK_HASH']) {
    header(':', true, 403);
    die('Unauthorized Request');
}

//Check Order Data
$order = json_decode($_POST['order'], 1);
if (!is_array($order)) {
    header(':', true, 400);
    die('Invalid Order Data');
}

//Everything Checks Out -- do your thing
echo "<pre>" . print_r($order, 1) . "</pre>";

どんな助けでも大歓迎です!

私はあなたがどのように解析するかを尋ねていると思います:

$order = json_decode($_POST['order'], 1);

requestb.in から得られるもの:

フォーム/ポスト パラメータ

order: {"id":"1191583","email":"office@burntimpressions.com","shipping_method":"","quantity_total":1,"weight_total":0,"product_total":0,"shipping_total":0,"handling_total":0,"tax_total":0,"discount_total":0,"order_total":0,"cc_number_masked":"","cc_exp":"","processor_response":"","payment_type":"","payment_status":"Approved","processor_balance":0,"customer_id":"","email_count":"1","ip_address":"71.161.83.59","tag_color":"","source_name":"Order Desk","source_id":"1191583","fulfillment_name":"","fulfillment_id":"","tag_name":"","folder_id":6814,"date_added":"2015-06-14 16:53:54","date_updated":"2015-06-14 16:54:27","shipping":{"first_name":"Galen","last_name":"Dively","company":"Vermont Novelty Toaster Corporation","address1":"136 Bay Street","address2":"Ste 2","address3":"","address4":"","city":"Saint Johnsbury","state":"Vermont","postal_code":"05819","country":"US","phone":"(916) 448-5517"},"customer":{"first_name":"Galen","last_name":"Dively","company":"Vermont Novelty Toaster Corporation","address1":"136 Bay Street","address2":"Ste 2","city":"Saint Johnsbury","state":"Vermont","postal_code":"05819","country":"US","phone":"(916) 448-5517"},"checkout_data":[],"order_metadata":[],"discount_list":[],"order_notes":[],"order_items":[{"id":"2090400","name":"selfie test","price":0,"quantity":1,"weight":0,"code":"selfie","delivery_type":"ship","category_code":"","variation_list":[],"metadata":[]}],"order_shipments":[]}

ヘッダー

Total-Route-Time: 0
Connect-Time: 1
X-Request-Id: 26eb3b73-bd15-4d75-9605-ea4fda0191dd
User-Agent: Guzzle/5.3.0 curl/7.19.7 PHP/5.5.21
X-Order-Desk-Store-Id: XXXXXXX
Content-Type: application/x-www-form-urlencoded
Connection: close
Content-Length: 2228
Via: 1.1 vegur
Host: requestb.in
X-Order-Desk-Hash: XXXXXXXXXXXXX
4

0 に答える 0