package mpwechat import ( base_ctl "SCRM/controllers" "SCRM/enums" "SCRM/service/wechat_service" "SCRM/utils" "fmt" "github.com/astaxie/beego" ) func MpWechatCtlRegistRouters() { beego.Router("/api/mpwechat/authorization", &MpWechatAPIController{}, "Get:GetAuthorizationInfo") beego.Router("/api/mpwechat/authurl", &MpWechatAPIController{}, "Get:GetAuthUrl") } type MpWechatAPIController struct { base_ctl.BaseAuthAPIController } func (c *MpWechatAPIController) GetAuthorizationInfo() { adminUserInfo := c.GetAdminUserInfo() authorization, err := wechat_service.GetAuthorizationByOrgID(adminUserInfo.CurrentOrgId) if err != nil { c.ServeFailJsonSend(enums.ErrorCodeDataException, "获取授权信息失败:("+err.Error()+")") return } returnData := make(map[string]interface{}, 0) returnData["authorization"] = authorization c.ServeSuccessJSON(returnData) return } func (c *MpWechatAPIController) GetAuthUrl() { adminUserInfo := c.GetAdminUserInfo() vcode, vtime := utils.GetOrgIdCode(adminUserInfo.CurrentOrgId, 0) url := fmt.Sprintf("%s%s?id=%d&vcode=%s&vtime=%d", beego.AppConfig.String("httpdomain"), "/openwechat/mp/authorization", adminUserInfo.CurrentOrgId, vtime, vcode) returnData := make(map[string]interface{}, 0) returnData["url"] = url c.ServeSuccessJSON(returnData) return }