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

效果

相关推荐
酒书1 天前
springcloud阿里云OCR(个人证照)识别对接
阿里云·云计算·ocr
平行云1 天前
实时云渲染支持数字孪生智能工厂:迈向“零原型”制造
人工智能·unity·ue5·云计算·webrtc·制造·实时云渲染
翼龙云_cloud1 天前
阿里云渠道商:阿里云弹性伸缩混合管理指南
服务器·阿里云·云计算
豆豆1 天前
如何在liunx环境安装PageAdmin Cms系统
linux·服务器·云计算·cms·建站系统·建站平台·网站管理系统
21my_code1 天前
阿里云资源
阿里云·云计算
AKAMAI1 天前
圆满循环:Akamai 的演进如何为 AI 推理时代奠定基石
人工智能·云计算
自己的九又四分之三站台2 天前
阿里云百炼
阿里云·云计算
Solar20252 天前
机械制造业TOB企业获客软件选型指南:从挑战到解决方案的深度解析
java·大数据·服务器·架构·云计算
Exquisite.2 天前
云原生高级前置复习
linux·云原生·云计算
翼龙云_cloud2 天前
阿里云渠道商:如何使用弹性伸缩同时管理实例和托管实例?
服务器·阿里云·云计算