第七色在线视频,2021少妇久久久久久久久久,亚洲欧洲精品成人久久av18,亚洲国产精品特色大片观看完整版,孙宇晨将参加特朗普的晚宴

為了賬號(hào)安全,請(qǐng)及時(shí)綁定郵箱和手機(jī)立即綁定
已解決430363個(gè)問題,去搜搜看,總會(huì)有你想問的

使用 php 發(fā)送 fcm 通知和消息

使用 php 發(fā)送 fcm 通知和消息

PHP
慕勒3428872 2022-11-04 16:40:28
我正在努力使用 react-native-firebase 實(shí)現(xiàn)通知onNotification 函數(shù)根本沒有被調(diào)用,所以我?guī)缀醑偭?。但我認(rèn)為這可能是服務(wù)器問題。所以我要求我們的 php 后端開發(fā)人員給我與 fcm 通知相關(guān)的服務(wù)器代碼。我認(rèn)為他似乎只發(fā)送消息而不是通知。如果是對(duì)的,我怎么能告訴他修復(fù)這個(gè)功能。如果不是,我不知道該怎么辦了..請(qǐng)幫助我了解這方面的知識(shí)!感謝你們!function sendFCM($notif_array, $id) {    $API_KEY = "api_key";    $url = 'https://fcm.googleapis.com/fcm/send';    $fields = array (            'registration_ids' => array (                    $id            ),            // 'data' => array (            //         "message" => $message,            //         "type" => $notif_type            // )            'content_available'=>true,            'priority'=>'high',            'data' => $notif_array    );    $fields = json_encode ( $fields );    $headers = array (            'Authorization: key=' . $API_KEY,            'Content-Type: application/json'    );    $ch = curl_init ();    curl_setopt ( $ch, CURLOPT_URL, $url );    curl_setopt ( $ch, CURLOPT_POST, true );    curl_setopt ( $ch, CURLOPT_HTTPHEADER, $headers );    curl_setopt ( $ch, CURLOPT_RETURNTRANSFER, true );    curl_setopt ( $ch, CURLOPT_POSTFIELDS, $fields );    $result = curl_exec ( $ch );    echo $result;    curl_close ( $ch );}
查看完整描述

1 回答

?
楊魅力

TA貢獻(xiàn)1811條經(jīng)驗(yàn) 獲得超6個(gè)贊

您應(yīng)該在 php 端添加此代碼:


function sendFCM($notif_array, $id) {

    $API_KEY = "api_key";

    $url = 'https://fcm.googleapis.com/fcm/send';

    $message = [

        'body'              =>  'Hello, This is a notification.',

        'title'             => 'Your Title',

        'notification_type' =>  'Test'

    ];


    $notification = [

        'body' => 'Hello, This is a notification.',

        'title' => 'Your Title',


    ];

    $fields = array (

        'registration_ids' => array (

                $id

        ),

        'notification'      => $notification,

        'data'              => $message,

        'priority'          => 'high',            

    );

    $fields = json_encode ( $fields );

    $headers = array (

        'Authorization: key=' . $API_KEY,

        'Content-Type: application/json'

    );


    $ch = curl_init ();

    curl_setopt ( $ch, CURLOPT_URL, $url );

    curl_setopt ( $ch, CURLOPT_POST, true );

    curl_setopt ( $ch, CURLOPT_HTTPHEADER, $headers );

    curl_setopt ( $ch, CURLOPT_RETURNTRANSFER, true );

    curl_setopt ( $ch, CURLOPT_POSTFIELDS, $fields );


    $result = curl_exec ( $ch );


    curl_close ( $ch );

    return 'success';

}

對(duì)于IOS:


 function iospush( $id ) {

    $msg = 'Test notification';

    $host = 'gateway.push.apple.com'; /Here is ecample */

    $passphrase = YourIOSpassphrase;

    $ios_notifiaction_certificate = '/add full path where ios certiticate stay';

    try {

        $streamContext = stream_context_create();


        stream_context_set_option( $streamContext, 'ssl', 'local_cert', $ios_notifiaction_certificate );

            stream_context_set_option( $streamContext, 'ssl', 'passphrase', $passphrase);

            $apns = stream_socket_client( 'ssl://'.$host, $error, $errstr, 60, STREAM_CLIENT_CONNECT|STREAM_CLIENT_PERSISTENT, $streamContext );



        $payload[ 'aps' ] = array( 'alert' => $msg, 'badge' => '0', 'sound' => 'default', 'notification_type' =>  'Test' );


        $payload = json_encode( $payload );


        $apnsMessage = chr(0) . pack( 'n', 32 ) . pack( 'H*',  $id ) . pack( 'n', strlen( $payload ) ) . $payload;


        $fwriteRes = fwrite( $apns, $apnsMessage, strlen( $apnsMessage ) );


        fclose( $apns );

        return 'Success';

    } catch( Exception  $e ) {

        return true;           

        // return $e->getMessage();

    }

}


查看完整回答
反對(duì) 回復(fù) 2022-11-04
  • 1 回答
  • 0 關(guān)注
  • 133 瀏覽

添加回答

舉報(bào)

0/150
提交
取消
微信客服

購(gòu)課補(bǔ)貼
聯(lián)系客服咨詢優(yōu)惠詳情

幫助反饋 APP下載

慕課網(wǎng)APP
您的移動(dòng)學(xué)習(xí)伙伴

公眾號(hào)

掃描二維碼
關(guān)注慕課網(wǎng)微信公眾號(hào)