从FoxyCart订单台获取JSON $ _POST

时间:2015-06-14 18:05:18

标签: php json post foxycart

我正在尝试创建一个脚本,以便从FoxyCart的Order Desk接收POST。我在requestb.in设置了一个临时请求bin。当我指向POST时,我得到新订单JSON罚款。我使用此代码在我的脚本中复制/粘贴了JSON字符串,我能够解析JSON并成功将变量添加到我的数据库中:

TimerTask task = new TimerTask() {
    public void run() {
        elapsedTime++;//amount of time passed
        timeLeft.setText("" + (time - elapsedTime));

        if (time - elapsedTime == 0) {
            cancel();
            score1 = 0;//resets score
            question.setText("GAME OVER");
        }
    }
};

Order Desk的文档说明了如何获得POST:

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

我什么都没得到。我已经尝试过我能想到的一切。通过这个论坛查看并找不到任何可以解析JSON的内容。我假设POST成功,因为我没有从Order Desk的管理面板中收到任何错误。

为了安全起见,订单台有此代码。 POST似乎通过了所有这些。

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

非常感谢任何帮助!

我想我在问你将如何解析:

<?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>";

我从requestb.in获得了什么:

FORM / POST PARAMETERS

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

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":[]}

0 个答案:

没有答案