pack() in php. Illegal hex digit warning

前端 未结 7 1735
梦如初夏
梦如初夏 2021-01-12 02:34

i am having some problems using pack() in php

$currencypair = \"EUR/USD\";
$buy_sell = \"buy\";
$alert_device_token =array(\"a\",\"a\",\"b\");
$message = \"         


        
7条回答
  •  粉色の甜心
    2021-01-12 02:44

    One of the reason for the error is related to the checksums,

    Because PHP's integer type is signed many crc32 checksums will result in negative integers on 32bit platforms. On 64bit installations all crc32() results will be positive integers though. So you need to use the "%u" formatter of sprintf() or printf() to get the string representation of the unsigned crc32() checksum in decimal format. http://www.php.net/crc32

    To fix the error this might be sufficient,

    sprintf('%u', CRC32($someString))
    

    In this case,

    pack('H*', str_replace(' ', '', sprintf('%u', CRC32($alert_device))))
    

    Ref: https://github.com/bearsunday/BEAR.Package/issues/136

提交回复
热议问题