Przeglądaj źródła

feat: 支持按信用代码/手机号查询已有认证与授权

旧系统已认证企业和个人可按 registerNo、名称或手机号定位,无需改 openCompanyId。

Co-authored-by: Cursor <cursoragent@cursor.com>
郭铭泽 2 tygodni temu
rodzic
commit
13364da97b
3 zmienionych plików z 150 dodań i 33 usunięć
  1. 3 3
      auth.go
  2. 49 17
      types.go
  3. 98 13
      user.go

+ 3 - 3
auth.go

@@ -3,9 +3,9 @@ package qiyuesuosdk
 import (
 	"time"
 
+	"git.sxidc.com/student-physical-examination/contract_lock_sdk/model/common"
 	v2auth_request "git.sxidc.com/student-physical-examination/contract_lock_sdk/model/v2auth/request"
 	v2auth_response "git.sxidc.com/student-physical-examination/contract_lock_sdk/model/v2auth/response"
-	"git.sxidc.com/student-physical-examination/contract_lock_sdk/model/common"
 )
 
 type companyCertPageResp struct {
@@ -238,10 +238,10 @@ func authorizedSealFromRecord(item authorizedSealRecordItem) AuthorizedCompanySe
 
 // QueryCompanySealAuthRecords 查询机构静默授权记录;status 传 "EFFECT" 查有效授权。
 func (c *Client) QueryCompanySealAuthRecords(openCompanyID, status string) ([]AuthRecord, error) {
-	return c.queryCompanySealAuthRecordsFor(CompanyLocateParams{OpenCompanyID: openCompanyID}, status)
+	return c.QueryCompanySealAuthRecordsFor(CompanyLocateParams{OpenCompanyID: openCompanyID}, status)
 }
 
-func (c *Client) queryCompanySealAuthRecordsFor(company CompanyLocateParams, status string) ([]AuthRecord, error) {
+func (c *Client) QueryCompanySealAuthRecordsFor(company CompanyLocateParams, status string) ([]AuthRecord, error) {
 	companyReq, err := company.toCompanyRequest()
 	if err != nil {
 		return nil, err

+ 49 - 17
types.go

@@ -15,9 +15,18 @@ type CompanyAuthStatus struct {
 	CompanyName string            `json:"companyName"`
 	Mobile      string            `json:"mobile"`
 	RegisterNo  string            `json:"registerNo"`
+	BizID       flexStringID      `json:"bizId"`
+	AuthEndTime string            `json:"authEndTime"`
 	Result      CompanyAuthResult `json:"result"`
 }
 
+func (s *CompanyAuthStatus) CompanyID() string {
+	if s == nil {
+		return ""
+	}
+	return s.BizID.String()
+}
+
 // CompanyAuthResult 认证审核结果。
 type CompanyAuthResult struct {
 	Status string `json:"status"`
@@ -38,9 +47,32 @@ type CreateUserParams struct {
 	Mobile     string
 }
 
+// UserLocateParams 定位契约锁个人用户;查询优先级与开放平台一致:用户 id > 手机号 > 证件号 > 三方用户 id > 登录账号。
+type UserLocateParams struct {
+	UserID     string
+	Mobile     string
+	CardNo     string
+	OpenUserID string
+	AccountNo  string
+}
+
 // UserInfo 契约锁用户基本信息。
 type UserInfo struct {
-	Name string
+	ID     string
+	BizID  string
+	Name   string
+	Mobile string
+	Status string
+}
+
+func (u *UserInfo) OpenUserID() string {
+	if u == nil {
+		return ""
+	}
+	if u.BizID != "" {
+		return u.BizID
+	}
+	return u.ID
 }
 
 // CompanySealSpec 企业公章关键字签署位置。
@@ -71,21 +103,21 @@ type SignDocumentRequest struct {
 
 // SignDualCompanyRequest 双企业公章签署(如账单合同甲乙双方)。
 type SignDualCompanyRequest struct {
-	PDF            []byte
-	Subject        string
-	ProcessID      string
-	Launcher       string
-	CompanySeals   []CompanySealSpec
+	PDF          []byte
+	Subject      string
+	ProcessID    string
+	Launcher     string
+	CompanySeals []CompanySealSpec
 }
 
 // Callback request / event types — 与契约锁开放平台事件名一致。
 
 const (
-	EventCompanyAuthSuccess     = "COMPANY_AUTH_SUCCESS"
-	EventCompanySealAuthSuccess = "COMPANY_SIGN_SILENT_AUTH"
-	EventUserAuthSuccess        = "USER_AUTH_SUCCESS"
+	EventCompanyAuthSuccess      = "COMPANY_AUTH_SUCCESS"
+	EventCompanySealAuthSuccess  = "COMPANY_SIGN_SILENT_AUTH"
+	EventUserAuthSuccess         = "USER_AUTH_SUCCESS"
 	EventPersonalSealAuthSuccess = "PERSONAL_SIGN_SILENT_AUTH"
-	EventCallbackCheck          = "CALLBACK_CHECK"
+	EventCallbackCheck           = "CALLBACK_CHECK"
 )
 
 // CallbackRequest 契约锁 HTTP 回调原始载荷。
@@ -130,13 +162,13 @@ type CompanySealAuthData struct {
 
 // PersonalSealAuthData 个人签名静默授权回调。
 type PersonalSealAuthData struct {
-	UserName   string `json:"userName"`
-	UserMobile string `json:"userMobile"`
-	UserEmail  string `json:"userEmail"`
-	UserID     string `json:"userId"`
-	OpenUserID string `json:"openUserId"`
-	AuthTime   string `json:"authTime"`
-	Status     string `json:"status"`
+	UserName     string `json:"userName"`
+	UserMobile   string `json:"userMobile"`
+	UserEmail    string `json:"userEmail"`
+	UserID       string `json:"userId"`
+	OpenUserID   string `json:"openUserId"`
+	AuthTime     string `json:"authTime"`
+	Status       string `json:"status"`
 	CallbackTime string `json:"callbackTime"`
 }
 

+ 98 - 13
user.go

@@ -14,26 +14,103 @@ import (
 	v2auth_response "git.sxidc.com/student-physical-examination/contract_lock_sdk/model/v2auth/response"
 )
 
-// FindUserByAccountNo 按 accountNo(通常等于 openUserId)查询用户。
-func (c *Client) FindUserByAccountNo(accountNo string) (*UserInfo, error) {
-	type result struct {
-		Name string `json:"name"`
+type userDetailResult struct {
+	ID     flexStringID `json:"id"`
+	BizID  flexStringID `json:"bizId"`
+	Name   string       `json:"name"`
+	Mobile string       `json:"mobile"`
+	Status string       `json:"status"`
+}
+
+func (r userDetailResult) toUserInfo() *UserInfo {
+	info := &UserInfo{
+		ID:     r.ID.String(),
+		BizID:  r.BizID.String(),
+		Name:   r.Name,
+		Mobile: r.Mobile,
+		Status: r.Status,
+	}
+	if info.ID == "" && info.BizID == "" && info.Name == "" {
+		return nil
+	}
+	return info
+}
+
+func (p UserLocateParams) toUserQuery() (url.Values, error) {
+	q := url.Values{}
+	switch {
+	case p.UserID != "":
+		q.Set("id", p.UserID)
+	case p.Mobile != "":
+		q.Set("mobile", p.Mobile)
+	case p.CardNo != "":
+		q.Set("cardNo", p.CardNo)
+	case p.OpenUserID != "":
+		q.Set("bizId", p.OpenUserID)
+	case p.AccountNo != "":
+		q.Set("accountNo", p.AccountNo)
+	default:
+		return nil, ErrInvalidParams
+	}
+	return q, nil
+}
+
+func (p UserLocateParams) toUserInfoRequest() (*common.UserInfoRequest, error) {
+	req := &common.UserInfoRequest{}
+	switch {
+	case p.UserID != "":
+		id, err := strconv.ParseInt(p.UserID, 10, 64)
+		if err != nil {
+			return nil, ErrInvalidParams
+		}
+		req.UserId = &id
+	case p.Mobile != "":
+		req.Mobile = p.Mobile
+	case p.CardNo != "":
+		req.CardNo = p.CardNo
+	case p.OpenUserID != "":
+		req.OpenUserId = p.OpenUserID
+	case p.AccountNo != "":
+		req.AccountNo = p.AccountNo
+	default:
+		return nil, ErrInvalidParams
+	}
+	return req, nil
+}
+
+func isUserNotFound(err error) bool {
+	if err == nil {
+		return false
+	}
+	msg := err.Error()
+	return strings.Contains(msg, "用户不存在") || strings.Contains(msg, "未查询到用户")
+}
+
+// FindUser 按手机号、证件号、三方用户 id 或登录账号查询契约锁用户;不存在时返回 nil。
+func (c *Client) FindUser(p UserLocateParams) (*UserInfo, error) {
+	q, err := p.toUserQuery()
+	if err != nil {
+		return nil, err
 	}
 	var resp struct {
 		apiResponse
-		Result result `json:"result"`
+		Result userDetailResult `json:"result"`
 	}
-	q := url.Values{"accountNo": {accountNo}}
-	if err := c.getQuery("/user", q, &resp); err != nil {
+	if err = c.getQuery("/user", q, &resp); err != nil {
 		return nil, err
 	}
-	if err := resp.err(); err != nil {
+	if err = resp.err(); err != nil {
+		if isUserNotFound(err) {
+			return nil, nil
+		}
 		return nil, err
 	}
-	if resp.Result.Name == "" {
-		return nil, nil
-	}
-	return &UserInfo{Name: resp.Result.Name}, nil
+	return resp.Result.toUserInfo(), nil
+}
+
+// FindUserByAccountNo 按 accountNo(通常等于 openUserId)查询用户。
+func (c *Client) FindUserByAccountNo(accountNo string) (*UserInfo, error) {
+	return c.FindUser(UserLocateParams{AccountNo: accountNo})
 }
 
 // CreateInternalUser 在契约锁创建内部用户。
@@ -110,8 +187,16 @@ func (c *Client) UserSignSilentURL(openUserID string, applyCompany ApplyCompanyP
 
 // QueryPersonalSignAuthRecords 查询个人静默授权记录。
 func (c *Client) QueryPersonalSignAuthRecords(openUserID, status string) ([]AuthRecord, error) {
+	return c.QueryPersonalSignAuthRecordsFor(UserLocateParams{OpenUserID: openUserID}, status)
+}
+
+func (c *Client) QueryPersonalSignAuthRecordsFor(user UserLocateParams, status string) ([]AuthRecord, error) {
+	authUser, err := user.toUserInfoRequest()
+	if err != nil {
+		return nil, err
+	}
 	req := v2auth_request.V2AuthSignsilentRecordRequest{
-		AuthUser: &common.UserInfoRequest{OpenUserId: openUserID},
+		AuthUser: authUser,
 		Status:   status,
 	}
 	var resp struct {