You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
672 lines
25 KiB
672 lines
25 KiB
package workWechat
|
|
|
|
import (
|
|
"appPlatform/api/version1/user"
|
|
"appPlatform/middleware/grocerystore"
|
|
"appPlatform/models/modelshr"
|
|
"appPlatform/models/modelsschool"
|
|
"appPlatform/overall"
|
|
"appPlatform/overall/publicmethod"
|
|
"encoding/json"
|
|
"errors"
|
|
"fmt"
|
|
"net/http"
|
|
"net/url"
|
|
"reflect"
|
|
"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
|
|
case "stzl":
|
|
redisFileKey = fmt.Sprintf("%v_%v_%v", redisFileKey, systemApp, overall.CONSTANT_CONFIG.ShuTongZhiLian.Agentid)
|
|
secretStr = overall.CONSTANT_CONFIG.ShuTongZhiLian.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, ",")
|
|
}
|
|
// fmt.Printf("人员信息--->%v\n", surverManInfo)
|
|
//获取权限
|
|
var orgList []string
|
|
sendData.Purview, _, orgList, sendData.Level = user.GetUserPower("appsystem", surverManInfo.Position, roleList)
|
|
|
|
// fmt.Printf("人员信息--->Purview:%v--->orgList:%v--->Level:%v\n", sendData.Purview, orgList, sendData.Level)
|
|
|
|
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)
|
|
}
|
|
|
|
/*
|
|
*
|
|
@ 作者: 秦东
|
|
@ 时间: 2024-10-23 15:04:38
|
|
@ 功能: 构造企业微信网页授权code
|
|
@ 参数
|
|
|
|
#
|
|
|
|
@ 返回值
|
|
|
|
#
|
|
|
|
@ 方法原型
|
|
|
|
#
|
|
*/
|
|
func (a *ApiMethod) ObtainAuthorization(c *gin.Context) {
|
|
//保障获取渠道一致
|
|
md5Token := GainTokenKey(c)
|
|
|
|
//来源于哪个系统
|
|
systemApp := c.Query("systemapp")
|
|
if systemApp == "" {
|
|
systemApp = "stzl"
|
|
}
|
|
isAgain := c.Query("isagain") //是否强制重新授权
|
|
isAgainInt, _ := strconv.Atoi(isAgain)
|
|
if isAgainInt == 0 {
|
|
isAgainInt = 1
|
|
}
|
|
//获取token
|
|
token, err := GainWechatToken(systemApp, md5Token, isAgainInt)
|
|
if err != nil {
|
|
publicmethod.Result(1, err, c, "身份认证失败")
|
|
return
|
|
}
|
|
//组装企业微信重定向地址参数
|
|
var urlRedirectKey []string
|
|
urlRedirectKey = append(urlRedirectKey, fmt.Sprintf("systemapp=%v", systemApp))
|
|
urlRedirectKey = append(urlRedirectKey, fmt.Sprintf("isagain=%v", isAgainInt))
|
|
userNum := c.Query("userid")
|
|
if userNum != "" {
|
|
urlRedirectKey = append(urlRedirectKey, fmt.Sprintf("userid=%v", userNum))
|
|
}
|
|
urlParameter := strings.Join(urlRedirectKey, "&") //合并成参数字符串
|
|
//企业微信重定向地址
|
|
watchWorkCallBackUrl := url.QueryEscape(fmt.Sprintf("%v/systemapi/wechat/wechatCallBack?%v", overall.CONSTANT_CONFIG.Appsetup.WebKpiUrl, urlParameter))
|
|
redirectUrl := fmt.Sprintf("https://open.weixin.qq.com/connect/oauth2/authorize?appid=%v&redirect_uri=%v&response_type=code&scope=snsapi_base&state=%v#wechat_redirect", overall.CONSTANT_CONFIG.WechatCompany.CompanyId, watchWorkCallBackUrl, token)
|
|
c.Redirect(http.StatusMovedPermanently, redirectUrl)
|
|
}
|
|
|
|
/*
|
|
*
|
|
@ 作者: 秦东
|
|
@ 时间: 2024-10-23 14:41:12
|
|
@ 功能: 企业微信参数地址重定向回调
|
|
@ 参数
|
|
|
|
#
|
|
|
|
@ 返回值
|
|
|
|
#
|
|
|
|
@ 方法原型
|
|
|
|
#
|
|
*/
|
|
func (a *ApiMethod) WechatCallBack(c *gin.Context) {
|
|
code := c.Query("code")
|
|
state := c.Query("state")
|
|
if code == "" || state == "" {
|
|
publicmethod.Result(0, code, c, "未能查询到您的信息!企业微信授权失败!")
|
|
return
|
|
}
|
|
systemApp := c.Query("systemapp")
|
|
if systemApp == "" {
|
|
systemApp = "stzl"
|
|
}
|
|
isAgain := c.Query("isagain")
|
|
isAgainInt, _ := strconv.Atoi(isAgain)
|
|
userNum := c.Query("userid")
|
|
md5Token := GainTokenKey(c) //保障获取渠道一致
|
|
token, _ := GainWechatToken(systemApp, md5Token, isAgainInt)
|
|
gainWechatInfo := fmt.Sprintf("https://qyapi.weixin.qq.com/cgi-bin/auth/getuserinfo?access_token=%v&code=%v", token, code)
|
|
wechatInfoByte := publicmethod.CurlGet(gainWechatInfo)
|
|
var callBackWechatInfo WorkWechatUserAuter
|
|
err := json.Unmarshal(wechatInfoByte, &callBackWechatInfo)
|
|
if err != nil {
|
|
publicmethod.Result(0, err, c, "未能查询到您的信息!企业微信授权失败!2")
|
|
return
|
|
}
|
|
if callBackWechatInfo.Errcode != 0 {
|
|
|
|
if callBackWechatInfo.Errcode == 42001 {
|
|
a.ObtainAuthorization(c)
|
|
return
|
|
}
|
|
publicmethod.Result(12, callBackWechatInfo, c, "未能查询到您的信息!企业微信授权失败!3")
|
|
return
|
|
}
|
|
var userWechatId string
|
|
if callBackWechatInfo.OpenId != "" {
|
|
userWechatId = callBackWechatInfo.OpenId
|
|
}
|
|
if callBackWechatInfo.Userid != "" {
|
|
userWechatId = callBackWechatInfo.Userid
|
|
}
|
|
if userWechatId == "" {
|
|
publicmethod.Result(1, err, c, "未能查询到您的信息!企业微信授权失败!")
|
|
return
|
|
}
|
|
wechatCont, err := SetUpWechatInfo(userWechatId)
|
|
if err != nil {
|
|
publicmethod.Result(13, err, c, "未能查询到您的信息!企业微信授权失败!")
|
|
return
|
|
}
|
|
// callBackLoginUrl := fmt.Sprintf("%v/#/?callback=1&usernum=%v&openid=%v&userkey=%v&token=%v", overall.CONSTANT_CONFIG.Appsetup.WebKpiUrl, userNum, wechatCont.UserInfo.Number, wechatCont.UserKey, wechatCont.Token)
|
|
callBackLoginUrl := fmt.Sprintf("%v?callback=1&usernum=%v&openid=%v&userkey=%v&token=%v", overall.CONSTANT_CONFIG.Appsetup.WebKpiUrl, userNum, wechatCont.UserInfo.Number, wechatCont.UserKey, wechatCont.Token)
|
|
c.Redirect(http.StatusMovedPermanently, callBackLoginUrl)
|
|
}
|
|
|
|
// 获取token Key
|
|
func GainTokenKey(c *gin.Context) (md5Token string) {
|
|
host := c.Request.Header.Get("Host")
|
|
userAgent := c.Request.Header.Get("User-Agent")
|
|
wechatTokenStr := fmt.Sprintf("%v_%v", host, userAgent)
|
|
var md5JiaMi publicmethod.Md5Encryption
|
|
md5JiaMi.Md5EncryptionInit(wechatTokenStr)
|
|
md5Token = md5JiaMi.Md5EncryptionAlgorithm()
|
|
return
|
|
}
|
|
|
|
/*
|
|
*
|
|
@ 作者: 秦东
|
|
@ 时间: 2024-01-20 14:06:00
|
|
@ 功能: 获取登陆人员信息
|
|
@ 参数
|
|
|
|
#
|
|
|
|
@ 返回值
|
|
|
|
#
|
|
|
|
@ 方法原型
|
|
|
|
#
|
|
*/
|
|
func SetUpWechatInfo(wechatOpenId string) (sendData WechatVerifyIdentity, err error) {
|
|
err = overall.CONSTANT_DB_HR.Where("`wechat` = ? OR `work_wechat` = ?", wechatOpenId, wechatOpenId).First(&sendData.UserInfo).Error
|
|
if err != nil {
|
|
return
|
|
}
|
|
if !publicmethod.IsInTrue[int](sendData.UserInfo.EmpType, []int{1, 3, 4, 5, 6, 7, 8, 9, 10}) {
|
|
err = errors.New("对不起!你没有权限进入!")
|
|
return
|
|
}
|
|
// uuIdVal := overallhandle.OnlyOneNumber(3)
|
|
userAgent := overall.CONSTANT_CONFIG.Appsetup.AppKey
|
|
var md5JiaMi publicmethod.Md5Encryption
|
|
md5JiaMi.Md5EncryptionInit(userAgent)
|
|
md5Token := md5JiaMi.Md5EncryptionAlgorithm()
|
|
//工号MD5加密
|
|
var md5JiaMiNumber publicmethod.Md5Encryption
|
|
md5JiaMiNumber.Md5EncryptionInit(sendData.UserInfo.Number)
|
|
sendData.UserKey = md5JiaMiNumber.Md5EncryptionAlgorithm()
|
|
|
|
sha1Str := fmt.Sprintf("%v%v%v%v", sendData.UserKey, sendData.UserInfo.Number, sendData.UserInfo.Password, md5Token)
|
|
sendData.Token = publicmethod.Sha1Encryption(sha1Str)
|
|
//组成Token字符串进行
|
|
|
|
wechatUserToken := fmt.Sprintf("%v%v", sendData.UserKey, sendData.Token)
|
|
var md5JiaMiWechat publicmethod.Md5Encryption
|
|
md5JiaMiWechat.Md5EncryptionInit(wechatUserToken)
|
|
wechatRedisKey := md5JiaMiWechat.Md5EncryptionAlgorithm()
|
|
wechatRedisToekn := fmt.Sprintf("Wechat:UserToken:%v_%v", wechatRedisKey, overall.CONSTANT_CONFIG.RedisPrefixStr.Alias)
|
|
|
|
saveInfo := publicmethod.MapOut[string]()
|
|
structValue := reflect.ValueOf(sendData.UserInfo)
|
|
structType := structValue.Type()
|
|
for i := 0; i < structValue.NumField(); i++ {
|
|
fieldValue := structValue.Field(i)
|
|
fieldType := structType.Field(i)
|
|
// fmt.Printf("%s: %v\n", fieldType.Name, fieldValue.Interface())
|
|
saveInfo[fieldType.Name] = fieldValue.Interface()
|
|
}
|
|
redisClient := grocerystore.RunRedis(overall.CONSTANT_REDIS4) //设定redis库
|
|
redisClient.SetRedisTime(7200)
|
|
redisClient.HashMsetAdd(wechatRedisToekn, saveInfo)
|
|
return
|
|
}
|
|
|
|
/*
|
|
*
|
|
@ 作者: 秦东
|
|
@ 时间: 2024-12-19 13:42:30
|
|
@ 功能: 查看手机流程表单详情单页企业微信网页授权code
|
|
@ 参数
|
|
|
|
#
|
|
|
|
@ 返回值
|
|
|
|
#
|
|
|
|
@ 方法原型
|
|
|
|
#
|
|
*/
|
|
func (a *ApiMethod) ObtaOnePage(c *gin.Context) {
|
|
//保障获取渠道一致
|
|
md5Token := GainTokenKey(c)
|
|
|
|
//来源于哪个系统
|
|
systemApp := c.Query("systemapp")
|
|
|
|
if systemApp == "" {
|
|
systemApp = "stzl"
|
|
}
|
|
callBackType := c.Query("call_back_type")
|
|
if callBackType == "" {
|
|
callBackType = "work_wechat"
|
|
}
|
|
isAgain := c.Query("isagain") //是否强制重新授权
|
|
isAgainInt, _ := strconv.Atoi(isAgain)
|
|
if isAgainInt == 0 {
|
|
isAgainInt = 1
|
|
}
|
|
//获取token
|
|
token, err := GainWechatToken(systemApp, md5Token, isAgainInt)
|
|
if err != nil {
|
|
publicmethod.Result(1, err, c, "身份认证失败")
|
|
return
|
|
}
|
|
//组装企业微信重定向地址参数
|
|
var urlRedirectKey []string
|
|
urlRedirectKey = append(urlRedirectKey, fmt.Sprintf("systemapp=%v", systemApp))
|
|
urlRedirectKey = append(urlRedirectKey, fmt.Sprintf("isagain=%v", isAgainInt))
|
|
userNum := c.Query("userid")
|
|
if userNum != "" {
|
|
urlRedirectKey = append(urlRedirectKey, fmt.Sprintf("userid=%v", userNum))
|
|
}
|
|
|
|
urlRedirectKey = append(urlRedirectKey, fmt.Sprintf("appKey=%v", c.Query("appKey")))
|
|
urlRedirectKey = append(urlRedirectKey, fmt.Sprintf("appId=%v", c.Query("appId")))
|
|
urlRedirectKey = append(urlRedirectKey, fmt.Sprintf("taskTitle=%v", c.Query("taskTitle")))
|
|
urlRedirectKey = append(urlRedirectKey, fmt.Sprintf("taskId=%v", c.Query("taskId")))
|
|
urlRedirectKey = append(urlRedirectKey, fmt.Sprintf("taskKey=%v", c.Query("taskKey")))
|
|
urlRedirectKey = append(urlRedirectKey, fmt.Sprintf("call_back_type=%v", callBackType))
|
|
|
|
urlRedirectKey = append(urlRedirectKey, fmt.Sprintf("masters_key=%v", c.Query("masters_key")))
|
|
|
|
urlParameter := strings.Join(urlRedirectKey, "&") //合并成参数字符串
|
|
//企业微信重定向地址
|
|
watchWorkCallBackUrl := url.QueryEscape(fmt.Sprintf("%v/systemapi/wechat/wechatCallBackPage?%v", overall.CONSTANT_CONFIG.Appsetup.WebKpiUrl, urlParameter))
|
|
redirectUrl := fmt.Sprintf("https://open.weixin.qq.com/connect/oauth2/authorize?appid=%v&redirect_uri=%v&response_type=code&scope=snsapi_base&state=%v#wechat_redirect", overall.CONSTANT_CONFIG.WechatCompany.CompanyId, watchWorkCallBackUrl, token)
|
|
c.Redirect(http.StatusMovedPermanently, redirectUrl)
|
|
}
|
|
|
|
/*
|
|
*
|
|
@ 作者: 秦东
|
|
@ 时间: 2024-10-23 14:41:12
|
|
@ 功能: 查看手机流程表单企业微信参数地址重定向回调
|
|
@ 参数
|
|
|
|
#
|
|
|
|
@ 返回值
|
|
|
|
#
|
|
|
|
@ 方法原型
|
|
|
|
#
|
|
*/
|
|
func (a *ApiMethod) WechatCallBackPage(c *gin.Context) {
|
|
code := c.Query("code")
|
|
state := c.Query("state")
|
|
if code == "" || state == "" {
|
|
publicmethod.Result(0, code, c, "未能查询到您的信息!企业微信授权失败!")
|
|
return
|
|
}
|
|
systemApp := c.Query("systemapp")
|
|
if systemApp == "" {
|
|
systemApp = "stzl"
|
|
}
|
|
isAgain := c.Query("isagain")
|
|
isAgainInt, _ := strconv.Atoi(isAgain)
|
|
userNum := c.Query("userid")
|
|
md5Token := GainTokenKey(c) //保障获取渠道一致
|
|
token, _ := GainWechatToken(systemApp, md5Token, isAgainInt)
|
|
gainWechatInfo := fmt.Sprintf("https://qyapi.weixin.qq.com/cgi-bin/auth/getuserinfo?access_token=%v&code=%v", token, code)
|
|
wechatInfoByte := publicmethod.CurlGet(gainWechatInfo)
|
|
var callBackWechatInfo WorkWechatUserAuter
|
|
err := json.Unmarshal(wechatInfoByte, &callBackWechatInfo)
|
|
if err != nil {
|
|
publicmethod.Result(0, err, c, "未能查询到您的信息!企业微信授权失败!2")
|
|
return
|
|
}
|
|
if callBackWechatInfo.Errcode != 0 {
|
|
|
|
if callBackWechatInfo.Errcode == 42001 {
|
|
a.ObtainAuthorization(c)
|
|
return
|
|
}
|
|
publicmethod.Result(12, callBackWechatInfo, c, "未能查询到您的信息!企业微信授权失败!3")
|
|
return
|
|
}
|
|
var userWechatId string
|
|
if callBackWechatInfo.OpenId != "" {
|
|
userWechatId = callBackWechatInfo.OpenId
|
|
}
|
|
if callBackWechatInfo.Userid != "" {
|
|
userWechatId = callBackWechatInfo.Userid
|
|
}
|
|
if userWechatId == "" {
|
|
publicmethod.Result(1, err, c, "未能查询到您的信息!企业微信授权失败!")
|
|
return
|
|
}
|
|
wechatCont, err := SetUpWechatInfo(userWechatId)
|
|
if err != nil {
|
|
publicmethod.Result(13, err, c, "未能查询到您的信息!企业微信授权失败!")
|
|
return
|
|
}
|
|
|
|
var urlRedirectKey []string
|
|
|
|
urlRedirectKey = append(urlRedirectKey, fmt.Sprintf("callback=%v", 1))
|
|
urlRedirectKey = append(urlRedirectKey, fmt.Sprintf("usernum=%v", userNum))
|
|
urlRedirectKey = append(urlRedirectKey, fmt.Sprintf("openid=%v", wechatCont.UserInfo.Number))
|
|
urlRedirectKey = append(urlRedirectKey, fmt.Sprintf("userkey=%v", wechatCont.UserKey))
|
|
urlRedirectKey = append(urlRedirectKey, fmt.Sprintf("token=%v", wechatCont.Token))
|
|
|
|
// urlRedirectKey = append(urlRedirectKey, fmt.Sprintf("appKey=%v", c.Query("appKey")))
|
|
// urlRedirectKey = append(urlRedirectKey, fmt.Sprintf("appId=%v", c.Query("appId")))
|
|
// urlRedirectKey = append(urlRedirectKey, fmt.Sprintf("taskId=%v", c.Query("taskId")))
|
|
// urlRedirectKey = append(urlRedirectKey, fmt.Sprintf("taskKey=%v", c.Query("taskKey")))
|
|
|
|
urlRedirectKey = append(urlRedirectKey, fmt.Sprintf("masters_key=%v", c.Query("masters_key")))
|
|
// urlRedirectKey = append(urlRedirectKey, fmt.Sprintf("runFlowId=%v", c.Query("runFlowId")))
|
|
var userCont modelshr.ManCont
|
|
userErr := userCont.GetCont(map[string]interface{}{"number": wechatCont.UserInfo.Number})
|
|
if userErr == nil {
|
|
CuliLogin(userCont, wechatCont.UserKey, wechatCont.Token)
|
|
}
|
|
|
|
urlParameter := strings.Join(urlRedirectKey, "&") //合并成参数字符串
|
|
// callBackLoginUrl := fmt.Sprintf("%v/#/?callback=1&usernum=%v&openid=%v&userkey=%v&token=%v", overall.CONSTANT_CONFIG.Appsetup.WebKpiUrl, userNum, wechatCont.UserInfo.Number, wechatCont.UserKey, wechatCont.Token)
|
|
// callBackLoginUrl := fmt.Sprintf("%v?callback=1&usernum=%v&openid=%v&userkey=%v&token=%v", overall.CONSTANT_CONFIG.Appsetup.WebKpiUrl, userNum, wechatCont.UserInfo.Number, wechatCont.UserKey, wechatCont.Token)
|
|
callBackType := c.Query("call_back_type")
|
|
if callBackType == "" {
|
|
callBackType = "work_wechat"
|
|
}
|
|
callBackLoginUrl := fmt.Sprintf("%v/#/work_wechat?%v", overall.CONSTANT_CONFIG.Appsetup.WebKpiUrl, urlParameter)
|
|
switch callBackType {
|
|
case "login":
|
|
callBackLoginUrl = fmt.Sprintf("%v/#/login?%v", overall.CONSTANT_CONFIG.Appsetup.WebKpiUrl, urlParameter)
|
|
default:
|
|
callBackLoginUrl = fmt.Sprintf("%v/#/work_wechat?%v", overall.CONSTANT_CONFIG.Appsetup.WebKpiUrl, urlParameter)
|
|
}
|
|
fmt.Printf("\n\n返回路径:%v\n\n", callBackLoginUrl)
|
|
c.Redirect(http.StatusMovedPermanently, callBackLoginUrl)
|
|
}
|
|
|
|
// 获取权限点位
|
|
func getRoleSeat(roleId string) (menuStr, buttonStr string) {
|
|
var roleInfo modelsschool.SystemRole
|
|
err := roleInfo.GetCont(map[string]interface{}{"r_id": roleId}, "r_menu_oper", "r_jurisdiction")
|
|
if err != nil {
|
|
return
|
|
}
|
|
menuStr = roleInfo.MenuOper
|
|
buttonStr = roleInfo.Jurisdiction
|
|
// jsonStr, _ := json.Marshal(roleInfo)
|
|
// fmt.Printf("roleInfo-->%v-menuStr->%v\n-buttonStr->%v----jsonStr--->%v\n", roleId, menuStr, buttonStr, string(jsonStr))
|
|
return
|
|
}
|
|
|
|
/**
|
|
@ 作者: 秦东
|
|
@ 时间: 2025-04-09 14:19:13
|
|
@ 功能: 处理登陆信息
|
|
*/
|
|
|
|
func CuliLogin(userCont modelshr.ManCont, userKeyCode, sha1Token string) {
|
|
menuoper, jurisdiction := getRoleSeat(userCont.Role)
|
|
writeRedisData := map[string]interface{}{
|
|
"userkey": userKeyCode,
|
|
"key": userCont.Key,
|
|
"usernumber": userCont.Number,
|
|
"userpwd": userCont.Password,
|
|
"usertoken": sha1Token,
|
|
"jurisdiction": jurisdiction,
|
|
"menuOper": menuoper,
|
|
"wand": 118,
|
|
}
|
|
//API Token数据
|
|
redisFileKey := fmt.Sprintf("ScanCode:Authentication:LoginApi_%v_%v", overall.CONSTANT_CONFIG.RedisPrefixStr.Alias, userKeyCode)
|
|
redisClient := grocerystore.RunRedis(overall.CONSTANT_REDIS5)
|
|
redisClient.SetRedisTime(10800)
|
|
redisClient.HashMsetAdd(redisFileKey, writeRedisData)
|
|
//缓存写入个人信息
|
|
redisMyContKey := fmt.Sprintf("ScanCode:Authentication:UserCont_%v_%v", overall.CONSTANT_CONFIG.RedisPrefixStr.Alias, userCont.Number)
|
|
myCont := publicmethod.MapOut[string]()
|
|
myCont["id"] = userCont.Id
|
|
myCont["number"] = userCont.Number //员工工号
|
|
myCont["name"] = userCont.Name //姓名
|
|
myCont["icon"] = userCont.Icon //头像
|
|
myCont["hireclass"] = userCont.HireClass //雇佣类型(1:雇佣入职;2:再入职;)
|
|
myCont["emptype"] = userCont.EmpType //用工关系(1:临时工 , 2:编外人员 ;3:实习&实习生;4:试用员工;5:待分配;6:待岗;7:临时调入;8:正式员工;9:长期病假;10:停薪留职;11:退休;12:辞职;13:辞退;14:离职)
|
|
myCont["company"] = userCont.Company //入职公司
|
|
myCont["maindeparment"] = userCont.MainDeparment //主部门
|
|
myCont["sunmaindeparment"] = userCont.SunMainDeparment //二级主部门
|
|
myCont["deparment"] = userCont.Deparment //部门
|
|
myCont["adminorg"] = userCont.AdminOrg //所属行政组织
|
|
myCont["teamid"] = userCont.TeamId //班组
|
|
myCont["position"] = userCont.Position //职位
|
|
myCont["jobclass"] = userCont.JobClass //职务分类
|
|
myCont["jobid"] = userCont.JobId //职务
|
|
myCont["jobleve"] = userCont.JobLeve //职务等级
|
|
myCont["wechat"] = userCont.Wechat //微信UserId
|
|
myCont["workwechat"] = userCont.WorkWechat //企业微信UserId
|
|
myCont["state"] = userCont.State //状态(1:启用;2:禁用;3:删除)
|
|
myCont["key"] = userCont.Key //key
|
|
myCont["isadmin"] = userCont.IsAdmin //是否为管理员(1:不是;2:分公司;3:集团管理员;4:超级管
|
|
myCont["password"] = userCont.Password //密码
|
|
myCont["role"] = userCont.Role //角色
|
|
myCont["idcardno"] = userCont.Idcardno //身份证号
|
|
myCont["passportno"] = userCont.Passportno //护照号码
|
|
myCont["globalroaming"] = userCont.Globalroaming //国际区号
|
|
myCont["mobilephone"] = userCont.Mobilephone //手机号码
|
|
myCont["email"] = userCont.Email //电子邮件
|
|
myCont["gender"] = userCont.Gender //性别(1:男性;2:女性;3:中性)
|
|
myCont["birthday"] = userCont.Birthday //birthday
|
|
myCont["myfolk"] = userCont.Myfolk //民族
|
|
myCont["nativeplace"] = userCont.Nativeplace //籍贯
|
|
myCont["idcardstartdate"] = userCont.Idcardstartdate //身份证有效期开始
|
|
myCont["idcardenddate"] = userCont.Idcardenddate //身份证有效期结束
|
|
myCont["idcardaddress"] = userCont.Idcardaddress //身份证地址
|
|
myCont["idcardIssued"] = userCont.IdcardIssued //身份证签发机关
|
|
myCont["health"] = userCont.Health //健康状况(1:良好;2:一般;3:较弱,4:有生理缺陷;5:残废)
|
|
myCont["maritalstatus"] = userCont.Maritalstatus //婚姻状况(1:未婚;2:已婚;3:丧偶;4:离异)
|
|
myCont["internaltelephone"] = userCont.Internaltelephone //内线电话
|
|
myCont["currentresidence"] = userCont.Currentresidence //现居住地址
|
|
myCont["constellationing"] = userCont.Constellation //星座(1:白羊座;2:金牛座;3:双子座;4:巨蟹座;5:狮子座;6:处女座;7:天枰座;8:天蝎座;9:射手座;10:摩羯座;11:水瓶座;12:双鱼座)
|
|
myCont["isdoubleworker"] = userCont.Isdoubleworker //是否双职工(1:是;2:否)
|
|
myCont["isveterans"] = userCont.Isveterans //是否为退役军人(1:是;2:否)
|
|
myCont["veteransnumber"] = userCont.Veteransnumber //退役证编号
|
|
myCont["jobstartdate"] = userCont.Jobstartdate //参加工作日期
|
|
myCont["entrydate"] = userCont.Entrydate //入职日期
|
|
myCont["probationperiod"] = userCont.Probationperiod //试用期
|
|
myCont["planformaldate"] = userCont.Planformaldate //预计转正日期
|
|
myCont["political_outlook"] = userCont.PoliticalOutlook //政治面貌(1:群众;2:无党派;3:台盟会员;4:九三社员;5:致公党员;6:农工党员;7:民进会员;8:民建会员;9:民盟盟员;10:民革会员,11:共青团员;12:预备党员;13:中共党员)
|
|
|
|
redisClient.HashMsetAdd(redisMyContKey, myCont)
|
|
}
|
|
|