package workWechat import ( "appPlatform/api/version1/user" "appPlatform/middleware/grocerystore" "appPlatform/models/modelshr" "appPlatform/overall" "appPlatform/overall/publicmethod" "encoding/json" "errors" "fmt" "strconv" "strings" "github.com/gin-gonic/gin" ) /* * @ 作者: 秦东 @ 时间: 2024-01-18 14:11:11 @ 功能: 获取token @ 参数 #systemApp 系统 #key 身份KEy #isAgain 重新授权 1:否,2:是 @ 返回值 # @ 方法原型 #token token值 #err 状态 */ func GainWechatToken(systemApp, key string, isAgain int) (token string, err error) { companyId := overall.CONSTANT_CONFIG.WechatCompany.CompanyId redisFileKey := fmt.Sprintf("Wechat:Token:%v_%v_%v", companyId, key, overall.CONSTANT_CONFIG.RedisPrefixStr.Alias) var secretStr string switch systemApp { case "kpi": redisFileKey = fmt.Sprintf("%v_%v_%v", redisFileKey, systemApp, overall.CONSTANT_CONFIG.WechatKpi.Agentid) secretStr = overall.CONSTANT_CONFIG.WechatKpi.Secret case "school": redisFileKey = fmt.Sprintf("%v_%v_%v", redisFileKey, systemApp, overall.CONSTANT_CONFIG.WechatSchool.Agentid) secretStr = overall.CONSTANT_CONFIG.WechatSchool.Secret default: redisFileKey = fmt.Sprintf("%v_%v", redisFileKey, systemApp) } redisClient := grocerystore.RunRedis(overall.CONSTANT_REDIS4) //设定redis库 if isAgain != 1 { token, err = getWechatServer(companyId, secretStr) if err != nil { return } redisClient.SetRedisTime(7200) redisClient.Set(redisFileKey, token) } else { isTrue, tokens := redisClient.Get(redisFileKey) if isTrue && token != "" { err = nil token = tokens return } else { token, err = getWechatServer(companyId, secretStr) if err != nil { return } redisClient.SetRedisTime(7200) redisClient.Set(redisFileKey, token) } } return } /* * @ 作者: 秦东 @ 时间: 2024-01-18 14:23:24 @ 功能: 获取微信Token(链接微信服务器) @ 参数 # @ 返回值 # @ 方法原型 # */ func getWechatServer(companyId, secretStr string) (token string, err error) { getTokenUrl := fmt.Sprintf("https://qyapi.weixin.qq.com/cgi-bin/gettoken?corpid=%v&corpsecret=%v", companyId, secretStr) // getTokenUrl := "https://qyapi.weixin.qq.com/cgi-bin/gettoken?corpid=" + companyId + "&corpsecret=" + secretStr tokenByte := publicmethod.CurlGet(getTokenUrl) var callBackCont WeChatCallBack err = json.Unmarshal(tokenByte, &callBackCont) if err != nil { return } if callBackCont.Errcode != 0 { err = errors.New("未能获得到TOKEN!") return } token = callBackCont.Accesstoken return } /* * @ 作者: 秦东 @ 时间: 2024-01-24 11:30:15 @ 功能: 获取人员信息单页(手机)查看权限 @ 参数 # @ 返回值 # @ 方法原型 # */ func (a *ApiMethod) LookOnePeopleArchives(c *gin.Context) { var requestData LookOneMan err := c.ShouldBindJSON(&requestData) if err != nil { publicmethod.Result(100, err, c) return } var sendData SendPower sendData.IsOk = 2 if requestData.SurveyMan == "" { publicmethod.Result(0, sendData, c) return } if requestData.UnSurveyMan == "" { requestData.UnSurveyMan = requestData.SurveyMan } var surverManInfo modelshr.ManCont err = surverManInfo.GetCont(map[string]interface{}{"`number`": requestData.SurveyMan}, "`emp_type`", "`company`", "`maindeparment`", "`admin_org`", "`position`", "`position`", "`role`") if err != nil { publicmethod.Result(0, sendData, c) return } var roleList []string if surverManInfo.Role != "" { roleList = strings.Split(surverManInfo.Role, ",") } //获取权限 var orgList []string sendData.Purview, _, orgList, sendData.Level = user.GetUserPower("appsystem", surverManInfo.Position, roleList) if publicmethod.IsInTrue[string]("210700510225772544", sendData.Purview) { //获取被查看人行政组织 var lookManInfo modelshr.PersonArchives lookManInfo.GetCont(map[string]interface{}{"`number`": requestData.UnSurveyMan}, "`company`", "`maindeparment`", "`admin_org`") switch sendData.Level { case 1: var sunOrg publicmethod.GetOrgAllParent sunOrg.GetOrgSun(surverManInfo.AdminOrg) sunOrg.Id = append(sunOrg.Id, surverManInfo.AdminOrg) if publicmethod.IsInTrue[int64](lookManInfo.Company, sunOrg.Id) || publicmethod.IsInTrue[int64](lookManInfo.MainDeparment, sunOrg.Id) || publicmethod.IsInTrue[int64](lookManInfo.AdminOrg, sunOrg.Id) { sendData.IsOk = 1 } case 2: var sunOrg publicmethod.GetOrgAllParent sunOrg.GetOrgSun(surverManInfo.MainDeparment) sunOrg.Id = append(sunOrg.Id, surverManInfo.MainDeparment) if publicmethod.IsInTrue[int64](lookManInfo.Company, sunOrg.Id) || publicmethod.IsInTrue[int64](lookManInfo.MainDeparment, sunOrg.Id) || publicmethod.IsInTrue[int64](lookManInfo.AdminOrg, sunOrg.Id) { sendData.IsOk = 1 } case 3: var sunOrg publicmethod.GetOrgAllParent sunOrg.GetOrgSun(surverManInfo.Company) sunOrg.Id = append(sunOrg.Id, surverManInfo.Company) if publicmethod.IsInTrue[int64](lookManInfo.Company, sunOrg.Id) || publicmethod.IsInTrue[int64](lookManInfo.MainDeparment, sunOrg.Id) || publicmethod.IsInTrue[int64](lookManInfo.AdminOrg, sunOrg.Id) { sendData.IsOk = 1 } case 4: departMent := strconv.FormatInt(lookManInfo.MainDeparment, 10) orgId := strconv.FormatInt(lookManInfo.AdminOrg, 10) companyId := strconv.FormatInt(lookManInfo.Company, 10) if publicmethod.IsInTrue[string](companyId, orgList) || publicmethod.IsInTrue[string](departMent, orgList) || publicmethod.IsInTrue[string](orgId, orgList) { sendData.IsOk = 1 } case 5: sendData.IsOk = 1 default: sendData.IsOk = 2 } } publicmethod.Result(0, sendData, c) }