41 lines
1.1 KiB
Go
41 lines
1.1 KiB
Go
package payment
|
||
|
||
import (
|
||
"encoding/json"
|
||
"fmt"
|
||
)
|
||
|
||
// DecryptNotify 解密回调通知
|
||
func (c *Client) DecryptNotify(rawJson string) (string, error) {
|
||
return c.DecryptResponse(rawJson, true)
|
||
}
|
||
|
||
// VerifyNotifySignature 验证回调通知签名
|
||
func (c *Client) VerifyNotifySignature(content, signature string) bool {
|
||
return c.VerifySignature(content, signature)
|
||
}
|
||
|
||
// ParseNotify 解析回调通知
|
||
func (c *Client) ParseNotify(rawJson string) (*NotifyRequest, error) {
|
||
var req NotifyRequest
|
||
if err := json.Unmarshal([]byte(rawJson), &req); err != nil {
|
||
return nil, fmt.Errorf("解析通知失败: %v", err)
|
||
}
|
||
return &req, nil
|
||
}
|
||
|
||
// VerifyAndParseNotify 验签并解析回调通知
|
||
func (c *Client) VerifyAndParseNotify(rawJson string) (*YouChuOrderNotifyRequest, error) {
|
||
decrypted, err := c.DecryptNotify(rawJson)
|
||
if err != nil {
|
||
return nil, fmt.Errorf("解密通知失败: %v", err)
|
||
}
|
||
|
||
var result YouChuOrderNotifyRequest
|
||
if err := json.Unmarshal([]byte(decrypted), &result); err != nil {
|
||
return nil, fmt.Errorf("解析解密后数据失败: %v,解密内容: %s", err, decrypted)
|
||
}
|
||
|
||
return &result, nil
|
||
}
|