当前位置:网站首页>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;
}
}
边栏推荐
- Data processing and visualization of machine learning [iris data classification | feature attribute comparison]
- Cookie object
- Docker compose integrates redis, MySQL and microservices, and services are containerized
- 极速搭建元宇宙画廊 #oncyber.io
- reflex
- [CEGUI] concept introduction
- 高通平台如何修改特殊电压
- 2021-02-21
- 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
- 1268_FreeRTOS任务上下文切换的实现
猜你喜欢

Transport layer protocol -- TCP protocol

一文读懂Dfinity生态中的首个NFT平台:IMPOSSIBLE THINGS

JVM (VI) Virtual machine bytecode execution engine (with stack execution process and bytecode instruction table)

Circuitbreaker fuse of resilience4j - circuitbreakerregistry register
![[Wayland] Wayland introduction and customized guidance](/img/4e/655d484ca7787f39aab446fdb1ae74.jpg)
[Wayland] Wayland introduction and customized guidance

4. creator mode
![[Wayland] Weston startup process analysis](/img/0e/24f374144ea7ea762a83f6598ebd48.jpg)
[Wayland] Weston startup process analysis

远程桌面不能复制粘贴解决办法

conda 安装tensorflow 测试tensorflow

Add jar package under idea2018 web project
随机推荐
Auto. JS learning note 9: basic methods such as using the script engine, starting the script file with the specified path, and closing
[Mozilla] basic concept analysis of IPDL
Canal ha mode configuration
[CEGUI] font resource loading process
golang中的定时器
原始套接字使用
CLAHE in opencv for 16 bit image enhancement display
Basic use of scratch
[CEGUI] concept introduction
MYSQL用户与权限管理,角色管理
MySQL user and permission management, role management
Cookie object
Pycharm view the current version of opencv
【系统分析师之路】第十八章 复盘系统安全分析与设计
Auto. JS learning note 10: instantiate a custom object and use json The stringify() method causes an error (resolved)
Redis (II) Memory mapped data structure
tp6调试(trace)
PLC如何自行构造移位功能块(FC)
[CEGUI] window environment compilation
数组,整型,字符变量在全局和局部的存在形式