提交查询后发送FCM通知

时间:2018-03-03 16:08:05

标签: php

我想在查询和FCM代码下面成功执行查询后发送Firebase通知。提前谢谢。

PHP查询

$query = mysqli_query($con, "insert into Patient_orders (patient_Phone, doctorname, doctorphone, patientname, nickname) VALUES ('$patientphone', '$doctorname', '$doctorphone','$patientname','$nickname')");

if($query){
    $response["success"]=1;
    echo json_encode($response);

如何将包含上述代码的通知代码放在一个查询中

define( 'API_ACCESS_KEY', '*****' ); // get this KEY from google

$registrationIds = array( $_GET['id'] ); // if u using GET-POST method 

$msg = array(
        'message'   => 'here is a message. message',
        'title'     => 'This is a title. title',
        'subtitle'  => 'This is a subtitle. subtitle',
        'vibrate'   => 1,
        'sound'     => 1,
        'largeIcon' => 'large_icon',
        'smallIcon' => 'small_icon'
    );


$fields = array(
        'to'   => '/topics/news',
        'data' => $msg
    );

$headers = array(
        'Authorization: key=' . API_ACCESS_KEY,
        'Content-Type: application/json'
    );

$ch = curl_init();
curl_setopt( $ch,CURLOPT_URL, 'https://fcm.googleapis.com/fcm/send' );
curl_setopt( $ch,CURLOPT_POST, true );
curl_setopt( $ch,CURLOPT_HTTPHEADER, $headers );
curl_setopt( $ch,CURLOPT_RETURNTRANSFER, true );
curl_setopt( $ch,CURLOPT_SSL_VERIFYPEER, false );
curl_setopt( $ch,CURLOPT_POSTFIELDS, json_encode( $fields ) );
$result = curl_exec($ch );
curl_close( $ch );
echo $result;

0 个答案:

没有答案