f
This commit is contained in:
@@ -74,7 +74,7 @@ func (c *Client) GenerateEnterpriseAuth(req *EnterpriseAuthRequest) (*Enterprise
|
||||
return nil, err
|
||||
}
|
||||
if res.Code != successCode {
|
||||
return nil, fmt.Errorf("获取法大大企业认证链接失败: code=%s msg=%s requestId=%s", res.Code, res.Msg, res.RequestID)
|
||||
return nil, NewAPIError("获取法大大企业认证链接失败", res.Code, res.Msg, res.RequestID)
|
||||
}
|
||||
|
||||
var data getCorpAuthURLData
|
||||
@@ -92,6 +92,83 @@ func (c *Client) GenerateEnterpriseAuth(req *EnterpriseAuthRequest) (*Enterprise
|
||||
}, nil
|
||||
}
|
||||
|
||||
// QueryCorpAuth 查询企业授权状态(POST /corp/get)
|
||||
// 文档:https://dev.fadada.com/api-doc/X2JXRJIYRE/ELN3ZLQWR6PLXGCE/5-1
|
||||
// 以 bindingStatus=authorized 判断是否已完成帐号授权绑定(比 get-auth-url 的 210002/210013 更准确)。
|
||||
func (c *Client) QueryCorpAuth(req *QueryCorpAuthRequest) (*QueryCorpAuthResult, error) {
|
||||
if req == nil {
|
||||
return nil, fmt.Errorf("查询请求不能为空")
|
||||
}
|
||||
corpIdentNo := strings.TrimSpace(req.CorpIdentNo)
|
||||
clientCorpID := strings.TrimSpace(req.ClientCorpID)
|
||||
openCorpID := strings.TrimSpace(req.OpenCorpID)
|
||||
filled := 0
|
||||
if corpIdentNo != "" {
|
||||
filled++
|
||||
}
|
||||
if clientCorpID != "" {
|
||||
filled++
|
||||
}
|
||||
if openCorpID != "" {
|
||||
filled++
|
||||
}
|
||||
if filled == 0 {
|
||||
return nil, fmt.Errorf("corpIdentNo、clientCorpId、openCorpId 不能同时为空")
|
||||
}
|
||||
if filled > 1 {
|
||||
// 文档要求三选一;业务优先级:openCorpId > corpIdentNo > clientCorpId
|
||||
if openCorpID != "" {
|
||||
corpIdentNo, clientCorpID = "", ""
|
||||
} else if corpIdentNo != "" {
|
||||
clientCorpID = ""
|
||||
}
|
||||
}
|
||||
|
||||
accessToken, err := c.ensureAccessToken()
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
res, err := c.http.PostBiz(pathGetCorp, accessToken, &getCorpReq{
|
||||
CorpIdentNo: corpIdentNo,
|
||||
ClientCorpID: clientCorpID,
|
||||
OpenCorpID: openCorpID,
|
||||
})
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
if res.Code != successCode {
|
||||
// 企业尚未在本应用下建档/授权时,视为未找到,不算业务异常
|
||||
if isCorpNotFoundCode(res.Code) {
|
||||
return &QueryCorpAuthResult{Found: false}, nil
|
||||
}
|
||||
return nil, NewAPIError("查询法大大企业授权状态失败", res.Code, res.Msg, res.RequestID)
|
||||
}
|
||||
|
||||
var data getCorpData
|
||||
if err := decodeData(res.Data, &data); err != nil {
|
||||
return nil, fmt.Errorf("解析企业授权状态失败: %w", err)
|
||||
}
|
||||
|
||||
binding := strings.TrimSpace(data.BindingStatus)
|
||||
ident := strings.TrimSpace(data.IdentStatus)
|
||||
return &QueryCorpAuthResult{
|
||||
Found: true,
|
||||
Authorized: binding == BindingStatusAuthorized,
|
||||
Identified: ident == IdentStatusIdentified,
|
||||
ClientCorpID: strings.TrimSpace(data.ClientCorpID),
|
||||
OpenCorpID: strings.TrimSpace(data.OpenCorpID),
|
||||
BindingStatus: binding,
|
||||
IdentStatus: ident,
|
||||
AvailableStatus: strings.TrimSpace(data.AvailableStatus),
|
||||
AuthScopes: append([]string{}, data.AuthScope...),
|
||||
}, nil
|
||||
}
|
||||
|
||||
func isCorpNotFoundCode(code string) bool {
|
||||
return strings.TrimSpace(code) == CodeCorpNotFound
|
||||
}
|
||||
|
||||
// QueryOrgVerified 查询企业是否已在法大大完成实名(POST /corp/get-identified-status)
|
||||
func (c *Client) QueryOrgVerified(req *QueryOrgIdentityRequest) (bool, error) {
|
||||
result, err := c.QueryOrgIdentity(req)
|
||||
@@ -125,7 +202,7 @@ func (c *Client) QueryOrgIdentity(req *QueryOrgIdentityRequest) (*QueryOrgIdenti
|
||||
return nil, err
|
||||
}
|
||||
if res.Code != successCode {
|
||||
return nil, fmt.Errorf("查询法大大企业实名状态失败: code=%s msg=%s requestId=%s", res.Code, res.Msg, res.RequestID)
|
||||
return nil, NewAPIError("查询法大大企业实名状态失败", res.Code, res.Msg, res.RequestID)
|
||||
}
|
||||
|
||||
var data getIdentifiedStatusData
|
||||
|
||||
Reference in New Issue
Block a user