|
@@ -54,9 +54,6 @@ func OutApi_RouteInit2(Router *gin.RouterGroup){
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
|
|
-
|
|
|
|
-
|
|
|
|
-
|
|
|
|
// @Tags 第三方接口服务-应用鉴权
|
|
// @Tags 第三方接口服务-应用鉴权
|
|
// @Summary 应用鉴权
|
|
// @Summary 应用鉴权
|
|
// @Description 应用鉴权
|
|
// @Description 应用鉴权
|
|
@@ -66,8 +63,17 @@ func OutApi_RouteInit2(Router *gin.RouterGroup){
|
|
// @Success 200 {object} model.ResponseToken "{"code": 0, "msg": "xxx", data:{}}"
|
|
// @Success 200 {object} model.ResponseToken "{"code": 0, "msg": "xxx", data:{}}"
|
|
// @Router /dxp/outapi/authorize [post]
|
|
// @Router /dxp/outapi/authorize [post]
|
|
func authorize(c *gin.Context){
|
|
func authorize(c *gin.Context){
|
|
|
|
+ //先判断服务器授权
|
|
|
|
+ ret,_,err := dao.Empower_GetInstance().GetLiceneseLeftDays()
|
|
|
|
+ if err != nil {
|
|
|
|
+ response.FailWithMessage(err.Error(),c,"JSON")
|
|
|
|
+ return
|
|
|
|
+ }
|
|
|
|
+ if ret == false {
|
|
|
|
+ response.FailWithMessage(err.Error(),c,"JSON")
|
|
|
|
+ return
|
|
|
|
+ }
|
|
var param model.LoginRequest
|
|
var param model.LoginRequest
|
|
-
|
|
|
|
if err := c.ShouldBindJSON(¶m); err != nil {
|
|
if err := c.ShouldBindJSON(¶m); err != nil {
|
|
response.FailWithMessage("invalid json provided",c,"JSON")
|
|
response.FailWithMessage("invalid json provided",c,"JSON")
|
|
return
|
|
return
|
|
@@ -217,12 +223,14 @@ func any(c *gin.Context){
|
|
|
|
|
|
if resType == "Service"{
|
|
if resType == "Service"{
|
|
|
|
|
|
- cnt := dao.GetApiCallCount(serviceInfo.AccessId)
|
|
|
|
- if cnt > serviceInfo.DayLimit {
|
|
|
|
- response.FailWithMessage("超出单日调用最大次数!",c,serviceInfo.Format)
|
|
|
|
- return
|
|
|
|
|
|
+ if serviceInfo.DayLimit > 0 {
|
|
|
|
+ cnt := dao.GetApiCallCount(serviceInfo.AccessId)
|
|
|
|
+ if cnt > serviceInfo.DayLimit {
|
|
|
|
+ response.FailWithMessage("超出单日调用最大次数!",c,serviceInfo.Format)
|
|
|
|
+ return
|
|
|
|
+ }
|
|
|
|
+ dao.IncApiCallCount(serviceInfo.AccessId)
|
|
}
|
|
}
|
|
- dao.IncApiCallCount(serviceInfo.AccessId)
|
|
|
|
request_body,_:=ioutil.ReadAll(c.Request.Body)
|
|
request_body,_:=ioutil.ReadAll(c.Request.Body)
|
|
|
|
|
|
//request_body,_ := json.Marshal(¶m)
|
|
//request_body,_ := json.Marshal(¶m)
|
|
@@ -234,7 +242,67 @@ func any(c *gin.Context){
|
|
fmt.Println("accesskey:",key)
|
|
fmt.Println("accesskey:",key)
|
|
fmt.Println("request url:",serviceInfo.ResData.ServiceUrl)
|
|
fmt.Println("request url:",serviceInfo.ResData.ServiceUrl)
|
|
fmt.Println("request param",string(request_body))
|
|
fmt.Println("request param",string(request_body))
|
|
- mapData,byteData,err := api_proxy.CQ119_GetInstance().CQ119_ApiCall(serviceInfo.ResData.ServiceUrl,request_body)
|
|
|
|
|
|
+
|
|
|
|
+ userReq := make(map[string]interface{},0)
|
|
|
|
+ if len(request_body) > 0 {
|
|
|
|
+ err := json.Unmarshal(request_body, &userReq)
|
|
|
|
+ if err != nil {
|
|
|
|
+ global.SystemLogger.Log(logrus.ErrorLevel,"请求参数格式不对,JSON转换失败:", err)
|
|
|
|
+ response.FailWithMessage(err.Error(),c,serviceInfo.Format)
|
|
|
|
+ return
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+ //拼接内置参数
|
|
|
|
+ search := ""
|
|
|
|
+ if userReq["search"] != nil {
|
|
|
|
+ search = userReq["search"].(string)
|
|
|
|
+ }
|
|
|
|
+ if serviceInfo.ResData.FixParams != nil && len(*serviceInfo.ResData.FixParams) > 0 {
|
|
|
|
+ if len(search) == 0 {
|
|
|
|
+ userReq["search"] = *serviceInfo.ResData.FixParams
|
|
|
|
+ }else{
|
|
|
|
+ //将search 参数和 fixparams 参数组装在一起
|
|
|
|
+ searchMap := make(map[string]interface{},0)
|
|
|
|
+ err := json.Unmarshal([]byte(search),&searchMap)
|
|
|
|
+ if err != nil {
|
|
|
|
+ global.SystemLogger.Log(logrus.ErrorLevel,"fix参数格式不对,JSON转换失败:", err)
|
|
|
|
+ response.FailWithMessage(err.Error(),c,serviceInfo.Format)
|
|
|
|
+ return
|
|
|
|
+ }
|
|
|
|
+ fixReq := make(map[string]interface{},0)
|
|
|
|
+ err = json.Unmarshal([]byte(*serviceInfo.ResData.FixParams), &fixReq)
|
|
|
|
+ if err != nil {
|
|
|
|
+ global.SystemLogger.Log(logrus.ErrorLevel,"fix参数格式不对,JSON转换失败:", err)
|
|
|
|
+ response.FailWithMessage(err.Error(),c,serviceInfo.Format)
|
|
|
|
+ return
|
|
|
|
+ }
|
|
|
|
+ for k,v := range fixReq {
|
|
|
|
+ searchMap[k] = v
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ newSearch, err := json.Marshal(searchMap)
|
|
|
|
+ if err != nil {
|
|
|
|
+ global.SystemLogger.Log(logrus.ErrorLevel,"请求参数格式不对,JSON转换失败:", err)
|
|
|
|
+ response.FailWithMessage(err.Error(),c,serviceInfo.Format)
|
|
|
|
+ return
|
|
|
|
+ }
|
|
|
|
+ userReq["search"] = string(newSearch)
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+
|
|
|
|
+ newReq, err := json.Marshal(userReq)
|
|
|
|
+ if err != nil {
|
|
|
|
+ global.SystemLogger.Log(logrus.ErrorLevel,"请求参数格式不对,JSON转换失败:", err)
|
|
|
|
+ response.FailWithMessage(err.Error(),c,serviceInfo.Format)
|
|
|
|
+ return
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ mapData,byteData,err := api_proxy.CQ119_GetInstance().CQ119_ApiCall(serviceInfo.ResData.ServiceUrl,newReq)
|
|
|
|
+ if serviceInfo.ResData.AuthWay == "gov" {
|
|
|
|
+ mapData,byteData,err = api_proxy.GovDataFormatToResource(byteData)
|
|
|
|
+ }
|
|
|
|
|
|
duration := time.Since(start)
|
|
duration := time.Since(start)
|
|
call_log.CallDuration = duration.Milliseconds()
|
|
call_log.CallDuration = duration.Milliseconds()
|
|
@@ -272,12 +340,14 @@ func any(c *gin.Context){
|
|
//})
|
|
//})
|
|
}else if resType == "Data"{
|
|
}else if resType == "Data"{
|
|
|
|
|
|
- cnt := dao.GetApiCallCount(dataInfo.AccessId)
|
|
|
|
- if cnt > dataInfo.DayLimit {
|
|
|
|
- response.FailWithMessage("超出单日调用最大次数!",c,dataInfo.Format)
|
|
|
|
- return
|
|
|
|
|
|
+ if dataInfo.DayLimit > 0 {
|
|
|
|
+ cnt := dao.GetApiCallCount(dataInfo.AccessId)
|
|
|
|
+ if cnt > dataInfo.DayLimit {
|
|
|
|
+ response.FailWithMessage("超出单日调用最大次数!",c,dataInfo.Format)
|
|
|
|
+ return
|
|
|
|
+ }
|
|
|
|
+ dao.IncApiCallCount(dataInfo.AccessId)
|
|
}
|
|
}
|
|
- dao.IncApiCallCount(dataInfo.AccessId)
|
|
|
|
|
|
|
|
var param model.DbQuery
|
|
var param model.DbQuery
|
|
if err := c.ShouldBindJSON(¶m); err != nil {
|
|
if err := c.ShouldBindJSON(¶m); err != nil {
|
|
@@ -371,7 +441,17 @@ func apiCall(c *gin.Context){
|
|
}
|
|
}
|
|
|
|
|
|
if param.AuthWay == "gov"{
|
|
if param.AuthWay == "gov"{
|
|
-
|
|
|
|
|
|
+ _,byteData,err := api_proxy.CQ119_GetInstance().CQ119_ApiCall(param.ServiceUrl,[]byte(param.RequestParam))
|
|
|
|
+ if err != nil {
|
|
|
|
+ response.FailWithMessage("call api failed.",c,"JSON")
|
|
|
|
+ return
|
|
|
|
+ }
|
|
|
|
+ mapData,_,err := api_proxy.GovDataFormatToResource(byteData)
|
|
|
|
+ if err != nil {
|
|
|
|
+ response.FailWithMessage(fmt.Sprintf("gov data swap to cq119 format failed.err:%s",err.Error()),c,"JSON")
|
|
|
|
+ return
|
|
|
|
+ }
|
|
|
|
+ response.OkWithData(mapData,c,"JSON")
|
|
}else if param.AuthWay == "119"{
|
|
}else if param.AuthWay == "119"{
|
|
result,_,err := api_proxy.CQ119_GetInstance().CQ119_ApiCall(param.ServiceUrl,[]byte(param.RequestParam))
|
|
result,_,err := api_proxy.CQ119_GetInstance().CQ119_ApiCall(param.ServiceUrl,[]byte(param.RequestParam))
|
|
if err != nil {
|
|
if err != nil {
|
|
@@ -421,12 +501,14 @@ func apiProxyToData(c *gin.Context){
|
|
|
|
|
|
if resType == "Data"{
|
|
if resType == "Data"{
|
|
|
|
|
|
- cnt := dao.GetApiCallCount(dataInfo.AccessId)
|
|
|
|
- if cnt > dataInfo.DayLimit {
|
|
|
|
- response.FailWithMessage("超出单日调用最大次数!",c,dataInfo.Format)
|
|
|
|
- return
|
|
|
|
|
|
+ if dataInfo.DayLimit > 0 {
|
|
|
|
+ cnt := dao.GetApiCallCount(dataInfo.AccessId)
|
|
|
|
+ if cnt > dataInfo.DayLimit {
|
|
|
|
+ response.FailWithMessage("超出单日调用最大次数!",c,dataInfo.Format)
|
|
|
|
+ return
|
|
|
|
+ }
|
|
|
|
+ dao.IncApiCallCount(dataInfo.AccessId)
|
|
}
|
|
}
|
|
- dao.IncApiCallCount(dataInfo.AccessId)
|
|
|
|
|
|
|
|
var param model.DbQuery
|
|
var param model.DbQuery
|
|
if err := c.ShouldBindJSON(¶m); err != nil {
|
|
if err := c.ShouldBindJSON(¶m); err != nil {
|
|
@@ -500,12 +582,14 @@ func apiProxyToService(c *gin.Context){
|
|
|
|
|
|
if resType == "Service"{
|
|
if resType == "Service"{
|
|
|
|
|
|
- cnt := dao.GetApiCallCount(serviceInfo.AccessId)
|
|
|
|
- if cnt > serviceInfo.DayLimit {
|
|
|
|
- response.FailWithMessage("超出单日调用最大次数!",c,serviceInfo.Format)
|
|
|
|
- return
|
|
|
|
|
|
+ if serviceInfo.DayLimit > 0 {
|
|
|
|
+ cnt := dao.GetApiCallCount(serviceInfo.AccessId)
|
|
|
|
+ if cnt > serviceInfo.DayLimit {
|
|
|
|
+ response.FailWithMessage("超出单日调用最大次数!",c,serviceInfo.Format)
|
|
|
|
+ return
|
|
|
|
+ }
|
|
|
|
+ dao.IncApiCallCount(serviceInfo.AccessId)
|
|
}
|
|
}
|
|
- dao.IncApiCallCount(serviceInfo.AccessId)
|
|
|
|
request_body,_:=ioutil.ReadAll(c.Request.Body)
|
|
request_body,_:=ioutil.ReadAll(c.Request.Body)
|
|
|
|
|
|
//request_body,_ := json.Marshal(¶m)
|
|
//request_body,_ := json.Marshal(¶m)
|
|
@@ -517,7 +601,72 @@ func apiProxyToService(c *gin.Context){
|
|
fmt.Println("accesskey:",key)
|
|
fmt.Println("accesskey:",key)
|
|
fmt.Println("request url:",serviceInfo.ResData.ServiceUrl)
|
|
fmt.Println("request url:",serviceInfo.ResData.ServiceUrl)
|
|
fmt.Println("request param",string(request_body))
|
|
fmt.Println("request param",string(request_body))
|
|
- mapData,byteData,err := api_proxy.CQ119_GetInstance().CQ119_ApiCall(serviceInfo.ResData.ServiceUrl,request_body)
|
|
|
|
|
|
+
|
|
|
|
+ userReq := make(map[string]interface{},0)
|
|
|
|
+ if len(request_body) > 0 {
|
|
|
|
+ err := json.Unmarshal(request_body, &userReq)
|
|
|
|
+ if err != nil {
|
|
|
|
+ global.SystemLogger.Log(logrus.ErrorLevel,"请求参数格式不对,JSON转换失败:", err)
|
|
|
|
+ response.FailWithMessage(err.Error(),c,serviceInfo.Format)
|
|
|
|
+ return
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+ //拼接内置参数
|
|
|
|
+ search := ""
|
|
|
|
+ if userReq["search"] != nil {
|
|
|
|
+ search = userReq["search"].(string)
|
|
|
|
+ }
|
|
|
|
+ if serviceInfo.ResData.FixParams != nil && len(*serviceInfo.ResData.FixParams) > 0 {
|
|
|
|
+ if len(search) == 0 {
|
|
|
|
+ userReq["search"] = *serviceInfo.ResData.FixParams
|
|
|
|
+ }else{
|
|
|
|
+ //将search 参数和 fixparams 参数组装在一起
|
|
|
|
+ searchMap := make(map[string]interface{},0)
|
|
|
|
+ err := json.Unmarshal([]byte(search),&searchMap)
|
|
|
|
+ if err != nil {
|
|
|
|
+ global.SystemLogger.Log(logrus.ErrorLevel,"fix参数格式不对,JSON转换失败:", err)
|
|
|
|
+ response.FailWithMessage(err.Error(),c,serviceInfo.Format)
|
|
|
|
+ return
|
|
|
|
+ }
|
|
|
|
+ fixReq := make(map[string]interface{},0)
|
|
|
|
+ err = json.Unmarshal([]byte(*serviceInfo.ResData.FixParams), &fixReq)
|
|
|
|
+ if err != nil {
|
|
|
|
+ global.SystemLogger.Log(logrus.ErrorLevel,"fix参数格式不对,JSON转换失败:", err)
|
|
|
|
+ response.FailWithMessage(err.Error(),c,serviceInfo.Format)
|
|
|
|
+ return
|
|
|
|
+ }
|
|
|
|
+ for k,v := range fixReq {
|
|
|
|
+ searchMap[k] = v
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ newSearch, err := json.Marshal(searchMap)
|
|
|
|
+ if err != nil {
|
|
|
|
+ global.SystemLogger.Log(logrus.ErrorLevel,"请求参数格式不对,JSON转换失败:", err)
|
|
|
|
+ response.FailWithMessage(err.Error(),c,serviceInfo.Format)
|
|
|
|
+ return
|
|
|
|
+ }
|
|
|
|
+ userReq["search"] = string(newSearch)
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+
|
|
|
|
+ newReq, err := json.Marshal(userReq)
|
|
|
|
+ if err != nil {
|
|
|
|
+ global.SystemLogger.Log(logrus.ErrorLevel,"请求参数格式不对,JSON转换失败:", err)
|
|
|
|
+ response.FailWithMessage(err.Error(),c,serviceInfo.Format)
|
|
|
|
+ return
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ fmt.Println("--------------------------------------")
|
|
|
|
+ fmt.Println(string(newReq))
|
|
|
|
+ fmt.Println("--------------------------------------")
|
|
|
|
+
|
|
|
|
+
|
|
|
|
+ mapData,byteData,err := api_proxy.CQ119_GetInstance().CQ119_ApiCall(serviceInfo.ResData.ServiceUrl,newReq)
|
|
|
|
+ if serviceInfo.ResData.AuthWay == "gov" {
|
|
|
|
+ mapData,byteData,err = api_proxy.GovDataFormatToResource(byteData)
|
|
|
|
+ }
|
|
|
|
|
|
duration := time.Since(start)
|
|
duration := time.Since(start)
|
|
call_log.CallDuration = duration.Milliseconds()
|
|
call_log.CallDuration = duration.Milliseconds()
|
|
@@ -555,12 +704,14 @@ func apiProxyToService(c *gin.Context){
|
|
//})
|
|
//})
|
|
}else if resType == "Data"{
|
|
}else if resType == "Data"{
|
|
|
|
|
|
- cnt := dao.GetApiCallCount(dataInfo.AccessId)
|
|
|
|
- if cnt > dataInfo.DayLimit {
|
|
|
|
- response.FailWithMessage("超出单日调用最大次数!",c,dataInfo.Format)
|
|
|
|
- return
|
|
|
|
|
|
+ if dataInfo.DayLimit > 0 {
|
|
|
|
+ cnt := dao.GetApiCallCount(dataInfo.AccessId)
|
|
|
|
+ if cnt > dataInfo.DayLimit {
|
|
|
|
+ response.FailWithMessage("超出单日调用最大次数!",c,dataInfo.Format)
|
|
|
|
+ return
|
|
|
|
+ }
|
|
|
|
+ dao.IncApiCallCount(dataInfo.AccessId)
|
|
}
|
|
}
|
|
- dao.IncApiCallCount(dataInfo.AccessId)
|
|
|
|
|
|
|
|
var param model.DbQuery
|
|
var param model.DbQuery
|
|
if err := c.ShouldBindJSON(¶m); err != nil {
|
|
if err := c.ShouldBindJSON(¶m); err != nil {
|