0

我用 PHP 创建了一个 shopify 应用程序。并为“app/uninstalled”注册了一个 webhook。这将从我的数据库中删除数据。

但是当我删除这个应用程序时,webhook 没有触发。因为商店没有从我的数据库中删除。

这是我的代码:

`POST /admin/webhooks.json
'webhook'  => array(
    "topic" => "app/uninstalled",
    "address" => "https://my-domain/apps/app-name/uninstall.php",
    "format" => 'json',
 ),`

谁能告诉我问题是什么以及我需要编辑哪些内容?

我已经尝试了很长时间,但现在我被困住了......

4

2 回答 2

0

如果您认为 webhook 已创建。放入这https://my-domain/apps/app-name/uninstall.php行代码

$webhook = file_get_contents('php://input');
$webhook = json_decode($webhook, TRUE);
$newFileName = "something.txt";
file_put_contents($newFileName, $webhook);

当您卸载应用程序并将其放入文件 something.txt 后,它将捕获 json shopify 发送,然后获取您要存储的信息。Json 通常看起来像

{
  "id": 690933842,
  "name": "Super Toys",
  "email": "super@supertoys.com",
  "domain": "super.myshopify.com",
  "province": "Tennessee",
  "country": "US",
  "address1": "190 MacLaren Street",
  "zip": "37178",
  "city": "Houston",
  "source": null,
  "phone": "3213213210",
  "latitude": null,
  "longitude": null,
  "primary_locale": "en",
  "address2": null,
  "created_at": null,
  "updated_at": null,
  "country_code": "US",
  "country_name": "United States",
  "currency": "USD",
  "customer_email": "super@supertoys.com",
  "timezone": "(GMT-05:00) Eastern Time (US & Canada)",
  "iana_timezone": null,
  "shop_owner": "Steve Jobs",
  "money_format": "$",
  "money_with_currency_format": "$ USD",
  "weight_unit": "kg",
  "province_code": "TN",
  "taxes_included": null,
  "tax_shipping": null,
  "county_taxes": null,
  "plan_display_name": "Shopify Plus",
  "plan_name": "enterprise",
  "has_discounts": true,
  "has_gift_cards": true,
  "myshopify_domain": null,
  "google_apps_domain": null,
  "google_apps_login_enabled": null,
  "money_in_emails_format": "$",
  "money_with_currency_in_emails_format": "$ USD",
  "eligible_for_payments": true,
  "requires_extra_payments_agreement": false,
  "password_enabled": null,
  "has_storefront": true,
  "eligible_for_card_reader_giveaway": false,
  "finances": true,
  "primary_location_id": 905684977,
  "checkout_api_supported": true,
  "multi_location_enabled": false,
  "setup_required": false,
  "force_ssl": false,
  "pre_launch_enabled": false,
  "enabled_presentment_currencies": [
    "USD"
  ]
}
于 2019-07-24T03:37:04.720 回答
0

尝试使用异常处理:-

<?php 
try
{
	$webhook_delete = array(
	'webhook' =>
	     array(
		'topic' => 'app/uninstalled',
		'address' => 'https://your-domain/app/delhook.php?shop=shop-name',
		'format' => 'json'
	     )
        );
        $result = $shopify('POST /admin/webhooks.json',$webhook_delete);
}
catch (shopify\ApiException $e)
{
      # HTTP status code was >= 400 or response contained the key 'errors'
	echo $e;
	print_r($e->getRequest());
	print_r($e->getResponse());
}
catch (shopify\CurlException $e)
{
      # cURL error
	echo $e;
	print_r($e->getRequest());
	print_r($e->getResponse());
}

您可以在链接中传递带有地址的商店名称,并且可以在 delhook.php 或您的文件上获取。

Delhook.php

if(isset($_REQUEST['shop'])) { 
  //here you can remove store from your database.
}

如果您收到任何错误,那么它将打印错误。

于 2018-01-29T11:54:19.430 回答