Отправить push-уведомление, когда заказ был назначен пользователю с люменом oneSignal - PullRequest
0 голосов
/ 09 апреля 2019

мне нужна помощь, когда я назначаю заказ конкретному пользователю, мне нужно отправить ему push-уведомление, чтобы уведомить о наличии заказа на его странице заказов, все хорошо, когда назначить заказ, но это не отправляет pushниже я показываю свой код моего Контроллера, разработанного в Lumen Laravel, в основном мне нужно, чтобы при обновлении статуса заказа отправлял уведомление на пользовательское устройство.Спасибо

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");
}
...