新增微信公众平台对接,增加缓存。默认10天
This commit is contained in:
parent
b4039aab81
commit
02561cf149
@ -1,7 +1,7 @@
|
|||||||
package v1
|
package v1
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"fmt"
|
"context"
|
||||||
"github.com/gin-gonic/gin"
|
"github.com/gin-gonic/gin"
|
||||||
v1 "hospital-open-api/api/requests/v1"
|
v1 "hospital-open-api/api/requests/v1"
|
||||||
"hospital-open-api/api/responses"
|
"hospital-open-api/api/responses"
|
||||||
@ -53,7 +53,13 @@ func (r *WeChat) GetScheme(c *gin.Context) {
|
|||||||
envVersion = "release"
|
envVersion = "release"
|
||||||
}
|
}
|
||||||
|
|
||||||
fmt.Println(req.Query)
|
// 获取缓存
|
||||||
|
redisKey := "c:official_account.scheme." + req.Path + "." + req.Query
|
||||||
|
scheme, _ := global.Redis.Get(context.Background(), redisKey).Result()
|
||||||
|
if scheme != "" {
|
||||||
|
responses.OkWithData(scheme, c)
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
// 构建请求数据
|
// 构建请求数据
|
||||||
JumpWxaData := &Scheme.GetSchemeJumpWxaRequest{
|
JumpWxaData := &Scheme.GetSchemeJumpWxaRequest{
|
||||||
@ -66,7 +72,7 @@ func (r *WeChat) GetScheme(c *gin.Context) {
|
|||||||
JumpWxa: JumpWxaData,
|
JumpWxa: JumpWxaData,
|
||||||
ExpireType: 1,
|
ExpireType: 1,
|
||||||
ExpireTime: 0,
|
ExpireTime: 0,
|
||||||
ExpireInterval: req.ExpireInterval,
|
ExpireInterval: 10,
|
||||||
}
|
}
|
||||||
|
|
||||||
openLink, err := GetSchemeRequest.GetScheme(1)
|
openLink, err := GetSchemeRequest.GetScheme(1)
|
||||||
|
|||||||
@ -8,5 +8,4 @@ type WeChatRequest struct {
|
|||||||
type GetScheme struct {
|
type GetScheme struct {
|
||||||
Path string `json:"path" form:"path" validate:"required" label:"页面路径"`
|
Path string `json:"path" form:"path" validate:"required" label:"页面路径"`
|
||||||
Query string `json:"query" form:"query" validate:"required" label:"参数"`
|
Query string `json:"query" form:"query" validate:"required" label:"参数"`
|
||||||
ExpireInterval int `json:"expire_interval" form:"expire_interval" validate:"required" label:"有效天数"`
|
|
||||||
}
|
}
|
||||||
|
|||||||
@ -1,11 +1,14 @@
|
|||||||
package Scheme
|
package Scheme
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
"context"
|
||||||
"encoding/json"
|
"encoding/json"
|
||||||
"errors"
|
"errors"
|
||||||
"fmt"
|
"fmt"
|
||||||
"hospital-open-api/extend/weChat"
|
"hospital-open-api/extend/weChat"
|
||||||
|
"hospital-open-api/global"
|
||||||
"strings"
|
"strings"
|
||||||
|
"time"
|
||||||
)
|
)
|
||||||
|
|
||||||
// GetSchemeJumpWxaRequest 跳转到的目标小程序信息
|
// GetSchemeJumpWxaRequest 跳转到的目标小程序信息
|
||||||
@ -74,5 +77,9 @@ func (r *GetSchemeRequest) GetScheme(userType int) (string, error) {
|
|||||||
return "", errors.New("失败")
|
return "", errors.New("失败")
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// 加入缓存
|
||||||
|
redisKey := "c:official_account.scheme." + r.JumpWxa.Path + "." + r.JumpWxa.Query
|
||||||
|
global.Redis.Set(context.Background(), redisKey, GetSchemeResponse.OpenLink, 60*60*24*10*time.Second)
|
||||||
|
|
||||||
return GetSchemeResponse.OpenLink, nil
|
return GetSchemeResponse.OpenLink, nil
|
||||||
}
|
}
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user