1
0
mirror of https://github.com/silenceper/wechat.git synced 2026-02-07 22:22:28 +08:00

Compare commits

..

5 Commits

Author SHA1 Message Date
copilot-swe-agent[bot]
8157cad2cb Fix: Change ErrorCode field type from int to string in SubscribeMsgSentList
Co-authored-by: silenceper <2044558+silenceper@users.noreply.github.com>
2025-10-24 10:30:40 +00:00
copilot-swe-agent[bot]
be6e95e987 Initial plan 2025-10-24 10:24:55 +00:00
silenceper
c806a0c172 Add star badge to README 2025-10-24 17:37:01 +08:00
zhangjiani
c136b878ce 调整企微回调URL参数tag,兼容kratos框架 (#855)
* fix: handle JSON parse error when API returns binary file instead of error JSON

* fix: add JSON tags to SignatureOptions struct fields for proper serialization

* fix: mod module

* fix: rollback

---------

Co-authored-by: tax <jia_deng@intsig.net>
2025-09-19 11:16:52 +08:00
zhangjiani
d4a81916d5 fix: handle JSON parse error when API returns binary file instead of error JSON (#852)
Co-authored-by: tax <jia_deng@intsig.net>
2025-09-14 19:47:00 +08:00
5 changed files with 24 additions and 13 deletions

View File

@@ -4,6 +4,8 @@
[![Go Report Card](https://goreportcard.com/badge/github.com/silenceper/wechat/v2)](https://goreportcard.com/report/github.com/silenceper/wechat/v2) [![Go Report Card](https://goreportcard.com/badge/github.com/silenceper/wechat/v2)](https://goreportcard.com/report/github.com/silenceper/wechat/v2)
[![pkg](https://img.shields.io/badge/dev-reference-007d9c?logo=go&logoColor=white&style=flat)](https://pkg.go.dev/github.com/silenceper/wechat/v2?tab=doc) [![pkg](https://img.shields.io/badge/dev-reference-007d9c?logo=go&logoColor=white&style=flat)](https://pkg.go.dev/github.com/silenceper/wechat/v2?tab=doc)
![GitHub release (latest SemVer)](https://img.shields.io/github/v/release/silenceper/wechat?sort=semver) ![GitHub release (latest SemVer)](https://img.shields.io/github/v/release/silenceper/wechat?sort=semver)
![star](https://gitcode.com/silenceper/wechat/star/badge.svg)
使用Golang开发的微信SDK简单、易用。 使用Golang开发的微信SDK简单、易用。

View File

@@ -556,7 +556,7 @@ type SubscribeMsgSentEvent struct {
type SubscribeMsgSentList struct { type SubscribeMsgSentList struct {
TemplateID string `xml:"TemplateId" json:"TemplateId"` TemplateID string `xml:"TemplateId" json:"TemplateId"`
MsgID string `xml:"MsgID" json:"MsgID"` MsgID string `xml:"MsgID" json:"MsgID"`
ErrorCode int `xml:"ErrorCode" json:"ErrorCode"` ErrorCode string `xml:"ErrorCode" json:"ErrorCode"`
ErrorStatus string `xml:"ErrorStatus" json:"ErrorStatus"` ErrorStatus string `xml:"ErrorStatus" json:"ErrorStatus"`
} }

View File

@@ -68,3 +68,18 @@ func DecodeWithError(response []byte, obj interface{}, apiName string) error {
} }
return nil return nil
} }
// HandleFileResponse 通用处理微信等接口返回:有时 JSON 错误,有时文件内容
func HandleFileResponse(response []byte, apiName string) ([]byte, error) {
var commErr CommonError
if err := json.Unmarshal(response, &commErr); err == nil {
// 能解析成 JSON判断是否为错误
if commErr.ErrCode != 0 {
commErr.apiName = apiName
return nil, &commErr
}
// 能解析成 JSON 且没错误码,极少情况(比如微信返回的业务数据是 JSON 但无 errcode 字段),可根据需要调整
}
// 不能解析成 JSON或没错误码直接返回原始内容
return response, nil
}

View File

@@ -8,10 +8,10 @@ import (
// SignatureOptions 微信服务器验证参数 // SignatureOptions 微信服务器验证参数
type SignatureOptions struct { type SignatureOptions struct {
Signature string `form:"msg_signature"` Signature string `form:"msg_signature" json:"msg_signature"`
TimeStamp string `form:"timestamp"` TimeStamp string `form:"timestamp" json:"timestamp"`
Nonce string `form:"nonce"` Nonce string `form:"nonce" json:"nonce"`
EchoStr string `form:"echostr"` EchoStr string `form:"echostr" json:"echostr"`
} }
// VerifyURL 验证请求参数是否合法并返回解密后的消息内容 // VerifyURL 验证请求参数是否合法并返回解密后的消息内容

View File

@@ -191,12 +191,6 @@ func (r *Client) GetTempFile(mediaID string) ([]byte, error) {
return nil, err return nil, err
} }
// 检查响应是否为错误信息 // 检查响应是否为错误信息,如果不是错误响应,则返回原始数据
err = util.DecodeWithCommonError(response, "GetTempFile") return util.HandleFileResponse(response, "GetTempFile")
if err != nil {
return nil, err
}
// 如果不是错误响应,则返回原始数据
return response, nil
} }