mirror of
https://github.com/silenceper/wechat.git
synced 2026-02-04 12:52:27 +08:00
* merge branch release-2.0 to v2 (#450) * feat: add/delete subscribe template (#449) * feat: 添加 SDKApiNotOpen 错误信息 (#448) * 添加微信客服SDK * polish:优化签名函数 * polish:优化注释内容 * polish:复用已有的Token以及CommonError,移除无用的输出 * polish:复用已有的消息加解密 * fix:修复错误信息被覆盖的问题 * polish:go fmt 文件 * polish:客服链接支持自定义参数并更新注释文档内容 * feat:支持微信客服回调请求的校验和消息的解析,复用原有的Signature和DecryptMsg方法 * feat:对外暴露SDKApiForbidden等错误 可以通过调用升级服务相关接口然后根据该错误判断微信客服配置来源 * feat:添加无效的open_kfid错误信息 * fix: 添加SDKApiNotOpen 错误信息 目前主要用于判断客户是否关闭了API授权,如果客户关闭了API功能导致服务异常,则可以引导用户执行相应的操作重新开启改功能 Co-authored-by: Afeyer <afeyer@h5base.cn> Co-authored-by: ZmJ <wzmmmmj@gmail.com> Co-authored-by: Afeyer <1500527791@qq.com> Co-authored-by: Afeyer <afeyer@h5base.cn> * Update go.yml (#452) * 修正字段问题 (#451) fix #443 * fix linux build failed when cgo disable (#453) Co-authored-by: ZmJ <wzmmmmj@gmail.com> Co-authored-by: Afeyer <1500527791@qq.com> Co-authored-by: Afeyer <afeyer@h5base.cn>
78 lines
2.1 KiB
Go
78 lines
2.1 KiB
Go
package notify
|
|
|
|
import (
|
|
"crypto/md5"
|
|
"encoding/base64"
|
|
"encoding/hex"
|
|
"encoding/xml"
|
|
"errors"
|
|
|
|
"github.com/silenceper/wechat/v2/util"
|
|
)
|
|
|
|
// reference: https://pay.weixin.qq.com/wiki/doc/api/jsapi.php?chapter=9_16&index=10
|
|
|
|
// RefundedResult 退款回调
|
|
type RefundedResult struct {
|
|
ReturnCode *string `xml:"return_code"`
|
|
ReturnMsg *string `xml:"return_msg"`
|
|
|
|
AppID *string `xml:"appid"`
|
|
MchID *string `xml:"mch_id"`
|
|
NonceStr *string `xml:"nonce_str"`
|
|
ReqInfo *string `xml:"req_info"`
|
|
}
|
|
|
|
// RefundedReqInfo 退款结果(明文)
|
|
type RefundedReqInfo struct {
|
|
TransactionID *string `xml:"transaction_id"`
|
|
OutTradeNO *string `xml:"out_trade_no"`
|
|
RefundID *string `xml:"refund_id"`
|
|
OutRefundNO *string `xml:"out_refund_no"`
|
|
TotalFee *int `xml:"total_fee"`
|
|
SettlementTotalFee *int `xml:"settlement_total_fee"`
|
|
RefundFee *int `xml:"refund_fee"`
|
|
SettlementRefundFee *int `xml:"settlement_refund_fee"`
|
|
RefundStatus *string `xml:"refund_status"`
|
|
SuccessTime *string `xml:"success_time"`
|
|
RefundRecvAccount *string `xml:"refund_recv_accout"`
|
|
RefundAccount *string `xml:"refund_account"`
|
|
RefundRequestSource *string `xml:"refund_request_source"`
|
|
}
|
|
|
|
// RefundedResp 消息通知返回
|
|
type RefundedResp struct {
|
|
ReturnCode string `xml:"return_code"`
|
|
ReturnMsg string `xml:"return_msg"`
|
|
}
|
|
|
|
// DecryptReqInfo 对退款结果进行解密
|
|
func (notify *Notify) DecryptReqInfo(result *RefundedResult) (*RefundedReqInfo, error) {
|
|
var err error
|
|
if result == nil || result.ReqInfo == nil {
|
|
return nil, errors.New("empty refunded_result or req_info")
|
|
}
|
|
|
|
base64Decode, err := base64.StdEncoding.DecodeString(*result.ReqInfo)
|
|
if err != nil {
|
|
return nil, err
|
|
}
|
|
|
|
hash := md5.New()
|
|
if _, err = hash.Write([]byte(notify.Key)); err != nil {
|
|
return nil, err
|
|
}
|
|
md5APIKey := hex.EncodeToString(hash.Sum(nil))
|
|
|
|
data, err := util.AesECBDecrypt(base64Decode, []byte(md5APIKey))
|
|
if err != nil {
|
|
return nil, err
|
|
}
|
|
|
|
res := &RefundedReqInfo{}
|
|
if err = xml.Unmarshal(data, res); err != nil {
|
|
return nil, err
|
|
}
|
|
return res, nil
|
|
}
|