首頁 >後端開發 >php教程 >极光推送按照官网例子写的demo报错"Response timeout"但手机客户端还是能收到推送消息,而且是多条?

极光推送按照官网例子写的demo报错"Response timeout"但手机客户端还是能收到推送消息,而且是多条?

WBOY
WBOY原創
2016-06-06 20:09:301117瀏覽

<code><?php require_once 'vendor/autoload.php';

use JPush\Model as M;
use JPush\JPushClient;
use JPush\Exception\APIConnectionException;
use JPush\Exception\APIRequestException;

// date_default_timezone_set(PRC); 
date_default_timezone_set("Asia/Shanghai");
$app_key='10310527ba9fce07c22bc849';
$master_secret='fa3bf270631e1a688281efbe';
// echo "<p>start";
$br = '<br>';
$client = new JPushClient($app_key, $master_secret);

$tname="TestTeacherAqq_com";
$day="2016-1-12 11:01:02";
$oid="123424";
$result = $client->push()
        ->setPlatform(M\all)
        ->setAudience(M\audience(M\alias(array($tname)))) 
        ->setNotification(M\notification("Linghaowan.The appointment at".$day." has finished. #".$oid))
        ->send();
// echo 'Push Success.' . $br;
// echo 'sendno : ' . $result->sendno . $br;
// echo 'msg_id : ' .$result->msg_id . $br;
// echo 'Response JSON : ' . $result->json . $br;

 ?></code>

后端只发一次,但手机端会接收到多达4条,浏览器上还会报错

<code>Fatal error: Uncaught exception 'JPush\Exception\APIConnectionException' with message 'Response timeout. Your request has probably be received by JPUsh Server,please check that whether need to be pushed again</code>

回复内容:

<code><?php require_once 'vendor/autoload.php';

use JPush\Model as M;
use JPush\JPushClient;
use JPush\Exception\APIConnectionException;
use JPush\Exception\APIRequestException;

// date_default_timezone_set(PRC); 
date_default_timezone_set("Asia/Shanghai");
$app_key='10310527ba9fce07c22bc849';
$master_secret='fa3bf270631e1a688281efbe';
// echo "<p>start";
$br = '<br>';
$client = new JPushClient($app_key, $master_secret);

$tname="TestTeacherAqq_com";
$day="2016-1-12 11:01:02";
$oid="123424";
$result = $client->push()
        ->setPlatform(M\all)
        ->setAudience(M\audience(M\alias(array($tname)))) 
        ->setNotification(M\notification("Linghaowan.The appointment at".$day." has finished. #".$oid))
        ->send();
// echo 'Push Success.' . $br;
// echo 'sendno : ' . $result->sendno . $br;
// echo 'msg_id : ' .$result->msg_id . $br;
// echo 'Response JSON : ' . $result->json . $br;

 ?></code>

后端只发一次,但手机端会接收到多达4条,浏览器上还会报错

<code>Fatal error: Uncaught exception 'JPush\Exception\APIConnectionException' with message 'Response timeout. Your request has probably be received by JPUsh Server,please check that whether need to be pushed again</code>

是网络延迟问题,可以把 SDK 中的 CONNECT_TIMEOUT 设置的长一些(10秒)就好了。

另外建议升级成最新的 SDK,新版的接口比老的好用很多!

陳述:
本文內容由網友自願投稿,版權歸原作者所有。本站不承擔相應的法律責任。如發現涉嫌抄襲或侵權的內容,請聯絡admin@php.cn