diff --git a/utils/alipay/cert.go b/utils/alipay/cert.go index 02864f7..ae3413a 100644 --- a/utils/alipay/cert.go +++ b/utils/alipay/cert.go @@ -44,34 +44,41 @@ func GetCert(appId string) (*CertConfig, error) { if c != nil { return c, nil } + dir, err := os.Getwd() if err != nil { return nil, fmt.Errorf("get current dir error: %v", err) } + filePath := fmt.Sprintf("%s/%s/%s/%s", dir, "cert", "alipay", appId) if !helper.FileExists(filePath) { - return nil, fmt.Errorf("appId[%s]支付宝密钥文件信息不存在,请联系技术人员处理", appId) + return nil, fmt.Errorf("appId[%s][%s]支付宝密钥文件信息不存在,请联系技术人员处理", appId, filePath) } + mchCertPath := fmt.Sprintf("%s/%s_%s.crt", filePath, "appCertPublicKey", appId) mchCertSN, err := getMchCertSN(mchCertPath) if err != nil { return nil, fmt.Errorf("get mchCertSN error: %v", err) } + rootCertPath := fmt.Sprintf("%s/%s", filePath, "alipayRootCert.crt") rootCertSN, err := getRootCertSN(rootCertPath) if err != nil { return nil, fmt.Errorf("get rootCertSN error: %v", err) } + publicKeyPath := fmt.Sprintf("%s/%s", filePath, "alipayCertPublicKey_RSA2.crt") publicKey, err := getPublicKey(publicKeyPath) if err != nil { return nil, fmt.Errorf("get publicKey error: %v", err) } + c = &CertConfig{ MchCertSN: mchCertSN, RootCertSN: rootCertSN, PublicKey: publicKey, } setCertConfig(appId, c) + return c, nil }