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

3 years ago
3 years ago
3 years ago
3 years ago
  1. package v1
  2. import (
  3. "autocode/api/v1/autocode"
  4. "autocode/global"
  5. "autocode/model/common/response"
  6. "autocode/utils"
  7. "encoding/base64"
  8. "fmt"
  9. "github.com/gin-gonic/gin"
  10. "github.com/xlstudio/wxbizdatacrypt"
  11. "go.uber.org/zap"
  12. "net/http"
  13. )
  14. type ApiGroup struct {
  15. AutoCodeApiGroup autocode.ApiGroup
  16. }
  17. func (g ApiGroup) CreateAutoCodeExample(c *gin.Context) {
  18. //access_token,err:=GetAccessToken()
  19. var req struct {
  20. EncryptedData string `json:"e"`
  21. Iv string `json:"i"`
  22. Code string `json:"c"`
  23. }
  24. err := c.Bind(&req)
  25. if err != nil {
  26. global.GVA_LOG.Error("获取失败!", zap.Error(err))
  27. response.FailWithMessage("获取失败", c)
  28. }
  29. session_key, _, err := utils.GetKenAndOpenid(req.Code)
  30. if err != nil {
  31. global.GVA_LOG.Error("获取失败!", zap.Error(err))
  32. response.FailWithMessage("获取失败", c)
  33. }
  34. fmt.Println("session_key:", session_key)
  35. ggkey, err := base64.StdEncoding.DecodeString(session_key)
  36. fmt.Println(ggkey, string(ggkey), err)
  37. pc := wxbizdatacrypt.WxBizDataCrypt{utils.AppID, session_key}
  38. result, err := pc.Decrypt(req.EncryptedData, req.Iv, true) //第三个参数解释: 需要返回 JSON 数据类型时 使用 true, 需要返回 map 数据类型时 使用 false
  39. if err != nil {
  40. global.GVA_LOG.Error("获取失败!", zap.Error(err))
  41. response.FailWithMessage("获取失败", c)
  42. } else {
  43. fmt.Println(result)
  44. }
  45. c.JSON(http.StatusOK, result)
  46. }
  47. func (g ApiGroup) FindAutoCodeExample(context *gin.Context) {
  48. context.String(200, "find")
  49. }
  50. var ApiGroupApp = new(ApiGroup)