我正在使用PHP创建Shopify应用程序。当有人卸载应用程序时,我想从数据库中删除商店信息。我已经找到了这段代码,但是我不知道从商店中卸载应用程序时该添加到哪里以及如何触发它。
$webhook_delete = [
'webhook' =>
[
'topic' => 'app/uninstalled',
'address' => 'https://icodebreakers.us/shopifyapp/delete_store_info.php?shop=' . $shop_url . '',
'format' => 'json',
],
];
$result = $shopify('POST /admin/webhooks.json', $webhook_delete);
答案 0 :(得分:0)
您在Webhook订阅创建代码中共享的代码。安装应用程序后,您需要在Shopify中创建此Webhook订阅。现在,在卸载应用程序后完成此操作,您将在Webhook订阅地址中提到的URL中收到通知。您可以验证请求并执行所需的任何任务。
答案 1 :(得分:0)
如果您使用ngrok,我相信它会在控制台中显示,这在您卸载应用程序时显示:
POST / abc /您的文件200确定
如果您认为已创建Webhook。在delete_store_info.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,然后获取用于存储在db中的信息。杰森通常看起来像
{
"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"
]
}
不需要?shop =,因为Shopify已经发送了您的信息。