1 Star 3 Fork 0

Evan Wu/xmcsrv-api-php-signature

加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
文件
克隆/下载
SignatureUtil.php 1.93 KB
一键复制 编辑 原始数据 按行查看 历史
吴强强 提交于 5年前 . xmcsrv-api-php-signature
<?php
class SignatureUtil
{
private $uuid;
private $appKey;
private $appSecret;
private $timeMillis;
private $movedCard;
public function __construct($uuid, $appKey, $appSecret, $timeMillis, $movedCard)
{
$this->uuid = $uuid;
$this->appKey = $appKey;
$this->appSecret = $appSecret;
$this->timeMillis = $timeMillis;
$this->movedCard = $movedCard;
}
public function getEncryptStr()
{
$encryptStr = $this->uuid . $this->appKey . $this->appSecret . $this->timeMillis;
for ($i = 0; $i < strlen($encryptStr); $i++) {
$encryptByte[] = ord($encryptStr[$i]);
}
$changeByte = $this->change($encryptStr, $this->movedCard);
$mergeByte = $this->mergeByte($encryptByte, $changeByte);
$asciiString = '';
for ($i = 0; $i < count($mergeByte); $i++) {
$asciiString .= chr($mergeByte[$i]);
}
return md5($asciiString);
}
protected function change($encryptStr, $movedCard)
{
$encryptByte = array();
for ($i = 0; $i < strlen($encryptStr); $i++) {
$encryptByte[] = ord($encryptStr[$i]);
}
$encryptLength = count($encryptByte);
$temp = '';
for ($i = 0; $i < $encryptLength; $i++) {
$temp = (($i % $movedCard) > (($encryptLength - $i) % $movedCard)) ? $encryptByte[$i] : $encryptByte[$encryptLength - ($i + 1)];
$encryptByte[$i] = $encryptByte[$encryptLength - ($i + 1)];
$encryptByte[$encryptLength - ($i + 1)] = $temp;
}
return $encryptByte;
}
protected function mergeByte($encryptByte, $changeByte)
{
$encryptLength2 = count($encryptByte) * 2;
$temp = array();
for ($i = 0; $i < count($encryptByte); $i++) {
$temp[$i] = $encryptByte[$i];
$temp[$encryptLength2 - 1 - $i] = $changeByte[$i];
}
return $temp;
}
}
Loading...
马建仓 AI 助手
尝试更多
代码解读
代码找茬
代码优化
PHP
1
https://gitee.com/wupz/xmcsrv-api-php-signature.git
git@gitee.com:wupz/xmcsrv-api-php-signature.git
wupz
xmcsrv-api-php-signature
xmcsrv-api-php-signature
master

搜索帮助