在PHP中使用GCM向iOS发送远程推送通知时InternalServerError的结果

前端之家收集整理的这篇文章主要介绍了在PHP中使用GCM向iOS发送远程推送通知时InternalServerError的结果前端之家小编觉得挺不错的,现在分享给大家,也给大家做个参考。
我尝试在我的应用程序中为iOS实施Google Cloud Messaging(GCM).我尝试了pod GcmExample Xcode Project上提供的代码并编写了一个 PHP脚本,它将通过 PHP cURL发送请求.

我的PHP代码如下:

gcmPush(
    "kU6GAbdQEg0:APA91bGSF42WITzubJ9lwQ2qUqL4ETtZfQEOthazc4tP1CRhxx8tKSRChwgtFK37-kt7RjG2P_Ncj2bDOONpPVsYkjxCNi3NDhMNWSkJ7pnlR83jdbMJfOKlD1CPXCgAvZjbwpzdeiTa","This is only a test from GCM for iOS.","PHP test"
    );

function gcmPush($GCM_regID,$message,$title) {

    $GOOGLE_API_KEY = "AIzaSyAd8pw7_J8i-FPswnhUMkFCDHtufSCFFTc";
    $url = 'https://android.googleapis.com/gcm/send';

    $fields = array(
        'to' => $GCM_regID,'notification' => array(
            'sound' => 'default','badge' => '1','body' => $message,'title' => $title
        )
    );

    $headers = array(
        'Authorization: key=' . $GOOGLE_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_POSTFIELDS,json_encode($fields));

    $result = curl_exec($ch);
    echo "\r\n";
    if ($result === FALSE) {
        die('Failed: ' . curl_error($ch) . "\r\n");
    } else {

        echo "Success\r\n";   
    }

    curl_close($ch);
}

请求成功,但Google GCM服务器的结果包含以下内容

{"multicast_id":6164898138439370127,"success":0,"failure":1,"canonical_ids":0,"results":[{"error":"InternalServerError"}]}

Google API密钥有什么问题吗?
我尝试使用此脚本将远程通知发送到GcmExample.xcworkspace并且它有效.
我想知道如何解决这个问题.

如果您在GCM for iOS中遇到此错误消息{“error”:“InternalServerError”},请确保您在Google Developer Console中上传了正确的P12证书.并确保为签名证书正确设置了配置文件,并按如下所示进行以下设置:

>发展:

@{kGGLInstanceIDRegisterAPNSOption:deviceToken,kGGLInstanceIDAPNSServerTypeSandBoxOption:@YES};

>生产/分销:

@{kGGLInstanceIDRegisterAPNSOption:deviceToken,kGGLInstanceIDAPNSServerTypeSandBoxOption:@NO};

原文链接:https://www.f2er.com/php/130717.html

猜你在找的PHP相关文章