我需要创建一个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>
我需要更改节点名称,并且只抓取几个所需的节点,而不是所有节点。 我无法理解从哪里开始。
为了更好地了解这里的情况,网址是:
我不是要求提供具体的情况代码,我要问的是我应该如何处理。
非常感谢
答案 0 :(得分:0)
1。您可以在shopify的管理面板中创建一个Webhook,在通知选项卡下,并将其指向您要发布数据的网址(在我的情况下,您可以选择xml) json也)。
2。然后抓住shopify-xml我使用了以下代码,它以“timber.xml”的形式存储在服务器上。
以下是示例代码段:
$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。
以下是示例代码段:
$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;