fix: 在每次请求中刷新token,确保token有效

This commit is contained in:
fcbhank 2021-08-17 21:01:04 +08:00
parent cce2cd3d9b
commit 19e349342c
1 changed files with 4 additions and 1 deletions

View File

@ -221,7 +221,6 @@ func InitJsonData(msgType string) JsonData {
func main() { func main() {
// 设置日志内容显示文件名和行号 // 设置日志内容显示文件名和行号
log.SetFlags(log.LstdFlags | log.Lshortfile) log.SetFlags(log.LstdFlags | log.Lshortfile)
accessToken := getAccessToken()
wecomChan := func(res http.ResponseWriter, req *http.Request) { wecomChan := func(res http.ResponseWriter, req *http.Request) {
_ = req.ParseForm() _ = req.ParseForm()
sendkey := req.FormValue("sendkey") sendkey := req.FormValue("sendkey")
@ -231,6 +230,8 @@ func main() {
msgContent := req.FormValue("msg") msgContent := req.FormValue("msg")
msgType := req.FormValue("msg_type") msgType := req.FormValue("msg_type")
log.Println("mes_type=", msgType) log.Println("mes_type=", msgType)
// 刷新token
accessToken := getAccessToken()
mediaId := CheckOrUploadMedia(msgType, req, accessToken) mediaId := CheckOrUploadMedia(msgType, req, accessToken)
log.Println("企业微信上传临时素材接口返回的media_id==>", mediaId) log.Println("企业微信上传临时素材接口返回的media_id==>", mediaId)
@ -242,6 +243,8 @@ func main() {
postData.Image = Pic{ postData.Image = Pic{
MediaId: mediaId, MediaId: mediaId,
} }
// 再次刷新token
accessToken = getAccessToken()
sendMessageUrl := fmt.Sprintf(SendMessageApi, accessToken) sendMessageUrl := fmt.Sprintf(SendMessageApi, accessToken)
postStatus := PostMsg(postData, sendMessageUrl) postStatus := PostMsg(postData, sendMessageUrl)