|
@@ -273,12 +273,8 @@ func (c *Client) CompanySignQualificationsFor(company CompanyLocateParams) (*Com
|
|
|
return &resp.Result, nil
|
|
return &resp.Result, nil
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
-// CompanySealCreatePageURL 获取制作电子公章的页面链接(method=page)。
|
|
|
|
|
-func (c *Client) CompanySealCreatePageURL(company CompanyLocateParams, companyDisplayName, sealName, operatorMobile string) (string, error) {
|
|
|
|
|
- if sealName == "" || operatorMobile == "" {
|
|
|
|
|
- return "", ErrInvalidParams
|
|
|
|
|
- }
|
|
|
|
|
- displayName := companyDisplayName
|
|
|
|
|
|
|
+func locateCompany(company CompanyLocateParams, companyDisplayName string) *common.Company {
|
|
|
|
|
+ displayName := strings.TrimSpace(companyDisplayName)
|
|
|
if displayName == "" {
|
|
if displayName == "" {
|
|
|
displayName = company.Name
|
|
displayName = company.Name
|
|
|
}
|
|
}
|
|
@@ -291,29 +287,82 @@ func (c *Client) CompanySealCreatePageURL(company CompanyLocateParams, companyDi
|
|
|
comp.Id = &id
|
|
comp.Id = &id
|
|
|
}
|
|
}
|
|
|
}
|
|
}
|
|
|
- modify := true
|
|
|
|
|
|
|
+ return comp
|
|
|
|
|
+}
|
|
|
|
|
+
|
|
|
|
|
+func isSealAlreadyExists(err error) bool {
|
|
|
|
|
+ if err == nil {
|
|
|
|
|
+ return false
|
|
|
|
|
+ }
|
|
|
|
|
+ msg := err.Error()
|
|
|
|
|
+ return strings.Contains(msg, "已存在") || strings.Contains(msg, "重复")
|
|
|
|
|
+}
|
|
|
|
|
+
|
|
|
|
|
+func (c *Client) createCompanySeal(company CompanyLocateParams, companyDisplayName, sealName, operatorMobile, method string) (*v2seal_response.V2SealCreateResponse, error) {
|
|
|
|
|
+ if sealName == "" || operatorMobile == "" {
|
|
|
|
|
+ return nil, ErrInvalidParams
|
|
|
|
|
+ }
|
|
|
req := v2seal_request.V2SealCreateRequest{
|
|
req := v2seal_request.V2SealCreateRequest{
|
|
|
BusinessType: "ELECTRONIC",
|
|
BusinessType: "ELECTRONIC",
|
|
|
SealType: "COMPANY",
|
|
SealType: "COMPANY",
|
|
|
- Method: "page",
|
|
|
|
|
|
|
+ Method: method,
|
|
|
Name: sealName,
|
|
Name: sealName,
|
|
|
SealCategoryName: "公章",
|
|
SealCategoryName: "公章",
|
|
|
- Company: comp,
|
|
|
|
|
|
|
+ Company: locateCompany(company, companyDisplayName),
|
|
|
OperatorInfo: &common.UserInfoRequest{
|
|
OperatorInfo: &common.UserInfoRequest{
|
|
|
Mobile: operatorMobile,
|
|
Mobile: operatorMobile,
|
|
|
},
|
|
},
|
|
|
- Modify: &modify,
|
|
|
|
|
|
|
+ }
|
|
|
|
|
+ if method == "auto" {
|
|
|
|
|
+ req.Spec = "CIRCULAR_42"
|
|
|
|
|
+ req.CustomSealAttribute = &common.CustomSealAttribute{
|
|
|
|
|
+ SealCategoryType: "enterprise",
|
|
|
|
|
+ }
|
|
|
|
|
+ }
|
|
|
|
|
+ if method == "page" {
|
|
|
|
|
+ modify := true
|
|
|
|
|
+ req.Modify = &modify
|
|
|
}
|
|
}
|
|
|
var resp sealCreateResp
|
|
var resp sealCreateResp
|
|
|
if err := c.postJSON("/v2/seal/create", req, &resp); err != nil {
|
|
if err := c.postJSON("/v2/seal/create", req, &resp); err != nil {
|
|
|
- return "", err
|
|
|
|
|
|
|
+ return nil, err
|
|
|
}
|
|
}
|
|
|
if err := resp.err(); err != nil {
|
|
if err := resp.err(); err != nil {
|
|
|
|
|
+ return nil, err
|
|
|
|
|
+ }
|
|
|
|
|
+ return &resp.Result, nil
|
|
|
|
|
+}
|
|
|
|
|
+
|
|
|
|
|
+// EnsureCompanyElectronicSeal 若法人单位尚无电子公章,则按公章样式自动生成一枚。
|
|
|
|
|
+func (c *Client) EnsureCompanyElectronicSeal(company CompanyLocateParams, companyDisplayName, operatorMobile string) error {
|
|
|
|
|
+ if quals, err := c.CompanySignQualificationsFor(company); err == nil && quals != nil && quals.ElectronicSeal {
|
|
|
|
|
+ return nil
|
|
|
|
|
+ }
|
|
|
|
|
+ if seals, err := c.ListCompanyElectronicSeals(company); err == nil && len(seals) > 0 {
|
|
|
|
|
+ return nil
|
|
|
|
|
+ }
|
|
|
|
|
+ return c.CreateCompanyElectronicSealAuto(company, companyDisplayName, operatorMobile)
|
|
|
|
|
+}
|
|
|
|
|
+
|
|
|
|
|
+// CreateCompanyElectronicSealAuto 自动生成一枚圆形电子公章(method=auto)。
|
|
|
|
|
+func (c *Client) CreateCompanyElectronicSealAuto(company CompanyLocateParams, companyDisplayName, operatorMobile string) error {
|
|
|
|
|
+ sealName := DeriveCompanySealName(companyDisplayName)
|
|
|
|
|
+ _, err := c.createCompanySeal(company, companyDisplayName, sealName, operatorMobile, "auto")
|
|
|
|
|
+ if err != nil && isSealAlreadyExists(err) {
|
|
|
|
|
+ return nil
|
|
|
|
|
+ }
|
|
|
|
|
+ return err
|
|
|
|
|
+}
|
|
|
|
|
+
|
|
|
|
|
+// CompanySealCreatePageURL 获取制作电子公章的页面链接(method=page)。
|
|
|
|
|
+func (c *Client) CompanySealCreatePageURL(company CompanyLocateParams, companyDisplayName, sealName, operatorMobile string) (string, error) {
|
|
|
|
|
+ result, err := c.createCompanySeal(company, companyDisplayName, sealName, operatorMobile, "page")
|
|
|
|
|
+ if err != nil {
|
|
|
return "", err
|
|
return "", err
|
|
|
}
|
|
}
|
|
|
- url := resp.Result.PageUrl
|
|
|
|
|
|
|
+ url := result.PageUrl
|
|
|
if url == "" {
|
|
if url == "" {
|
|
|
- url = resp.Result.LocalPageUrl
|
|
|
|
|
|
|
+ url = result.LocalPageUrl
|
|
|
}
|
|
}
|
|
|
if url == "" {
|
|
if url == "" {
|
|
|
return "", ErrSealCreatePageUnavailable
|
|
return "", ErrSealCreatePageUnavailable
|