标签:timestamp reg server time names 软件 utf8 remote 数据
php端
<?php
namespace app\controllers;
use yii\web\Controller;
class TestController extends Controller
{
public function actionIndex(){
// return $this->get_real_ip();
$time=time().‘000‘;
$ip=$this->get_real_ip();
return $this->aes128Encrypt(‘e234242423‘,"timestamp=".$time."&ip=".$ip);
$sign=bin2hex($this->aes128Encrypt(‘跟软件后台的密钥字符相同‘,"timestamp=".$time."&ip=".$ip));
return $sign;
}
public function aes128Encrypt($key, $data) {
$padding = 16 - (strlen($data) % 16);
$data .= str_repeat(chr($padding), $padding);
$keySize = 16;
$ivSize = 16;
$rawKey = $key;
$genKeyData = ‘‘;
return md5(‘sdfsfs‘,true);
return md5( $genKeyData.$rawKey, true );
do
{
$genKeyData = $genKeyData.md5( $genKeyData.$rawKey, true );
} while( strlen( $genKeyData ) < ($keySize + $ivSize) );
return $genKeyData;
$generatedKey = substr( $genKeyData, 0, $keySize );
$generatedIV = substr( $genKeyData, $keySize, $ivSize );
return mcrypt_encrypt(MCRYPT_RIJNDAEL_128, $generatedKey, $data, MCRYPT_MODE_CBC, $generatedIV);
}
public function get_real_ip(){
$ip=false;
if(!empty($_SERVER["HTTP_CLIENT_IP"])){
$ip = $_SERVER["HTTP_CLIENT_IP"];
}
if (!empty($_SERVER[‘HTTP_X_FORWARDED_FOR‘])) {
$ips = explode (", ", $_SERVER[‘HTTP_X_FORWARDED_FOR‘]);
if ($ip) { array_unshift($ips, $ip); $ip = FALSE; }
for ($i = 0; $i < count($ips); $i++) {
if (!eregi ("^(10|172\.16|192\.168)\.", $ips[$i])) {
$ip = $ips[$i];
break;
}
}
}
return ($ip ? $ip : $_SERVER[‘REMOTE_ADDR‘]);
}
}
ios端
标签:timestamp reg server time names 软件 utf8 remote 数据
原文地址:http://www.cnblogs.com/xiong63/p/6528096.html