update
This commit is contained in:
@@ -182,24 +182,20 @@ func (s *CompanyInfoService) GetCompanyInfo(companyName string, apis []string) (
|
||||
// EvaluateTaxHealth 执行税务健康测评
|
||||
func (s *TaxHealthService) EvaluateTaxHealth(request TaxEvalRequest) (*TaxEvalResponse, error) {
|
||||
// 生成随机数和时间戳
|
||||
r, _ := rand.Int(rand.Reader, big.NewInt(10000))
|
||||
nonce := strconv.FormatInt(r.Int64(), 10)
|
||||
nonce := "12345"
|
||||
timestamp := strconv.FormatInt(time.Now().Unix()*1000, 10)
|
||||
fmt.Println(nonce)
|
||||
fmt.Println(timestamp)
|
||||
apiURL := "https://api.cmdp.cn/v1/eval/tax-risk"
|
||||
fmt.Println(apiURL)
|
||||
// 序列化请求体
|
||||
jsonData, err := json.Marshal(request)
|
||||
fmt.Println(string(jsonData))
|
||||
jsonDataStr := string(jsonData)
|
||||
fmt.Println(jsonDataStr)
|
||||
if err != nil {
|
||||
return nil, fmt.Errorf("序列化请求体失败: %v", err)
|
||||
}
|
||||
|
||||
// 生成签名
|
||||
signData := s.userID + timestamp + nonce + apiURL + string(jsonData)
|
||||
signData := s.userID + timestamp + nonce + apiURL + jsonDataStr
|
||||
signature, err := s.generateSignature([]byte(signData))
|
||||
fmt.Println(signature)
|
||||
if err != nil {
|
||||
return nil, fmt.Errorf("生成签名失败: %v", err)
|
||||
}
|
||||
@@ -214,7 +210,7 @@ func (s *TaxHealthService) EvaluateTaxHealth(request TaxEvalRequest) (*TaxEvalRe
|
||||
"x-gi-timestamp": timestamp,
|
||||
}
|
||||
// 发送POST请求
|
||||
response, err := s.httpClient.Post(apiURL, jsonData, "application/json", headers)
|
||||
response, err := s.httpClient.Post(apiURL, []byte(jsonDataStr), "application/json", headers)
|
||||
fmt.Println(string(response))
|
||||
if err != nil {
|
||||
return nil, fmt.Errorf("发送请求失败: %v", err)
|
||||
@@ -273,6 +269,7 @@ func (s *CompanyInfoService) generateSignature(plainText []byte) (string, error)
|
||||
return sign(plainText, s.privateKey)
|
||||
}
|
||||
func sign(data []byte, privateKeyHex string) (string, error) {
|
||||
|
||||
prvKeyBytes, err := hex.DecodeString(privateKeyHex)
|
||||
if err != nil {
|
||||
return "", fmt.Errorf("failed to decode private key hex: %v", err)
|
||||
@@ -289,11 +286,12 @@ func sign(data []byte, privateKeyHex string) (string, error) {
|
||||
return "", fmt.Errorf("failed to parse private key")
|
||||
}
|
||||
prvKey.PublicKey.Curve = sm2.P256Sm2()
|
||||
// 使用ScalarBaseMult计算公钥坐标,这是SM2曲线标准做法
|
||||
prvKey.PublicKey.X, prvKey.PublicKey.Y = sm2.P256Sm2().ScalarBaseMult(prvKey.D.Bytes())
|
||||
prvKey.PublicKey.X, prvKey.PublicKey.Y = prvKey.PublicKey.Curve.ScalarBaseMult(prvKey.D.Bytes())
|
||||
}
|
||||
|
||||
r, s, err := sm2.Sm2Sign(prvKey, data, nil, rand.Reader)
|
||||
// 使用空 UID
|
||||
uid := []byte{}
|
||||
r, s, err := sm2.Sm2Sign(prvKey, data, uid, rand.Reader)
|
||||
if err != nil {
|
||||
return "", fmt.Errorf("sign failed: %v", err)
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user