seal.go 3.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111
  1. package qiyuesuosdk
  2. import (
  3. "strconv"
  4. "strings"
  5. v2seal_request "git.sxidc.com/student-physical-examination/contract_lock_sdk/model/v2seal/request"
  6. v2seal_response "git.sxidc.com/student-physical-examination/contract_lock_sdk/model/v2seal/response"
  7. "git.sxidc.com/student-physical-examination/contract_lock_sdk/model/common"
  8. )
  9. // CompanySignQualifications 法人单位签章资质(是否已有可用电子章等)。
  10. type CompanySignQualifications struct {
  11. ElectronicSeal bool `json:"electronicSeal"`
  12. SM2Cert bool `json:"sm2Cert"`
  13. RSACert bool `json:"rsaCert"`
  14. }
  15. type companySignQualificationsResp struct {
  16. apiResponse
  17. Result CompanySignQualifications `json:"result"`
  18. }
  19. type sealCreateResp struct {
  20. apiResponse
  21. Result v2seal_response.V2SealCreateResponse `json:"result"`
  22. }
  23. // UserPortalURL 由开放平台 API 地址推导用户前台地址(制章/登录)。
  24. func UserPortalURL(apiAddress string) string {
  25. addr := strings.TrimRight(apiAddress, "/")
  26. if strings.Contains(addr, ":9182") {
  27. return strings.Replace(addr, ":9182", ":9180", 1)
  28. }
  29. return addr
  30. }
  31. // CompanySignQualificationsFor 查询法人单位是否具备电子印章等签章资质。
  32. func (c *Client) CompanySignQualificationsFor(company CompanyLocateParams) (*CompanySignQualifications, error) {
  33. companyReq, err := company.toCompanyRequest()
  34. if err != nil {
  35. return nil, err
  36. }
  37. var resp companySignQualificationsResp
  38. if err := c.postJSON("/company/sign/qualifications", map[string]any{
  39. "companyRequest": companyReq,
  40. }, &resp); err != nil {
  41. return nil, err
  42. }
  43. if err := resp.err(); err != nil {
  44. return nil, err
  45. }
  46. return &resp.Result, nil
  47. }
  48. // CompanySealCreatePageURL 获取制作电子公章的页面链接(method=page)。
  49. func (c *Client) CompanySealCreatePageURL(company CompanyLocateParams, companyDisplayName, sealName, operatorMobile string) (string, error) {
  50. if sealName == "" || operatorMobile == "" {
  51. return "", ErrInvalidParams
  52. }
  53. displayName := companyDisplayName
  54. if displayName == "" {
  55. displayName = company.Name
  56. }
  57. comp := &common.Company{Name: displayName}
  58. if company.RegisterNo != "" {
  59. comp.RegisterNo = company.RegisterNo
  60. }
  61. if company.ID != "" {
  62. if id, err := strconv.ParseInt(company.ID, 10, 64); err == nil {
  63. comp.Id = &id
  64. }
  65. }
  66. modify := true
  67. req := v2seal_request.V2SealCreateRequest{
  68. BusinessType: "ELECTRONIC",
  69. SealType: "COMPANY",
  70. Method: "page",
  71. Name: sealName,
  72. SealCategoryName: "公章",
  73. Company: comp,
  74. OperatorInfo: &common.UserInfoRequest{
  75. Mobile: operatorMobile,
  76. },
  77. Modify: &modify,
  78. }
  79. var resp sealCreateResp
  80. if err := c.postJSON("/v2/seal/create", req, &resp); err != nil {
  81. return "", err
  82. }
  83. if err := resp.err(); err != nil {
  84. return "", err
  85. }
  86. url := resp.Result.PageUrl
  87. if url == "" {
  88. url = resp.Result.LocalPageUrl
  89. }
  90. if url == "" {
  91. return "", ErrSealCreatePageUnavailable
  92. }
  93. return url, nil
  94. }
  95. // IsSealNotFoundError 静默授权时「查询的印章不存在」。
  96. func IsSealNotFoundError(err error) bool {
  97. if err == nil {
  98. return false
  99. }
  100. msg := err.Error()
  101. return strings.Contains(msg, "查询的印章不存在") || strings.Contains(msg, "无可授权的印章")
  102. }