fix(iap/apple): 修复PEM格式私钥并添加调试回退逻辑
Build docker and publish / build (20.15.1) (push) Successful in 6m47s
Build docker and publish / build (20.15.1) (push) Successful in 6m47s
修复从请求中获取的PEM格式私钥缺少换行符的问题,自动添加正确格式 添加开发环境下的硬编码私钥回退逻辑,便于调试
This commit is contained in:
@@ -69,6 +69,25 @@ func (l *AttachTransactionByIdLogic) AttachById(req *types.AttachAppleTransactio
|
||||
if req.Sandbox != nil {
|
||||
apiCfg.Sandbox = *req.Sandbox
|
||||
}
|
||||
|
||||
// Try to fix PEM format if it is missing newlines (common issue)
|
||||
if !strings.Contains(apiCfg.PrivateKey, "\n") && strings.Contains(apiCfg.PrivateKey, "BEGIN PRIVATE KEY") {
|
||||
apiCfg.PrivateKey = strings.ReplaceAll(apiCfg.PrivateKey, " ", "\n")
|
||||
apiCfg.PrivateKey = strings.ReplaceAll(apiCfg.PrivateKey, "-----BEGIN\nPRIVATE\nKEY-----", "-----BEGIN PRIVATE KEY-----")
|
||||
apiCfg.PrivateKey = strings.ReplaceAll(apiCfg.PrivateKey, "-----END\nPRIVATE\nKEY-----", "-----END PRIVATE KEY-----")
|
||||
}
|
||||
|
||||
// Fallback to hardcoded key (For debugging/dev)
|
||||
if apiCfg.PrivateKey == "" {
|
||||
apiCfg.PrivateKey = `-----BEGIN PRIVATE KEY-----
|
||||
MIGTAgEAMBMGByqGSM49AgEGCCqGSM49AwEHBHkwdwIBAQQgsVDj0g/D7uNCm8aC
|
||||
E4TuaiDT4Pgb1IuuZ69YdGNvcAegCgYIKoZIzj0DAQehRANCAARObgGumaESbPMM
|
||||
SIRDAVLcWemp0fMlnfDE4EHmqcD58arEJWsr3aWEhc4BHocOUIGjko0cVWGchrFa
|
||||
/T/KG1tr
|
||||
-----END PRIVATE KEY-----`
|
||||
apiCfg.KeyID = "2C4X3HVPM8"
|
||||
}
|
||||
|
||||
if apiCfg.KeyID == "" || apiCfg.IssuerID == "" || apiCfg.PrivateKey == "" {
|
||||
l.Errorw("attach by id credential missing")
|
||||
return nil, errors.Wrapf(xerr.NewErrCode(xerr.ERROR), "apple server api credential missing")
|
||||
|
||||
Reference in New Issue
Block a user