当前位置:网站首页>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;
}
}
边栏推荐
- SAP Hana error message sys_ XSA authentication failed SQLSTATE - 28000
- Propagation of transactions
- Circuitbreaker fuse of resilience4j - circuitbreakerevent event
- Basic use of scratch
- Common tree summary
- [MySQL] index invalidation and index optimization
- Implementation principle of redisson distributed lock
- Cookie object
- [CEGUI] window environment compilation
- Qt自定义窗口圆角
猜你喜欢

C 语言仅凭自学能到什么高度?
![[Wayland] Wayland introduction and customized guidance](/img/4e/655d484ca7787f39aab446fdb1ae74.jpg)
[Wayland] Wayland introduction and customized guidance

GNU EFI development environment settings

HALCON联合C#检测表面缺陷——仿射变换(三)

Circuitbreaker fuse of resilience4j - Summary

MySQL 7 affair

Getting started with cloud API basics -- basic knowledge of picgo writing plug-ins
![[Mozilla] basic concept analysis of IPDL](/img/b2/97b4db069052133ee614ecb1a8369e.jpg)
[Mozilla] basic concept analysis of IPDL

容器江湖的爱恨情仇

2. factory mode
随机推荐
【ParquetEncodingException: empty fields are illegal, the field should be ommited completely instead
[CEGUI] concept introduction
Chapter 3 search
JVM (VI) Virtual machine bytecode execution engine (with stack execution process and bytecode instruction table)
Docker compose integrates redis, MySQL and microservices, and services are containerized
[Mozilla] basic concept analysis of IPDL
Pandorabox uses firewall rules to define non internet time
Checkpoint of the four cornerstones of Flink
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"
np.meshgrid()函数 以及 三维空间中的坐标位置生成 以及 numpy.repeat()函数介绍
[CEGUI] log system
Tp6 debugging (trace)
Periodic pains of cross-border e-commerce? Papaya mobile power as an independent station enabler
数组,整型,字符变量在全局和局部的存在形式
First NFT platform in dfinity Ecology: impossible thoughts
2021-09-15
Getting started with cloud API basics -- basic knowledge of picgo writing plug-ins
[DDS] ddsi-rtps specification
用于图像处理的高性能计算框架
【实验】MySQL主从复制及读写分离