15 changed files with 439 additions and 42 deletions
@ -0,0 +1,43 @@ |
|||
package workWechat |
|||
|
|||
import ( |
|||
"appPlatform/overall/publicmethod" |
|||
|
|||
"github.com/gin-gonic/gin" |
|||
) |
|||
|
|||
type ApiMethod struct{} |
|||
|
|||
// 微信相关项目入口
|
|||
func (a *ApiMethod) Index(c *gin.Context) { |
|||
outputCont := publicmethod.MapOut[string]() |
|||
outputCont["index"] = "微信相关项目入口" |
|||
publicmethod.Result(0, outputCont, c) |
|||
} |
|||
|
|||
// 微信返回结构体
|
|||
type RevokeMsgSendCallBack struct { |
|||
Errcode int `json:"errcode"` //返回码
|
|||
Errmsg string `json:"errmsg"` //对返回码的文本描述内容
|
|||
} |
|||
|
|||
// 微信返回结构体(Token)
|
|||
type WeChatCallBack struct { |
|||
RevokeMsgSendCallBack |
|||
Accesstoken string `json:"access_token"` |
|||
Expiresin int64 `json:"expires_in"` |
|||
Ticket string `json:"ticket"` |
|||
} |
|||
|
|||
// 查看单一人员档案信息
|
|||
type LookOneMan struct { |
|||
SurveyMan string `json:"surveyman"` //调查人
|
|||
UnSurveyMan string `json:"unsurveyman"` //被调查人
|
|||
} |
|||
|
|||
// 输出权限及是否可操作
|
|||
type SendPower struct { |
|||
IsOk int `json:"isOk"` //调查人
|
|||
Level int `json:"level"` //调查人权限范围
|
|||
Purview []string `json:"purview"` //被调查人
|
|||
} |
|||
@ -0,0 +1,201 @@ |
|||
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) |
|||
} |
|||
@ -0,0 +1,19 @@ |
|||
package workwechatrouter |
|||
|
|||
import ( |
|||
"appPlatform/api/version1" |
|||
|
|||
"github.com/gin-gonic/gin" |
|||
) |
|||
|
|||
// 微信路由
|
|||
func (a *ApiRouter) RouterGroupPc(router *gin.RouterGroup) { |
|||
apiRouter := router.Group("wechat") |
|||
|
|||
var methodBinding = version1.AppApiEntry.WechatApi |
|||
{ |
|||
apiRouter.GET("", methodBinding.Index) //入口
|
|||
apiRouter.POST("", methodBinding.Index) //入口
|
|||
apiRouter.POST("lookOnePeopleArchives", methodBinding.LookOnePeopleArchives) //获取人员信息单页(手机)查看权限
|
|||
} |
|||
} |
|||
@ -0,0 +1,3 @@ |
|||
package workwechatrouter |
|||
|
|||
type ApiRouter struct{} |
|||
Loading…
Reference in new issue