Skip to content

Commit

Permalink
v1.5.96
Browse files Browse the repository at this point in the history
  • Loading branch information
iGoogle-ink committed Aug 19, 2023
1 parent 27f4a0a commit 52db751
Show file tree
Hide file tree
Showing 35 changed files with 116 additions and 110 deletions.
5 changes: 5 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,11 @@ func main() {

# 三、其他说明

* 如需自定义Log输出,请调用以下方法设置自定义Logger,实现 `xlog.XLogger` 接口即可。
* `xlog.SetDebugLog()`
* `xlog.SetInfoLog()`
* `xlog.SetWarnLog()`
* `xlog.SetErrLog()`
* 各支付方式接入,请仔细查看 `xxx_test.go` 使用方式
* `gopay/wechat/v3/client_test.go`
* `gopay/alipay/client_test.go`
Expand Down
4 changes: 2 additions & 2 deletions alipay/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,7 @@ func (a *Client) SetBodySize(sizeMB int) {
// Deprecated
// 推荐使用 PostAliPayAPISelfV2()
// 示例:请参考 client_test.go 的 TestClient_PostAliPayAPISelf() 方法
func (a *Client) PostAliPayAPISelf(ctx context.Context, bm gopay.BodyMap, method string, aliRsp interface{}) (err error) {
func (a *Client) PostAliPayAPISelf(ctx context.Context, bm gopay.BodyMap, method string, aliRsp any) (err error) {
var bs []byte
if bs, err = a.doAliPay(ctx, bm, method); err != nil {
return err
Expand Down Expand Up @@ -139,7 +139,7 @@ func (a *Client) RequestParam(bm gopay.BodyMap, method string) (string, error) {
// PostAliPayAPISelfV2 支付宝接口自行实现方法
// 注意:biz_content 需要自行通过bm.SetBodyMap()设置,不设置则没有此参数
// 示例:请参考 client_test.go 的 TestClient_PostAliPayAPISelfV2() 方法
func (a *Client) PostAliPayAPISelfV2(ctx context.Context, bm gopay.BodyMap, method string, aliRsp interface{}) (err error) {
func (a *Client) PostAliPayAPISelfV2(ctx context.Context, bm gopay.BodyMap, method string, aliRsp any) (err error) {
var (
bs, bodyBs []byte
)
Expand Down
4 changes: 2 additions & 2 deletions alipay/common_api.go
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ func FormatURLParam(body gopay.BodyMap) (urlParam string) {
// beanPtr:需要解析到的结构体指针
// 文档:https://opendocs.alipay.com/mini/introduce/aes
// 文档:https://opendocs.alipay.com/open/common/104567
func DecryptOpenDataToStruct(encryptedData, secretKey string, beanPtr interface{}) (err error) {
func DecryptOpenDataToStruct(encryptedData, secretKey string, beanPtr any) (err error) {
if encryptedData == util.NULL || secretKey == util.NULL {
return errors.New("encryptedData or secretKey is null")
}
Expand All @@ -45,7 +45,7 @@ func DecryptOpenDataToStruct(encryptedData, secretKey string, beanPtr interface{
return errors.New("传入参数类型必须是以指针形式")
}
if beanValue.Elem().Kind() != reflect.Struct {
return errors.New("传入interface{}必须是结构体")
return errors.New("传入any必须是结构体")
}
var (
block cipher.Block
Expand Down
14 changes: 7 additions & 7 deletions alipay/sign.go
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ A:开发者上传自己的应用公钥证书后,开放平台会为开发者
// certPathOrData x509证书文件路径(appPublicCert.crt、alipayPublicCert.crt) 或证书 buffer
// 返回 sn:证书序列号(app_cert_sn、alipay_cert_sn)
// 返回 err:error 信息
func GetCertSN(certPathOrData interface{}) (sn string, err error) {
func GetCertSN(certPathOrData any) (sn string, err error) {
var certData []byte
switch pathOrData := certPathOrData.(type) {
case string:
Expand Down Expand Up @@ -95,7 +95,7 @@ func GetCertSN(certPathOrData interface{}) (sn string, err error) {
// rootCertPathOrData x509证书文件路径(alipayRootCert.crt) 或文件 buffer
// 返回 sn:证书序列号(alipay_root_cert_sn)
// 返回 err:error 信息
func GetRootCertSN(rootCertPathOrData interface{}) (sn string, err error) {
func GetRootCertSN(rootCertPathOrData any) (sn string, err error) {
var (
certData []byte
certEnd = `-----END CERTIFICATE-----`
Expand Down Expand Up @@ -265,7 +265,7 @@ func VerifySyncSign(aliPayPublicKey, signData, sign string) (ok bool, err error)
// 返回参数ok:是否验签通过
// 返回参数err:错误信息
// 验签文档:https://opendocs.alipay.com/open/200/106120
func VerifySyncSignWithCert(alipayPublicKeyCert interface{}, signData, sign string) (ok bool, err error) {
func VerifySyncSignWithCert(alipayPublicKeyCert any, signData, sign string) (ok bool, err error) {
switch alipayPublicKeyCert.(type) {
case string:
if alipayPublicKeyCert == util.NULL {
Expand Down Expand Up @@ -311,7 +311,7 @@ func (a *Client) autoVerifySignByCert(sign, signData string, signDataErr error)
// 返回参数ok:是否验签通过
// 返回参数err:错误信息
// 验签文档:https://opendocs.alipay.com/open/200/106120
func VerifySign(alipayPublicKey string, notifyBean interface{}) (ok bool, err error) {
func VerifySign(alipayPublicKey string, notifyBean any) (ok bool, err error) {
if alipayPublicKey == util.NULL || notifyBean == nil {
return false, errors.New("alipayPublicKey or notifyBean is nil")
}
Expand Down Expand Up @@ -357,7 +357,7 @@ func VerifySign(alipayPublicKey string, notifyBean interface{}) (ok bool, err er
// 返回参数ok:是否验签通过
// 返回参数err:错误信息
// 验签文档:https://opendocs.alipay.com/open/200/106120
func VerifySignWithCert(aliPayPublicKeyCert, notifyBean interface{}) (ok bool, err error) {
func VerifySignWithCert(aliPayPublicKeyCert, notifyBean any) (ok bool, err error) {
if notifyBean == nil || aliPayPublicKeyCert == nil {
return false, errors.New("aliPayPublicKeyCert or notifyBean is nil")
}
Expand All @@ -373,7 +373,7 @@ func VerifySignWithCert(aliPayPublicKeyCert, notifyBean interface{}) (ok bool, e
var bm gopay.BodyMap

switch nb := notifyBean.(type) {
case map[string]interface{}:
case map[string]any:
bm = make(gopay.BodyMap, len(nb))
for key, val := range nb {
bm[key] = val
Expand Down Expand Up @@ -429,7 +429,7 @@ func verifySign(signData, sign, signType, alipayPublicKey string) (err error) {
return nil
}

func verifySignCert(signData, sign, signType string, alipayPublicKeyCert interface{}) (err error) {
func verifySignCert(signData, sign, signType string, alipayPublicKeyCert any) (err error) {
var (
h hash.Hash
hashs crypto.Hash
Expand Down
2 changes: 1 addition & 1 deletion apple/cert.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ func ParseECPrivateKeyFromPEM(key []byte) (*ecdsa.PrivateKey, error) {
return nil, errors.New("decode private key error")
}
// Parse the key
var parsedKey interface{}
var parsedKey any
if parsedKey, err = x509.ParseECPrivateKey(block.Bytes); err != nil {
if parsedKey, err = x509.ParsePKCS8PrivateKey(block.Bytes); err != nil {
return nil, err
Expand Down
2 changes: 1 addition & 1 deletion apple/token.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ func (c *Client) generatingToken() (string, error) {
}

token := jwt.NewWithClaims(jwt.SigningMethodES256, claims)
token.Header = map[string]interface{}{
token.Header = map[string]any{
"alg": "ES256",
"kid": c.kid,
"typ": "JWT",
Expand Down
2 changes: 1 addition & 1 deletion apple/unsign_jwt.go
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ func ExtractClaims(signedPayload string, tran jwt.Claims) (err error) {
if err = verifyCert(rootCertStr, intermediaCertStr); err != nil {
return err
}
_, err = jwt.ParseWithClaims(tokenStr, tran, func(token *jwt.Token) (interface{}, error) {
_, err = jwt.ParseWithClaims(tokenStr, tran, func(token *jwt.Token) (any, error) {
return extractPublicKeyFromToken(tokenStr)
})
if err != nil {
Expand Down
12 changes: 6 additions & 6 deletions body_map.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,11 +12,11 @@ import (
"github.com/go-pay/gopay/pkg/util"
)

type BodyMap map[string]interface{}
type BodyMap map[string]any

type xmlMapMarshal struct {
XMLName xml.Name
Value interface{} `xml:",cdata"`
Value any `xml:",cdata"`
}

type xmlMapUnmarshal struct {
Expand All @@ -25,7 +25,7 @@ type xmlMapUnmarshal struct {
}

// 设置参数
func (bm BodyMap) Set(key string, value interface{}) BodyMap {
func (bm BodyMap) Set(key string, value any) BodyMap {
bm[key] = value
return bm
}
Expand Down Expand Up @@ -65,7 +65,7 @@ func (bm BodyMap) GetString(key string) string {
}

// 获取原始参数
func (bm BodyMap) GetInterface(key string) interface{} {
func (bm BodyMap) GetInterface(key string) any {
if bm == nil {
return nil
}
Expand Down Expand Up @@ -94,7 +94,7 @@ func (bm BodyMap) JsonBody() (jb string) {
}

// Unmarshal to struct or slice point
func (bm BodyMap) Unmarshal(ptr interface{}) (err error) {
func (bm BodyMap) Unmarshal(ptr any) (err error) {
bs, err := json.Marshal(bm)
if err != nil {
return err
Expand Down Expand Up @@ -226,7 +226,7 @@ func (bm BodyMap) CheckEmptyError(keys ...string) error {
return nil
}

func convertToString(v interface{}) (str string) {
func convertToString(v any) (str string) {
if v == nil {
return NULL
}
Expand Down
8 changes: 4 additions & 4 deletions paypal/model.go
Original file line number Diff line number Diff line change
Expand Up @@ -230,10 +230,10 @@ type InvoiceTemplateUpdateRsp struct {
// ==================================分割==================================

type Patch struct {
Op string `json:"op"` // The possible values are: add、remove、replace、move、copy、test
Path string `json:"path,omitempty"`
Value interface{} `json:"value"` // The value to apply. The remove operation does not require a value.
From string `json:"from,omitempty"`
Op string `json:"op"` // The possible values are: add、remove、replace、move、copy、test
Path string `json:"path,omitempty"`
Value any `json:"value"` // The value to apply. The remove operation does not require a value.
From string `json:"from,omitempty"`
}

type OrderDetail struct {
Expand Down
2 changes: 1 addition & 1 deletion paypal/payout_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ func TestCreateBatchPayout(t *testing.T) {
bm.Set("sender_batch_id", "2022060811140003").
Set("email_subject", "You have a payout!").
Set("email_message", "You have received a payout! Thanks for using our service!")
}).Set("items", []map[string]interface{}{
}).Set("items", []map[string]any{
{
"recipient_type": "EMAIL",
"amount": map[string]string{
Expand Down
4 changes: 2 additions & 2 deletions pkg/jwt/ecdsa.go
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ func (m *SigningMethodECDSA) Alg() string {

// Implements the Verify method from SigningMethod
// For this verify method, key must be an ecdsa.PublicKey struct
func (m *SigningMethodECDSA) Verify(signingString, signature string, key interface{}) error {
func (m *SigningMethodECDSA) Verify(signingString, signature string, key any) error {
var err error

// Decode the signature
Expand Down Expand Up @@ -97,7 +97,7 @@ func (m *SigningMethodECDSA) Verify(signingString, signature string, key interfa

// Implements the Sign method from SigningMethod
// For this signing method, key must be an ecdsa.PrivateKey struct
func (m *SigningMethodECDSA) Sign(signingString string, key interface{}) (string, error) {
func (m *SigningMethodECDSA) Sign(signingString string, key any) (string, error) {
// Get the key
var ecdsaKey *ecdsa.PrivateKey
switch k := key.(type) {
Expand Down
4 changes: 2 additions & 2 deletions pkg/jwt/hmac.go
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ func (m *SigningMethodHMAC) Alg() string {
}

// Verify the signature of HSXXX tokens. Returns nil if the signature is valid.
func (m *SigningMethodHMAC) Verify(signingString, signature string, key interface{}) error {
func (m *SigningMethodHMAC) Verify(signingString, signature string, key any) error {
// Verify the key is the right type
keyBytes, ok := key.([]byte)
if !ok {
Expand Down Expand Up @@ -79,7 +79,7 @@ func (m *SigningMethodHMAC) Verify(signingString, signature string, key interfac

// Implements the Sign method from SigningMethod for this signing method.
// Key must be []byte
func (m *SigningMethodHMAC) Sign(signingString string, key interface{}) (string, error) {
func (m *SigningMethodHMAC) Sign(signingString string, key any) (string, error) {
if keyBytes, ok := key.([]byte); ok {
if !m.Hash.Available() {
return "", ErrHashUnavailable
Expand Down
6 changes: 3 additions & 3 deletions pkg/jwt/map_claims.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,9 @@ import (
"errors"
)

// Claims type that uses the map[string]interface{} for JSON decoding
// Claims type that uses the map[string]any for JSON decoding
// This is the default claims type if you don't supply one
type MapClaims map[string]interface{}
type MapClaims map[string]any

// VerifyAudience Compares the aud claim against cmp.
// If required is false, this method will return true if the value matches or is unset
Expand All @@ -18,7 +18,7 @@ func (m MapClaims) VerifyAudience(cmp string, req bool) bool {
aud = append(aud, v)
case []string:
aud = v
case []interface{}:
case []any:
for _, a := range v {
vs, ok := a.(string)
if !ok {
Expand Down
2 changes: 1 addition & 1 deletion pkg/jwt/parser.go
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ func (p *Parser) ParseWithClaims(tokenString string, claims Claims, keyFunc Keyf
}

// Lookup key
var key interface{}
var key any
if keyFunc == nil {
// keyFunc was not provided. short circuiting validation
return token, NewValidationError("no Keyfunc was provided.", ValidationErrorUnverifiable)
Expand Down
4 changes: 2 additions & 2 deletions pkg/jwt/rsa.go
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ func (m *SigningMethodRSA) Alg() string {

// Implements the Verify method from SigningMethod
// For this signing method, must be an *rsa.PublicKey structure.
func (m *SigningMethodRSA) Verify(signingString, signature string, key interface{}) error {
func (m *SigningMethodRSA) Verify(signingString, signature string, key any) error {
var err error

// Decode the signature
Expand Down Expand Up @@ -81,7 +81,7 @@ func (m *SigningMethodRSA) Verify(signingString, signature string, key interface

// Implements the Sign method from SigningMethod
// For this signing method, must be an *rsa.PrivateKey structure.
func (m *SigningMethodRSA) Sign(signingString string, key interface{}) (string, error) {
func (m *SigningMethodRSA) Sign(signingString string, key any) (string, error) {
var rsaKey *rsa.PrivateKey
var ok bool

Expand Down
4 changes: 2 additions & 2 deletions pkg/jwt/rsa_pss.go
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,7 @@ func init() {

// Implements the Verify method from SigningMethod
// For this verify method, key must be an rsa.PublicKey struct
func (m *SigningMethodRSAPSS) Verify(signingString, signature string, key interface{}) error {
func (m *SigningMethodRSAPSS) Verify(signingString, signature string, key any) error {
var err error

// Decode the signature
Expand Down Expand Up @@ -116,7 +116,7 @@ func (m *SigningMethodRSAPSS) Verify(signingString, signature string, key interf

// Implements the Sign method from SigningMethod
// For this signing method, key must be an rsa.PrivateKey struct
func (m *SigningMethodRSAPSS) Sign(signingString string, key interface{}) (string, error) {
func (m *SigningMethodRSAPSS) Sign(signingString string, key any) (string, error) {
var rsaKey *rsa.PrivateKey

switch k := key.(type) {
Expand Down
6 changes: 3 additions & 3 deletions pkg/jwt/signing_method.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,9 @@ var signingMethodLock = new(sync.RWMutex)

// Implement SigningMethod to add new methods for signing or verifying tokens.
type SigningMethod interface {
Verify(signingString, signature string, key interface{}) error // Returns nil if signature is valid
Sign(signingString string, key interface{}) (string, error) // Returns encoded signature or error
Alg() string // returns the alg identifier for this method (example: 'HS256')
Verify(signingString, signature string, key any) error // Returns nil if signature is valid
Sign(signingString string, key any) (string, error) // Returns encoded signature or error
Alg() string // returns the alg identifier for this method (example: 'HS256')
}

// Register the "alg" name and a factory function for signing method.
Expand Down
18 changes: 9 additions & 9 deletions pkg/jwt/token.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,17 +16,17 @@ var TimeFunc = time.Now
// the key for verification. The function receives the parsed,
// but unverified Token. This allows you to use properties in the
// Header of the token (such as `kid`) to identify which key to use.
type Keyfunc func(*Token) (interface{}, error)
type Keyfunc func(*Token) (any, error)

// A JWT Token. Different fields will be used depending on whether you're
// creating or parsing/verifying a token.
type Token struct {
Raw string // The raw token. Populated when you Parse a token
Method SigningMethod // The signing method used or to be used
Header map[string]interface{} // The first segment of the token
Claims Claims // The second segment of the token
Signature string // The third segment of the token. Populated when you Parse a token
Valid bool // Is the token valid? Populated when you Parse/Verify a token
Raw string // The raw token. Populated when you Parse a token
Method SigningMethod // The signing method used or to be used
Header map[string]any // The first segment of the token
Claims Claims // The second segment of the token
Signature string // The third segment of the token. Populated when you Parse a token
Valid bool // Is the token valid? Populated when you Parse/Verify a token
}

// Create a new Token. Takes a signing method
Expand All @@ -36,7 +36,7 @@ func New(method SigningMethod) *Token {

func NewWithClaims(method SigningMethod, claims Claims) *Token {
return &Token{
Header: map[string]interface{}{
Header: map[string]any{
"typ": "JWT",
"alg": method.Alg(),
},
Expand All @@ -46,7 +46,7 @@ func NewWithClaims(method SigningMethod, claims Claims) *Token {
}

// Get the complete, signed token
func (t *Token) SignedString(key interface{}) (string, error) {
func (t *Token) SignedString(key any) (string, error) {
var sig, sstr string
var err error
if sstr, err = t.SigningString(); err != nil {
Expand Down
2 changes: 1 addition & 1 deletion pkg/util/string.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ package util

import "encoding/json"

func ConvertToString(v interface{}) (str string) {
func ConvertToString(v any) (str string) {
if v == nil {
return NULL
}
Expand Down
Loading

0 comments on commit 52db751

Please sign in to comment.