【问题标题】:ApnsPHP - Getting error while sending Push NotificationApnsPHP - 发送推送通知时出错
【发布时间】:2013-04-18 11:07:25
【问题描述】:

我集成了推送通知库来发送推送通知。当我在本地机器上对其进行测试时,它运行良好,但是当我将库示例代码上传到实时服务器时,它抛出了错误,我将响应粘贴在下面...我发现整个响应中的真正错误是 --> 'ERROR :无法发送消息 ID 1:缺少有效负载 (4)'。我需要帮助来解决这个问题。

Thu, 18 Apr 2013 12:58:29 +0200 ApnsPHP[17833]: INFO: Trying ssl://gateway.sandbox.push.apple.com:2195... 
Thu, 18 Apr 2013 12:58:30 +0200 ApnsPHP[17833]: INFO: Connected to ssl://gateway.sandbox.push.apple.com:2195.
Thu, 18 Apr 2013 12:58:30 +0200 ApnsPHP[17833]: INFO: Sending messages queue, run #1: 1 message(s) left in queue. 
Thu, 18 Apr 2013 12:58:30 +0200 ApnsPHP[17833]: STATUS: Sending message ID 1 [custom identifier: Message-Badge-33] (1/3): 45 bytes. 
Thu, 18 Apr 2013 12:58:30 +0200 ApnsPHP[17833]: ERROR: Unable to send message ID 1: Missing payload (4). 
Thu, 18 Apr 2013 12:58:30 +0200 ApnsPHP[17833]: INFO: Disconnected. Thu, 18 Apr 2013 12:58:30 +0200 ApnsPHP[17833]: INFO: Trying ssl://gateway.sandbox.push.apple.com:2195... 
Thu, 18 Apr 2013 12:58:30 +0200 ApnsPHP[17833]: INFO: Connected to ssl://gateway.sandbox.push.apple.com:2195. 
Thu, 18 Apr 2013 12:58:30 +0200 ApnsPHP[17833]: INFO: Sending messages queue, run #2: 1 message(s) left in queue. 
Thu, 18 Apr 2013 12:58:30 +0200 ApnsPHP[17833]: WARNING: Message ID 1 [custom identifier: Message-Badge-33] has an unrecoverable error (4), removing from queue without retrying... 
Thu, 18 Apr 2013 12:58:31 +0200 ApnsPHP[17833]: INFO: Disconnected. 

.

array(1) { [1]=> array(3) 
{ 
   ["MESSAGE"]=> object(ApnsPHP_Message)#3 (9) 
   { 
    ["_bAutoAdjustLongPayload:protected"]=> bool(true) ["_aDeviceTokens:protected"]=> array(1)
    { 
      [0]=> string(64) "FB7B2A31F06532EAD2973C1512A27A4F48FE22D9AFB9EE9F33B566B73A768935" 
    } 
   ["_sText:protected"]=> string(26) "Hello APNs-enabled device!" ["_nBadge:protected"]=> int(3) ["_sSound:protected"]=> string(7) "default" ["_bContentAvailable:protected"]=> NULL ["_aCustomProperties:protected"]=> array(2) 
  { 
    ["acme2"]=> array(2) { [0]=> string(4) "bang" [1]=> string(4) "whiz" } 
    ["acme3"]=> array(2) { [0]=> string(4) "bing" [1]=> string(4) "bong" } 
  }
  ["_nExpiryValue:protected"]=> int(30) ["_mCustomIdentifier:protected"]=> string(16) "Message-Badge-33" 
   } 
  ["BINARY_NOTIFICATION"]=> string(45) "QoÑô û{*1ðe2êÒ—<¢zOHþ"Ù¯¹îŸ3µf·:v‰5" ["ERRORS"]=> array(1) { [0]=> array(5) { ["command"]=> int(8) ["statusCode"]=> int(4) ["identifier"]=> int(1) ["time"]=> int(1366282710) ["statusMessage"]=> string(15) "Missing payload" 
   }
  }
 }
} 

提前致谢

PS:google 群里也有人发过同样的问题,但是没有解决办法。

【问题讨论】:

  • 感谢@Deanna 修复格式...@Dave 你知道这个错误吗?

标签: php ios apple-push-notifications apns-php


【解决方案1】:

经过一天的测试,我找到了问题所在:json_encode 函数采用 5.3 PHP 版本的第二个参数“options”: http://php.net/manual/en/function.json-encode.php

本地我有 PHP V5.3.x,所以代码在 json_encode 函数中使用第二个参数可以正常工作。但是在实时服务器上,PHP 版本是 5.2.6,因此 json_encode 代码中的第二个参数会导致问题并抛出“Missing Payload”错误。我刚刚删除了第二个参数,它对我来说很好:)

【讨论】:

  • 幸运的是,我在调查同一错误后的十分钟内就找到了您的答案。感谢您回答您的问题!对我来说完全一样的问题。
  • 遇到了同样的问题,而且效果很好。干杯!
  • 请注意,实际上 apns-php 明确要求 php >= 5.3。
猜你喜欢
  • 2015-07-11
  • 2020-11-20
  • 1970-01-01
  • 1970-01-01
  • 2018-09-22
  • 2012-12-23
  • 2014-03-27
  • 2018-02-17
  • 2019-08-30
相关资源
最近更新 更多