php 混淆 js,通过php实现对js的加密混淆

使用php对js进行混淆加密,具体方法如下:

//js路径

$jsPath = __DIR__.'/assets/js/*';

//不需要压缩的JS

$exclude = array(

'jQuery.ui.position.min.js',

'easy_validator.pack.js',

'easydialog.min.js',

'jquery.ad-gallery.js',

'jquery.autocomplete.js',

'jquery.bgiframe.min.js',

'jquery.fancybox-1.3.4.pack.js',

'jquery.min.js',

'jquery.mousewheel-3.0.4.pack.js',

'jquery.uploadify.js',

'jquery.validationEngine-zh_CN.js',

'jquery.validationEngine.js',

'exportting.js',

'highcharts.js',

'jquery.bgiframe.min.js',

);

//js混淆加密并更换名称

foreach(glob($jsPath) as $filePath)

{

$fileName = array_pop(explode('/',$filePath));

if( !in_array($fileName,$exclude) )

{

$content = file_get_contents($filePath);

//js混淆

$params = array(

'code' => $content,

'operate' => 'uglify',

);

$response = remote::post($params);

if( $response['status'] == true)

{

//js加密

$params = array(

'operate' => 'pack',

'code' => $response['text'],

);

$response = remote::post($params);

if( $response['status'] == true)

{

$text = $response['text'];

file_put_contents($filePath,$text);

//更换js文件名

$id = uuid(false).'.js';

$newPath = str_replace($fileName,$id,$filePath);

rename($filePath,$newPath);

error_log("{$filePath}======>{$newPath}\n", 3, "log.txt");

}

}

}

else

{

$id = uuid(false).'.js';

$newPath = str_replace($fileName,$id,$filePath);

rename($filePath,$newPath);

error_log("{$filePath}======>{$newPath}\n", 3, "log.txt");

}

sleep(1);

}

class remote

{

public static $timeout = 30;

const HTTP_OK = 200;

const HTTP_FAIL = 401;

const HTTP_ERROR = 500;

public static function post($params=array())

{

$paramss = '';

$headers[] = 'Accept application/json, text/javascript, */*; q=0.01';

$headers[] = 'Content-Type application/x-www-form-urlencoded; charset=UTF-8';

$headers[] = 'Accept-Language zh-cn,zh;q=0.8,en-us;q=0.5,en;q=0.3';

$user_agent = 'Mozilla/5.0 (Macintosh; Intel Mac OS X 10.8; rv:20.0) Gecko/20100101 Firefox/20.0';

$ch = curl_init('http://tool.lu/js/ajax.html');

curl_setopt($ch,CURLOPT_HTTPHEADER, $headers);

curl_setopt($ch,CURLOPT_REFERER,'http://tool.lu/js/');

curl_setopt($ch,CURLOPT_USERAGENT,$user_agent);

curl_setopt($ch,CURLOPT_TIMEOUT,self::$timeout);

curl_setopt($ch,CURLOPT_RETURNTRANSFER, true);

if(!empty($params)) {

curl_setopt($ch,CURLOPT_POST, 1);

curl_setopt($ch,CURLOPT_POSTFIELDS,$params);

}

$response = curl_exec($ch);

$status = curl_getinfo($ch, CURLINFO_HTTP_CODE);

switch($status) {

case self::HTTP_OK:

case self::HTTP_FAIL:

$json = json_decode($response, true);

break;

case self::HTTP_ERROR:

default:

$json = null;

break;

}

curl_close($ch);

return $json;

}

}

function uuid( $more = true, $admin = false )

{

if ( $more )

{

return uniqid( md5( mt_rand() ), true );

}

else

{

if ( $admin ) return uniqid( "zzz", false );

return uniqid( create_guid_section( 3 ), false );

}

}

function create_guid_section( $characters )

{

$return = "";

for ( $i = 0; $i < $characters; $i++ )

{

$return .= dechex( mt_rand( 0, 15 ) );

}

return $return;

}

  • 0
    点赞
  • 2
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值