Forráskód Böngészése

feat: 个人静默授权按机构 applyCompany 传参与查询

UserSignSilentURL 支持 applyCompany;新增按 openCompanyId 查询授权记录。

Co-authored-by: Cursor <cursoragent@cursor.com>
郭铭泽 4 napja
szülő
commit
3b4d55ed10
2 módosított fájl, 57 hozzáadás és 11 törlés
  1. 13 4
      types.go
  2. 44 7
      user.go

+ 13 - 4
types.go

@@ -140,12 +140,21 @@ type PersonalSealAuthData struct {
 	CallbackTime string `json:"callbackTime"`
 }
 
+// ApplyCompanyParams 个人静默签授权目标法人单位(applyCompany)。
+type ApplyCompanyParams struct {
+	OpenCompanyID string
+	Name          string
+	RegisterNo    string
+}
+
 // AuthRecord 静默授权记录摘要。
 type AuthRecord struct {
-	Status    string
-	StartTime string
-	EndTime   string
-	AuthScope string
+	Status                    string
+	StartTime                 string
+	EndTime                   string
+	AuthScope                 string
+	ApplyCompanyOpenCompanyID string
+	ApplyCompanyName          string
 }
 
 // DefaultPersonalAuthDuration 个人静默授权默认时长(旧系统 10 个月,避免跨年重叠)。

+ 44 - 7
user.go

@@ -69,7 +69,8 @@ func (c *Client) CreateInternalUserSkipMobileConflict(p CreateUserParams) error
 }
 
 // UserSignSilentURL 获取个人签名静默授权页;authEnd 为空则默认 10 个月。
-func (c *Client) UserSignSilentURL(openUserID string, authEnd time.Time, completeToPage string) (string, error) {
+// applyCompany 传入当前体检机构(openCompanyId 通常等于 tenant_id),授权记录按机构维度拆分。
+func (c *Client) UserSignSilentURL(openUserID string, applyCompany ApplyCompanyParams, authEnd time.Time, completeToPage string) (string, error) {
 	if authEnd.IsZero() {
 		authEnd = time.Now().Add(DefaultPersonalAuthDuration)
 	}
@@ -81,6 +82,13 @@ func (c *Client) UserSignSilentURL(openUserID string, authEnd time.Time, complet
 		AuthorizedMode:     []string{"FACEAUTH", "PINAUTH"},
 		CompleteToPage:     completeToPage,
 	}
+	if applyCompany.OpenCompanyID != "" || applyCompany.Name != "" || applyCompany.RegisterNo != "" {
+		req.ApplyCompany = &common.PersonalApplyCompany{
+			Name:          applyCompany.Name,
+			RegisterNo:    applyCompany.RegisterNo,
+			OpenCompanyId: applyCompany.OpenCompanyID,
+		}
+	}
 	var resp struct {
 		apiResponse
 		Result v2auth_response.V2AuthPersonalsignsilentUrlResponse `json:"result"`
@@ -112,16 +120,39 @@ func (c *Client) QueryPersonalSignAuthRecords(openUserID, status string) ([]Auth
 	}
 	out := make([]AuthRecord, 0, len(resp.Result))
 	for _, item := range resp.Result {
-		out = append(out, AuthRecord{
-			Status:  item.Status,
-			EndTime: item.AuthEndDate,
-			AuthScope: item.AuthScope,
-		})
+		out = append(out, authRecordFromResponse(item))
 	}
 	return out, nil
 }
 
-// IsUserSignAuthorized 是否存在有效个人静默授权。
+func authRecordFromResponse(item v2auth_response.V2AuthSignsilentRecordResponse) AuthRecord {
+	rec := AuthRecord{
+		Status:    item.Status,
+		EndTime:   item.AuthEndDate,
+		AuthScope: item.AuthScope,
+	}
+	if item.ApplyCompany != nil {
+		rec.ApplyCompanyOpenCompanyID = item.ApplyCompany.OpenCompanyId
+		rec.ApplyCompanyName = item.ApplyCompany.Name
+	}
+	return rec
+}
+
+// PersonalSignAuthRecordForCompany 查询指定 openUserId 对某法人单位的静默授权记录。
+func (c *Client) PersonalSignAuthRecordForCompany(openUserID, openCompanyID, status string) (*AuthRecord, bool, error) {
+	records, err := c.QueryPersonalSignAuthRecords(openUserID, status)
+	if err != nil {
+		return nil, false, err
+	}
+	for i := range records {
+		if records[i].ApplyCompanyOpenCompanyID == openCompanyID {
+			return &records[i], true, nil
+		}
+	}
+	return nil, false, nil
+}
+
+// IsUserSignAuthorized 是否存在任意有效个人静默授权。
 func (c *Client) IsUserSignAuthorized(openUserID string) (bool, error) {
 	records, err := c.QueryPersonalSignAuthRecords(openUserID, "EFFECT")
 	if err != nil {
@@ -130,6 +161,12 @@ func (c *Client) IsUserSignAuthorized(openUserID string) (bool, error) {
 	return len(records) > 0, nil
 }
 
+// IsUserSignAuthorizedForCompany 是否已对指定法人单位完成有效个人静默授权。
+func (c *Client) IsUserSignAuthorizedForCompany(openUserID, openCompanyID string) (bool, error) {
+	_, found, err := c.PersonalSignAuthRecordForCompany(openUserID, openCompanyID, "EFFECT")
+	return found, err
+}
+
 // structFormFields 将 struct 转为 multipart 表单字段(与旧系统 HttpMultipart 行为一致)。
 func structFormFields(v any, arrayConnector string) (map[string]string, error) {
 	b, err := json.Marshal(v)