Эх сурвалжийг харах

fix: 静默授权记录 sealBean.id 兼容 JSON 字符串

Co-authored-by: Cursor <cursoragent@cursor.com>
郭铭泽 5 өдөр өмнө
parent
commit
fedcd60041
2 өөрчлөгдсөн 70 нэмэгдсэн , 6 устгасан
  1. 25 6
      auth.go
  2. 45 0
      jsonflex.go

+ 25 - 6
auth.go

@@ -1,7 +1,6 @@
 package qiyuesuosdk
 
 import (
-	"strconv"
 	"time"
 
 	v2auth_request "git.sxidc.com/student-physical-examination/contract_lock_sdk/model/v2auth/request"
@@ -26,7 +25,27 @@ type companySealAuthURLResp struct {
 
 type companyAuthRecordResp struct {
 	apiResponse
-	Result []common.AuthorizedSealRecordBean `json:"result"`
+	Result []authorizedSealRecordItem `json:"result"`
+}
+
+type authorizedSealRecordItem struct {
+	AuthorizedSealRecord *authorizedSealRecord `json:"authorizedSealRecord"`
+	SealBean             *authorizedSealBean   `json:"sealBean"`
+}
+
+type authorizedSealRecord struct {
+	SealId    string `json:"sealId"`
+	StartTime string `json:"startTime"`
+	EndTime   string `json:"endTime"`
+	AuthScope string `json:"authScope"`
+	Status    string `json:"status"`
+}
+
+type authorizedSealBean struct {
+	ID            flexStringID `json:"id"`
+	Name          string       `json:"name"`
+	Type          string       `json:"type"`
+	SealAttribute string       `json:"sealAttribute"`
 }
 
 // CompanyCertificationURL 获取法人单位在线认证页 URL。
@@ -201,17 +220,17 @@ func (c *Client) ListAuthorizedCompanySeals(company CompanyLocateParams, status
 	return out, nil
 }
 
-func authorizedSealFromRecord(item common.AuthorizedSealRecordBean) AuthorizedCompanySeal {
+func authorizedSealFromRecord(item authorizedSealRecordItem) AuthorizedCompanySeal {
 	seal := AuthorizedCompanySeal{}
 	if item.AuthorizedSealRecord != nil {
 		seal.ID = item.AuthorizedSealRecord.SealId
 	}
 	if item.SealBean != nil {
-		if seal.ID == "" && item.SealBean.Id != nil {
-			seal.ID = strconv.FormatInt(*item.SealBean.Id, 10)
+		if seal.ID == "" {
+			seal.ID = item.SealBean.ID.String()
 		}
 		seal.Name = item.SealBean.Name
-		seal.Type = item.SealBean.Type_
+		seal.Type = item.SealBean.Type
 		seal.SealAttribute = item.SealBean.SealAttribute
 	}
 	return seal

+ 45 - 0
jsonflex.go

@@ -0,0 +1,45 @@
+package qiyuesuosdk
+
+import (
+	"encoding/json"
+	"fmt"
+	"strconv"
+)
+
+// flexStringID 兼容契约锁部分接口将大整数 id 以 JSON 字符串返回的情况。
+type flexStringID string
+
+func (f *flexStringID) UnmarshalJSON(data []byte) error {
+	if len(data) == 0 || string(data) == "null" {
+		*f = ""
+		return nil
+	}
+	switch data[0] {
+	case '"':
+		var s string
+		if err := json.Unmarshal(data, &s); err != nil {
+			return err
+		}
+		*f = flexStringID(s)
+		return nil
+	default:
+		var n json.Number
+		if err := json.Unmarshal(data, &n); err != nil {
+			return err
+		}
+		*f = flexStringID(n.String())
+		return nil
+	}
+}
+
+func (f flexStringID) String() string {
+	return string(f)
+}
+
+func (f flexStringID) Int64() (int64, error) {
+	s := f.String()
+	if s == "" {
+		return 0, fmt.Errorf("empty id")
+	}
+	return strconv.ParseInt(s, 10, 64)
+}