| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142 |
- package qiyuesuosdk
- import (
- "time"
- 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 {
- apiResponse
- AuthURL string `json:"authurl"`
- }
- type companyCertStatusResp struct {
- apiResponse
- Result CompanyAuthStatus `json:"result"`
- }
- type companySealAuthURLResp struct {
- apiResponse
- Result v2auth_response.V2AuthCompanysignsilentUrlResponse `json:"result"`
- }
- type companyAuthRecordResp struct {
- apiResponse
- Result []common.AuthorizedSealRecordBean `json:"result"`
- }
- // CompanyCertificationURL 获取法人单位在线认证页 URL。
- func (c *Client) CompanyCertificationURL(p OrgCertParams) (string, error) {
- if p.OpenCompanyID == "" || p.Mobile == "" || p.CompanyName == "" || p.Charger == "" {
- return "", ErrInvalidParams
- }
- type reqBody struct {
- Name string `json:"name"`
- Charger string `json:"charger"`
- Mobile string `json:"mobile"`
- OpenCompanyId string `json:"openCompanyId"`
- Modes []string `json:"modes"`
- Customer bool `json:"customer"`
- }
- fields, err := structFormFields(reqBody{
- Name: p.CompanyName,
- Charger: p.Charger,
- Mobile: p.Mobile,
- OpenCompanyId: p.OpenCompanyID,
- Modes: []string{"AUTHFILE", "BANKPAY"},
- Customer: true,
- }, ",")
- if err != nil {
- return "", err
- }
- var resp companyCertPageResp
- err = c.postMultipart("/companyauth/pcpage", fields, "", nil, &resp)
- if err != nil {
- return "", err
- }
- if err = resp.err(); err != nil {
- return "", err
- }
- return resp.AuthURL, nil
- }
- // CompanyCertificationStatus 查询法人单位认证状态;未注册时 found=false。
- func (c *Client) CompanyCertificationStatus(openCompanyID string) (*CompanyAuthStatus, bool, error) {
- var resp companyCertStatusResp
- err := c.postMultipart("/companyauth/status", map[string]string{
- "openCompanyId": openCompanyID,
- }, "", nil, &resp)
- if err != nil {
- return nil, false, err
- }
- if err = resp.err(); err != nil {
- if resp.Code == 2002002 {
- return nil, false, nil
- }
- return nil, false, err
- }
- return &resp.Result, true, nil
- }
- // CompanySealAuthURL 获取机构印章静默授权页;authEnd 为空则默认 1 年。
- func (c *Client) CompanySealAuthURL(openCompanyID, adminMobile string, authEnd time.Time) (string, error) {
- if authEnd.IsZero() {
- authEnd = time.Now().Add(DefaultCompanySealAuthDuration)
- }
- timeEditable := false
- req := v2auth_request.V2AuthCompanysignsilentUrlRequest{
- SealMultipleRequest: &common.SealMultipleRequest{
- Company: &common.CompanyRequest{OpenCompanyId: openCompanyID},
- },
- AuthUser: &common.SilentUserRequest{Mobile: adminMobile},
- AuthInformation: []string{"AUTHORIZE_SEAL", "AUTHORIZE_COMPANY_CERTIFICATE"},
- AuthorizedMode: []string{"FACEAUTH", "PINAUTH"},
- AuthEndDate: authEnd.Format("2006-01-02"),
- AuthTimeModifiable: &timeEditable,
- }
- var resp companySealAuthURLResp
- if err := c.postJSON("/v2/auth/companysignsilent/url", req, &resp); err != nil {
- return "", err
- }
- if err := resp.err(); err != nil {
- return "", err
- }
- return resp.Result.Url, nil
- }
- // QueryCompanySealAuthRecords 查询机构静默授权记录;status 传 "EFFECT" 查有效授权。
- func (c *Client) QueryCompanySealAuthRecords(openCompanyID, status string) ([]AuthRecord, error) {
- req := v2auth_request.V2AuthSignsilentCompanyRecordRequest{
- AuthCompany: &common.CompanyRequest{OpenCompanyId: openCompanyID},
- Status: status,
- }
- var resp companyAuthRecordResp
- if err := c.postJSON("/v2/auth/signsilent/company/record", req, &resp); err != nil {
- return nil, err
- }
- if err := resp.err(); err != nil {
- return nil, err
- }
- out := make([]AuthRecord, 0, len(resp.Result))
- for _, item := range resp.Result {
- out = append(out, AuthRecord{
- Status: item.AuthorizedSealRecord.Status,
- StartTime: item.AuthorizedSealRecord.StartTime,
- EndTime: item.AuthorizedSealRecord.EndTime,
- AuthScope: item.AuthorizedSealRecord.AuthScope,
- })
- }
- return out, nil
- }
- // IsCompanySealAuthorized 是否存在有效机构印章静默授权。
- func (c *Client) IsCompanySealAuthorized(openCompanyID string) (bool, error) {
- records, err := c.QueryCompanySealAuthRecords(openCompanyID, "EFFECT")
- if err != nil {
- return false, err
- }
- return len(records) > 0, nil
- }
|