f
This commit is contained in:
@@ -90,7 +90,7 @@ func (s *NuoerService) logError(transactionID, apiKey, seqNo string, err error,
|
||||
s.logger.LogError(seqNo, transactionID, apiKey, err, payload)
|
||||
}
|
||||
|
||||
func (s *NuoerService) CallAPI(ctx context.Context, apiKey, apiPath string, body map[string]string) (*nuoerResponse, error) {
|
||||
func (s *NuoerService) CallAPI(ctx context.Context, apiKey, apiPath string, body map[string]string, encryptionType ...int) (*nuoerResponse, error) {
|
||||
requestURL := strings.TrimSuffix(s.config.URL, "/")
|
||||
if apiPath != "" {
|
||||
if !strings.HasPrefix(apiPath, "/") {
|
||||
@@ -106,14 +106,27 @@ func (s *NuoerService) CallAPI(ctx context.Context, apiKey, apiPath string, body
|
||||
transactionID = id
|
||||
}
|
||||
|
||||
// 对调用方传入的 body 全量参与加签(排除空值,按 key 升序,见 Sign)
|
||||
sign := Sign(body, s.config.AppSecret)
|
||||
var encType int
|
||||
if len(encryptionType) > 0 {
|
||||
encType = encryptionType[0]
|
||||
}
|
||||
|
||||
requestBody := body
|
||||
if encType == 2 {
|
||||
requestBody = encryptBodyMD5(body)
|
||||
}
|
||||
|
||||
// 对请求 body 全量参与加签(排除空值,按 key 升序,见 Sign)
|
||||
sign := Sign(requestBody, s.config.AppSecret)
|
||||
|
||||
requestPayload := map[string]interface{}{
|
||||
"appId": s.config.AppID,
|
||||
"sign": sign,
|
||||
"apiKey": apiKey,
|
||||
"body": body,
|
||||
"body": requestBody,
|
||||
}
|
||||
if encType > 0 {
|
||||
requestPayload["encryptionType"] = encType
|
||||
}
|
||||
|
||||
if s.logger != nil {
|
||||
|
||||
Reference in New Issue
Block a user