对接第三方数据过程中
JAVA加密方法为 DigestUtils.md5Hex("123456".getBytes());
PHP对应代码
/**
* Class JavaMd5Hex
* 使用方式
* $this->encodeHexString($this->md5Hex($str));
*/
class JavaMd5Hex
{
/**
* 16进制转string拼接
* @param array $bytes [description]
* @return [type] [description]
* @author Lerko
* @dateTime 2018-01-25T10:18:31+0800
*/
public function encodeHexString(array $bytes)
{
$LOWER = ['0', '1', '2', '3', '4', '5', '6', '7', '8', '9', 'a', 'b', 'c', 'd', 'e', 'f'];
$length = count($bytes);
$charArr = [];
foreach ($bytes as $value) {
$value = intval($value);
$charArr[] = $LOWER[$this->uright(0xF0 & $value, 4)];
$charArr[] = $LOWER[0x0F & $value];
}
return implode("", $charArr);
}
/** php 无符号右移 */
public function uright($a, $n)
{
$c = 2147483647 >> ($n - 1);
return $c & ($a >> $n);
}
/**
* 模拟DigestUtils.md5
* @param [string] $string 加密字符
* @return [array] 加密之后的byte数组
* @author Lerko
* @dateTime 2018-01-25T09:28:33+0800
*/
public function md5Hex($string)
{
return unpack("c*", md5($string, true));
}
}