新增微信公众平台对接,增加缓存。默认10天
This commit is contained in:
parent
b4039aab81
commit
02561cf149
@ -1,7 +1,7 @@
|
||||
package v1
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"context"
|
||||
"github.com/gin-gonic/gin"
|
||||
v1 "hospital-open-api/api/requests/v1"
|
||||
"hospital-open-api/api/responses"
|
||||
@ -53,7 +53,13 @@ func (r *WeChat) GetScheme(c *gin.Context) {
|
||||
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{
|
||||
@ -66,7 +72,7 @@ func (r *WeChat) GetScheme(c *gin.Context) {
|
||||
JumpWxa: JumpWxaData,
|
||||
ExpireType: 1,
|
||||
ExpireTime: 0,
|
||||
ExpireInterval: req.ExpireInterval,
|
||||
ExpireInterval: 10,
|
||||
}
|
||||
|
||||
openLink, err := GetSchemeRequest.GetScheme(1)
|
||||
|
||||
@ -6,7 +6,6 @@ type WeChatRequest struct {
|
||||
|
||||
// GetScheme 获取页面加密scheme码
|
||||
type GetScheme struct {
|
||||
Path string `json:"path" form:"path" validate:"required" label:"页面路径"`
|
||||
Query string `json:"query" form:"query" validate:"required" label:"参数"`
|
||||
ExpireInterval int `json:"expire_interval" form:"expire_interval" validate:"required" label:"有效天数"`
|
||||
Path string `json:"path" form:"path" validate:"required" label:"页面路径"`
|
||||
Query string `json:"query" form:"query" validate:"required" label:"参数"`
|
||||
}
|
||||
|
||||
@ -1,11 +1,14 @@
|
||||
package Scheme
|
||||
|
||||
import (
|
||||
"context"
|
||||
"encoding/json"
|
||||
"errors"
|
||||
"fmt"
|
||||
"hospital-open-api/extend/weChat"
|
||||
"hospital-open-api/global"
|
||||
"strings"
|
||||
"time"
|
||||
)
|
||||
|
||||
// GetSchemeJumpWxaRequest 跳转到的目标小程序信息
|
||||
@ -74,5 +77,9 @@ func (r *GetSchemeRequest) GetScheme(userType int) (string, error) {
|
||||
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
|
||||
}
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user