阿里云函数计算GBK编码

阿里云函数计算GBK编码

前端树莓派,需要后端处理编码问题;

参考文档阿里文档:"https://help.aliyun.com/zh/functioncompute/fc-2-0/user-guide/configure-an-api-gateway-trigger?spm=a2c4g.11186623.help-menu-2508973.d_2_8_19_1.de5c36d4D0LuA6"

修改属性,在线函数调试成功

# 正常代码

CJsonEncoder 是处理时间的,可以移除该属性

python 复制代码
    def SUCESEE(self, data):
        if data is None:
            data = {}
        rep = {
            'isBase64Encoded': 'false',
            'statusCode': '200',
            'headers': {'x-custom-header': 'no', 'Content-Type': 'application/json;charset=UTF-8'},
            'body': {'code': 10000, 'msg': 'Success', 'data': data}
        }
        return json.dumps(rep, cls=CJsonEncoder)

GBK编码代码

python 复制代码
     # 返回GBK编码-中控屏使用(不推送,仅存档)
    def GBK_DATA(self, data):
        rep = {
            'isBase64Encoded': 'false',
            'statusCode': '200',
            'headers': {'x-custom-header': 'no', 'Content-Type': 'text/html; charset=GBK'},  # GBK-代码
            'body': {'code': 10000, 'msg': 'Success', 'data': data}
        }
        rep['body'] = json.dumps(rep['body'], cls=CJsonEncoder, ensure_ascii=True).encode('GBK').decode('latin1')  # GBK-代码
        return json.dumps(rep, cls=CJsonEncoder)

效果

相关推荐
ha_lydms7 小时前
DataWorks离线同步 OSS文件
大数据·阿里云·oss·dataworks·maxcompute·数据同步·离线计算
JiL 奥8 小时前
Ubuntu系统安装AWS SAM
云计算·aws
liyuanchao_blog8 小时前
linuxptp适配记录
linux·云计算
YongCheng_Liang9 小时前
从零开始学虚拟化:性能优化全指南(资源分配 + 存储网络 + 监控)
运维·云计算
YongCheng_Liang10 小时前
从零开始学虚拟化:高可用与灾备技术全解析(集群 + 备份 + 异地灾备)
运维·云计算
珠海西格20 小时前
“主动预防” vs “事后补救”:分布式光伏防逆流技术的代际革命,西格电力给出标准答案
大数据·运维·服务器·分布式·云计算·能源
xianyinsuifeng1 天前
RAG + Code Analysis 的标准路线
数据仓库·自动化·云计算·原型模式·aws
Genie cloud1 天前
在 Mac 上使用 Docker 安装宝塔并部署 LNMP 环境
macos·docker·容器·云计算
php_kevlin1 天前
阿里云AI接口接口
阿里云·云计算
万博智云OneProCloud1 天前
CloudEndure 退出中国市场之后,AWS 容灾该走向哪里?
云计算·aws