gammu使用getussd检查余额是加密的

时间:2013-05-15 00:29:46

标签: php sms-gateway gammu

我正在开发消息广播消息 检查平衡时我遇到了问题。 响应如下:

Service reply        : "00500075006C007300610020003000200073002F006400200031004A
0075006E00310033002E0020004700610075006C002000420075006C0061006E0061006E00200031
002E003500470042002C005200700034003900720062002F0062006C006E002E0020004E00470045
0042005500540026004D0055005200410048000A00310020004D00610075000A003200200049006E
007400650072006E00650074002F00420042000A003300200050006B007400200053007500700065
0072002000480065006D00610074000A003400200050006B00740020004E0065006C0070006F006E
000A0035002000500072006F006D006F004B006F006E00740065006E000A00360020006D00500075
006C00730061000A00370020004D00790049006E0066006F000A"

如何阅读(解密)呢?

2 个答案:

答案 0 :(得分:3)

我知道这是一个老帖子。仍然希望为可能需要它的人做出贡献,曾经遇到过这个问题。

<?php
function decode_string($str){
    //split the reply in chunks of 4 characters (each 4 character is hex encoded), use | as separator
    $str = str_replace(" ", "", $str); // remove normal space, you might have better ways of doing this
    $chunk = chunk_split($str, 4, '|');
    $coded_array = explode('|', $chunk);
    $n = count($coded_array);
    $decoded = '';
    for($i = 0; $i < $n; $i++){
        $decoded .= chr(hexdec($coded_array[$i]));
    }
    return $decoded;
}

$reply = "00500075006C007300610020003000200073002F006400200031004A".
"0075006E00310033002E0020004700610075006C002000420075006C0061006E0061006E00200031".
"002E003500470042002C005200700034003900720062002F0062006C006E002E0020004E00470045".
"0042005500540026004D0055005200410048000A00310020004D00610075000A003200200049006E".
"007400650072006E00650074002F00420042000A003300200050006B007400200053007500700065".
"0072002000480065006D00610074000A003400200050006B00740020004E0065006C0070006F006E".
"000A0035002000500072006F006D006F004B006F006E00740065006E000A00360020006D00500075".
"006C00730061000A00370020004D00790049006E0066006F000A";
echo "<pre>";
echo decode_string($reply);
echo "</pre>";
?>

输出:

Pulsa 0 s/d 1Jun13. Gaul Bulanan 1.5GB,Rp49rb/bln. NGEBUT&MURAH
1 Mau
2 Internet/BB
3 Pkt Super Hemat
4 Pkt Nelpon
5 PromoKonten
6 mPulsa
7 MyInfo

答案 1 :(得分:1)

刚遇到同样的问题。 显然,这些消息可以像SMS(文本)一样进行PDU编码。

但是这种跳跃直接进入了眼睛 - 这是四个字节的十六进制值(可能是Unicode?然后可能会读入ByteArray并解码为String可能会有效)。

这是一个快速的Python 3脚本:

reply = "00500075006C007300610020003000200073002F006400200031004A" \
"0075006E00310033002E0020004700610075006C002000420075006C0061006E0061006E00200031" \
"002E003500470042002C005200700034003900720062002F0062006C006E002E0020004E00470045" \
"0042005500540026004D0055005200410048000A00310020004D00610075000A003200200049006E" \
"007400650072006E00650074002F00420042000A003300200050006B007400200053007500700065" \
"0072002000480065006D00610074000A003400200050006B00740020004E0065006C0070006F006E" \
"000A0035002000500072006F006D006F004B006F006E00740065006E000A00360020006D00500075" \
"006C00730061000A00370020004D00790049006E0066006F000A"

def chunks(l, n):
  """ Yield successive n-sized chunks from l.
      http://stackoverflow.com/questions/312443/how-do-you-split-a-list-into-evenly-sized-chunks-in-python
  """
  for i in range(0, len(l), n):
    yield l[i:i+n]

for chunk in list(chunks(reply, 4)):
  print( chr( int( chunk[2:],16) ), end="" )

输出:

Pulsa 0 s/d 1Jun13. Gaul Bulanan 1.5GB,Rp49rb/bln. NGEBUT&MURAH
1 Mau
2 Internet/BB
3 Pkt Super Hemat
4 Pkt Nelpon
5 PromoKonten
6 mPulsa
7 MyInfo