切换主体

This commit is contained in:
ziming 2026-03-26 10:44:29 +08:00
parent cf9ecc4486
commit d5460e9415
4 changed files with 49 additions and 12 deletions

View File

@ -66,14 +66,24 @@ func (w *BankMultiActivityImpl) Notify(ctx context.Context, mchId string, header
return
}
decodeBodyStr, err := t.Notify(ctx, headers, respBody)
body, decodeBodyStr, err := t.Notify(ctx, headers, respBody)
if err != nil {
return
}
var plainText bo.PlainText
if err = json.Unmarshal([]byte(decodeBodyStr), &response); err != nil {
return nil, err
}
return
return &bo.WechatVoucherNotifyBo{
ID: body.Id,
CreateTime: body.CreateTime,
ResourceType: body.ResourceType,
EventType: body.EventType,
Summary: body.Summary,
//OriginalType: body.OriginalType,
//AssociatedData: body.AssociatedData,
PlainText: plainText,
}, nil
}

View File

@ -63,12 +63,12 @@ func (srv *Marketing) Query(appId, openId, couponId string) (response *SendResp,
}
// Notify .
func (srv *Marketing) Notify(_ context.Context, headers *http.Header, respBody []byte) (response string, err error) {
func (srv *Marketing) Notify(_ context.Context, headers *http.Header, respBody []byte) (body *utils.WxNotifyBody, response string, err error) {
bizStr, err := srv.GetDecodeBody(headers, respBody)
wxNotifyBody, bizStr, err := srv.GetDecodeBody(headers, respBody)
if err != nil {
return "", err
return nil, "", err
}
return bizStr, nil
return wxNotifyBody, bizStr, nil
}

View File

@ -0,0 +1,22 @@
package utils
import (
"testing"
)
func TestAes(t *testing.T) {
aesUtil, err := NewAesUtil("d9af70585b18ae206d981548c766563f")
if err != nil {
t.Errorf("NewAesUtil() error = %v", err)
return
}
gotResponse, err := aesUtil.DecryptToString("coupon", "pV96KsdLrSAd", "IfJmKJnBYezruwmk+IA+ENQBn13oWiLR1YnYi3bhYaqYreaXwFcFWbnnQjWfh8RDF36S1v+H1eLj0OtiQVDveLJ9vOcCrtr0M8bkV6NpRN7amqcf02vg+xLcs6UiZDedkN353nMnVVY1SAyuJj0AjKTUJrMhPNtxzdPpL/A3bMVCHrw4sqUItAOsDWVyJ5Kb09BEbdNOesmFkCc+Pcqmr554UHXzjQxzYimMpdbZ8OCovEy6JY1jnbxyiduDI7XBiTvxLr5CzLGlxNk1tIHUSrrDnRzUCpFJzNETgcrF3JWvQVAPThelGnTLN/TT3/pyM7/Kz60YNGaSbJTNKOtxbLXopk72x5hlt45fgrueP+RsnVQWmjULJ0AVEVmPNtlHTYRw7WV0cGwwrF7CCSDifYPed9QZPU1+awVtnGb3If53l109HojJiJB7Y0C/ZPX/vH/KLmtUx+10YKIFOo3vYnxEBV5lv4D5ZqXn4gOOtufVH/URYqgRqnzNFqJV6sW2qP6K9AgBhe/BO4AoeDDHG00XP89XFbeHmR2zZ019jBapq92YkvDVtQc2oLr9MWPoHJUhkmApwB6AmOK7ldWJ14P/Fws3/zBzCxVSlQsgLoDyBKm461ZnA6k09c+hffhTutLt89HYv+pqA1nukdTGuCWqPqUgx0AsK5i1CngrBQZJwc7+ylpakpOrX8oulyuA3So65hgMuqgl5dgkR0e8nvjjv7dVl0aRkqTZt3VL7BB1xwGqbvO3aTEuqqPrFQKLpnaY5Gz64dgg6huQFOBnZww=")
if err != nil {
t.Errorf("DecryptToString() error = %v", err)
return
}
t.Log(gotResponse)
}

View File

@ -576,10 +576,10 @@ func (srv *MchConfig) Verify(request *http.Request) (string, error) {
return EncryptOAEPWithPublicKey(string(respBody), srv.wechatPayPublicKey)
}
func (srv *MchConfig) GetDecodeBody(headers *http.Header, respBody []byte) (string, error) {
func (srv *MchConfig) GetDecodeBody(headers *http.Header, respBody []byte) (*WxNotifyBody, string, error) {
if respBody == nil {
return "", fmt.Errorf("request HttpBody is nil")
return nil, "", fmt.Errorf("request HttpBody is nil")
}
err := ValidateResponse(
@ -589,20 +589,25 @@ func (srv *MchConfig) GetDecodeBody(headers *http.Header, respBody []byte) (stri
respBody,
)
if err != nil {
return "", err
return nil, "", err
}
var wxNotifyBody WxNotifyBody
if err = json.Unmarshal(respBody, &wxNotifyBody); err != nil {
return "", err
return nil, "", err
}
aesUtil, err := NewAesUtil(srv.aesKey)
if err != nil {
return "", err
return nil, "", err
}
return aesUtil.DecryptToString(wxNotifyBody.Resource.AssociatedData, wxNotifyBody.Resource.Nonce, wxNotifyBody.Resource.Ciphertext)
decryptedText, err := aesUtil.DecryptToString(wxNotifyBody.Resource.AssociatedData, wxNotifyBody.Resource.Nonce, wxNotifyBody.Resource.Ciphertext)
if err != nil {
return nil, "", err
}
return &wxNotifyBody, decryptedText, nil
}
// BuildSortedQueryString 函数接受一个 map返回按照字段名排序后的 URL 键值对格式字符串