Home  >  Article  >  Backend Development  >  WebQQ web page hash encryption algorithm PHP version_PHP tutorial

WebQQ web page hash encryption algorithm PHP version_PHP tutorial

WBOY
WBOYOriginal
2016-07-13 10:48:20836browse

A hash encryption algorithm we found on QQ is the js version. Below we change the hash encryption algorithm of the js version to the php version of the encryption algorithm. I hope the method will be helpful to you.

Due to the recent serious spam messages on QQ, the official chose to make some adjustments to the implementation details of some functions of WebQQ. Among them, there is an additional hash parameter for obtaining the friend's POST value.

This hash is encrypted in js.

The following is the js source code

The code is as follows Copy code
 代码如下 复制代码

Convert to PHP version for processing, the source code is as follows

 代码如下 复制代码
/**
* 获取好友时的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('N', mb_convert_encoding($str, 'UCS-4BE', 'UTF-8'));
 
 return

$ord;
}

/* End of file commons.php */

www.bkjia.comtruehttp: //www.bkjia.com/PHPjc/632811.htmlTechArticleA hash encryption algorithm we found on QQ is the js version. Below we will use the js version of the hash encryption algorithm. Change it to the PHP version of the encryption algorithm. I hope the method will be helpful to you. Due to the recent Q...
Statement:
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