license.go 2.5 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879
  1. package client
  2. import (
  3. "context"
  4. "encoding/json"
  5. "errors"
  6. "mop-account-system/common"
  7. )
  8. type CommonConfigData struct {
  9. Error string `json:"error"`
  10. Errcode string `json:"errcode"`
  11. Data struct {
  12. OrganName string `json:"organName"`
  13. } `json:"data"`
  14. }
  15. var commonConfig CommonConfigData
  16. func getCommonConfig(ctx context.Context) error {
  17. var headers = map[string]string{
  18. "Accept": "application/json, text/plain, */*",
  19. "Content-Type": "application/json",
  20. }
  21. url := "http://mop-private-init-server:8080/api/v1/mop/mop-private-init-server/common/config"
  22. rsp, err := Request(ctx).SetHeaders(headers).Get(url)
  23. if err != nil || rsp.StatusCode() != 200 {
  24. return errors.New("mop-private-init-server err")
  25. }
  26. json.Unmarshal(rsp.Body(), &commonConfig)
  27. return nil
  28. }
  29. type LicenseData struct {
  30. OrganName string `json:"organName"` //企业名称
  31. AppCount int `json:"appCount"` //可创建的小程序数量上限
  32. CooAppCount int `json:"cooAppCount"` //应用的数量
  33. ReviewOrganCount int `json:"reviewOrganCount"` //可认证通过的企业数量
  34. ExpireTime int64 `json:"expireTime"` //服务有效期
  35. CreateOperAdminByInitServer bool `json:"createOperAdminByInitServer"` //init服务是否创建运营端管理账号
  36. OrganStatusNeverExpire bool `json:"organStatusNeverExpire"` //企业状态是否永不过期
  37. AppGrayCount int `json:"appGrayCount"` //灰度数量
  38. }
  39. type GetLicenseRsp struct {
  40. Data LicenseData `json:"data"`
  41. Errcode string `json:"errcode"`
  42. Errmsg string `json:"error"`
  43. }
  44. func GetLicense(ctx context.Context) (*LicenseData, error) {
  45. if commonConfig.Data.OrganName == "" {
  46. getCommonConfig(ctx)
  47. }
  48. var headers = map[string]string{
  49. "Accept": "application/json, text/plain, */*",
  50. "Content-Type": "application/json",
  51. "Organ-Name": commonConfig.Data.OrganName, //私有化部署的时候,需要修改机构名称
  52. }
  53. url := "http://mop-license-checker:8080/api/v1/mop/mop-license-checker/license"
  54. rsp, _ := Request(ctx).SetHeaders(headers).Get(url)
  55. if rsp.StatusCode() != 200 {
  56. return nil, errors.New("status code error")
  57. }
  58. var licenseInfo GetLicenseRsp
  59. err := json.Unmarshal(rsp.Body(), &licenseInfo)
  60. if err != nil {
  61. common.GinLog.Errorf("GetLicense json err:%s", err.Error())
  62. return nil, err
  63. }
  64. common.GinLog.Infof("GetLicense info:%+v", licenseInfo)
  65. return &licenseInfo.Data, nil
  66. }