很抱歉再次打扰,但我真的需要帮助将这个Python2代码转换为PHP。
net, cid, lac = 25002, 9164, 4000
import urllib
a = '000E00000000000000000000000000001B0000000000000000000000030000'
b = hex(cid)[2:].zfill(8) + hex(lac)[2:].zfill(8)
c = hex(divmod(net,100)[1])[2:].zfill(8) + hex(divmod(net,100)[0])[2:].zfill(8)
string = (a + b + c + 'FFFFFFFF00000000').decode('hex')
data = urllib.urlopen('http://www.google.com/glm/mmap',string)
r = data.read().encode('hex')
print float(int(r[14:22],16))/1000000, float(int(r[22:30],16))/1000000
如果有人可以提供帮助,那将会很棒!,提前谢谢!
编辑:
我明白了。你可以编辑你的帖子,包括你到目前为止翻译的内容。
<?php
$net = 25002;
$cid = 9164;
$lac = 4000;
$a = '000E00000000000000000000000000001B0000000000000000000000030000'
$b = hex($cid)[2:].zfill(8) + hex($lac)[2:].zfill(8)
$c = hex(divmod($net,100)[1])[2:].zfill(8) + hex(divmod($net,100)[0])[2:].zfill(8)
$string = ($a + $b + $c + 'FFFFFFFF00000000').decode('hex')
$data = 'http://www.google.com/glm/mmap'.$string
$r = $data.read().encode('hex')
print float(int($r[14:22],16))/1000000, float(int($r[22:30],16))/1000000
?>
答案 0 :(得分:5)
因为我的午餐休息期间魔兽世界服务器停机了:
// net, cid, lac = 25002, 9164, 4000
$net = 25002;
$cid = 9164;
$lac = 4000;
// import urllib
//a = '000E00000000000000000000000000001B0000000000000000000000030000'
$a = '000E00000000000000000000000000001B0000000000000000000000030000';
//b = hex(cid)[2:].zfill(8) + hex(lac)[2:].zfill(8)
$b = sprintf("%08x%08x", $cid, $lac);
//c = hex(divmod(net,100)[1])[2:].zfill(8) + hex(divmod(net,100)[0])[2:].zfill(8)
$c = sprintf("%08x%08x", $net % 100, floor($net / 100));
//string = (a + b + c + 'FFFFFFFF00000000').decode('hex')
$string = $a . $b . $c . 'FFFFFFFF00000000';
$newstring = '';
for( $i = 0, $count = strlen($string); $i < $count; $i++ ) {
$newstring .= sprintf("%c", hexdec($string{$i} . $string{++$i}));
}
//data = urllib.urlopen('http://www.google.com/glm/mmap',string)
$ch = curl_init('http://www.google.com/glm/mmap');
curl_setopt($ch, CURLOPT_POST, true);
curl_setopt($ch, CURLOPT_POSTFIELDS, $newstring);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
//r = data.read().encode('hex')
$r = curl_exec($ch);
//print float(int(r[14:22],16))/1000000, float(int(r[22:30],16))/1000000
$r = array_pop(unpack("H*", $r));
printf("%f, %f", hexdec(substr($r, 14, 8)) / 1000000, hexdec(substr($r, 22, 8)) / 1000000);
我很想看到更优雅的十六进制转换。
答案 1 :(得分:0)
有一个小程序可以将Python代码转换为PHP:您可以尝试从https://github.com/bunkahle/py2php
进行转换。