Skip to content

微信小程序服务器接收消息推送(安全模式)对于JSON类型的数据支持不完善 #4068

Description

@chankam1024

简要描述

xml格式的数据在WxMaMessage类中有fromEncryptedXml方法,包含5个参数。
public static WxMaMessage fromEncryptedXml(String encryptedXml,
WxMaConfig wxMaConfig, String timestamp, String nonce,
String msgSignature)
该方法可以验证消息是否来源微信官方+解密消息。而json格式的数据,只有如下方法:
public static WxMaMessage fromEncryptedJson(String encryptedJson, WxMaConfig config)
该方法只能解密消息,无法验证消息来源。

我目前曲线救国的方案

// 1. 解析请求体,获取Encrypt字段
JSONObject bodyJson = JSONObject.parseObject(body);
String encrypt = bodyJson.getString("Encrypt");
// 2. 验证并解密
WxMaCryptUtils cryptUtils = new WxMaCryptUtils(wxMaService.getWxMaConfig());
String plainText = cryptUtils.decryptContent(msgSignature, timestamp, nonce, encrypt);

虽然可用,但觉得不太优雅,按理说应该也要有一个5个参数重载的fromEncryptedJson方法,同时验证并解密消息。

官方文档地址

https://developers.weixin.qq.com/miniprogram/dev/framework/server-ability/message-push.html

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions