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.
140 lines
4.3 KiB
140 lines
4.3 KiB
package wechatstatice
|
|
|
|
import (
|
|
"encoding/json"
|
|
"fmt"
|
|
"key_performance_indicators/middleware/grocerystore"
|
|
"key_performance_indicators/middleware/wechatapp/wxbizjsonmsgcrypt"
|
|
"key_performance_indicators/middleware/wechatapp/wxbizmsgcrypt"
|
|
"key_performance_indicators/overall"
|
|
"key_performance_indicators/overall/publicmethod"
|
|
)
|
|
|
|
/*
|
|
获取企业微信token
|
|
@systemApp 系统
|
|
*/
|
|
func GetWechatToken(systemApp string) (token string, err error) {
|
|
redisClient := grocerystore.RunRedis(overall.CONSTANT_REDIS3)
|
|
companyId := overall.CONSTANT_CONFIG.WechatCompany.CompanyId
|
|
redisFileKey := fmt.Sprintf("Wechat:GainToken:%v_%v", overall.CONSTANT_CONFIG.RedisPrefixStr.Alias, companyId)
|
|
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)
|
|
}
|
|
isTrue, token := redisClient.Get(redisFileKey)
|
|
if isTrue == true {
|
|
return
|
|
}
|
|
//重新获取token
|
|
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 {
|
|
return
|
|
}
|
|
token = callBackCont.Accesstoken
|
|
redisClient.SetRedisTime(7200)
|
|
redisClient.Set(redisFileKey, token)
|
|
return
|
|
}
|
|
|
|
/*
|
|
企业微信方式应用消息URL组装
|
|
@systemApp 系统
|
|
*/
|
|
/**
|
|
@ 作者: 秦东
|
|
@ 时间: 2022-09-27 10:41:33
|
|
@ 功能: 企业微信发送应用消息URL组装
|
|
@ 参数
|
|
#systemApp 系统
|
|
#class 类型
|
|
@ 返回值
|
|
#sendUrl 发送应用消息URL
|
|
#token token
|
|
#err 系统信息
|
|
*/
|
|
func GetSendMsgTokenUrl(systemApp, class string) (sendUrl string, token string, err error) {
|
|
token, err = GetWechatToken(systemApp)
|
|
if err != nil {
|
|
return
|
|
}
|
|
switch class {
|
|
case "update":
|
|
sendUrl = fmt.Sprintf("https://qyapi.weixin.qq.com/cgi-bin/message/update_template_card?access_token=%v", token)
|
|
case "recall":
|
|
sendUrl = fmt.Sprintf("https://qyapi.weixin.qq.com/cgi-bin/message/recall?access_token=%v", token)
|
|
default:
|
|
sendUrl = fmt.Sprintf("https://qyapi.weixin.qq.com/cgi-bin/message/send?access_token=%v", token)
|
|
}
|
|
return
|
|
}
|
|
|
|
//企业微信解密
|
|
/**
|
|
@ 作者: 秦东
|
|
@ 时间: 2022-09-27 11:57:56
|
|
@ 功能: 企业微信加解密-json
|
|
@ 参数
|
|
#token 应用Token
|
|
#encodingAesKey 应用Encodingaeskey
|
|
@ 返回值
|
|
#wxcpt 初始化加解密类
|
|
*/
|
|
func WechatDecryptJson(systemApp string) (wxcpt *wxbizjsonmsgcrypt.WXBizMsgCrypt) {
|
|
var token string
|
|
var encodingAesKey string
|
|
switch systemApp {
|
|
case "kpi":
|
|
token = overall.CONSTANT_CONFIG.WechatKpi.Token
|
|
encodingAesKey = overall.CONSTANT_CONFIG.WechatKpi.Encodingaeskey
|
|
default:
|
|
token = overall.CONSTANT_CONFIG.WechatSchool.Token
|
|
encodingAesKey = overall.CONSTANT_CONFIG.WechatSchool.Encodingaeskey
|
|
}
|
|
fmt.Printf("WechatDecryptJson------->%v------->%v------->%v\n", token, overall.CONSTANT_CONFIG.WechatCompany.CompanyId, encodingAesKey)
|
|
wxcpt = wxbizjsonmsgcrypt.NewWXBizMsgCrypt(token, encodingAesKey, overall.CONSTANT_CONFIG.WechatCompany.CompanyId, wxbizjsonmsgcrypt.JsonType)
|
|
return
|
|
}
|
|
|
|
/*
|
|
*
|
|
@ 作者: 秦东
|
|
@ 时间: 2022-09-27 13:21:07
|
|
@ 功能: 企业微信加解密-XML
|
|
@ 参数
|
|
|
|
#token 应用Token
|
|
#encodingAesKey 应用Encodingaeskey
|
|
|
|
@ 返回值
|
|
|
|
#wxcpt 初始化加解密类
|
|
*/
|
|
func WechatDecryptXml(systemApp string) (wxcpt *wxbizmsgcrypt.WXBizMsgCrypt) {
|
|
var token string
|
|
var encodingAesKey string
|
|
switch systemApp {
|
|
case "kpi":
|
|
token = overall.CONSTANT_CONFIG.WechatKpi.Token
|
|
encodingAesKey = overall.CONSTANT_CONFIG.WechatKpi.Encodingaeskey
|
|
default:
|
|
token = overall.CONSTANT_CONFIG.WechatSchool.Token
|
|
encodingAesKey = overall.CONSTANT_CONFIG.WechatSchool.Encodingaeskey
|
|
}
|
|
fmt.Printf("WechatDecryptXml------->%v------->%v------->%v\n", token, overall.CONSTANT_CONFIG.WechatCompany.CompanyId, encodingAesKey)
|
|
wxcpt = wxbizmsgcrypt.NewWXBizMsgCrypt(token, encodingAesKey, overall.CONSTANT_CONFIG.WechatCompany.CompanyId, wxbizmsgcrypt.XmlType)
|
|
return
|
|
}
|
|
|