finclip-app-manager/infrastructure/client/httpcall/appletEcol.go

262 lines
7.0 KiB
Go
Raw Normal View History

2023-10-31 14:07:26 +08:00
package httpcall
import (
"context"
"encoding/json"
"errors"
"fmt"
"net/http"
"finclip-app-manager/infrastructure/config"
)
const (
NotifyResultSuccess = "success"
NotifyResultFail = "fail"
)
const (
StOrganApproved = 3 //审核通过状态
StOrganUnApproved = 5 //已冻结
StOrganPersonalReviewing = 6 //个人账号升级企业账号审核中
StOrganPersonalUnPass = 7 //个人账号升级企业账号被拒绝
)
const (
ORGAN_STATUS_NORMAL = 1 //正常
ORGAN_STATUS_FREEZE = 2 //已冻结
ORGAN_STATUS_DELAY = 3 //已延期
)
//func JudgeGroupStatusValid(status int) (valid bool) {
// valid = true
// if status != StOrganApproved &&
// status != StOrganPersonalReviewing &&
// status != StOrganPersonalUnPass {
// valid = false
// }
// return
//}
//
//const (
// TypeNotificationApproval = 1000
//)
//
//const (
// TabNotificationSystem = "system"
//)
//
//type RoleData struct {
// IsOK bool `json:"isOK"`
//}
//
//type RoleResponse struct {
// Errcode string `json:"errcode"`
// Error string `json:"error"`
// Data RoleData `json:"data"`
//}
//
//type NotificationContent struct {
// Title string `json:"title"`
// Msg string `json:"msg"`
// Reason string `json:"reason"`
// Result string `json:"result"`
//}
//
//type NotificationRequest struct {
// OrganTraceID string `json:"organTraceId"`
// Tab string `json:"tab"`
// Type int `json:"type"`
// Content NotificationContent `json:"content"`
//}
//
//type AppletEcol struct {
// ClientBase
//}
//
//func NewAppletEcol() *AppletEcol {
// return &AppletEcol{
// ClientBase: ClientBase{
// Service: "Applets-ecol",
// },
// }
//}
//
//func (c *Client) GetDomainInfo(ctx context.Context, appID string) (*DomainResponseData, error) {
// url := config.Cfg.MOPDomainURL
// if url == "" {
// log.Errorf(ErrEmptyURL)
// return nil, errors.New(ErrEmptyURL)
// } else if url[len(url)-1] == '/' {
// url = url + appID
// } else {
// url = url + "/" + appID
// }
// base := ClientBase{}
// base.URL = url
// base.Method = "GET"
// base.RequestHeader = make(map[string]string)
// //zipkin上报
// /*{
// spanId := c.Request.Header.Get("Zipkin-Span-Id")
// value := c.GetString("zipkin_trace_span_id_" + spanId)
// a.RequestHeader["Zipkin-Span-Context"] = value
// }*/
// if err := base.Fetch(ctx); err != nil {
// log.Errorf(err.Error())
// return nil, err
// } else if base.StatusCode != http.StatusOK {
// log.Errorf(err.Error())
// return nil, errors.New(ErrHttpCode)
// }
// resp := DomainResponse{}
// if err := json.Unmarshal(base.ResponseBody, &resp); err != nil {
// log.Errorf("Failed to unmarshal DomainResponse: %v\n", err)
// return nil, err
// }
// return &resp.Data, nil
//}
//
func (c *Client) GetDomainInfoByOrganId(ctx context.Context, organId string) (*DomainResponseData, error) {
url := config.Cfg.MOPDomainURLV2 + "?organId=" + organId
rsp, err := c.Request(ctx).SetHeaders(c.getNewDefaultReqHeader()).Get(url)
if err != nil {
log.Errorf("GetDomainInfoByOrganId err:%s", err.Error())
return nil, err
}
if rsp.StatusCode() != http.StatusOK {
log.Errorf("GetDomainInfoByOrganId status code err:%v,rsp:%s", rsp.StatusCode(), rsp.Body())
return nil, errors.New("status code err")
}
resp := DomainResponse{}
if err = json.Unmarshal(rsp.Body(), &resp); err != nil {
log.Errorf("Failed to unmarshal DomainResponse: %v\n", err)
return nil, err
}
return &resp.Data, nil
}
//
//func (c *Client) HasRole(ctx context.Context, userID string) (bool, *RoleResponse, error) {
// url := config.Cfg.GetRoleURL
// if url == "" {
// log.Errorf(ErrEmptyURL)
// return false, nil, errors.New(ErrEmptyURL)
// }
// if url[len(url)-1] == '/' {
// url = url + userID
// } else {
// url = url + "/" + userID
// }
// base := ClientBase{}
//
// base.URL = url
// base.Method = "GET"
// err := base.Fetch(ctx)
// if err != nil {
// log.Errorf(err.Error())
// return false, nil, err
// } else if base.StatusCode != http.StatusOK {
// log.Errorf(err.Error())
// return false, nil, errors.New(ErrHttpCode)
// }
// resp := RoleResponse{}
// if err := json.Unmarshal(base.ResponseBody, &resp); err != nil {
// log.Errorf("Failed to unmarshal roleResponse: %v\n", err)
// return false, nil, errors.New(ErrSystemCall)
// }
// if resp.Data.IsOK {
// return true, nil, nil
// }
// return false, &resp, nil
//}
//
//func (c *Client) GetDeveloperInfo(ctx context.Context, developId string) (*DeveloperData, error) {
// var headers = map[string]string{
// "Accept": "application/json, text/plain, */*",
// "Content-Type": "application/json",
// "url-call": "internal",
// }
// urlPrefix := config.Cfg.PersonInfoProviderURL
// url := urlPrefix + developId
// log.Infof("GetDeveloperInfo url:%s", url)
//
// rsp, err := c.Request(ctx).SetHeaders(headers).Get(url)
//
// if err != nil {
// log.Errorf("GetDeveloperInfo fetch err:%s", err.Error())
// return nil, err
// }
// if rsp.StatusCode() != http.StatusOK {
// log.Errorf("GetDeveloperInfo StatusCode err,body:%s", rsp.String())
// return nil, errors.New(ErrHttpCode)
// }
// resp := GetDevelopResponse{}
// if err := json.Unmarshal(rsp.Body(), &resp); err != nil {
// log.Errorf("Failed to unmarshal response to GetDeveloperInfo, error: %v\n", err)
// return nil, err
// }
//
// log.Infof("GetDeveloperInfo rsp:%+v", resp)
//
// return &resp.Data, nil
//}
func (c *Client) UatOrganStatusIsValid(status int) bool {
return status == StOrganApproved ||
status == StOrganPersonalReviewing ||
status == StOrganPersonalUnPass ||
status == StOrganUnApproved
}
func (c *Client) OrganStatusIsValid(status int) bool {
return status == StOrganApproved ||
status == StOrganPersonalReviewing ||
status == StOrganPersonalUnPass
}
func (c *Client) JudgeGroupStatusValid(status int) (valid bool) {
valid = true
if status != StOrganApproved &&
status != StOrganPersonalReviewing &&
status != StOrganPersonalUnPass {
valid = false
}
return
}
type CheckEnterpriseIsExpiredRsp struct {
Error string `json:"error"`
Errcode string `json:"errcode"`
Data struct {
IsExpired bool `json:"isExpired"`
} `json:"data"`
}
func (c *Client) CheckEnterpriseIsExpired(ctx context.Context, userId string) (bool, error) {
url := fmt.Sprintf(config.Cfg.CheckOrganIsExpiredUrl+"?userId=%s", userId)
var headers = map[string]string{
"Accept": "application/json, text/plain, */*",
"Content-Type": "application/json",
"url-call": "internal",
}
rspData := CheckEnterpriseIsExpiredRsp{}
rsp, err := c.Request(ctx).SetHeaders(headers).Get(url)
if err != nil {
log.Errorf("CheckEnterpriseIsExpired request err:%s", err.Error())
return false, err
}
if rsp.StatusCode() != http.StatusOK {
log.Errorf("CheckEnterpriseIsExpired status code err,code:%d", rsp.StatusCode())
return false, errors.New("status code err")
}
err = json.Unmarshal(rsp.Body(), &rspData)
if err != nil {
log.Errorf("CheckEnterpriseIsExpired json unmarshal err:%s", err.Error())
return false, err
}
log.Debugf("enterprise is expired rsp:%+v", rspData)
return rspData.Data.IsExpired, nil
}