PHP警告:pack():类型H:非法的十六进制数字r错误

时间:2012-12-16 22:14:37

标签: php binary runtime-error apple-push-notifications devicetoken

  

可能重复:
  pack() in php. Illegal hex digit warning

我正在使用apple的推送通知服务,为了发送通知,您必须以二进制格式构建消息。我在下面的行中遇到以下错误:

  

警告:pack():输入H:非法的十六进制数字r

     

警告:pack():输入H:非法的十六进制数字y

     

注意:第130行的C:\ xampp \ htdocs \ firecom \ FireComAPNS.php中的数组到字符串转换

以下是抛出错误的代码行:

$msg = chr(0).pack('n', 32).pack('H*', $devicetoken).pack('n',strlen($payload)) . $payload;

$devicetoken=773f5436825a7115417d3d1e036da20e806efeef547b7c3fe4da724d97c01b30

我在互联网上搜索了很多,但我不知道如何搞乱二进制文件,任何对正在发生的事情的帮助都会非常感激!

1 个答案:

答案 0 :(得分:0)

为php<尝试此功能5.4.0

function hex2bin($hexdata) {
   $bindata="";
   for ($i=0;$i<strlen($hexdata);$i+=2) {
      $bindata.=chr(hexdec(substr($hexdata,$i,2)));
   }

   return $bindata;
}