package application import ( "finclip-app-manager/domain/entity" "finclip-app-manager/domain/entity/proto/apiproto" "finclip-app-manager/domain/service" "finclip-app-manager/infrastructure/config" "finclip-app-manager/infrastructure/utility" "net/http" "strconv" "strings" "github.com/gin-gonic/gin" "gitlab.finogeeks.club/finclip-backend/apm" ) type InternalGetAppVerInfoRsp struct { AppID string `json:"appId"` Name string `json:"name"` Sequence int `json:"sequence"` AppClass string `json:"appClass"` AppType string `json:"appType"` Status entity.Status `json:"status"` PublishedStatus entity.SpecificStatus `json:"publishedStatus"` UnpublishedStatus entity.SpecificStatus `json:"unpublishedStatus"` ActionStatus entity.SpecificStatus `json:"actionStatus"` DeveloperID string `json:"developerId"` GroupID string `json:"groupId"` GroupName string `json:"groupName"` Created int64 `json:"created"` CreatedBy string `json:"createdBy"` CustomData entity.CustomDataInfo `json:"customData"` Version string `json:"version"` CorporationID string `json:"corporationId"` CoreDescription string `json:"coreDescription"` Logo string `json:"logo"` } func InternalGetAppVerInfo(c *gin.Context) { traceCtx := apm.ApmClient().TraceContextFromGin(c) appId := c.Param("appId") seqStr := c.Param("sequence") SDKKey := c.GetHeader(utility.SDK_KEY_SIGNAL) sdkVer := c.GetHeader(utility.SDKKEY_VER_HEADER_KEY) log.Infof("InternalGetAppVerInfo req appId:%s,seq:%s,sdk-key:%s,sdk-ver:%s", appId, seqStr, SDKKey, sdkVer) if appId == "" { log.Errorf("InternalGetAppVerInfo appId empty!!!") utility.MakeLocRsp(c, http.StatusBadRequest, utility.FS_LACK_OF_APPID, gin.H{}) return } if SDKKey == "" { log.Errorf("InternalGetAppVerInfo sdk-key empty!!!") utility.MakeLocRsp(c, http.StatusBadRequest, utility.FS_LACK_OF_SDKKEY, gin.H{}) return } //sdkKey白名单的校验 if !utility.InArry(SDKKey, config.WhiteSDKArry) { if config.Cfg.PublishEnv == entity.ENV_PRIVATE { svr := service.NewBindingService() checkStatus := svr.CheckReviewBySdkKey(traceCtx, SDKKey) if checkStatus != utility.OK { log.Errorf("RuntimeGetAppVersionInfo sdk not in reviewlist,sdk-key:%s", SDKKey) utility.MakeLocRsp(c, http.StatusForbidden, checkStatus, gin.H{}) return } } else { log.Errorf("RuntimeGetAppVersionInfo sdk not in white sdk arry,sdk-key:%s", SDKKey) utility.MakeLocRsp(c, http.StatusForbidden, utility.FS_COOPERATION_TERMINATED, gin.H{}) return } } sequence, err := strconv.Atoi(seqStr) if err != nil { log.Errorf("InternalGetAppVerInfo sequence format err,seq:%s,err:%s", seqStr, err.Error()) utility.MakeLocRsp(c, http.StatusForbidden, utility.FS_BAD_JSON, gin.H{}) return } svr := service.NewAppService() data, rsp := svr.OpenApiGetAppVerInfo(traceCtx, appId, sequence, sdkVer) log.Infof("OpenApiGetAppVerInfo rsp data:%+v,info:%+v", data, rsp) if rsp.ErrCode != utility.OK { rsp.MakeRsp(c, gin.H{}) } else { data.GroupName = ChangeGroupName(data.GroupName) rsp.MakeRsp(c, data) } return } func ChangeGroupName(groupName string) string { if len(groupName) == 18 && strings.Contains(groupName, "个人-") { phone := groupName[7:] if isOK := utility.IsMobile(phone); isOK { newName := "个人-" for i := 0; i < len(phone); i++ { if i >= 3 && i <= 6 { newName += "*" } else { newName += string(phone[i]) } } groupName = newName } } return groupName } type GetGroupIdByAppIdRspData struct { GroupId string `json:"groupId"` AppName string `json:"appName"` } type GetGroupIdByAppIdRsp struct { Data GetGroupIdByAppIdRspData `json:"data"` Errcode string `json:"errcode"` Errmsg string `json:"error"` } func GetGroupIdByAppId(c *gin.Context) { traceCtx := apm.ApmClient().TraceContextFromGin(c) appID := c.Param("appId") if appID == "" { log.Errorf("GetGroupIdByAppId app id empty!") utility.MakeLocRsp(c, http.StatusBadRequest, utility.FS_LACK_OF_APPID, gin.H{}) return } log.Infof("GetGroupIdByAppId req appId:%s", appID) app, err := service.NewAppService().GetAppInfoByAppId(traceCtx, appID) if err != nil { log.Errorf("GetGroupIdByAppId db err:%s", err.Error()) utility.MakeLocRsp(c, http.StatusInternalServerError, utility.FS_DB_ERR, gin.H{}) return } rspData := GetGroupIdByAppIdRsp{} rspData.Data.GroupId = app.GroupID rspData.Data.AppName = app.Name rspData.Errmsg = "" rspData.Errmsg = "OK" c.JSON(http.StatusOK, rspData) } type GetRuleEngineVerPubListRspItem struct { Version int `json:"version"` VersionStr string `json:"versionStr"` } type VerToDescItem struct { Version int `json:"version"` Desc string `json:"desc"` } type GetRuleEngineVerPubListRsp struct { VerList []GetRuleEngineVerPubListRspItem `json:"verList"` //大于等于MaxPubVer的序列号列表 NowPubVer GetRuleEngineVerPubListRspItem `json:"nowPubVer"` //当前上架版本 MaxPubVer GetRuleEngineVerPubListRspItem `json:"maxPubVer"` //已发布、已下架、审核通过三种状态里面的最大版本号 VerToDesc []VerToDescItem `json:"verToDesc"` //序列号到版本描述的映射 } func GetRuleEngineVerPubList(c *gin.Context) { traceCtx := apm.ApmClient().TraceContextFromGin(c) appId := c.Param("appId") if appId == "" { log.Errorf("GetRuleEngineVerPubList app id empty !") utility.MakeLocRsp(c, http.StatusBadRequest, utility.FS_APP_ID_NOT_FOUND, gin.H{}) return } log.Infof("GetRuleEngineVerPubList appId:%s", appId) svr := service.NewAppService() data, rsp := svr.GetRuleEngineVerPubList(traceCtx, appId) rsp.MakeRsp(c, data) return } func RuleEngineGetAppInfo(c *gin.Context) { traceCtx := apm.ApmClient().TraceContextFromGin(c) appID := c.Param("appId") if appID == "" { log.Infof("RuleEngineGetAppInfo appId empty!!!") utility.MakeLocRsp(c, http.StatusBadRequest, utility.FS_LACK_OF_APPID, gin.H{}) return } sdkKey := c.GetHeader(utility.SDK_KEY_SIGNAL) sdkVer := c.GetHeader(utility.SDKKEY_VER_HEADER_KEY) log.Infof("RuleEngineGetAppInfo req appId:%s sdkKey:%s sdkver:%s", appID, sdkKey, sdkVer) svr := service.NewAppService() data, rsp := svr.RuntimeGetPubAppInfo(traceCtx, sdkKey, appID, sdkVer) if rsp.ErrCode != utility.OK { rsp.MakeRsp(c, gin.H{}) } else { rsp.MakeRsp(c, data) } } func RuleEngineGetAppVerInfo(c *gin.Context) { traceCtx := apm.ApmClient().TraceContextFromGin(c) appId := c.Param("appId") seqStr := c.Param("version") log.Infof("RuleEngineGetAppVerInfo req appId:%s,seq:%s", appId, seqStr) if appId == "" { log.Errorf("RuleEngineGetAppVerInfo appId empty!!!") utility.MakeLocRsp(c, http.StatusBadRequest, utility.FS_LACK_OF_APPID, gin.H{}) return } sequence, err := strconv.Atoi(seqStr) if err != nil { log.Errorf("RuleEngineGetAppVerInfo sequence format err,seq:%s,err:%s", seqStr, err.Error()) utility.MakeLocRsp(c, http.StatusBadRequest, utility.FS_BAD_JSON, gin.H{}) return } sdkKey := c.GetHeader(utility.SDK_KEY_SIGNAL) if sdkKey == "" { log.Errorf("RuleEngineGetAppVerInfo sdk key empty!!!") utility.MakeLocRsp(c, http.StatusBadRequest, utility.FS_SDKKEY_NOT, gin.H{}) return } sdkVer := c.GetHeader(utility.SDKKEY_VER_HEADER_KEY) svr := service.NewAppService() data, rsp := svr.RuleEngineGetAppVerInfo(traceCtx, appId, sequence, sdkKey, sdkVer) if rsp.ErrCode != utility.OK { rsp.MakeRsp(c, gin.H{}) } else { rsp.MakeRsp(c, data) } } type GrayNotifyAppReq struct { AppId string `json:"appId"` Version int `json:"version"` Status bool `json:"status"` } func GrayNotifyApp(c *gin.Context) { traceCtx := apm.ApmClient().TraceContextFromGin(c) req := GrayNotifyAppReq{} if err := c.BindJSON(&req); err != nil { log.Errorf("GrayNotifyApp bind err:%s", err.Error()) utility.MakeLocRsp(c, http.StatusBadRequest, utility.FS_BAD_JSON, gin.H{}) return } err := service.NewAppService().UpdateGrayPubStatus(traceCtx, req.AppId, req.Version, req.Status) if err != nil { log.Errorf("GrayNotifyApp db err:%s", err.Error()) utility.MakeLocRsp(c, http.StatusInternalServerError, utility.FS_DB_ERR, gin.H{}) return } utility.MakeLocRsp(c, http.StatusOK, utility.OK, gin.H{}) return } type GetPubVerListRspItem struct { AppID string `json:"appId" bson:"appId"` Name string `json:"name" bson:"name"` Version string `json:"version" bson:"version"` Sequence int `json:"sequence" bson:"sequence"` AppBuildID string `json:"appBuildID" bson:"appBuildID"` AppBuildInfoId string `json:"buildInfoId" bson:"buildInfoId"` StartParams entity.AppStartParams `json:"startParams"` WechatInfo WechatInfoRsp `json:"wechatInfo" bson:"wechatInfo"` } func GetAppVerBuildInfos(c *gin.Context) { traceCtx := apm.ApmClient().TraceContextFromGin(c) appId := c.Query("appId") if appId == "" { log.Errorf("appId is empty!!!") utility.MakeLocRsp(c, http.StatusBadRequest, utility.FS_LACK_OF_APPID, gin.H{}) return } log.Infof("get app ver build info req appid:[%s]", appId) svr := service.NewAppService() appInfo, err := svr.GetAppInfoByAppId(traceCtx, appId) if err != nil { log.Errorf("GetAppVerBuildInfos db err:%s", err.Error()) if service.NotFound(err) { utility.MakeLocRsp(c, http.StatusNotFound, utility.FS_APP_ID_NOT_FOUND, gin.H{}) return } utility.MakeLocRsp(c, http.StatusInternalServerError, utility.FS_DB_ERR, gin.H{}) return } buildSvr := service.NewAppAppletInfoService() trialResult, err := buildSvr.GetTrialInfoByAppId(traceCtx, appId) if err != nil && !service.NotFound(err) { log.Errorf("GetTrialInfoByAppId db err:%s", err.Error()) utility.MakeLocRsp(c, http.StatusInternalServerError, utility.FS_DB_ERR, gin.H{}) return } log.Debugf("trialResult data:", trialResult) appSvr := service.NewAppService() publishedList, _, err := appSvr.GetAllPublishedVerList(traceCtx, appId) if err != nil { log.Errorf("GetAllPublishedVerList err:%s", err.Error()) utility.MakeLocRsp(c, http.StatusInternalServerError, utility.FS_DB_ERR, gin.H{}) return } var pubResult []GetPubVerListRspItem for _, v := range publishedList { pubItem := GetPubVerListRspItem{} if len(v.AppBuildID) > 0 { buildInfo := &entity.AppBuildInfo{} buildInfo, err = buildSvr.GetInfoById(traceCtx, v.AppBuildID) if err != nil { log.Infof("GetInfoById err:%s", err.Error()) buildInfo, err = buildSvr.GetInfoByBuildInfoId(traceCtx, v.AppBuildID) if err != nil { log.Infof("GetInfoByBuildInfoId err:%s", err.Error()) } } else { pubItem.AppID = v.AppID pubItem.AppBuildID = v.AppBuildID pubItem.AppBuildInfoId = buildInfo.BuildInfoId pubItem.Sequence = v.Sequence pubItem.Version = v.Version pubItem.Name = v.Name pubItem.StartParams = buildInfo.StartParams } wechatInfo, err := hCaller.GetWeChatInfo(traceCtx, appId) if err != nil { log.Errorf("GetWeChatInfo err:%s", err.Error()) utility.MakeLocRsp(c, http.StatusInternalServerError, utility.FS_SYSTEM_CALL, gin.H{}) return } if wechatInfo.Updated == 0 { wechatInfo.Updated = appInfo.PublishedStatus.LastUpdated } pubItem.WechatInfo = WechatInfoRsp{ WechatAppSecret: wechatInfo.WechatAppSecret, WechatAppId: wechatInfo.WechatAppId, WechatPath: wechatInfo.WechatPath, WechatSize: wechatInfo.WechatSize, QrcodeUrl: wechatInfo.QrcodeUrl, QrcodeDownloadUrl: wechatInfo.QrcodeDownloadUrl, Updated: wechatInfo.Updated, //ShowHint:wechatInfo.ShowHint, } pubResult = append(pubResult, pubItem) } } log.Debugf("pubResult data:", pubResult) utility.MakeLocRsp(c, http.StatusOK, utility.OK, gin.H{"trialVer": trialResult, "pubVer": pubResult}) return } type GetGrayStatisticsVerListReq struct { AppId string `form:"appId"` Version int `form:"version"` BeginTime int64 `form:"begin_time"` EndTime int64 `form:"end_time"` } func GetGrayStatisticsVerList(c *gin.Context) { traceCtx := apm.ApmClient().TraceContextFromGin(c) req := GetGrayStatisticsVerListReq{} if err := c.Bind(&req); err != nil { log.Errorf("GetGrayStatisticsVerList req bind err:%s", err.Error()) utility.MakeLocRsp(c, http.StatusBadRequest, utility.FS_BAD_JSON, gin.H{}) return } log.Infof("GetGrayStatisticsVerList req:%+v", req) svr := service.NewAppService() data, rsp := svr.GetGrayStatisticsVerList(traceCtx, req.AppId, req.Version, req.BeginTime, req.EndTime) if rsp.ErrCode == utility.OK { rsp.MakeRsp(c, data) } else { rsp.MakeRsp(c, gin.H{}) } return } type RuleEngineBatchGetAppReq struct { SdkKey string `json:"sdkKey"` SdkVer string `json:"sdkVer"` AppList []string `json:"appList"` AppVerList []struct { AppId string `json:"appId"` Sequence int `json:"sequence"` } `json:"appVerList"` } type RuleEngineBatchGetAppRsp struct { AppFailList []string `json:"appFailList"` AppVerFailList []string `json:"appVerFailList"` AppDataList []interface{} `json:"appDataList"` AppVerDataList []interface{} `json:"appVerDataList"` } func RuleEngineBatchGetApp(c *gin.Context) { traceCtx := apm.ApmClient().TraceContextFromGin(c) req := RuleEngineBatchGetAppReq{} rsp := RuleEngineBatchGetAppRsp{} rsp.AppFailList = make([]string, 0) rsp.AppVerFailList = make([]string, 0) rsp.AppDataList = make([]interface{}, 0) rsp.AppVerDataList = make([]interface{}, 0) if err := c.BindJSON(&req); err != nil { log.Errorf("RuleEngineBatchGetApp bind err:%s", err.Error()) utility.MakeLocRsp(c, http.StatusBadRequest, utility.FS_BAD_JSON, gin.H{}) return } log.Infof("http RuleEngineBatchGetApp req:%+v", req) //首先获取小程序详情 rs := service.NewAppService() for _, appId := range req.AppList { data, tempRsp := rs.RuntimeGetPubAppInfo(traceCtx, req.SdkKey, appId, req.SdkVer) if tempRsp.ErrCode != utility.OK { log.Errorf("RuleEngineBatchGetApp get info data:%v,resp:%+v", data, tempRsp) rsp.AppFailList = append(rsp.AppFailList, appId) continue } log.Debugf("RuleEngineBatchGetApp info:%+v", data.CustomData.SourceFile) log.Infof("http RuleEngineBatchGetApp info:", utility.InterfaceToJsonString(data)) rsp.AppDataList = append(rsp.AppDataList, data) } //获取小程序版本详情 for _, appVer := range req.AppVerList { rspData, tempRsp := rs.RuleEngineGetAppVerInfo(traceCtx, appVer.AppId, appVer.Sequence, req.SdkKey, req.SdkVer) if tempRsp.ErrCode != utility.OK { rsp.AppVerFailList = append(rsp.AppVerFailList, appVer.AppId) continue } rsp.AppVerDataList = append(rsp.AppVerDataList, rspData) } log.Infof("http RuleEngineBatchGetApp resp:", utility.InterfaceToJsonString(rsp)) utility.MakeLocRsp(c, http.StatusOK, utility.OK, rsp) return } func GetAppTagAndClassification(c *gin.Context) { traceCtx := apm.ApmClient().TraceContextFromGin(c) svr := service.NewAppService() appClassList, err := svr.GetAppClassList(traceCtx) if err != nil { log.Debugf("GetAppTagAndClassification err:%s", err.Error()) utility.MakeLocRsp(c, http.StatusInternalServerError, utility.FS_DB_ERR, gin.H{}) return } appTagList, err := svr.GetAppTagList(traceCtx) if err != nil { log.Debugf("GetAppTagAndClassification err:%s", err.Error()) utility.MakeLocRsp(c, http.StatusInternalServerError, utility.FS_DB_ERR, gin.H{}) return } c.JSON(http.StatusOK, gin.H{"appTag": appTagList, "appClass": appClassList}) } /** * @api {PUT} /api/v1/mop/finstore/update-expire/:type/:businessId [S/S][MOP]更新小程序过期时间 * @apiGroup Finclip App Manager * @apiVersion __API_VERSION__ * * @apiParam {string=app,binding} type 更新类型-app:小程序,binding:应用 * @apiParam {string=app,binding} businessId 业务Id(小程序Id或应用Id) * @apiParam (RequestBody) {Number} expire 到期时间,单位/ms * @apiParamExample {json} Request-Example: * /api/v1/finstore/update-expire/app/5edf44b56ef940000153c3f7 * { * "expire":1596445961000, * } * @apiErrorExample Error Status: * HTTP/1.1 !=200 服务端异常 */ //支付系统同步过期信息到应用市场 func UpdateExpireInfo(c *gin.Context) { traceCtx := apm.ApmClient().TraceContextFromGin(c) req := apiproto.UpdateExpireInfoReq{} rsp := make(map[string]interface{}) if err := c.BindJSON(&req); err != nil { log.Errorf("UpdateExpireInfo bind err:%s", err.Error()) utility.MakeLocRsp(c, http.StatusBadRequest, utility.FS_BAD_JSON, rsp) return } upType := c.Param("type") bussId := c.Param("businessId") if upType == "" || bussId == "" { log.Errorf("UpdateExpireInfo param err:%s", "type or businessId empty") utility.MakeLocRsp(c, http.StatusBadRequest, utility.FS_BAD_JSON, rsp) return } log.Infof("NotifySyncInfoHand req,upType:%s,buss id:%s,expire:%d", upType, bussId, req.Expire) if req.Expire == 0 { req.Expire = service.MAX_EXPIRE_DATA } svrRsp := &utility.SvrRsp{} switch upType { case "app": appSvr := service.NewAppService() svrRsp = appSvr.UpExpire(traceCtx, bussId, req.Expire) case "binding": bindSvr := service.NewBindingService() svrRsp = bindSvr.UpExpire(traceCtx, bussId, req.Expire) default: log.Errorf("UpdateExpireInfo up type err:%s,up type:%s", "up type err", upType) utility.MakeLocRsp(c, http.StatusBadRequest, utility.FS_BAD_JSON, rsp) return } svrRsp.MakeRsp(c, rsp) return } //根据小程序包标识符(md5、sha256)进行小程序信息的获取 func BatchAppsByIdentity(c *gin.Context) { var ( req = apiproto.BatchAppsByIdentityReq{} traceCtx = apm.ApmClient().TraceContextFromGin(c) ) if err := c.BindJSON(&req); err != nil { log.Errorf("bind para err:%s", err.Error()) utility.MakeLocRsp(c, http.StatusBadRequest, utility.FS_BAD_JSON, gin.H{}) return } if len(req.Apps) == 0 { log.Errorf("BatchAppsByIdentity apps empty ...") utility.MakeLocRsp(c, http.StatusOK, utility.OK, gin.H{}) return } req.IdentityType = strings.ToLower(req.IdentityType) sdkKey := c.GetHeader(utility.SDK_KEY_SIGNAL) log.Infof("BatchAppsByIdentity req:%+v", req) svr := service.NewAppService() rsp := svr.BatchAppsByIdentity(traceCtx, sdkKey, &req) utility.MakeLocRsp(c, int(rsp.GetResult().Httpcode), rsp.GetResult().Errcode, rsp.GetData()) return } //根据小程序包标识符(md5、sha256)获取小程序包是否合法 func IdentityAppsCheck(c *gin.Context) { var ( traceCtx = apm.ApmClient().TraceContextFromGin(c) req = apiproto.IdentityAppsCheckReq{} ) if err := c.BindJSON(&req); err != nil { log.Errorf("bind para err:%s", err.Error()) utility.MakeLocRsp(c, http.StatusBadRequest, utility.FS_PARAM_ERR, gin.H{}) return } if len(req.Apps) == 0 { log.Errorf("IdentityAppsCheck apps empty ...") utility.MakeLocRsp(c, http.StatusOK, utility.OK, gin.H{}) return } sdk := c.GetHeader(utility.SDK_KEY_SIGNAL) log.Debugf("IdentityAppsCheck req:%+v", req) svr := service.NewAppService() rsp := svr.IdentityAppsCheck(traceCtx, sdk, &req) //todo 处理nil utility.MakeLocRsp(c, int(rsp.GetResult().Httpcode), rsp.GetResult().Errcode, rsp.GetData()) return } //根据sdkKey获取关联的应用 //再根据关联的应用获取所有的小程序 type GetAppListBySdkKeyHandReq struct { BindingId string `form:"bindingId"` PageNo int `form:"pageNo"` PageSize int `form:"pageSize"` } type GetAppListBySdkKeyHandRspItem struct { AppId string `bson:"appId" json:"appId"` Name string `bson:"name" json:"name"` Logo string `bson:"logo" json:"logo"` Sequence int `bson:"sequence" json:"sequence"` } type GetAppListBySdkKeyHandRsp struct { Total int `json:"total"` List []GetAppListBySdkKeyHandRspItem `json:"list"` } func GetAppListByBindIdHand(c *gin.Context) { traceCtx := apm.ApmClient().TraceContextFromGin(c) req := GetAppListBySdkKeyHandReq{} if err := c.BindQuery(&req); err != nil { log.Errorf("GetAppListBySdkKeyHand bind error:%s", err.Error()) utility.MakeLocRsp(c, http.StatusBadRequest, utility.FS_BAD_JSON, gin.H{}) return } log.Infof("GetAppListByBindIdHand req:%+v", req) if req.BindingId == "" { log.Errorf("GetAppListBySdkKeyHand binding id empty") utility.MakeLocRsp(c, http.StatusBadRequest, utility.FS_BINDINGID_NOT, gin.H{}) return } if req.PageNo <= 0 { req.PageNo = 1 } if req.PageSize >= 100 || req.PageSize <= 0 { req.PageSize = 100 } svr := service.NewAppService() total, apps, err := svr.GetLinkAppsByBindingID(traceCtx, req.BindingId, req.PageNo, req.PageSize, "") if err != nil { log.Errorf("GetLinkAppsByBindingID err:%s", err.Error()) utility.MakeLocRsp(c, http.StatusInternalServerError, utility.FS_DB_ERR, gin.H{}) return } rsp := GetAppListBySdkKeyHandRsp{ Total: total, List: make([]GetAppListBySdkKeyHandRspItem, 0), } for _, v := range apps { item := GetAppListBySdkKeyHandRspItem{ AppId: v.AppID, Name: v.Name, Logo: v.Logo, Sequence: v.Sequence, } rsp.List = append(rsp.List, item) } utility.MakeLocRsp(c, http.StatusOK, utility.OK, rsp) } type GetAppListBySdkKeyReq struct { SDKKey string `form:"sdkKey"` PageNo int `form:"pageNo"` PageSize int `form:"pageSize"` } type GetAppBySDKKeyRspItem struct { AppId string `bson:"appId" json:"appId"` Name string `bson:"name" json:"name"` Logo string `bson:"logo" json:"logo"` AppTag []string `bson:"appTag" json:"appTag"` AppClass string `bson:"appClass" json:"appClass"` CoreDescription string `bson:"coreDescription" json:"coreDescription"` SourceFileUrl string `bson:"sourceFileUrl" json:"sourceFileUrl"` } type GetAppBySDKKeyRsp struct { Total int `json:"total"` List []GetAppBySDKKeyRspItem `json:"list"` } func GetAppBySDKKey(c *gin.Context) { traceCtx := apm.ApmClient().TraceContextFromGin(c) req := GetAppListBySdkKeyReq{} if err := c.BindQuery(&req); err != nil { log.Errorf("GetAppBySDKKey bind error:%s", err.Error()) utility.MakeLocRsp(c, http.StatusBadRequest, utility.FS_BAD_JSON, gin.H{}) return } log.Infof("GetAppBySDKKey req:%+v", req) if req.SDKKey == "" { log.Errorf("GetAppListBySdkKeyHand sdkKey empty") utility.MakeLocRsp(c, http.StatusBadRequest, utility.FS_SDKKEY_NOT, gin.H{}) return } if req.PageSize >= 100 || req.PageSize <= 0 { req.PageSize = 100 } svr := service.NewAppService() total, apps, err := svr.GetLinkAppsBySDKKey(traceCtx, req.SDKKey, req.PageNo, req.PageSize) if err != nil { log.Errorf("GetAppBySDKKey err:%s", err.Error()) utility.MakeLocRsp(c, http.StatusInternalServerError, utility.FS_DB_ERR, gin.H{}) return } rsp := GetAppBySDKKeyRsp{ Total: total, List: make([]GetAppBySDKKeyRspItem, 0), } for _, v := range apps { latestVersion, _ := svr.GetLatestPubAppVer(traceCtx, v.AppID) item := GetAppBySDKKeyRspItem{ AppId: v.AppID, Name: v.Name, Logo: v.Logo, AppTag: v.AppTag, AppClass: v.AppClass, CoreDescription: v.CoreDescription, SourceFileUrl: latestVersion.CustomData.SourceFile[0].SourceFileUrl, } rsp.List = append(rsp.List, item) } utility.MakeLocRsp(c, http.StatusOK, utility.OK, rsp) } type GetAppsInfoByListHandReq struct { AppIdList string `form:"list"` //用逗号分隔 } type GetAppsInfoByListHandRspItem struct { AppId string `json:"appId"` Name string `json:"name"` Logo string `json:"logo"` Desc string `json:"desc"` GroupId string `json:"groupId"` } type GetAppsInfoByListHandRsp struct { List []GetAppsInfoByListHandRspItem `json:"list"` } func GetAppsInfoByListHand(c *gin.Context) { traceCtx := apm.ApmClient().TraceContextFromGin(c) req := GetAppsInfoByListHandReq{} if err := c.BindQuery(&req); err != nil { log.Errorf("GetAppsInfoByListHand bind error:%s", err.Error()) utility.MakeLocRsp(c, http.StatusBadRequest, utility.FS_BAD_JSON, gin.H{}) return } appIdList := strings.Split(req.AppIdList, ",") if len(appIdList) == 0 { log.Errorf("GetAppsInfoByListHand appId list zero") utility.MakeLocRsp(c, http.StatusOK, utility.OK, gin.H{}) return } log.Infof("GetAppsInfoByListHand req:%+v", req) svr := service.NewAppService() apps, err := svr.GetAppsByAppIds(traceCtx, appIdList) if err != nil { log.Errorf("GetAppsByAppIds err:%s", err.Error()) utility.MakeLocRsp(c, http.StatusInternalServerError, utility.FS_DB_ERR, gin.H{}) return } log.Infof("get result:%+v", apps) rsp := GetAppsInfoByListHandRsp{ List: make([]GetAppsInfoByListHandRspItem, 0), } for _, v := range apps { item := GetAppsInfoByListHandRspItem{} item.AppId = v.AppID item.Name = v.Name item.Logo = v.Logo item.Desc = v.CoreDescription item.GroupId = v.GroupID rsp.List = append(rsp.List, item) } log.Infof("get rsp:%+v", rsp) utility.MakeLocRsp(c, http.StatusOK, utility.OK, rsp) } type SearchAppHandReq struct { SearchTxt string `form:"searchTxt"` BindingId string `form:"bindingId"` PageNo int `form:"pageNo"` PageSize int `form:"pageSize"` } type SearchAppHandRspItem struct { AppId string `bson:"appId" json:"appId"` Name string `bson:"name" json:"name"` Logo string `bson:"logo" json:"logo"` Desc string `bson:"desc" json:"desc"` Sequence int `bson:"sequence" json:"sequence"` } type SearchAppHandRsp struct { Total int `json:"total"` List []SearchAppHandRspItem `json:"list"` } //搜索应用已经上架的小程序信息 func SearchAppHand(c *gin.Context) { traceCtx := apm.ApmClient().TraceContextFromGin(c) req := SearchAppHandReq{} if err := c.BindQuery(&req); err != nil { log.Errorf("SearchAppHand bind error:%s", err.Error()) utility.MakeLocRsp(c, http.StatusBadRequest, utility.FS_BAD_JSON, gin.H{}) return } if req.BindingId == "" { log.Errorf("SearchAppHand binding id empty") utility.MakeLocRsp(c, http.StatusBadRequest, utility.FS_BINDINGID_NOT, gin.H{}) return } if req.PageNo <= 0 { req.PageNo = 1 } if req.PageSize >= 100 || req.PageSize <= 0 { req.PageSize = 100 } rsp := SearchAppHandRsp{ Total: 0, List: make([]SearchAppHandRspItem, 0), } svr := service.NewAppService() total, apps, err := svr.GetLinkAppsByBindingID(traceCtx, req.BindingId, req.PageNo, req.PageSize, req.SearchTxt) if err != nil { log.Errorf("GetLinkAppsByBindingID err:%s", err.Error()) utility.MakeLocRsp(c, http.StatusIMUsed, utility.FS_DB_ERR, gin.H{}) return } rsp.Total = total for _, v := range apps { item := SearchAppHandRspItem{ AppId: v.AppID, Name: v.Name, Logo: v.Logo, Desc: v.CoreDescription, Sequence: v.Sequence, } rsp.List = append(rsp.List, item) } utility.MakeLocRsp(c, http.StatusOK, utility.OK, rsp) } //账号系统同步信息到应用市场 type NotifySyncInfoHandReq struct { TraceId string `json:"traceId"` SubId string `json:"subId"` Type string `json:"type"` Data map[string]interface{} `json:"data"` } func NotifySyncInfoHand(c *gin.Context) { //traceCtx := apm.ApmClient().TraceContextFromGin(c) req := NotifySyncInfoHandReq{} if err := c.BindJSON(&req); err != nil { log.Errorf("NotifySyncInfoHand bind err:%s", err.Error()) utility.MakeLocRsp(c, http.StatusBadRequest, utility.FS_BAD_JSON, gin.H{}) return } //log.Infof("NotifySyncInfoHand req:%+v", req) //svr := service.NewNotifySyncInfoService() //httpCode, errcode := svr.NotifySyncInfo(traceCtx, req.TraceId, req.SubId, req.Type, req.Data) //common.MakeRsp(c, httpCode, errcode, rsp) return }