荣耀支付增加验单

This commit is contained in:
ayflying
2025-07-29 10:51:42 +08:00
parent d1a7ba8119
commit ccc50a7dd0
2 changed files with 38 additions and 3 deletions

View File

@@ -8,6 +8,7 @@ import (
"encoding/base64"
"encoding/pem"
"errors"
"github.com/ayflying/utility_go/package/pay"
)
type Pay struct {
@@ -15,8 +16,11 @@ type Pay struct {
AppId string `json:"appId"`
}
func New() *Pay {
return &Pay{}
func New(pay *Pay) *Pay {
return &Pay{
AppId: pay.AppId,
PubKey: pay.PubKey,
}
}
// VerifyRSASignature 验证RSA数字签名
@@ -31,8 +35,9 @@ func (p *Pay) VerifyRSASignature(data []byte, sign string) (bool, error) {
return false, errors.New("签名解码失败: " + err.Error())
}
pubkey := pay.FormatPublicKey(p.PubKey)
// 解析PEM格式的公钥
block, _ := pem.Decode([]byte(p.PubKey))
block, _ := pem.Decode([]byte(pubkey))
if block == nil {
return false, errors.New("无效的PEM格式公钥")
}