Home > php教程 > php手册 > body text

WebQQ网页hash加密算法PHP版

WBOY
Release: 2016-05-25 16:44:26
Original
813 people have browsed it

由于最近QQ垃圾信息群发严重,官方选择将WebQQ部分功能实现细节方面做了点手脚,其中获取好友的POST值多了一个hash参数,这个hash是在js里加密完成的,以下是js源码:

function getHash(b, i) { 

for (var a = i + "password error", 

s = "",  

j = [];;) if (s.length

if (s += b, s.length == a.length) break 

} else { 

s = s.slice(0, a.length); 

break 

}    

for (var d = 0; d

a = ["0", "1", "2", "3", "4", "5", "6", "7", "8", "9", "A", "B", "C", "D", "E", "F"]; 

s = "";  

for (d = 0; d > 4 & 15], 

s += a[j[d] & 15]; 

return s; 

 

转成PHP版本处理,源码如下:

<?php
/** 
 * 获取好友时的POST参数Hash算法
 *
 * public
 * @param string $qq qq号
 * @param string $ptwebqq cookies中的ptwebqq
 * @return string
 */
function get_hash($qq, $ptwebqq) {
    for ($a = $ptwebqq . "password error", $s = "", $j = array();;) {
        if (strlen($s) <= strlen($a)) {
            $s.= $qq;
            if ($s == strlen($a)) break;
        } else {
            $s = substr($s, 0, strlen($a));
            break;
        }
    }
    for ($d = 0; $d < strlen($s); $d++) {
        $j[$d] = uniord(substr($s, $d)) ^ uniord(substr($a, $d));
    }
    $a = array(
        "0",
        "1",
        "2",
        "3",
        "4",
        "5",
        "6",
        "7",
        "8",
        "9",
        "A",
        "B",
        "C",
        "D",
        "E",
        "F"
    );
    $s = "";
    for ($d = 0; $d < count($j); $d++) {
        $s.= $a[$j[$d] >> 4 & 15];
        $s.= $a[$j[$d] & 15];
    }
    return $s;
}
/** 
 * 模拟 JavaScript charCodeAt函数
 *
 * protected
 * @param string $str
 * @return int
 */
function uniord($str) {
    list(, $ord) = unpack(&#39;N&#39;, mb_convert_encoding($str, &#39;UCS-4BE&#39;, &#39;UTF-8&#39;));
    return $ord;
}
/* End of file commons.php */
Copy after login

   


教程链接:

随意转载~但请保留教程地址★

Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Recommendations
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!