scrm-go

mpwechat_controller.go 1.3KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253
  1. package mpwechat
  2. import (
  3. base_ctl "SCRM/controllers"
  4. "SCRM/enums"
  5. "SCRM/service/wechat_service"
  6. "SCRM/utils"
  7. "fmt"
  8. "github.com/astaxie/beego"
  9. )
  10. func MpWechatCtlRegistRouters() {
  11. beego.Router("/api/mpwechat/authorization", &MpWechatAPIController{}, "Get:GetAuthorizationInfo")
  12. beego.Router("/api/mpwechat/authurl", &MpWechatAPIController{}, "Get:GetAuthUrl")
  13. }
  14. type MpWechatAPIController struct {
  15. base_ctl.BaseAuthAPIController
  16. }
  17. func (c *MpWechatAPIController) GetAuthorizationInfo() {
  18. adminUserInfo := c.GetAdminUserInfo()
  19. authorization, err := wechat_service.GetAuthorizationByOrgID(adminUserInfo.CurrentOrgId)
  20. if err != nil {
  21. c.ServeFailJsonSend(enums.ErrorCodeDataException, "获取授权信息失败:("+err.Error()+")")
  22. return
  23. }
  24. returnData := make(map[string]interface{}, 0)
  25. returnData["authorization"] = authorization
  26. c.ServeSuccessJSON(returnData)
  27. return
  28. }
  29. func (c *MpWechatAPIController) GetAuthUrl() {
  30. adminUserInfo := c.GetAdminUserInfo()
  31. vcode, vtime := utils.GetOrgIdCode(adminUserInfo.CurrentOrgId, 0)
  32. url := fmt.Sprintf("%s%s?id=%d&vcode=%s&vtime=%d", beego.AppConfig.String("httpdomain"), "/openwechat/mp/authorization", adminUserInfo.CurrentOrgId, vtime, vcode)
  33. returnData := make(map[string]interface{}, 0)
  34. returnData["url"] = url
  35. c.ServeSuccessJSON(returnData)
  36. return
  37. }