使用php在gcm中不匹配发件人ID

时间:2016-02-04 18:03:51

标签: php google-cloud-messaging

我收到mismatch senderid错误。

gcm中,我将发件人ID重复检查为客户端应用项目ID和api_key。

我的代码是,

    $ids = array( 'APA91bFDc......._p' );
    $data = array( 'message' => 'Hello World!' );
    $apiKey = 'AIzaSyA0_CFcI.........saGySJBE';
    $url = 'https://gcm-http.googleapis.com/gcm/send';
    $sender_id = '1063000000016';

    $post = array(
                    'registration_ids'  => $ids,
                    'data'              => $data,
                    );

    $headers = array( 
                        'Authorization: key=' . $apiKey,
                        'Sender: id=' .$sender_id,
                        '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, json_encode( $post ) );

    $result = curl_exec( $ch );

    if ( curl_errno( $ch ) )
    {
        echo 'GCM error: ' . curl_error( $ch );
    }

    curl_close( $ch );     
    echo $result;

我的回答是

 {"multicast_id":7107329859481637548,"success":0,"failure":1,"canonical_ids":0,"results":[{"error":"MismatchSenderId"}]}

为什么我要面对这个问题?

我提到过以前的问题,比如 GCM Sender Id MismatchAndroid C2DM sender idUnique SMS sender id?

修改

我刚刚将自己的发件人ID添加到标头中。在哪里提到发件人ID以及如何在php中提及

0 个答案:

没有答案