我需要一些帮助,当我向特定用户分配订单时,我需要向他发送推送通知,以通知他的“订单”页面中有订单,分配订单时一切都很好,但它没有发送推送,在下面,我显示了我在Lumen Laravel中开发的Controller的代码,基本上,我需要在更新订单状态时向用户设备发送通知。谢谢
function sendMessage(){
$content = array(
"es" => 'THE MESSAGE'
);
$fields = array(
'app_id' => "MY-APP-ID",
'include_player_ids' => array("USER-ID"),
'contents' => $content
);
$fields = json_encode($fields);
print("\nJSON sent:\n");
print($fields);
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, "https://onesignal.com/api/v1/notifications");
curl_setopt($ch, CURLOPT_HTTPHEADER, array('Content-Type: application/json; charset=utf-8'));
curl_setopt($ch, CURLOPT_RETURNTRANSFER, TRUE);
curl_setopt($ch, CURLOPT_HEADER, FALSE);
curl_setopt($ch, CURLOPT_POST, TRUE);
curl_setopt($ch, CURLOPT_POSTFIELDS, $fields);
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, FALSE);
$response = curl_exec($ch);
curl_close($ch);
return $response;
}
public function update(Request $request)
{
$product = DB::table('tableOrders')
->where('id', $request->id)
->update(['delivery_boy_id' => $request->delivery_boy_id, 'status' => $request->status]);
return response()->json($product);
$response = sendMessage();
$return["allresponses"] = $response;
$return = json_encode( $return);
print("\n\nJSON received:\n");
print($return);
print("\n");
}