package paymentService import ( "PaymentCenter/config" "context" "crypto/md5" "encoding/hex" "encoding/pem" "errors" "fmt" "github.com/go-pay/gopay" "github.com/qit-team/snow-core/kernel/server" "github.com/tjfoc/gmsm/x509" "os" "strings" "testing" ) func TestMarketSendRequest_Market(t *testing.T) { c := context.Background() //解析启动命令 opts := config.GetOptions() if opts.ShowVersion { fmt.Printf("%s\ncommit %s\nbuilt on %s\n", server.Version, server.BuildCommit, server.BuildDate) os.Exit(0) } //加载配置 opts.ConfFile = "../../../.env" _, err := config.Load(opts.ConfFile) if err != nil { return } request := PayOrderRequest{ OrderId: 12312312312, ChannelType: 6, Description: "测试商品", Amount: 1, PayerClientIp: "192.168.110.235", Ali: AliPay{ AppId: "9021000139661858", PrivateKey: "MIIEogIBAAKCAQEAiJ6MGX+/0oDMbVcFOew70ukNft55HvBmfD2+oBMMZ7ZfvPXGTQYtsA/0Q8BY9CMQh/Oa42jXiM7Upn3STMD7ZcaNtdJcUItQln1xfjKBQHfl2TPnvyVpOP96QsJQCOga5ThI9Nuv6R7nVsO+4HvbJ4m8fuRQboBwhf88pqfDMbvjd6WW7ZcqO7GoFODmbIsGZrakMMJ5taMY+gYZhPGlZSMUFq7NzGIcw4rdpRE4j24nUwbkIC6S5pcbLPz1j6gbp4u9FYXPNhq09P9m8ho/UctKPYA/Awx3sh4STTCUFND0hSBRS88IF7Ta5IEkMx8mpekh4mXH/DMNu6SnbuoV4wIDAQABAoIBAG8aAHT8HtLhS13f1rA0HLJ4NDFoWrd+aNnAnLUwyHXPKixQ8uLQk3cKgmpWkgB4Q4lL4jntmNn42ZZL3CnvBoLN5ZBncgtOQEsh2Jn4GISE/LaWL3CSy+8+U/7WZp/XoYenLi1yOqwqJZe5uBB2qNKOgGvw4Df824Uc/AXLiEF4ik07fSxGUmLbri5OASJqyMHu4iFYGd+Vc1ulafBDoSVuj5UPqNINba6YdJUU32P9xvkQkjosdjlf5nkzDXqDmNiXfee4mhFD1lpQvpRrZ2xRB78PA6Lzm9agrX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nFXtyuCljANnXnM38ft+ikhE5mMNgKmJYLHvT\nyWWWgwHoSAWEuml7EGbE/2AK2h3k0MdfiWLzdmpPCRG/RJHk6UB1pMHPilI+c0MVu16OPpKbg5Vf\nLTv7dsAB40AzKsvyYw88/Ezi1osTXo6QQwda7uefvudirtb8FcQM9R66cJxl3kt1FXbpYwheIm/p\nj1mq64swCoIYu4NrsUYtn6CV542DTQMI5QdXkn+PzUUly8F6kDp+KpMNd0avfWNL5+O++z+F5Szy\n1CPta1D7EQ/eYmMP+mOQ35oifWIoFCpN6qQVBS/Hob1J/UUyg7BW\n-----END CERTIFICATE-----\n"), }, } PaymentService(c, request) } func GetCertSN(certPathOrData any) (sn string, err error) { var certData []byte switch pathOrData := certPathOrData.(type) { case string: certData, err = os.ReadFile(pathOrData) if err != nil { return gopay.NULL, err } case []byte: certData = pathOrData default: return gopay.NULL, errors.New("certPathOrData 证书类型断言错误") } if block, _ := pem.Decode(certData); block != nil { cert, err := x509.ParseCertificate(block.Bytes) if err != nil { return gopay.NULL, err } name := cert.Issuer.String() serialNumber := cert.SerialNumber.String() h := md5.New() h.Write([]byte(name)) h.Write([]byte(serialNumber)) sn = hex.EncodeToString(h.Sum(nil)) } if sn == gopay.NULL { return gopay.NULL, errors.New("failed to get sn,please check your cert") } return sn, nil } func GetRootCertSN(rootCertPathOrData any) (sn string, err error) { var ( certData []byte certEnd = `-----END CERTIFICATE-----` ) switch pathOrData := rootCertPathOrData.(type) { case string: certData, err = os.ReadFile(pathOrData) if err != nil { return gopay.NULL, err } case []byte: certData = pathOrData default: return gopay.NULL, errors.New("rootCertPathOrData 断言异常") } pems := strings.Split(string(certData), certEnd) for _, c := range pems { if block, _ := pem.Decode([]byte(c + certEnd)); block != nil { cert, err := x509.ParseCertificate(block.Bytes) if err != nil { continue } if !allowSignatureAlgorithm[cert.SignatureAlgorithm.String()] { continue } name := cert.Issuer.String() serialNumber := cert.SerialNumber.String() h := md5.New() h.Write([]byte(name)) h.Write([]byte(serialNumber)) if sn == gopay.NULL { sn += hex.EncodeToString(h.Sum(nil)) } else { sn += "_" + hex.EncodeToString(h.Sum(nil)) } } } if sn == gopay.NULL { return gopay.NULL, errors.New("failed to get sn,please check your cert") } return sn, nil } // 允许进行 sn 提取的证书签名算法 var allowSignatureAlgorithm = map[string]bool{ "MD2-RSA": true, "MD5-RSA": true, "SHA1-RSA": true, "SHA256-RSA": true, "SHA384-RSA": true, "SHA512-RSA": true, "SHA256-RSAPSS": true, "SHA384-RSAPSS": true, "SHA512-RSAPSS": true, }