我正在安装一个Webhook,当他们添加新的administrators
时会通知customers
。
文档在Ruby中,但是我正在laravel中尝试这样做。
这就是我所做的:
CustomerInstallShopifyWebhook
web.php
中添加了该地址的路线现在,当我添加customer
时,仍然没有收到通知。
我的工作分配正确了吗?
CustomerInstallShopifyWebhook
class CustomerInstallShopifyWebhook implements ShouldQueue
{
use Dispatchable, InteractsWithQueue, Queueable, SerializesModels;
public $domain;
public $token;
public $store;
public function __construct($domain, $token, \App\Store $store)
{
$this->domain = $domain;
$this->token = $token;
$this->store = $store;
}
public function handle()
{
//
$shopify = \Shopify::retrieve($this->domain, $this->token);
$customerCreate = array
(
'webhook'=>array
(
'topic'=> 'customers/create',
'address'=> 'https://shopify.com/webhook/shopify/customer-created',
'format'=> 'json'
)
);
$customerCreate_webhook = $sc->call('POST', '/admin/webhooks.json', $customerCreate);
header('Content-type: application/json');
echo json_encode(array("state"=>"success", "customer_create"=>$customerCreate_webhook));
}
}
路线
Route::post('webhook/shopify/customer-created', function(\Illuminate\Http\Request $request) {
$query = "?key=**********&to=0501149794&msg=Testing Shopify App&sender_id=Shopify";
$final_uri = $baseurl.$query;
$response = file_get_contents($final_uri);
header ("Content-Type:text/xml");
})->middleware('webhook');