我在php中有这个功能,当对该功能有动作时,它会向App A和App B发送2个通知。 但是,我只会在一个APP中收到1个通知。 我正在使用apnsphp来推送通知。
以下是我的情况: 我有一个2应用程序:应用程序A和应用程序B. 这两个应用程序都使用不同的apns证书。
是否有可能出现apns cert缓存?
场景1) 使用APP A& A登录到IPAD时同时使用APP B登录到IPAD,收到APP A的推送通知,而不是APP B。
场景2) 使用APP A登录IPAD并使用APP B登录iPhone(单独设备)时,收到APP A的推送通知,而不是APP B。
场景3) 当使用APP A从iPad登录到OUT并使用APP B登录到iPad(同一设备)或iPhone(单独设备)时,会收到推送通知App B.
我从apnsphp收到此错误:
["ERRORS"]=> array(2) {
[0]=>
array(3) {
["identifier"]=> int(1)
["statusCode"]=> int(999)
["statusMessage"]=> string(53) "Internal error (0 bytes written instead of 223 bytes)"
}
[1]=>
array(5) {
["command"]=> int(8)
["statusCode"]=> int(8)
["identifier"]=> int(1)
["time"]=> int(1415012295)
["statusMessage"]=> string(13) "Invalid token"
}
}
以下是日志:
Tue, 04 Nov 2014 10:02:25 +0800 ApnsPHP[4136]: INFO: Trying tls://gateway.push.apple.com:2195...
Tue, 04 Nov 2014 10:02:26 +0800 ApnsPHP[4136]: INFO: Connected to
tls://gateway.push.apple.com:2195. Tue, 04 Nov 2014 10:02:26 +0800 ApnsPHP[4136]: INFO: Sending
messages queue, run #1: 1 message(s) left in queue. Tue, 04 Nov 2014 10:02:26 +0800
ApnsPHP[4136]: STATUS: Sending message ID 1 [custom identifier: CakeApns] (1/3): 166 bytes. Tue,
04 Nov 2014 10:02:27 +0800 ApnsPHP[4136]: INFO: Disconnected.
Tue, 04 Nov 2014 10:02:27 +0800 ApnsPHP[4136]: INFO: Sending messages queue, run #1: 1 message(s)
left in queue. Tue, 04 Nov 2014
10:02:27 +0800 ApnsPHP[4136]: STATUS: Sending message ID 1 [custom identifier: CakeApns] (1/3):
221 bytes. Tue, 04 Nov 2014 10:02:27 +0800 ApnsPHP[4136]: ERROR: Unable to send message ID 1:
Internal error (0 bytes written instead of 221 bytes) (999). Tue, 04 Nov 2014 10:02:27 +0800
ApnsPHP[4136]: INFO: Trying tls://gateway.push.apple.com:2195... Tue, 04 Nov 2014 10:02:28 +0800
ApnsPHP[4136]: INFO: Connected to tls://gateway.push.apple.com:2195. Tue, 04 Nov 2014 10:02:28
+0800 ApnsPHP[4136]: INFO: Sending messages queue, run #2: 1 message(s) left in queue. Tue, 04
Nov 2014 10:02:28 +0800 ApnsPHP[4136]: STATUS: Sending message ID 1 [custom identifier: CakeApns]
(2/3): 221 bytes. Tue, 04 Nov 2014 10:02:28 +0800 ApnsPHP[4136]: ERROR: Unable to send message ID
1: Invalid token (8). Tue, 04 Nov 2014 10:02:28 +0800 ApnsPHP[4136]: INFO: Disconnected. Tue, 04
Nov 2014 10:02:28 +0800 ApnsPHP[4136]: INFO: Trying tls://gateway.push.apple.com:2195... Tue, 04
Nov 2014 10:02:29 +0800 ApnsPHP[4136]: INFO: Connected to tls://gateway.push.apple.com:2195. Tue,
04 Nov 2014 10:02:29 +0800 ApnsPHP[4136]: INFO: Sending messages queue, run #3: 1 message(s) left
in queue. Tue, 04 Nov 2014 10:02:29 +0800 ApnsPHP[4136]: WARNING: Message ID 1 [custom
identifier: CakeApns] has an unrecoverable error (8), removing from queue without retrying...
Tue, 04 Nov 2014 10:02:30 +0800 ApnsPHP[4136]: INFO: Disconnected.
答案 0 :(得分:0)
我通过编辑ApnsComponent文件来解决它。
我添加了一个新的公共变量:previousData 该变量将存储它所连接的当前combined_cert_path。当我切换我的证书路径时,我将检查证书路径是否与我连接的证书路径相同。如果不一样,我会重新连接到apns。如果它是相同的路径,我将返回true。
检查是为了防止服务器重新连接并增加发送时间。
private function __connect() {
if($this->previousData == ""){
$this->previousData = $this->combined_cert_path;
$this->__push = new ApnsPHP_Push($this->env, $this->combined_cert_path);
$this->__push->setProviderCertificatePassphrase($this->cert_passphrase);
$logger = new ApnsPHP_Log_Custom(!$this->__logEnabled);
$this->__push->setLogger($logger);
//$this->__push->setSendRetryTimes($this->__sendRetryTimes);
$this->__push->connect();
return $this->__logError();
}
else if($this->previousData != $this->combined_cert_path){
$this->previousData = $this->combined_cert_path;
$this->__push = new ApnsPHP_Push($this->env, $this->combined_cert_path);
$this->__push->setProviderCertificatePassphrase($this->cert_passphrase);
$logger = new ApnsPHP_Log_Custom(!$this->__logEnabled);
$this->__push->setLogger($logger);
//$this->__push->setSendRetryTimes($this->__sendRetryTimes);
$this->__push->connect();
return $this->__logError();
}else{
return true;
}
}