当前位置:网站首页>PHP interface generates cache and MD5 encryption uniformly
PHP interface generates cache and MD5 encryption uniformly
2022-06-12 10:20:00 【Qu Shuai 369】
<?php
namespace app\store\controller\api;
use library\Controller;
use think\Db;
use think\facade\Cache;
/**
* Public class
* Class Base
* @package app\store\controller\api
*/
class Base extends Controller
{
public function initialize()
{
if(input('a','') != 1) {
$appid = input('appid','');
$secret = 'XXXXXXXXX';
$nonce = input('nonce','');
$timestamp = input('timestamp','');
$token = input('token');
if($appid != config('wechat.miniapp.appid')) {
echo json_encode(['status'=>101,'msg' => 'appid Incorrect ']);die;
}
if($nonce == ''){
echo json_encode(['status'=>102,'msg' => ' The lack of nonce']);die;
}
if($timestamp == '') {
echo json_encode(['status'=>103,'msg' => ' The lack of timestamp']);die;
}
if($token == '') {
echo json_encode(['status'=>104,'msg' => ' The lack of token']);die;
}
if(md5($appid.$secret.$nonce.$timestamp) != $token) {
echo json_encode(['status'=>105,'msg' => 'token error ']);die;
}
if(Db::name('api_log')->where('token',$token)->find()) {
echo json_encode(['status'=>105,'msg' => 'token invalid ']);die;
}
$data = [
'token'=>$token,
'application' => $_SERVER['REQUEST_URI'],
//'value'=> json_encode(input())
];
Db::name('api_log')->insert($data);
// Cache interface
$apiList = [
'/ygyAdmin/public/store/api.goods/getFirstAd'=> [2,null,120],
'/ygyAdmin/public/store/api.data/banner' => [2,['type'],100]
];
if(isset($apiList[$_SERVER['REQUEST_URI']])) {
echo $this->api_cache($apiList[$_SERVER['REQUEST_URI']][0],$apiList[$_SERVER['REQUEST_URI']][1],$apiList[$_SERVER['REQUEST_URI']][2]);
die;
}
}
}
/**
* @param $type 1=> File cache ,2=>redis cache
* @param $api Interface
* @param $param Banded ginseng
* @param $time Cache time
*/
private function api_cache($type,$param=['page'],$time=3600) {
if($type == 2) {
$cache = Cache::store('redis');
} else {
$cache = Cache::store('file');
}
$host = 'http://wechat.XXXXXX.com';
$key = $host . $_SERVER['REQUEST_URI'] .'?a=1';
$data = input();
if($param) foreach ($param as $k=>$v) {
if(isset($data[$v]) && $data[$v] !=='') {
$key .= '&'.$v.'='.$data[$v];
}
}
$data = $cache->get($key);
if(!$data) {
$data = file_get_contents($key);
$cache->set($key,$data,$time);
}
return $data;
}
}
边栏推荐
- Periodic pains of cross-border e-commerce? Papaya mobile power as an independent station enabler
- 2022京东618预售定金怎么退?京东618定金能退吗?
- Basic use of scratch
- Redis (II) Memory mapped data structure
- [Wayland] Wayland agreement description
- MYSQL用户与权限管理,角色管理
- ASP.NET Core权限系统实战(零)
- Antique mfc/gdi+ Frame LCD display control
- Implementation principle of redisson distributed lock
- Autojs learning notes 6:text (txt) Findone() will report an error when switching apps. Finally, solve the implementation effect and switch any app until the script finds the control with the specified
猜你喜欢

【926. 将字符串翻转到单调递增】

Li Yang, a scientific and technological innovator and CIO of the world's top 500 group: the success of digital transformation depends on people. Decision makers should always focus on "firewood"

Transport layer protocol -- TCP protocol

容器江湖的爱恨情仇

MySQL 7 affair

MYSQL用户与权限管理,角色管理

CONDA install tensorflow test tensorflow

Web3.0与数字时尚,该如何落地?

Code types and data structures corresponding to the five object types of redis

Research on autojs wechat: the control IP in wechat on different versions of wechat or simulators is different.
随机推荐
Circuitbreaker fuse of resilience4j - circuitbreakerconfig configuration
Explication du principe d'appariement le plus à gauche de MySQL
FPGA VGA display based on de2-115 platform
古董级MFC/GDI+框架LCD显示控件
Chapter 3 search
2021-01-13
MySQL 7 affair
SAP Hana error message sys_ XSA authentication failed SQLSTATE - 28000
First NFT platform in dfinity Ecology: impossible thoughts
PLC如何自行构造移位功能块(FC)
1268_FreeRTOS任务上下文切换的实现
ServletContext object
Checkpoint of the four cornerstones of Flink
ASP. Net core permission system practice (zero)
Spark complex structure data retrieval method
【926. 将字符串翻转到单调递增】
Periodic pains of cross-border e-commerce? Papaya mobile power as an independent station enabler
2021-09-13
MySQL user and permission management, role management
MYSQL的最左匹配原则的原理讲解