fix: 在每次请求中刷新token,确保token有效
This commit is contained in:
parent
cce2cd3d9b
commit
19e349342c
|
@ -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)
|
||||||
|
|
Loading…
Reference in New Issue