使用php表单shopify webhook的xml解析器

使用php表单shopify webhook的xml解析器,php,xml,parsing,shopify,Php,Xml,Parsing,Shopify,我正在使用webhook在创建订单时更新我的MS sql server,下面是我从shopify webhook获得的xml <?xml version="1.0" encoding="UTF-8"?> <order> <buyer-accepts-marketing type="boolean">true</buyer-accepts-marketing> <closed-at type="datetime" nil="true"&

我正在使用webhook在创建订单时更新我的MS sql server,下面是我从shopify webhook获得的xml

<?xml version="1.0" encoding="UTF-8"?>
<order>
  <buyer-accepts-marketing type="boolean">true</buyer-accepts-marketing>
  <closed-at type="datetime" nil="true"></closed-at>
  <currency>USD</currency>
  <email>jon@doe.ca</email>
  <financial-status>voided</financial-status>
  <fulfillment-status>pending</fulfillment-status>
  <gateway>bogus</gateway>
  <id type="integer">123456</id>
  <name>#9999</name>
  <note nil="true"></note>
  <number type="integer">234</number>
  <subtotal-price type="decimal">229.94</subtotal-price>
  <taxes-included type="boolean">false</taxes-included>
  <total-discounts type="decimal">0.0</total-discounts>
  <total-line-items-price type="decimal">229.94</total-line-items-price>
  <total-price type="decimal">239.94</total-price>
  <total-price-usd type="decimal" nil="true"></total-price-usd>
  <total-tax type="decimal">0.0</total-tax>
  <total-weight type="integer">0</total-weight>
  <updated-at type="datetime">2012-11-23T12:34:25-05:00</updated-at>
  <created-at type="datetime">2012-11-23T12:34:25-05:00</created-at>
  <token nil="true"></token>
  <landing-site nil="true"></landing-site>
  <referring-site nil="true"></referring-site>
  <cancelled-at type="datetime">2012-11-23T12:34:25-05:00</cancelled-at>
  <cancel-reason>customer</cancel-reason>
  <cart-token nil="true"></cart-token>
  <browser-ip nil="true"></browser-ip>
  <landing-site-ref nil="true"></landing-site-ref>
  <order-number type="integer">1234</order-number>
  <discount-codes type="array"/>
  <note-attributes type="array">
  </note-attributes>
  <processing-method nil="true"></processing-method>
  <line-items type="array">
    <line-item>
      <requires-shipping type="boolean">true</requires-shipping>
      <fulfillment-service>manual</fulfillment-service>
      <grams type="integer">5000</grams>
      <price type="decimal">199.99</price>
      <quantity type="integer">1</quantity>
      <sku>SKU2006-001</sku>
      <title>Sledgehammer</title>
      <product-id type="integer" nil="true"></product-id>
      <variant-id type="integer" nil="true"></variant-id>
      <vendor nil="true"></vendor>
      <variant-title nil="true"></variant-title>
      <fulfillment-status nil="true"></fulfillment-status>
      <name>Sledgehammer</name>
      <variant-inventory-management nil="true"></variant-inventory-management>
      <properties type="array">
      </properties>
    </line-item>
    <line-item>
      <requires-shipping type="boolean">true</requires-shipping>
      <fulfillment-service>manual</fulfillment-service>
      <grams type="integer">500</grams>
      <price type="decimal">29.95</price>
      <quantity type="integer">1</quantity>
      <sku>SKU2006-020</sku>
      <title>Wire Cutter</title>
      <product-id type="integer" nil="true"></product-id>
      <variant-id type="integer" nil="true"></variant-id>
      <vendor nil="true"></vendor>
      <variant-title nil="true"></variant-title>
      <fulfillment-status nil="true"></fulfillment-status>
      <name>Wire Cutter</name>
      <variant-inventory-management nil="true"></variant-inventory-management>
      <properties type="array">
      </properties>
    </line-item>
  </line-items>
  <shipping-lines type="array">
    <shipping-line>
      <title>Generic Shipping</title>
      <code nil="true"></code>
      <price type="decimal">10.0</price>
      <source>shopify</source>
    </shipping-line>
  </shipping-lines>
  <tax-lines type="array"/>
  <billing-address>
    <first-name>Bob</first-name>
    <last-name>Biller</last-name>
    <address1>123 Billing Street</address1>
    <address2 nil="true"></address2>
    <city>Billtown</city>
    <company>My Company</company>
    <country>United States</country>
    <phone>555-555-BILL</phone>
    <province>Kentucky</province>
    <zip>K2P0B0</zip>
    <latitude type="decimal" nil="true"></latitude>
    <longitude type="decimal" nil="true"></longitude>
    <name>Bob Biller</name>
    <country-code>US</country-code>
    <province-code>KY</province-code>
  </billing-address>
  <shipping-address>
    <first-name>Steve</first-name>
    <last-name>Shipper</last-name>
    <address1>123 Shipping Street</address1>
    <address2 nil="true"></address2>
    <city>Shippington</city>
    <company>Shipping Company</company>
    <country>United States</country>
    <phone>555-555-SHIP</phone>
    <province>Kentucky</province>
    <zip>K2P0S0</zip>
    <latitude type="decimal" nil="true"></latitude>
    <longitude type="decimal" nil="true"></longitude>
    <name>Steve Shipper</name>
    <country-code>US</country-code>
    <province-code>KY</province-code>
  </shipping-address>
  <fulfillments type="array"/>
  <customer>
    <email>john@test.com</email>
    <accepts-marketing type="boolean" nil="true"></accepts-marketing>
    <first-name>John</first-name>
    <last-name>Smith</last-name>
    <orders-count type="integer">0</orders-count>
    <total-spent type="decimal">0.0</total-spent>
    <note nil="true"></note>
    <created-at type="datetime" nil="true"></created-at>
    <updated-at type="datetime" nil="true"></updated-at>
    <state>disabled</state>
    <last-order-id type="integer" nil="true"></last-order-id>
    <tags></tags>
    <last-order-name nil="true"></last-order-name>
  </customer>
</order>
如您所见,我可以使用“行项目”中的数据,例如“数量”、“sku”节点,但如何使用“订单”中的数据,我的意思是“总价”节点

对不起,如果我这样做了,你会感到困惑


提前非常感谢您……

从代码的第一眼就可以看出。。您可以通过以下方式访问“总价”节点:

$order = $dom->getElementsByTagName('order');

foreach($order as $get){

    foreach($get->childNodes as $child) {
        if ($child->localName == 'total-price') {
        var_dump($child->textContent); // this will get your total-price :)
        }
    }
顺便说一下。。如果从订单节点开始,效果会更好……)我希望我回答了你的问题。我在本地测试它,所以它应该可以工作

更新:

更容易从我的职位以上

$order = $dom->getElementsByTagName('order');

foreach($order as $get){
    $total = $get->getElementsByTagName( "total-price" );
    var_dump($total->item(0)->nodeValue);
}

从代码的第一眼看。。您可以通过以下方式访问“总价”节点:

$order = $dom->getElementsByTagName('order');

foreach($order as $get){

    foreach($get->childNodes as $child) {
        if ($child->localName == 'total-price') {
        var_dump($child->textContent); // this will get your total-price :)
        }
    }
顺便说一下。。如果从订单节点开始,效果会更好……)我希望我回答了你的问题。我在本地测试它,所以它应该可以工作

更新:

更容易从我的职位以上

$order = $dom->getElementsByTagName('order');

foreach($order as $get){
    $total = $get->getElementsByTagName( "total-price" );
    var_dump($total->item(0)->nodeValue);
}

以下是解决问题的步骤,您需要创建两个文件

1) iTunesAPI的包装文件,如“tune.php”

2) 文件格式检索结果“从\u api.php获取\u结果”

步骤1:获取Api url

确保您的iTunesAPI正常工作

例如

在这里输入代码

$authentic_api = $this->endpointurl . '?api_key=' . $this->api_key . '&method=' . 'aj.jobs.search' . '&keywords=' . $this->keywords . '&location=' . $this->location. '&perpage=' . $this->perpage ;

echo $authentic_api;

OUTPUT:

http://www.authenticjobs.com/api/?api_key=3fb9a030d223ac8bb06eb07fea846182&method=aj.jobs.search&keywords=&location=&perpage=100
在“新建”选项卡中检查输出api,确保它以XML格式或HTML格式显示结果

步骤2:将api结果存储为XML或HTML格式,反之亦然

e、 g

步骤3:解析xml或html结果解析结果以获取所选数据。并将其存储在数组中,并将值返回到“get_result_from_api.php”

第4步:使用foreach循环打印输出,您需要打印从包装器类获得的结果

**e.g for your xml results**

foreach($results as $result)
      {
        echo 'Currency : '.$result['currency'].'<br />';
        echo 'Email : '.$result['email'].'<br />';
        echo 'financial-status : '.$result['financial-status'].'<br />'; 
        //And all the other elements by it's tag name..
      } 
**例如,用于xml结果**
foreach($results作为$result)
{
回显“货币:”.$result[“货币”]。
; 回显“Email:”.$result['Email']。
; 回显“财务状况:”.$result[“财务状况”]。
; //以及所有其他元素的标签名。。 }
希望这些东西能帮助你


因为“希望是美好的,可能是最好的,美好的事物永不消逝!”

以下是解决问题的步骤,您需要制作两个文件

1) iTunesAPI的包装文件,如“tune.php”

2) 文件格式检索结果“从\u api.php获取\u结果”

步骤1:获取Api url

确保您的iTunesAPI正常工作

例如

在这里输入代码

$authentic_api = $this->endpointurl . '?api_key=' . $this->api_key . '&method=' . 'aj.jobs.search' . '&keywords=' . $this->keywords . '&location=' . $this->location. '&perpage=' . $this->perpage ;

echo $authentic_api;

OUTPUT:

http://www.authenticjobs.com/api/?api_key=3fb9a030d223ac8bb06eb07fea846182&method=aj.jobs.search&keywords=&location=&perpage=100
在“新建”选项卡中检查输出api,确保它以XML格式或HTML格式显示结果

步骤2:将api结果存储为XML或HTML格式,反之亦然

e、 g

步骤3:解析xml或html结果解析结果以获取所选数据。并将其存储在数组中,并将值返回到“get_result_from_api.php”

第4步:使用foreach循环打印输出,您需要打印从包装器类获得的结果

**e.g for your xml results**

foreach($results as $result)
      {
        echo 'Currency : '.$result['currency'].'<br />';
        echo 'Email : '.$result['email'].'<br />';
        echo 'financial-status : '.$result['financial-status'].'<br />'; 
        //And all the other elements by it's tag name..
      } 
**例如,用于xml结果**
foreach($results作为$result)
{
回显“货币:”.$result[“货币”]。
; 回显“Email:”.$result['Email']。
; 回显“财务状况:”.$result[“财务状况”]。
; //以及所有其他元素的标签名。。 }
希望这些东西能帮助你

因为“希望是好东西,可能是最好的东西,美好的东西永不消逝!”

它更容易使用它更容易使用