PHP code example of code-lives / decrypt

1. Go to this page and download the library: Download code-lives/decrypt library. Choose the download type require.

2. Extract the ZIP file and open the index.php.

3. Add this code to the index.php.
    
        
<?php
require_once('vendor/autoload.php');

/* Start to develop here. Best regards https://php-download.com/ */

    

code-lives / decrypt example snippets



1.前端和后端定义 一个公用的加密参数 SECRET_KEY='123'

2.前端 请求接口header 传参

    sign         md5(SECRET_KEY+timestamp) 
    
    timestamp    时间戳
    
3.后端接收 timestamp 拿着后端定义好的 SECRET_KEY 进行加密 md5(SECRET_KEY+timestamp) 

4.加密后进行 和前端加密的sign 进行对比。



$apidecode = new \api\decode\apidecode($secret_key);

$sign = $apidecode->encode();

$sign=array('sign' => , 'time' => );



$apidecode = new \api\decode\apidecode($secret_key);

$status = $apidecode->decode($sign, $timestamp);

if(!$status){

    exit('非法操作');
    
}