PaymentCenter/app/third/paymentService/psbc/notify.go

41 lines
1.1 KiB
Go
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

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
}