【问题标题】:Shopify- need to create a webhookShopify - 需要创建一个 webhook
【发布时间】:2014-11-25 07:48:03
【问题描述】:

我需要创建一个 web-hook,用于将 xml 数据发布到存储库。

xml格式应该是这样的:

<Order OrderID="xxxx" AffiliateID="xxxxxx">
<ShipToName>Bob Sanders</ShipToName>           
<ShipToContact>Bob Sanders</ShipToContact>
<ShipToName2></ShipToName2>        
<AddressLine1>21 N. Long St.</AddressLine1>        
<AddressLine2>Unit A</AddressLine2>
<AddressLine3></AddressLine3>
<City>Barrington Hills</City>                        
<Country>US</Country>                  
<State>Il</State>      
<Province></Province>  
<Zip>60010</Zip>
<Email>madman@gmail.com</Email>
<Phone>7086639935</Phone>
<SpecialInstructions></SpecialInstructions>
<SpecialInstructions2></SpecialInstructions2>

目前是这样的:

    <order>
<buyer-accepts-marketing type="boolean">true</buyer-accepts-marketing>
<cancel-reason nil="true"/>
<cancelled-at type="dateTime" nil="true"/>
<cart-token>6343c2a1ec2e675202ad9fdccb8fe862</cart-token>
<checkout-token>c62fcb629ce1df6a7202be1e4f34f237</checkout-token>
<closed-at type="dateTime" nil="true"/>
<confirmed type="boolean">true</confirmed>
<created-at type="dateTime">2014-11-24T23:22:22-07:00</created-at>
<currency>USD</currency>
<email>kads@hfi.com</email>
<financial-status>pending</financial-status>
<fulfillment-status nil="true"/>
<gateway>Cash on Delivery (COD)</gateway>
<id type="integer">282488743</id>
<landing-site>/</landing-site>
<location-id type="integer" nil="true"/>
<name>#SH1001</name>
<note nil="true"/>
<number type="integer">1</number>

我需要更改节点名称并只抓取几个必需的节点而不是全部。 我不明白从哪里开始。

为了更好地理解这里的情况是网址:

  1. https://shibumi-home.myshopify.com/admin/orders.xml[需要修改的XML]
  2. http://divinepnc.com/a/webhooks-shopify/a.xml【应该怎样】

我不是要求提供该情况的确切代码,我只想问我应该如何进行。

非常感谢

【问题讨论】:

  • 只需解析从 Shopify 发送的 XML,然后从这些部分中放入您需要的 XML 文件。

标签: xml shopify webhooks


【解决方案1】:

1. 您可以从 shopify 的管理面板中的通知选项卡下创建一个 Webhook,并将其指向您要发布数据的 url(在我的情况下为 xml,您可以选择json 也)。

2. 然后,我使用以下代码抓取 shopify-xml,该代码以“timber.xml”的形式存储在服务器上。

下面是示例代码sn-p:

$webhookContent = "";
$webhook = fopen('php://input' , 'rb');
while (!feof($webhook)) {
    $webhookContent .= fread($webhook,18920);
}
fclose($webhook);
//error_log($webhookContent);
$fp = fopen($_SERVER['DOCUMENT_ROOT'] . "/a/webhooks-shopify/timber.xml","wb");
fwrite($fp,$webhookContent);
fclose($fp);

3.为了将抓取的shopify-xml转换为所需的xml,我使用了PHP DOM LIBRARY

下面是示例代码sn-p:

$doc = new DOMDocument; 
$doc->load('timber.xml');
$thedocument = $doc->documentElement;
//this gives you a list of elements by tag name
$order_number = $thedocument->getElementsByTagName('order-number')->item(0);
$order_number_val = $order_number->textContent;

$shipping_address = $thedocument->getElementsByTagName('shipping-address')->item(0);
$shipping_address = $shipping_address->lastChild;
$shipping_address = $shipping_address->previousSibling;
$shipping_address = $shipping_address->previousSibling;
$shipping_address_val = $shipping_address->textContent;

$address1 = $thedocument->getElementsByTagName('shipping-address')->item(0);
$address1 = $address1->firstChild;
$address1_val = $address1->textContent;

【讨论】:

    猜你喜欢
    • 2019-05-04
    • 2017-11-13
    • 1970-01-01
    • 1970-01-01
    • 2013-04-30
    • 1970-01-01
    • 1970-01-01
    • 2021-12-26
    • 2021-05-21
    相关资源
    最近更新 更多