64 lines
1.8 KiB
Go
64 lines
1.8 KiB
Go
package esign
|
||
|
||
import (
|
||
"fmt"
|
||
"net/url"
|
||
"strings"
|
||
)
|
||
|
||
// QueryOrgIdentityInfo 查询机构认证信息
|
||
// 根据orgId、orgName或orgIDCardNum查询机构实名认证信息
|
||
func (s *OrgAuthService) QueryOrgIdentityInfo(req *QueryOrgIdentityRequest) (*QueryOrgIdentityResponse, error) {
|
||
// 构建查询参数
|
||
params := url.Values{}
|
||
if req.OrgID != "" {
|
||
params.Add("orgId", req.OrgID)
|
||
} else if req.OrgName != "" {
|
||
params.Add("orgName", req.OrgName)
|
||
} else if req.OrgIDCardNum != "" {
|
||
params.Add("orgIDCardNum", req.OrgIDCardNum)
|
||
if req.OrgIDCardType != "" {
|
||
params.Add("orgIDCardType", string(req.OrgIDCardType))
|
||
}
|
||
} else {
|
||
return nil, fmt.Errorf("至少提供orgId, orgName或orgIDCardNum之一")
|
||
}
|
||
|
||
// 构建urlPath带query - 不使用URL编码,保持原始参数值
|
||
urlPath := "/v3/organizations/identity-info"
|
||
if len(params) > 0 {
|
||
var queryParts []string
|
||
for key, values := range params {
|
||
for _, value := range values {
|
||
queryParts = append(queryParts, key+"="+value)
|
||
}
|
||
}
|
||
urlPath += "?" + strings.Join(queryParts, "&")
|
||
}
|
||
|
||
// 发送API请求
|
||
responseBody, err := s.httpClient.Request("GET", urlPath, nil)
|
||
if err != nil {
|
||
return nil, fmt.Errorf("查询机构认证信息失败: %v", err)
|
||
}
|
||
|
||
// 解析响应
|
||
var response QueryOrgIdentityResponse
|
||
if err := UnmarshalResponse(responseBody, &response); err != nil {
|
||
return nil, err
|
||
}
|
||
|
||
if err := CheckResponseCode(int(response.Code), response.Message); err != nil {
|
||
return nil, err
|
||
}
|
||
|
||
fmt.Printf("查询机构认证信息成功!\n")
|
||
return &response, nil
|
||
}
|
||
|
||
// QueryOrgIdentityInfo 查询机构认证信息(客户端方法)
|
||
// 通过Client提供的便捷方法
|
||
func (c *Client) QueryOrgIdentityInfo(req *QueryOrgIdentityRequest) (*QueryOrgIdentityResponse, error) {
|
||
return c.orgAuth.QueryOrgIdentityInfo(req)
|
||
}
|