Base64编码德code字节数组 - 从的iOS APNS令牌 [英] Base64 decode byte array - APNS token from iOS

查看:280
本文介绍了Base64编码德code字节数组 - 从的iOS APNS令牌的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我收到一个设备令牌,连接codeD为Base64字节数组。输入如下:

I am receiving a device token, encoded as a base64 "byte" array. The input looks like this:

J6Kwrh15AqXKiaQminI/Eb/Mtj4nMkPhQYsROhJXmes=

有人告诉我这是一个base64连接codeD值,但使用 base64_de code 收益解码它:

string(32) "'¢°®y¥Ê‰¤&Šr?¿Ì¶>'2CáA‹:W™ë"

我发现这个脚本的某处应该被输出的实际APNS令牌:

I found this script somewhere which should be outputting the actual APNS token:

$a = base64_decode("J6Kwrh15AqXKiaQminI/Eb/Mtj4nMkPhQYsROhJXmes=");
$b = array();

foreach(str_split($a) as $c)
    $b[] = sprintf("%08b", ord($c));

exit(implode(' ', $b));

但它返回:

00100111 10100010 10110000 10101110 00011101 01111001 00000010 10100101 11001010 10001001 10100100 00100110 10001010 01110010 00111111 00010001 10111111 11001100 10110110 00111110 00100111 00110010 01000011 11100001 01000001 10001011 00010001 00111010 00010010 01010111 10011001 11101011

和我期望是这样的:

c9d4c07c fbbc26d6 ef87a44d 53e16983 1096a5d5 fd825475 56659ddd f715defc

什么是错的?

推荐答案

要生成一个十六进制,你可以使用这样的事情:

To generate a hex, you could use something like that:

$a = unpack("H*", base64_decode("J6Kwrh15AqXKiaQminI/Eb/Mtj4nMkPhQYsROhJXmes="));
print_r($a);

$ A 现在跟你十六进制的数组)

($a is now an array with you hex)

要包括你可以使用的间距

to include the spacing you could use

$a = unpack("H*hex", base64_decode("J6Kwrh15AqXKiaQminI/Eb/Mtj4nMkPhQYsROhJXmes="));
$b = str_split($a["hex"], 8);
$output = "";
foreach ($b as $current) {
    $output .= "$current ";
}
echo($output);

和最后一切都包裹成一个功能:

and finally everything wrapped into a function:

function base64_decode_apns_token($token) {
    $a = unpack("H*hex", base64_decode($token));
    $b = str_split($a["hex"], 8);
    $output = "";

    foreach ($b as $current) {
        $output .= "$current ";
    }

    return trim($output);
}

这篇关于Base64编码德code字节数组 - 从的iOS APNS令牌的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆