Browse Source

更新

master
huangjiajun 1 year ago
parent
commit
0da4ba477b
2 changed files with 24 additions and 1 deletions
  1. +23
    -0
      card_pay/api.go
  2. +1
    -1
      card_pay/card_pay.go

+ 23
- 0
card_pay/api.go View File

@@ -5,6 +5,7 @@ import (
"crypto" "crypto"
"crypto/rand" "crypto/rand"
"crypto/rsa" "crypto/rsa"
"crypto/x509"
"encoding/base64" "encoding/base64"
"fmt" "fmt"
"golang.org/x/crypto/ssh" "golang.org/x/crypto/ssh"
@@ -140,3 +141,25 @@ func CardPayGetSign(privateKeyStr string, data string) (string, error) {
} }
return base64.StdEncoding.EncodeToString(sign), nil return base64.StdEncoding.EncodeToString(sign), nil
} }
func RsaEncrypts(pubStr, data string) string {
// 公钥加密
// 读取公钥证书
certSlc, errCert := base64.StdEncoding.DecodeString(pubStr)
if errCert != nil {
return ""
}
//证书解析
certBody, errCertBody := x509.ParseCertificate(certSlc)
if errCertBody != nil {
return ""
}
// 提取公钥
rsaPublicKey := certBody.PublicKey.(*rsa.PublicKey)
// 对明文进行加密,PKCS(公钥密码标准),#1就是RSA的标准
cipherByte, err := rsa.EncryptPKCS1v15(rand.Reader, rsaPublicKey, []byte(data))
if err != nil {
return ""
}
return base64.StdEncoding.EncodeToString(cipherByte)

}

+ 1
- 1
card_pay/card_pay.go View File

@@ -4,7 +4,7 @@ package card_pay
func BindCard(keyArr, param map[string]string) (string, error) { func BindCard(keyArr, param map[string]string) (string, error) {
//param = map[string]string{ //param = map[string]string{
// "version": "2.0", // "version": "2.0",
// "mchtOrderNo": "123", //流水号不能为空
// "mchtOrderNo": "123456", //流水号不能为空
// "memberId": "562902003186055", //分账模式(splitModel)为“1-普通分账”的,该值一律传商户自编的编号。 // "memberId": "562902003186055", //分账模式(splitModel)为“1-普通分账”的,该值一律传商户自编的编号。
// "transType": "01", //值可填“01 快捷支付、02 代收”。 不填时默认 01 快捷支付 // "transType": "01", //值可填“01 快捷支付、02 代收”。 不填时默认 01 快捷支付
// "userName": RsaEncrypts("黄加价"), //分账主体商户姓名 // "userName": RsaEncrypts("黄加价"), //分账主体商户姓名


Loading…
Cancel
Save