分类 所有文章 下的文章 - 空痕博客
首页
小记
php
python
uni
前端
其他
机器人
QQ机器人
APP
KHMD
KHMD-v3
其他页面
友情链接
用户留言
联系空痕
热门文章
PHP搭建QQ机器人(QQ官方)
下载文件到指定文件夹
欢迎回来 Typecho !
UTS引用原生jar包进行原生插件开发
PHP封装功能较全CURL函数
标签搜索
uniapp
PHP
APP
KongHen
机器人
QQ
UTS
ID3
python
pyinstaller
redis
Echarts
模板
邮箱
js
lyear
发布
登录
找到
7
篇与
相关的结果
2025-06-22
Echarts绘制中国地图并将南海诸岛化为简图
下载中国地图数据 下载地址:DataV.GeoAtlas地理小工具 绘制演示 绘制演示图片 绘制地图 显示南海诸岛简图 地图绘制时设置`china`有南海诸岛简图,设置`China`则没有简图 echarts.registerMap('china', usaJson);隐藏海南诸岛边界线 搜索100000_JD,删除图中的数据片段 隐藏南海诸岛边界线代码位置图片 隐藏南海诸岛 搜索海南,修改海南省的数据,将图中的数据修改为以下数据 南海诸岛数据修改位置图片 "coordinates": [ [ [ [ 110.106396, 20.026812 ], [ 110.042339, 19.991384 ], [ 109.997375, 19.980136 ], [ 109.965346, 19.993634 ], [ 109.898825, 19.994196 ], [ 109.855093, 19.984073 ], [ 109.814441, 19.993072 ], [ 109.76147, 19.981261 ], [ 109.712195, 20.017253 ], [ 109.657993, 20.01163 ], [ 109.585312, 19.98801 ], [ 109.526797, 19.943573 ], [ 109.498464, 19.873236 ], [ 109.411001, 19.895184 ], [ 109.349407, 19.898561 ], [ 109.300748, 19.917693 ], [ 109.25948, 19.898561 ], [ 109.255784, 19.867045 ], [ 109.231147, 19.863105 ], [ 109.159082, 19.79048 ], [ 109.169553, 19.736411 ], [ 109.147379, 19.704863 ], [ 109.093792, 19.68965 ], [ 109.048829, 19.619764 ], [ 108.993394, 19.587065 ], [ 108.92872, 19.524468 ], [ 108.855424, 19.469182 ], [ 108.806148, 19.450561 ], [ 108.765496, 19.400894 ], [ 108.694047, 19.387346 ], [ 108.644772, 19.349518 ], [ 108.609048, 19.276661 ], [ 108.591186, 19.141592 ], [ 108.598577, 19.055633 ], [ 108.630606, 19.003017 ], [ 108.637997, 18.924346 ], [ 108.595497, 18.872256 ], [ 108.593033, 18.809386 ], [ 108.65278, 18.740258 ], [ 108.663866, 18.67337 ], [ 108.641077, 18.565614 ], [ 108.644772, 18.486738 ], [ 108.68912, 18.447571 ], [ 108.776583, 18.441894 ], [ 108.881293, 18.416344 ], [ 108.905315, 18.389087 ], [ 108.944735, 18.314107 ], [ 109.006329, 18.323198 ], [ 109.108575, 18.323766 ], [ 109.138756, 18.268081 ], [ 109.17448, 18.260125 ], [ 109.287813, 18.264671 ], [ 109.355566, 18.215221 ], [ 109.441182, 18.199303 ], [ 109.467051, 18.173718 ], [ 109.527413, 18.169169 ], [ 109.584696, 18.143579 ], [ 109.661688, 18.175424 ], [ 109.726362, 18.177698 ], [ 109.749767, 18.193618 ], [ 109.785492, 18.339672 ], [ 109.919767, 18.375457 ], [ 110.022629, 18.360121 ], [ 110.070672, 18.376025 ], [ 110.090382, 18.399309 ], [ 110.116867, 18.506602 ], [ 110.214186, 18.578662 ], [ 110.246215, 18.609859 ], [ 110.329366, 18.642185 ], [ 110.367555, 18.631977 ], [ 110.499366, 18.651824 ], [ 110.499366, 18.751592 ], [ 110.578206, 18.784458 ], [ 110.590525, 18.838841 ], [ 110.585597, 18.88075 ], [ 110.619474, 19.152334 ], [ 110.676756, 19.286264 ], [ 110.706321, 19.320153 ], [ 110.729727, 19.378878 ], [ 110.787009, 19.399765 ], [ 110.844292, 19.449996 ], [ 110.888023, 19.518827 ], [ 110.920668, 19.552668 ], [ 111.008747, 19.60398 ], [ 111.061718, 19.612436 ], [ 111.071573, 19.628784 ], [ 111.043856, 19.763448 ], [ 111.013675, 19.850159 ], [ 110.966248, 20.018377 ], [ 110.940994, 20.028499 ], [ 110.871393, 20.01163 ], [ 110.808567, 20.035808 ], [ 110.778386, 20.068415 ], [ 110.744509, 20.074036 ], [ 110.717408, 20.148778 ], [ 110.687843, 20.163947 ], [ 110.655814, 20.134169 ], [ 110.562191, 20.110006 ], [ 110.526467, 20.07516 ], [ 110.495054, 20.077408 ], [ 110.387265, 20.113378 ], [ 110.318279, 20.108882 ], [ 110.28933, 20.056047 ], [ 110.243135, 20.077408 ], [ 110.144585, 20.074598 ], [ 110.106396, 20.026812 ] ] ]下载修改后的完整文件 下载完整文件 下载地址:https://www.khkj6.com/usr/uploads/2025/06/3432059456.json 提取码: 参考文档 vue echarts 中国地图处理南海诸岛为简图-CSDN
所有文章
前端
# Echarts
KongHen02
6月22日
0
6
0
2025-02-20
php利用redis实现接口数据缓存
php利用redis实现服务端数据缓存。 要求php版本大于8.0 缓存类 文件RedisCache.php <?php /** * 请求缓存类 * 利用redis实现数据缓存 * * 作者:KongHen02 * */ class RedisCache { private string $key; private Redis $redis; public function __construct(int $db = 0, bool $device = false) { $config = [ 'host' => '127.0.0.1', 'port' => 6379, 'timeout' => 2, 'database' => $db ]; try { $this->redis = new Redis(); $this->redis->connect( $config['host'], $config['port'], $config['timeout'] ); $this->redis->select($config['database']); } catch (RedisException $e) { error_log("Redis连接失败: " . $e->getMessage()); throw new RuntimeException("缓存服务不可用"); } $this->key = $this->generateKey($device); } public function getCache(): mixed { try { header('X-Cache: ' . ($this->redis->exists($this->key) ? 'HIT' : 'MISS')); $data = $this->redis->get($this->key); return $data !== false ? unserialize($data) : null; } catch (RedisException $e) { error_log("读取缓存数据失败: " . $e->getMessage()); return null; } } public function setCache(mixed $data, int $ttl = 7200): bool { try { return $this->redis->setex( $this->key, $ttl, serialize($data) ); } catch (RedisException $e) { error_log("写入缓存数据失败: " . $e->getMessage()); return false; } } public function __destruct() { try { $this->redis?->close(); } catch (RedisException $e) { error_log("关闭Redis连接失败: " . $e->getMessage()); } } private function generateKey(bool $device): string { $url = $_SERVER['HTTP_HOST']; $urlArray = explode("?", $_SERVER['REQUEST_URI']); $url .= $urlArray[0]; $params = $_POST; ksort($params); $keyParts = [ $_SERVER['REQUEST_METHOD'], $device ? $this->detectDevice() : null, $url, substr(md5($urlArray[1]), 0, 8), substr(md5(http_build_query($params)), 0, 8) ]; return implode(':', array_filter($keyParts)); } private function detectDevice(): string { $ua = strtolower($_SERVER['HTTP_USER_AGENT'] ?? ''); return match(true) { (bool)preg_match('/mobile|android|iphone|ipod|windows phone/', $ua) => 'mobile', (bool)preg_match('/tablet|ipad|kindle/', $ua) => 'tablet', default => 'desktop' }; } } ?>使用说明 <?php // 导入缓存类 require_once($_SERVER['DOCUMENT_ROOT'] . "/RedisCache.php"); try { // 0:redis表序;0-15;必填 // true:是否区分客户端类型(手机/平板/电脑);true/false(默认);可空 $RedisCache = new RedisCache(0, true); if (($result = $RedisCache->getCache()) !== null) { exit($result); } } catch (RuntimeException $e) { // 缓存服务不可用时继续执行 header('X-Cache-Status: Down'); } // 业务逻辑处理 $result = "数据内容,不限制类型"; // 缓存成功结果 if (isset($result)) { // $result:需要缓存的数据;mixed;必填 // 7200:数据有效期;int(默认7200);可空 $RedisCache?->setCache($result, 7200); } echo($result); ?>
所有文章
PHP
# PHP
# redis
KongHen02
2月20日
6
0
0
2024-12-02
UTS封装uni.request请求拦截器
UTS封装请求拦截器主要就是数据类型的问题 简单封装示例:每次请求在请求头中携带设备信息 /** * 封装请求体携带设备信息 * 说明:header携带设备信息 * * 作者:KongHen02 */ export type RequestParams = { url: string; method: RequestMethod; data?: string; header?: UTSJSONObject; timeout?: number; sslVerify?: boolean; withCredentials?: boolean; firstIpv4?: boolean; } export type RequestRoot = { code: number; msg: string; data?: any } export type RequestRes = { data?: any; error?: string; } // 获取系统信息 export const getSystemInfo = (): string => { const system = uni.getSystemInfoSync() // 返回app信息,依次为appid,系统名称,系统版本,app版本,设备id,使用____分割 return system.appId + "____" + system.osName + "____" + system.osVersion + "____" + system.appVersionCode + "____" + system.deviceId } // 发送请求并携带设备信息 export const sendRequest = (options: RequestParams): Promise<RequestRes> => { let info = getSystemInfo(); let header = {} if (options.header != null) { header = UTSJSONObject.assign(options.header as UTSJSONObject, { app: info }) }else { header = UTSJSONObject.assign(header, { app: info }) } // 返回一个Promise return new Promise((resolve, reject) => { uni.request<RequestRoot>({ // ...options, // 展开其他请求配置 url: options.url, method: options.method, data: options.data ?? "", header: header, timeout: options.timeout ?? 6000, sslVerify: options.sslVerify ?? true, withCredentials: options.withCredentials ?? false, firstIpv4: options.firstIpv4 ?? false, success: (res) => { const data = res.data as RequestRoot if(data.code == 200) { // 在请求成功时解析Promise resolve({ data: data.data } as RequestRes) }else { uni.showToast({ title: data.msg, icon: "error" }) reject({ error: data['msg'] as string } as RequestRes) } }, fail: (err) => { uni.showToast({ title: err.errMsg, icon: "error" }) // 在请求失败时拒绝Promise reject({ error: err.errMsg as string } as RequestRes) } } as RequestOptions<any>); }); } 使用示例 // 导入封装的函数 import { sendRequest } from "@/common/request.uts" // 定义存储的变量 // 1. 数组 const list = ref<UTSJSONObject[]>([]) // 2. 对象 // const list = ref<UTSJSONObject>({}) // 请求示例:使用Promise的方式调用sendRequest函数 sendRequest({ url: 'https://api.example.com/data', method: 'GET' }).then(res => { // 处理请求成功的结果 list.value = res.data as UTSJSONObject[] // 数组,对应的存储数组的变量 // list.value = res.data as UTSJSONObject // 对象,对应的存储对象的变量 console.log('处理结果:', data.value); }).catch(err => { // 处理请求失败的情况 console.error('请求失败:', err); }) 在模板中使用示例 注意使用变量中数据的方法只能为下标[""]方法,.操作符不可以,会报错 <view v-for="item in noticeList" :key="item['id']"> <image mode="widthFix" :src="item['image']"></image> <view> <text>{{ item['title'] }}</text> <text>{{ item['sort'] }}</text> </view> </view>说明: 因为书写习惯原因,我自己的所有后端返回数据均为json,返回对象参数如下 参数描述示例code错误码200: 成功, 400: 失败, 或其他msg请求结果说明请求成功/请求失败等data请求返回的结果json数组/对象示例如下: data为数组 { code: 200, msg: "请求成功", data: [] } data为对象 { code: 200, msg: "请求成功", data: {} } 对应封装的请求中的自定义类型RootRes(request.uts文件中)
所有文章
uts
KongHen02
1年前
0
2
0
2024-06-05
PHP封装功能较全CURL函数
经常用到,之前一直重复写,今天写脚本的时候就封装了一个,方便重复利用 <?php /** * httpRequest * 发送curl请求 * * @param string $url 请求的URL * @param string $method 请求方法,默认是'GET' * @param string $back 返回类型,默认为空,可以为'all'或'cookie' * @param array $params 请求参数,默认为空数组 * @param array $headers 请求头,默认为空数组 * @return array 响应数据 * */ function sendCurlRequest($url, $method = 'GET', $back = "", $params = [], $headers = []) { // 初始化cURL会话 $ch = curl_init(); // 设置请求URL if ($method == 'GET' && !empty($params)) { $url .= '?' . http_build_query($params); } curl_setopt($ch, CURLOPT_URL, $url); // 设置请求方法 if($method == 'POST') { curl_setopt($ch, CURLOPT_POST, true); curl_setopt($ch, CURLOPT_POSTFIELDS, http_build_query($params)); } // 返回而不是输出内容 curl_setopt($ch, CURLOPT_RETURNTRANSFER, true); // 允许跟随重定向 curl_setopt($ch, CURLOPT_FOLLOWLOCATION, true); // 设置返回类型 if ($back === "all") { // 设置为true以包含响应头 curl_setopt($ch, CURLOPT_HEADER, true); // 设置为false以包含响应体 curl_setopt($ch, CURLOPT_NOBODY, false); } elseif ($back === "cookie") { // 设置为true以包含响应头 curl_setopt($ch, CURLOPT_HEADER, true); } // 设置请求头 if (!empty($headers)) { curl_setopt($ch, CURLOPT_HTTPHEADER, $headers); } // 设置超时(可选) curl_setopt($ch, CURLOPT_TIMEOUT, 30); // 执行cURL会话 $response = curl_exec($ch); // 获取HTTP状态码 $httpCode = curl_getinfo($ch, CURLINFO_HTTP_CODE); // 获取错误信息 $error = curl_error($ch); // 处理cookie $cookies = []; if ($back == "cookie" || $back == "all") { // 分离头部和主体 $header_size = curl_getinfo($ch, CURLINFO_HEADER_SIZE); $header = substr($response, 0, $header_size); if ($back == "all") { $body = substr($response, $header_size); } // 解析头部中的Cookie preg_match_all('/^Set-Cookie:\s*([^;]*)/mi', $header, $matches); foreach ($matches[1] as $item) { parse_str($item, $cookie); $cookies = array_merge($cookies, $cookie); } } // 关闭cURL会话 curl_close($ch); // 构建返回数据 if ($error) { $data = ['code' => 400, 'msg' => $error]; } else if ($httpCode >= 400) { $data = ['code' => 400, 'msg' => "HTTP error $httpCode"]; } else if ($back == "all") { $data = ['code' => 200, 'cookie' => $cookies, 'body' => $body]; } else if ($back == "cookie") { $data = ['code' => 200, 'cookie' => $cookies]; } else { $data = ['code' => 200, 'body' => $response]; } // 返回响应数据 return $data; }
所有文章
PHP
KongHen02
1年前
0
158
0
2023-12-13
PHP搭建QQ机器人(QQ官方)
使用PHP搭建QQ机器人websoket客户端接收处理消息
所有文章
QQ机器人
# 机器人
# QQ
KongHen02
2年前
5
658
3
1
2
下一页
易航博客