0

我正在编写 php 代码以向多个 iphone 设备发送推送通知。当我执行 php 代码时,我在下面的行中收到警告消息

$apnsMessage = chr(0) . chr(0) . chr(32) . pack('H*', str_replace(' ', '', $deviceToken)) . chr(0) . chr(strlen($payload)) . $payload;

喜欢

Warning: pack() [function.pack]: Type H: illegal hex digit in /myapp.com/pushgrams/pushtest.php on line 39

谁能告诉我如何解决这个问题?

4

1 回答 1

0

这是您为 Apple 推送通知打包的方式:

// APNs packet prepare
function pck($token, $notification, $msg_id = 0, $expiration = 604800) {
  $token = str_replace(" ", "", $token);
  $pck  = pack('CNNnH*', 1, $msg_id, $expiration > 0 ? time() + $expiration : 0, strlen($token) / 2, $token) . 
          pack('n', strlen($notification)) . $notification;

  return $pck;
}

这是您准备通知的方式:

$m = '{"aps":{"alert":"' . $msg. '","sound":"default"},"acme2":["bang","whiz"],"acme3":["bing","bong"]}';
$p  = pck($k, $m);
于 2013-12-02T18:34:10.853 回答