当前位置: 首页 > news >正文

pako处理 urlencode(gzcompress(json_encode($res))) php的加密方式web解析

<!DOCTYPE html>
<html><head><title>PHP字符串解码工具</title><script src="https://cdnjs.cloudflare.com/ajax/libs/pako/2.1.0/pako.min.js"></script><style>body {font-family: Arial, sans-serif;max-width: 800px;margin: 0 auto;padding: 20px;line-height: 1.6;}.result {margin-top: 20px;padding: 15px;border: 1px solid #ddd;border-radius: 5px;background-color: #f9f9f9;}.json-result {background-color: #f0f8ff;border-color: #add8e6;}.text-result {background-color: #fff8e1;border-color: #ffd700;}.error-result {background-color: #ffe6e6;border-color: #ff6b6b;}pre {white-space: pre-wrap;word-wrap: break-word;}h2 {color: #333;}button {padding: 8px 16px;background-color: #4caf50;color: white;border: none;border-radius: 4px;cursor: pointer;}button:hover {background-color: #45a049;}</style></head><body><h1>PHP字符串解码工具</h1><p>该工具用于解码PHP gzcompress编码的字符串。</p><div class="result" id="resultContainer"><h2>解码结果将显示在这里</h2></div><script>function decodePhpGzcompress(encodedStr) {try {console.log("开始解码...");// 1. 手动解析URL编码const bytes = [];let i = 0;encodedStr = encodedStr.replace(/\+/g, " ");  //去掉空格while (i < encodedStr.length) {if (encodedStr[i] === "%") {const hex = encodedStr.substring(i + 1, i + 3);bytes.push(parseInt(hex, 16));i += 3;} else {bytes.push(encodedStr.charCodeAt(i));i += 1;}}console.log("解析出的字节:", bytes);// 2. 跳过zlib头(前2字节)const rawData = new Uint8Array(bytes).subarray(2);console.log("去掉zlib头后的数据:", Array.from(rawData));// 3. 使用inflateRaw解压缩const decompressed = pako.inflateRaw(rawData);console.log("解压缩后的字节:", Array.from(decompressed));// 4. 正确转换为字符串(使用TextDecoder)const textDecoder = new TextDecoder("utf-8", { fatal: false });let decodedString = textDecoder.decode(decompressed);console.log("转换为字符串:", decodedString);// 5. 清理非法JSON字符decodedString = cleanJsonString(decodedString);console.log("清理后的字符串:", decodedString);// 6. JSON解析 - 增强版错误处理try {// 首先检查是否为空字符串if (!decodedString || decodedString.trim() === "") {console.log("解码结果为空字符串");return {success: true,type: "text",content: "",message: "解码成功,结果为空字符串",};}const parsed = JSON.parse(decodedString);console.log("最终结果(JSON):", parsed);return {success: true,type: "json",content: parsed,message: "解码成功,结果为JSON对象",};} catch (jsonError) {console.warn("标准JSON解析失败,返回纯文本...");// 如果JSON解析失败,返回原始解码后的文本return {success: true,type: "text",content: decodedString,message: "解码成功,结果为文本(非JSON格式)",originalError: jsonError.message,};}} catch (error) {console.error("解码失败:", error);return {success: false,type: "error",content: null,message: "解码过程发生错误",error: error.message,};}}// 清理JSON字符串中的非法字符function cleanJsonString(str) {// 移除非ASCII可打印字符return str.replace(/[\x00-\x08\x0B\x0C\x0E-\x1F\x7F-\uFFFF]/g,function (match) {// 保留换行和制表符,其他替换为空if (match === "\n" || match === "\t") return match;return "";}).trim(); // 去除首尾空白}// 使用示例const encodedStr ="x%9C%ABVJI%2CIT%B22%D4Q%2A%C9%2C%C9IU%B2RJOW%AA%05%00V%1E%07+";const result = decodePhpGzcompress(encodedStr);console.log("解码结果:", result);// 显示结果到页面displayResult(result);</script></body>
</html>
http://www.dtcms.com/a/422564.html

相关文章:

  • 深入理解 SSE:服务器发送事件及其在前后端中的实践
  • Web典型路由结构之Next.js (App Router, v13+) )(文件系统驱动的路由:File-based Routing)声明式路由:文件即路由
  • 【设计模式】解释器模式
  • 【前端知识】iframe 使用详细说明
  • 推荐一款集成AI功能的数据库管理工具
  • Flask 入门:轻量级 Python Web 框架的快速上手
  • 每日前端宝藏库 | tinykeys ✨
  • 第7章:TS快速入门和前端项目初始化
  • 合肥 做网站的深圳办公室装修设计公司
  • Android实现RecyclerView粘性头部效果,模拟微信账单列表的月份标题平移
  • 建三江建设局网站网站建设自我评价怎么写比较好
  • 华为Fit4手表:个性化表盘,让生活更有温度
  • Spring Boot - 从PF4J到SBP:深入解析Java插件化架构的演进与实践
  • 河南做网站企起做平面什么网站的素材不侵权
  • 哪个网站做ppt模板赚钱手机棋牌游戏平台
  • 鸿蒙app开发中 拿到json文件数据进行动画的播放
  • 第三章 鸽巢原理
  • 智慧政务——解读57页清华大学:DeepSeek政务场景应用与解决方案【附全文阅读】
  • Transformer模型:深度解析自然语言处理的革命性架构
  • 声网AI逐字拆解问题,30天重塑口语清晰表达
  • Java异常简介
  • VSCode Web版本安装
  • 实用软件 | 实时监控andriod设备硬件状态-devcheck
  • 非关系型数据库(NoSQL):特性、类型与应用指南​
  • 性能革命的底层逻辑:深入理解 Spring Cloud Gateway 的 Reactor 核心
  • 2025 年 AI+BI 趋势下,Wyn 商业智能软件如何重构企业决策效率?
  • 网站开发合同印花税公司网站建设重点内容
  • CMake cmake_parse_arguments
  • 4、存储系统架构 - 从机械到闪存的速度革命
  • 淘宝店铺全量商品接口深度开发:从分页优化到数据完整性保障