271 lines
13 KiB
Go
271 lines
13 KiB
Go
package utility
|
||
|
||
import (
|
||
pb "finclip-app-manager/infrastructure/protobuf/golang"
|
||
"net/http"
|
||
|
||
"github.com/gin-gonic/gin"
|
||
)
|
||
|
||
const (
|
||
OK = "OK"
|
||
FS_NOT_FOUND = "FS_NOT_FOUND"
|
||
FS_BAD_JSON = "FS_BAD_JSON"
|
||
FS_DB_ERR = "FS_DB_ERR"
|
||
FS_SYSTEM_CALL = "FS_SYSTEM_CALL"
|
||
FS_LACK_OF_APPID = "FS_LACK_OF_APPID"
|
||
FS_LACK_OF_SDKKEY = "FS_LACK_OF_SDKKEY"
|
||
FS_APP_ID_NOT_FOUND = "FS_APP_ID_NOT_FOUND"
|
||
FS_APP_SEQUENCE_NOT_FOUND = "FS_APP_SEQUENCE_NOT_FOUND"
|
||
FS_GET_GROUP_FAILED = "FS_GET_GROUP_FAILED"
|
||
FS_GET_DOMAIN_INFO_ERROR = "FS_GET_DOMAIN_INFO_ERROR"
|
||
FS_GET_ACCOUNTINFO_ERROR = "FS_GET_ACCOUNTINFO_ERROR"
|
||
FS_GET_MENUINFO_ERROR = "FS_GET_MENUINFO_ERROR"
|
||
FS_FORBIDDEN = "FS_FORBIDDEN"
|
||
FS_PUBLISHING_OR_UNPUBLISHING = "FS_PUBLISHING_OR_UNPUBLISHING"
|
||
FS_ACCESS_RULE_NOT_SET = "FS_ACCESS_RULE_NOT_SET"
|
||
FS_INVALID_STATE = "FS_INVALID_STATE"
|
||
FS_LACK_OF_ORGANIZAITON_ID = "FS_LACK_OF_ORGANIZATION_ID"
|
||
FS_LACK_OF_USER_ID = "FS_LACK_OF_USER_ID"
|
||
FS_SEQUENCE_LESS_THAN_CURRENT = "FS_SEQUENCE_LESS_THAN_CURRENT"
|
||
FS_SPECIFIED_APP_ID_NOT_DELETEABLE = "FS_SPECIFIED_APP_ID_NOT_DELETEABLE"
|
||
FS_APP_OWNED_BY_USER = "FS_APP_OWNED_BY_USER"
|
||
FS_INVALID_APPROVAL_STATE = "FS_INVALID_APPROVAL_STATE"
|
||
FS_INVALID_BINDING_OPERATION = "FS_INVALID_BINDING_OPERATION"
|
||
FS_LACK_OF_BINDING_ID = "FS_LACK_OF_BINDING_ID"
|
||
FS_APP_ASSOCIATED = "FS_APP_ASSOCIATED"
|
||
FS_APP_NOT_ASSOCIATED = "FS_APP_NOT_ASSOCIATED"
|
||
FS_INVALID_COOPERATE_STATUS = "FS_INVALID_COOPERATE_STATUS"
|
||
FS_APP_NOT_PUBLISHED = "FS_APP_NOT_PUBLISHED"
|
||
FS_APP_BUNDLEID_REPEAT = "FS_APP_BUNDLEID_REPEAT"
|
||
FS_COOPERATION_TERMINATED = "FS_COOPERATION_TERMINATED"
|
||
FS_ORGAN_STATUS_INVALID = "FS_ORGAN_STATUS_INVALID"
|
||
FS_APP_NOT_ASS_BIND = "FS_APP_NOT_ASS_BIND"
|
||
FS_BIND_NOT_FOUND = "FS_BIND_NOT_FOUND"
|
||
FS_SERVICE_UNAVAILABLE = "FS_SERVICE_UNAVAILABLE"
|
||
FS_APP_PAY_EXPIRE = "FS_APP_PAY_EXPIRE"
|
||
FS_BIND_PAY_EXPIRE = "FS_BIND_PAY_EXPIRE"
|
||
FS_BINDING_NAME_REPEAT = "FS_BINDING_NAME_REPEAT"
|
||
FS_TIMESTAMP_TIMEOUT = "FS_TIMESTAMP_TIMEOUT"
|
||
FS_UUID_INVAILD = "FS_UUID_INVAILD"
|
||
FS_SIGNATURE_INVAILD = "FS_SIGNATURE_INVAILD"
|
||
FS_SIGNATURE_SDKKEY_INVAILD = "FS_SIGNATURE_SDKKEY_INVAILD"
|
||
FS_LICENSE_SERVER_ERROR = "FS_LICENSE_SERVER_ERROR"
|
||
FC_OPERA_LIMIT_BIND_OVER_ERROR = "FC_OPERA_LIMIT_BIND_OVER_ERROR"
|
||
FC_PRI_OPERA_LIMIT_BIND_OVER_ERROR = "FC_PRI_OPERA_LIMIT_BIND_OVER_ERROR"
|
||
FS_BUNDLE_ID_COUNT_OVER = "FS_BUNDLE_ID_COUNT_OVER"
|
||
FS_BUNDLE_ID_NOT_FOUND = "FS_BUNDLE_ID_NOT_FOUND"
|
||
FS_BUNDLE_ID_COUNT_OVER_TO_WEB_ERR = "FS_BUNDLE_ID_COUNT_OVER_TO_WEB_ERR"
|
||
FC_OPERA_LIMIT_APPID_OVER_ERROR = "FC_OPERA_LIMIT_APPID_OVER_ERROR"
|
||
FC_PRI_LIMIT_APPID_OVER_ERROR = "FC_PRI_LIMIT_APPID_OVER_ERROR"
|
||
FS_BINDINGID_NOT = "FS_BINDINGID_NOT"
|
||
FS_SDKKEY_NOT = "FS_SDKKEY_NOT"
|
||
FS_LICENSE_INVALID_ERR = "FS_LICENSE_INVALID_ERR"
|
||
FS_BIND_BUNDLE_LIMIT = "FS_BIND_BUNDLE_LIMIT"
|
||
FS_LINK_AUDIT_APPLY_EXIST = "FS_LINK_AUDIT_EXIST"
|
||
FS_EXPORT_APP_CLASS_ERR = "FS_EXPORT_APP_CLASS_ERR"
|
||
FS_ALIYUN_ADD_ERR = "FS_ALIYUN_ADD_ERR"
|
||
FS_DATA_HAS_DEL_ERR = "FS_DATA_HAS_DEL_ERR"
|
||
FS_MENU_ID_EXITS_ERR = "FS_MENU_ID_EXITS_ERR"
|
||
FS_SERVER_ERR = "FS_SERVER_ERR"
|
||
FS_IDENTITY_NOT_FOUND_ERR = "FS_IDENTITY_NOT_FOUND_ERR"
|
||
FS_QRCODE_HAS_EXPIRE = "FS_QRCODE_HAS_EXPIRE"
|
||
FS_ROLLBACK_FORBID = "FS_ROLLBACK_FORBID"
|
||
FS_PUBLISH_FORBID = "FS_PUBLISH_FORBID"
|
||
FS_MULTI_ROLLBACK_FORBID = "FS_MULTI_ROLLBACK_FORBID"
|
||
FS_NOT_TRIAL_INFO = "FS_NOT_TRIAL_INFO"
|
||
FS_REDIS_ERR = "FS_REDIS_ERR"
|
||
FS_MANAGE_APP_NO_AUTH = "FS_MANAGE_APP_NO_AUTH"
|
||
FS_APPID_ORGANID_ERR = "FS_APPID_ORGANID_ERR"
|
||
FS_APP_MARKET_LIMIT_ERROR = "FS_APP_MARKET_LIMIT_ERROR"
|
||
FS_APPLET_ID_IN_USE = "FS_APPLET_ID_IN_USE"
|
||
FS_APP_IS_FORBIDDEN = "FS_APP_IS_FORBIDDEN"
|
||
FS_BIND_IS_FORBIDDEN = "FS_BIND_IS_FORBIDDEN"
|
||
FS_PARAM_ERR = "FS_PARAM_ERR"
|
||
FS_BUNDLE_AVAILABLE_NUM_LIMIT = "FS_BUNDLE_AVAILABLE_NUM_LIMIT"
|
||
FS_BUNDLE_ALL_NUM_LIMIT = "FS_BUNDLE_ALL_NUM_LIMIT"
|
||
FS_OPER_BUNDLE_NUM_LIMIT = "FS_OPER_BUNDLE_NUM_LIMIT"
|
||
FS_OPER_CREATE_BUNDLE_ERR = "FS_OPER_CREATE_BUNDLE_ERR"
|
||
FS_OPER_HANDLE_ERR = "FS_OPER_HANDLE_ERR"
|
||
FS_QR_CODE_EXPIRED = "FS_QR_CODE_EXPIRED"
|
||
FS_OPER_REPEAT_BUNDLE_ERR = "FS_OPER_REPEAT_BUNDLE_ERR"
|
||
FS_OPER_AUTO_BIND_DOING_ERR = "FS_OPER_AUTO_BIND_DOING_ERR"
|
||
FS_NOT_REVIEW_BINDING_ERR = "FS_NOT_REVIEW_BINDING_ERR"
|
||
FC_LACK_OF_TO_BINDING_ID = "FC_LACK_OF_TO_BINDING_ID"
|
||
FC_BINDING_ID_EQUAL_TO_INDING_ID = "FC_BINDING_ID_EQUAL_TO_INDING_ID"
|
||
FC_MOVE_BINDING_NO_AUTH = "FC_MOVE_BINDING_NO_AUTH"
|
||
FC_LACK_OF_BUNDLE_ERR = "FC_LACK_OF_BUNDLE_ERR"
|
||
FC_APP_EXT_WX_ACCESS_TOKEN_ERR = "FC_APP_EXT_WX_ACCESS_TOKEN_ERR"
|
||
)
|
||
|
||
var ErrorMap = map[string]string{
|
||
OK: "",
|
||
FS_NOT_FOUND: "资源不存在",
|
||
FS_BAD_JSON: "参数格式错误,解析失败",
|
||
FS_DB_ERR: "数据库内部错误",
|
||
FS_SYSTEM_CALL: "系统内部错误",
|
||
FS_LACK_OF_APPID: "缺少appId",
|
||
FS_LACK_OF_SDKKEY: "缺少sdkKey",
|
||
FS_APP_ID_NOT_FOUND: "小程序不存在,请检查 AppID",
|
||
FS_GET_GROUP_FAILED: "企业状态校验异常",
|
||
FS_GET_DOMAIN_INFO_ERROR: "获取域名失败,相关服务不可用",
|
||
FS_GET_ACCOUNTINFO_ERROR: "获取账号信息失败",
|
||
FS_FORBIDDEN: "账号没有权限",
|
||
FS_PUBLISHING_OR_UNPUBLISHING: "正在申请上架或者申请下架",
|
||
FS_ACCESS_RULE_NOT_SET: "可见性范围未设置",
|
||
FS_INVALID_STATE: "应用当前状态不允许执行此操作",
|
||
FS_LACK_OF_ORGANIZAITON_ID: "缺少机构id",
|
||
FS_LACK_OF_USER_ID: "缺少用户id",
|
||
FS_SEQUENCE_LESS_THAN_CURRENT: "序列号不得低于当前已上架序列号",
|
||
FS_SPECIFIED_APP_ID_NOT_DELETEABLE: "指定appId的应用不可删除",
|
||
FS_APP_OWNED_BY_USER: "应用正在使用,不可删除",
|
||
FS_INVALID_APPROVAL_STATE: "审核后的状态值不合法",
|
||
FS_INVALID_BINDING_OPERATION: "应用操作不合法",
|
||
FS_LACK_OF_BINDING_ID: "缺少应用id",
|
||
FS_APP_ASSOCIATED: "小程序已关联",
|
||
FS_APP_NOT_ASSOCIATED: "小程序未关联",
|
||
FS_INVALID_COOPERATE_STATUS: "当前合作状态不允许执行此操作",
|
||
FS_APP_NOT_PUBLISHED: "小程序审核未通过或已下架",
|
||
FS_APP_BUNDLEID_REPEAT: "Bundle Id已存在",
|
||
FS_ORGAN_STATUS_INVALID: "小程序所属企业账号状态异常,请登录平台处理",
|
||
FS_COOPERATION_TERMINATED: "当前应用已经停止合作",
|
||
FS_APP_NOT_ASS_BIND: "小程序与本应用的关联关系没有生效,请检查关联关系",
|
||
FS_BIND_NOT_FOUND: "当前应用未在平台备案,请检查 SDK 初始化配置信息",
|
||
FS_SERVICE_UNAVAILABLE: "小程序已下架,相关服务暂不可用",
|
||
FS_APP_PAY_EXPIRE: "小程序已过有效期,相关服务暂不可用",
|
||
FS_BIND_PAY_EXPIRE: "当前应用已过期",
|
||
FS_BINDING_NAME_REPEAT: "应用名称已存在",
|
||
FS_APP_SEQUENCE_NOT_FOUND: "小程序版本错误",
|
||
FS_TIMESTAMP_TIMEOUT: "时间戳失效",
|
||
FS_UUID_INVAILD: "无效的uuid",
|
||
FS_SIGNATURE_INVAILD: "无效的signature",
|
||
FS_SIGNATURE_SDKKEY_INVAILD: "SDK Key 出错,请联系管理员处理",
|
||
FS_LICENSE_SERVER_ERROR: "license错误",
|
||
FC_OPERA_LIMIT_BIND_OVER_ERROR: "应用数量已达上限,如需新增应用,请联系平台运营方",
|
||
FC_PRI_OPERA_LIMIT_BIND_OVER_ERROR: "操作失败,当前环境应用个数已达license上限",
|
||
FC_OPERA_LIMIT_APPID_OVER_ERROR: "小程序数量已达上限,如需新增小程序,请联系平台运营方",
|
||
FC_PRI_LIMIT_APPID_OVER_ERROR: "操作失败,当前环境小程序个数已达license上限",
|
||
FS_BINDINGID_NOT: "应用id缺失",
|
||
FS_SDKKEY_NOT: "sdk key缺失",
|
||
FS_BUNDLE_ID_COUNT_OVER: "license权限不足", //bundle id达到上限
|
||
FS_BUNDLE_ID_NOT_FOUND: "无法绑定非运营端添加的bundleId", //bundle id达到上限
|
||
FS_BUNDLE_ID_COUNT_OVER_TO_WEB_ERR: "操作失败,当前环境Bundle ID已达到licesne上限",
|
||
FS_LICENSE_INVALID_ERR: "您当前的 license 异常,请联系管理员处理",
|
||
FS_BIND_BUNDLE_LIMIT: "bundle绑定达到限制",
|
||
FS_LINK_AUDIT_APPLY_EXIST: "小程序关联应用审核中",
|
||
FS_EXPORT_APP_CLASS_ERR: "导出小程序类型错误",
|
||
FS_ALIYUN_ADD_ERR: "阿里云添加失败",
|
||
FS_DATA_HAS_DEL_ERR: "数据已被删除,请刷新重试",
|
||
FS_MENU_ID_EXITS_ERR: "按钮ID或名称已存在",
|
||
FS_SERVER_ERR: "服务错误,请刷新重试",
|
||
FS_GET_MENUINFO_ERROR: "获取菜单列表失败",
|
||
FS_IDENTITY_NOT_FOUND_ERR: "该文件签名不存在",
|
||
FS_QRCODE_HAS_EXPIRE: "二维码过期,请刷新",
|
||
FS_ROLLBACK_FORBID: "该版本不可回退",
|
||
FS_PUBLISH_FORBID: "该版本不可发布",
|
||
FS_MULTI_ROLLBACK_FORBID: "不可连续回退",
|
||
FS_NOT_TRIAL_INFO: "该版本非体验版",
|
||
FS_REDIS_ERR: "redis异常",
|
||
FS_MANAGE_APP_NO_AUTH: "该用户无权限",
|
||
FS_APPID_ORGANID_ERR: "机构和小程序对不上",
|
||
FS_APP_IS_FORBIDDEN: "小程序被禁用,相关服务暂不可用",
|
||
FS_BIND_IS_FORBIDDEN: "BundleID 被禁用,相关服务暂不可用",
|
||
FS_PARAM_ERR: "参数错误",
|
||
FS_BUNDLE_AVAILABLE_NUM_LIMIT: "应用绑定正常状态的Bundle ID数量超过限制",
|
||
FS_BUNDLE_ALL_NUM_LIMIT: "应用绑定Bundle ID数量超过限制",
|
||
FS_OPER_BUNDLE_NUM_LIMIT: "正常状态的Bundle ID数量已达上限",
|
||
FS_OPER_CREATE_BUNDLE_ERR: "运营端创建合作应用必须含有非禁用的Bundle ID",
|
||
FS_OPER_HANDLE_ERR: "操作类型不支持",
|
||
FS_QR_CODE_EXPIRED: "二维码已失效",
|
||
FS_OPER_REPEAT_BUNDLE_ERR: "存在重复的bundleID",
|
||
FS_OPER_AUTO_BIND_DOING_ERR: "请等待上次自动关联小程序完成",
|
||
FS_NOT_REVIEW_BINDING_ERR: "不是审核应用",
|
||
FC_LACK_OF_TO_BINDING_ID: "缺少目标应用id",
|
||
FC_BINDING_ID_EQUAL_TO_INDING_ID: "源应用和目标应用id相同",
|
||
FC_MOVE_BINDING_NO_AUTH: "没有权限移动此Bundle ID",
|
||
FC_LACK_OF_BUNDLE_ERR: "缺少bundle信息",
|
||
FC_APP_EXT_WX_ACCESS_TOKEN_ERR: "获取ACCESS_TOKEN失败, 请检查appID和secret",
|
||
}
|
||
|
||
func GetErrMsg(errcode string) string {
|
||
errmsg, ok := ErrorMap[errcode]
|
||
if !ok {
|
||
return ""
|
||
}
|
||
return errmsg
|
||
}
|
||
|
||
type SvrRsp struct {
|
||
HttpStatus int
|
||
ErrCode string
|
||
ErrMsg string
|
||
}
|
||
|
||
func DefaultSvrRsp() *SvrRsp {
|
||
return &SvrRsp{
|
||
HttpStatus: http.StatusOK,
|
||
ErrCode: OK,
|
||
ErrMsg: GetErrMsg(OK),
|
||
}
|
||
}
|
||
|
||
func NewSvrRsp() *SvrRsp {
|
||
return &SvrRsp{
|
||
HttpStatus: http.StatusOK,
|
||
ErrCode: OK,
|
||
ErrMsg: "",
|
||
}
|
||
}
|
||
|
||
func (s *SvrRsp) Set(status int, errCode, errMsg string) *SvrRsp {
|
||
s.HttpStatus = status
|
||
s.ErrCode = errCode
|
||
s.ErrMsg = errMsg
|
||
return s
|
||
}
|
||
|
||
func (s *SvrRsp) SetLoc(status int, errCode string) *SvrRsp {
|
||
s.HttpStatus = status
|
||
s.ErrCode = errCode
|
||
s.ErrMsg = GetErrMsg(errCode)
|
||
return s
|
||
}
|
||
|
||
func MakeLocRsp(c *gin.Context, status int, errcode string, data interface{}) {
|
||
c.JSON(status, gin.H{
|
||
"errcode": errcode,
|
||
"error": GetErrMsg(errcode),
|
||
"data": data,
|
||
})
|
||
}
|
||
|
||
func MakeErrRsp(c *gin.Context, httpStatus int, errCode string, err string, data interface{}) {
|
||
c.JSON(httpStatus, gin.H{
|
||
"error": err,
|
||
"errcode": errCode,
|
||
"data": data,
|
||
})
|
||
}
|
||
|
||
func (s *SvrRsp) MakeRsp(c *gin.Context, data interface{}) {
|
||
c.JSON(s.HttpStatus, gin.H{
|
||
"errcode": s.ErrCode,
|
||
"error": s.ErrMsg,
|
||
"data": data,
|
||
})
|
||
}
|
||
|
||
func MakeGrpcCommonResult(httpStatus int, errCode string, result **pb.CommonResult) {
|
||
*result = &pb.CommonResult{}
|
||
(*result).Error = ErrorMap[errCode]
|
||
(*result).Errcode = errCode
|
||
(*result).Httpcode = int32(httpStatus)
|
||
}
|
||
|
||
func MakeGrpcCommonResultNoLoc(httpStatus int, errCode, errmsg string, result **pb.CommonResult) {
|
||
*result = &pb.CommonResult{}
|
||
(*result).Error = errmsg
|
||
(*result).Errcode = errCode
|
||
(*result).Httpcode = int32(httpStatus)
|
||
}
|