You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

63 lines
1.5 KiB

package v1
import (
"autocode/api/v1/autocode"
"autocode/global"
"autocode/model/common/response"
"autocode/utils"
"encoding/base64"
"fmt"
"github.com/gin-gonic/gin"
"github.com/xlstudio/wxbizdatacrypt"
"go.uber.org/zap"
"net/http"
)
type ApiGroup struct {
AutoCodeApiGroup autocode.ApiGroup
}
func (g ApiGroup) CreateAutoCodeExample(c *gin.Context) {
//access_token,err:=GetAccessToken()
var req struct {
EncryptedData string `json:"e"`
Iv string `json:"i"`
Code string `json:"c"`
}
err := c.Bind(&req)
if err != nil {
global.GVA_LOG.Error("获取失败!", zap.Error(err))
response.FailWithMessage("获取失败", c)
}
session_key, _, err := utils.GetKenAndOpenid(req.Code)
if err != nil {
global.GVA_LOG.Error("获取失败!", zap.Error(err))
response.FailWithMessage("获取失败", c)
}
fmt.Println("session_key:", session_key)
ggkey, err := base64.StdEncoding.DecodeString(session_key)
fmt.Println(ggkey, string(ggkey), err)
pc := wxbizdatacrypt.WxBizDataCrypt{utils.AppID, session_key}
result, err := pc.Decrypt(req.EncryptedData, req.Iv, true) //第三个参数解释: 需要返回 JSON 数据类型时 使用 true, 需要返回 map 数据类型时 使用 false
if err != nil {
global.GVA_LOG.Error("获取失败!", zap.Error(err))
response.FailWithMessage("获取失败", c)
} else {
fmt.Println(result)
}
c.JSON(http.StatusOK, result)
}
func (g ApiGroup) FindAutoCodeExample(context *gin.Context) {
context.String(200, "find")
}
var ApiGroupApp = new(ApiGroup)