阿里云函数计算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)

效果

相关推荐
云计算老刘5 小时前
3.Shell 变量基础知识
chrome·正则表达式·centos·云计算
XINVRY-FPGA12 小时前
EP4CE30F23I7N Altera Cyclone IV E SRAM FPGA
嵌入式硬件·fpga开发·云计算·硬件工程·信息与通信·信号处理·fpga
boonya17 小时前
阿里云效一站式DevOps解决方案
阿里云·云计算·devops·阿里云效·一站式服务
方安乐17 小时前
超简单腾讯云免费部署vue项目
云计算·腾讯云
Akamai中国18 小时前
加速采用安全的企业级 Kubernetes 环境
人工智能·云计算·云服务·云存储
云计算小黄同学18 小时前
CC攻击和DDOS的特征与防护(基于阿里云)
网络·安全·阿里云·ddos
wanhengidc18 小时前
云手机如何进行数据备份
运维·服务器·科技·智能手机·云计算
云计算小黄同学18 小时前
【基于阿里云ACK】详细介绍k8s日志系统的设计与部署
阿里云·kubernetes·云计算
阿里云通信18 小时前
国内如何合规接入 WhatsApp Business API?阿里云作为 Meta Premier BSP 的完整技术指南
阿里云·云计算·whatsapp api·whatsapp bsp·whatsapp 服务商