最近推播遇到一個問題
同一組API_KEY跟同一組RID
有時連續發送會有一部分成功送出
但也有一部分會呈現失敗
失敗原因會顯示
string(147) "<HTML>
<HEAD>
<TITLE>Unauthorized</TITLE>
</HEAD>
<BODY BGCOLOR="#FFFFFF" TEXT="#000000">
<H1>Unauthorized</H1>
<H2>Error 401</H2>
</BODY>
</HTML>
這訊息是說API KEY不正確
是常態問題?還是程式問題??
完整程式如下
>>>>>前面參數略過
$message = array("message" => $message);
$url = 'https://android.googleapis.com/gcm/send';
$json = array(
'registration_ids' => $registatoin_ids,
'data' => $message,
);
$headers = array(
'Authorization: key=' . $API_KEY,
'Content-Type: application/json'
);
$curl = curl_init();
curl_setopt($curl, CURLOPT_URL, $url);
curl_setopt($curl, CURLOPT_POST, true);
curl_setopt($curl, CURLOPT_HTTPHEADER, $headers);
curl_setopt($curl, CURLOPT_RETURNTRANSFER, true); //忽略SSL驗證
curl_setopt($curl, CURLOPT_SSL_VERIFYPEER, false);
curl_setopt($curl, CURLOPT_POSTFIELDS, json_encode($json));
$result = curl_exec($curl);
curl_close($curl);
跪求高手們指導指導小弟,感恩