1
This commit is contained in:
@@ -162,7 +162,7 @@ func (a *API) AccessAPISign(baseUrl, action, method string, pathParam string, bi
|
||||
if action != TokenActive {
|
||||
a.CheckToken()
|
||||
}
|
||||
Authorization, err := a.signParamRSA(bizParams, LaKaLaPrivateKey)
|
||||
Authorization, err := a.signParamPrivateKey(bizParams, LaKaLaPrivateKey)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
@@ -231,9 +231,10 @@ type ApplyContractParam struct {
|
||||
EcTypeCode string `json:"ec_type_code"` // 合同类别 M String(12) EC001 : 特约商户支付服务合作协议V3.1(商户入网) PASSPORT(护照);HK_MACAO_PASS(港澳居民往来内地通行证);TAIWAN_PASS(台湾居民来往大陆通行证);
|
||||
CertName string `json:"cert_name"` // 法人/经营者姓名 M String(32)
|
||||
CertNo string `json:"cert_no"` // 法人/经营者证件号码 M String(32)
|
||||
CertType string `json:"cert_type"` // 法人/经营者证件类型 M String(32)
|
||||
Mobile string `json:"mobile"` // 签约手机号 M String(16) 1.小微个人商户(无营业执照),签约手机号必须填写商户经营者本人手机号;2.个体工商户或企业商户(有营业执照),签约手机号必须填写法人手机号或者经办人手机号 合同签署人手机号,请慎重填写,不可修改
|
||||
BusinessLicenseMo string `json:"business_license_no"` // 营业执照号 C String(32) 个体工商户或企业商户 必传
|
||||
BusinessLicenseMame string `json:"business_license_name"` // 营业执照名称 C String(32) 个体工商户或企业商户 必传
|
||||
BusinessLicenseNo string `json:"business_license_no"` // 营业执照号 C String(32) 个体工商户或企业商户 必传
|
||||
BusinessLicenseName string `json:"business_license_name"` // 营业执照名称 C String(32) 个体工商户或企业商户 必传
|
||||
OpenningBankCode string `json:"openning_bank_code"` // 企业/经营者结算开户行号 M String(32)
|
||||
OpenningBankName string `json:"openning_bank_name"` // 企业/经营者结算开户行名称 M String(128)
|
||||
AcctTypeCode string `json:"acct_type_code"` // 企业/经营者结算卡性质 M String(2) 57 对公、 58 对私
|
||||
|
||||
@@ -5,6 +5,26 @@ import (
|
||||
"testing"
|
||||
)
|
||||
|
||||
func TestApplyElectronicContract(t *testing.T) {
|
||||
api.ApplyElectronicContract(&ApplyContractParam{
|
||||
OrderNo: "9839312025071609240676528932",
|
||||
OrgId: 983931,
|
||||
EcTypeCode: "EC008",
|
||||
CertType: "RESIDENT_ID",
|
||||
CertName: "石锋",
|
||||
CertNo: "610126198012230014",
|
||||
Mobile: "18048531223",
|
||||
BusinessLicenseNo: "915101003431062533",
|
||||
BusinessLicenseName: "成都若溪科技有限公司",
|
||||
OpenningBankCode: "305651000261",
|
||||
OpenningBankName: "中国民生银行股份有限公司成都金牛支行",
|
||||
AcctTypeCode: "58",
|
||||
AcctNo: "6226192004500005",
|
||||
AcctName: "石锋",
|
||||
EcContentParameters: "{\"A1\":\"成都若溪科技有限公司\",\"A29\":\"0.2\",\"A30\":\"0.2\",\"A31\":\"0.2\",\"A32\":\"0.2\",\"A33\":\"0.2\",\"A34\":\"0.2\",\"A88\":\"0.2\",\"A96\":\"D1\",\"A97\":\"开通\",\"A100\":\"不开通\",\"A101\":\"中国境内\",\"A104\":2025,\"A105\":7,\"A106\":16,\"A107\":2025,\"A108\":7,\"A109\":16}",
|
||||
})
|
||||
}
|
||||
|
||||
func TestCreateOrder(t *testing.T) {
|
||||
api.CreateOrder(&CreateOrderReq{
|
||||
OutOrderNo: "KFPT20220714160009228907288",
|
||||
|
||||
@@ -6,12 +6,6 @@ import (
|
||||
"testing"
|
||||
)
|
||||
|
||||
func TestSign(t *testing.T) {
|
||||
|
||||
api.signParamRSA(nil, LaKaLaPublicKey)
|
||||
|
||||
}
|
||||
|
||||
func TestPayStatusQuery(t *testing.T) {
|
||||
api.PayStatusQuery(&PayStatusQueryReq{
|
||||
MerchantNo: "822290059430BFA",
|
||||
|
||||
@@ -13,7 +13,6 @@ import (
|
||||
"errors"
|
||||
"fmt"
|
||||
"git.rosy.net.cn/baseapi/utils"
|
||||
"github.com/tjfoc/gmsm/sm4"
|
||||
"io"
|
||||
"io/ioutil"
|
||||
"math/big"
|
||||
@@ -135,35 +134,35 @@ type UploadImgResp struct {
|
||||
}
|
||||
|
||||
// signParamRSA 支付签名
|
||||
func (a *API) signParamRSA(params map[string]interface{}, RSAPrivate string) (sig string, err error) {
|
||||
block, _ := pem.Decode([]byte(RSAPrivate))
|
||||
private, err := x509.ParsePKCS8PrivateKey(block.Bytes)
|
||||
if err != nil {
|
||||
return "", err
|
||||
}
|
||||
|
||||
// 签名参数
|
||||
body, err := json.Marshal(params)
|
||||
if err != nil {
|
||||
return "", err
|
||||
}
|
||||
|
||||
//bodyData := base64.StdEncoding.EncodeToString(body)
|
||||
nonceStr := GenerateSecureRandomString(12)
|
||||
timeStamp := utils.Int64ToStr(time.Now().Unix())
|
||||
context := fmt.Sprintf("%s\n%s\n%s\n%s\n%s\n", a.appID, a.serialNo, timeStamp, nonceStr, string(body))
|
||||
|
||||
// 进行rsa加密签名
|
||||
hashed := sha256.Sum256([]byte(context))
|
||||
signedData, err := rsa.SignPKCS1v15(rand.Reader, private.(*rsa.PrivateKey), crypto.SHA256, hashed[:])
|
||||
if err != nil {
|
||||
return "", err
|
||||
}
|
||||
|
||||
signData := base64.StdEncoding.EncodeToString(signedData)
|
||||
authorization := fmt.Sprintf(`LKLAPI-SHA256withRSA appid="%s",serial_no="%s",timestamp="%s",nonce_str="%s",signature="%s"`, a.appID, a.serialNo, timeStamp, nonceStr, signData)
|
||||
return authorization, nil
|
||||
}
|
||||
//func (a *API) signParamRSA(params map[string]interface{}, RSAPrivate string) (sig string, err error) {
|
||||
// block, _ := pem.Decode([]byte(RSAPrivate))
|
||||
// private, err := x509.ParsePKCS8PrivateKey(block.Bytes)
|
||||
// if err != nil {
|
||||
// return "", err
|
||||
// }
|
||||
//
|
||||
// // 签名参数
|
||||
// body, err := json.Marshal(params)
|
||||
// if err != nil {
|
||||
// return "", err
|
||||
// }
|
||||
//
|
||||
// //bodyData := base64.StdEncoding.EncodeToString(body)
|
||||
// nonceStr := GenerateSecureRandomString(12)
|
||||
// timeStamp := utils.Int64ToStr(time.Now().Unix())
|
||||
// context := fmt.Sprintf("%s\n%s\n%s\n%s\n%s\n", a.appID, a.serialNo, timeStamp, nonceStr, string(body))
|
||||
//
|
||||
// // 进行rsa加密签名
|
||||
// hashed := sha256.Sum256([]byte(context))
|
||||
// signedData, err := rsa.SignPKCS1v15(rand.Reader, private.(*rsa.PrivateKey), crypto.SHA256, hashed[:])
|
||||
// if err != nil {
|
||||
// return "", err
|
||||
// }
|
||||
//
|
||||
// signData := base64.StdEncoding.EncodeToString(signedData)
|
||||
// authorization := fmt.Sprintf(`LKLAPI-SHA256withRSA appid="%s",serial_no="%s",timestamp="%s",nonce_str="%s",signature="%s"`, a.appID, a.serialNo, timeStamp, nonceStr, signData)
|
||||
// return authorization, nil
|
||||
//}
|
||||
|
||||
// signParamRSA 支付签名
|
||||
func (a *API) signParamPrivateKey(params map[string]interface{}, RSAPrivate string) (sig string, err error) {
|
||||
@@ -220,34 +219,6 @@ func GetOrderNumber(length int) string {
|
||||
return utils.Time2TimeStrByFormat(time.Now(), TimeFormat) + string(bytes)
|
||||
}
|
||||
|
||||
func SM4ECBEncrypt(plaintext, key []byte) ([]byte, error) {
|
||||
if len(key) != sm4.BlockSize {
|
||||
return nil, fmt.Errorf("SM4 密钥长度必须为 %d 字节", sm4.BlockSize)
|
||||
}
|
||||
// 补位处理 (PKCS5Padding)
|
||||
paddedText := PKCS5Padding(plaintext, sm4.BlockSize)
|
||||
|
||||
// ECB 模式加密
|
||||
ciphertext := make([]byte, len(paddedText))
|
||||
for i := 0; i < len(paddedText); i += sm4.BlockSize {
|
||||
block := paddedText[i : i+sm4.BlockSize]
|
||||
encryptedBlock, err := sm4.Sm4Ecb(key, block, true) // true 表示加密
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
copy(ciphertext[i:], encryptedBlock)
|
||||
}
|
||||
|
||||
return ciphertext, nil
|
||||
}
|
||||
|
||||
// PKCS5Padding 填充(与 PKCS7Padding 对于 128位分组等价)
|
||||
func PKCS5Padding(data []byte, blockSize int) []byte {
|
||||
padding := blockSize - len(data)%blockSize
|
||||
padtext := bytes.Repeat([]byte{byte(padding)}, padding)
|
||||
return append(data, padtext...)
|
||||
}
|
||||
|
||||
type CallBackResult struct {
|
||||
Code string `json:"code"`
|
||||
Message string `json:"message"`
|
||||
|
||||
@@ -47,8 +47,8 @@ oQIDAQAB
|
||||
|
||||
// 私钥文件目录C:\Users\Administrator\Desktop\拉克拉\拉卡拉私钥生成\RSA密钥生成工具V1.0.0\RSAKeys
|
||||
const (
|
||||
AppID = "OP00000003" // 接入方唯一ID lakala分配
|
||||
SerialNo = "00dfba8194c41b84cf" // 接入方生成的cer证书序列号 lakala分配
|
||||
AppID = "OP10001133" // 接入方唯一ID lakala分配
|
||||
SerialNo = "01970f6b2f33" // 接入方生成的cer证书序列号 lakala分配
|
||||
SM4Key = "LHo55AjrT4aDhAIBZhb5KQ==" // 国密4-参数加密使用 lakala分配
|
||||
MerchantNo = "82229007392000A" // 商户号 商户进件产生
|
||||
TermNo = "D9296400" // 终端号 商户进件产生
|
||||
|
||||
Reference in New Issue
Block a user