php.ini 中的 pack()非法十六进制数字警告
我在 php 中使用 pack() 时遇到一些问题
$currencypair = "EUR/USD";
$buy_sell = "buy";
$alert_device_token =array("a","a","b");
$message = "Your " . $currencypair . " " . $buy_sell . " alert price has been reached!";
$payload['aps'] = array (
'alert' => $message,
'badge' => 1,
'sound' => 'default'
);
$payload = json_encode($payload);
foreach ($alert_device_token as $alert_device)
{
$apnsMessage = chr(0) . chr(0) . chr(32) .
pack('H*', str_replace(' ', '', $alert_device)) .
chr(0) . chr(strlen($payload)) . $payload;
echo $apnsMessage;
}
现在有时我会在运行相同的代码时收到以下警告 -
Warning: pack() [function.pack]: Type H: illegal hex digit g in /code/FR2BVl
但非法的十六进制数字不断变化。关于此警告的任何想法以及删除它的方法。
i am having some problems using pack() in php
$currencypair = "EUR/USD";
$buy_sell = "buy";
$alert_device_token =array("a","a","b");
$message = "Your " . $currencypair . " " . $buy_sell . " alert price has been reached!";
$payload['aps'] = array (
'alert' => $message,
'badge' => 1,
'sound' => 'default'
);
$payload = json_encode($payload);
foreach ($alert_device_token as $alert_device)
{
$apnsMessage = chr(0) . chr(0) . chr(32) .
pack('H*', str_replace(' ', '', $alert_device)) .
chr(0) . chr(strlen($payload)) . $payload;
echo $apnsMessage;
}
Now sometimes i get following warnings running the same code -
Warning: pack() [function.pack]: Type H: illegal hex digit g in /code/FR2BVl
the illegal hex digit keeps varying though. Any ideas about this warning and ways to remove it.
check it live here
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(7)
pack
将十六进制数转换为二进制,例如:生成
!3
,因为!
的代码为 0x21,而3
的代码为0x33。由于g
不是十六进制数字,因此给出警告。为了对 pack 的H
格式有用,参数必须是十六进制数。如果$alert_device
不是 - 您应该使用其他东西,具体取决于它是什么以及您期望的结果。pack
converts hexadecimal number to binary, e.g.:produces
!3
, since!
has code 0x21 and3
has code 0x33. Sinceg
is not hex digit, warning is given. To be useful for pack'sH
format, the argument must be hex number. If$alert_device
isn't - you should use something else, depending on what it is and what you expect as the result.错误的原因之一与校验和有关,
要修复错误,这可能就足够了,
在这种情况下,
参考:https://github.com/bearsunday/BEAR.Package/issues/136< /a>
One of the reason for the error is related to the checksums,
To fix the error this might be sufficient,
In this case,
Ref: https://github.com/bearsunday/BEAR.Package/issues/136
我在使用 Ionic/Cordova/PhoneGap 开发混合应用程序时遇到了同样的问题。由于相同的代码在 Android 和 iOS 设备中运行,因此我犯了一个错误,将 Google FCM 令牌存储为 APNS 令牌。 APNS 令牌是纯十六进制的,但 Google FCM 令牌可以包含非十六进制字符。因此,使用 PHP 的
pack()
函数打包 Google FCM 令牌将导致非法十六进制数字
错误。I was having the same issue when developing a hybrid app using Ionic/Cordova/PhoneGap. As the same code is run in Android and iOS devices, I had made a mistake of storing Google FCM token as APNS token. The APNS token is purely hexadecimal but Google FCM token can have non-hexadecimal characters. So, packing a Google FCM token using PHP's
pack()
function will result in theillegal hex digit
error.使用 strtr(rtrim(base64_encode(pack('H*', sprintf('%u', $algo($data)))), '='), '+/', '-_')< /code> 而不是使用
pack('H*', $value)
。Use
strtr(rtrim(base64_encode(pack('H*', sprintf('%u', $algo($data)))), '='), '+/', '-_')
insted of usingpack('H*', $value)
.在本例中,
$alert_device
是一个数组。对于包装来说,它需要一个值。
使用
pack('H*', str_replace(' ', '', $alert_device[0]))
代替。In this case,
$alert_device
is an array.For packing it needs a value.
Use
pack('H*', str_replace(' ', '', $alert_device[0]))
instead.您必须更改
为
You must change
To
尝试以 utf-8 编码保存文件。
Try to save your file in utf-8 encoding.