wx.go 1.7 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768
  1. package v1
  2. import (
  3. "git.getensh.com/common/gopkgs/logger"
  4. "git.getensh.com/common/gopkgs/tasker/httptasker"
  5. "git.getensh.com/common/gopkgs/util"
  6. "github.com/gin-gonic/gin"
  7. "go.uber.org/zap"
  8. "net/http"
  9. "property-management-gateway/errors"
  10. param_v1 "property-management-gateway/param/v1"
  11. "property-management-gateway/pb"
  12. "property-management-gateway/pb/v1"
  13. )
  14. //
  15. // @Summary 公众号添加小程序入口
  16. // @Description 公众号添加小程序入口
  17. // @Tags 微信相关
  18. // @Accept json
  19. // @Produce json
  20. // @Param token header string true " "
  21. // @Param body body v1.WxPublicAddMiniBody true " "
  22. // @Success 200 {object} v1.WxPublicAddMiniResponse
  23. // @Failure 500 {object} base.HTTPError
  24. // @Router /api/v1/wx/public/mini [post]
  25. func (c *Controller) WxPublicAddMini(ctx *gin.Context) {
  26. // 解析参数
  27. req := &param_v1.WxPublicAddMiniRequest{}
  28. parseParamTask := func() error {
  29. err := util.ShouldBind(ctx, &req.Header, nil, nil, &req.WxPublicAddMiniBody)
  30. if err != nil {
  31. logger.Error("func",
  32. zap.String("call", "util.ShouldBind"),
  33. zap.String("error", err.Error()))
  34. return errors.ParamsError
  35. }
  36. return nil
  37. }
  38. // 业务处理
  39. handleServiceTask := func() error {
  40. resp := param_v1.WxPublicAddMiniResponse{}
  41. rpcReq := &v1.WxPublicAddMiniRequest{
  42. MiniPagepath:req.MiniPagepath,
  43. MiniUrl:req.MiniUrl,
  44. }
  45. _, err := pb.Thirdparty.WxPublicAddMini(ctx, rpcReq)
  46. if err != nil {
  47. s, _ := json.MarshalToString(req)
  48. logger.Error("func",
  49. zap.String("call", "Thirdparty.WxPublicAddMini"),
  50. zap.String("params", s),
  51. zap.String("error", err.Error()))
  52. return errors.ErrorTransForm(err)
  53. }
  54. ctx.JSON(http.StatusOK, resp)
  55. return nil
  56. }
  57. // 执行任务
  58. httptasker.Exec(ctx, parseParamTask, handleServiceTask)
  59. }