From c19acca0cc92f35c9308b4fe86d7220d4a57f593 Mon Sep 17 00:00:00 2001 From: dustoair <107600816+dustoair@users.noreply.github.com> Date: Sun, 24 Jul 2022 11:53:31 +0800 Subject: [PATCH] map panic issue --- main.go | 3 ++- third_part/WeChat.go | 14 +++++++++----- 2 files changed, 11 insertions(+), 6 deletions(-) diff --git a/main.go b/main.go index 7e0bb9a..7bc7052 100644 --- a/main.go +++ b/main.go @@ -3,6 +3,7 @@ package main import ( "WechatGateWay/global" "WechatGateWay/handle" + "WechatGateWay/third_part" "fmt" "github.com/spf13/viper" "log" @@ -28,7 +29,7 @@ func init() { global.WechatSendAid = viper.GetString("wechat.SendAid") // receive_id 企业应用的回调,表示corpid global.WxCrypt = global.NewWXBizMsgCrypt(global.WechatToken, global.WechatEncodingAesKey, global.WechatCorpId, global.XmlType) - //go third_part.GetRemoteToken(global.WechatCorpId, global.WechatSendSecret) + third_part.GetRemoteToken(global.WechatCorpId, global.WechatSendSecret) log.Println("server init success") } func main() { diff --git a/third_part/WeChat.go b/third_part/WeChat.go index ee98f35..0dea815 100644 --- a/third_part/WeChat.go +++ b/third_part/WeChat.go @@ -50,13 +50,17 @@ func GetRemoteToken(corpId, appSecret string) string { } resp.Body.Close() tokenResponse := utils.ParseJson(string(respData)) - //log.Println("企业微信获取access_token接口返回==>", tokenResponse) - accessToken := tokenResponse["access_token"].(string) - //存到gloabl - global.WechatAccessToken = accessToken - log.Println("WechatAccessToken已更新") + var accessToken string + _, ok := tokenResponse["access_token"] + if ok { + accessToken = fmt.Sprintf("%s", tokenResponse["access_token"]) + //存到gloabl + global.WechatAccessToken = accessToken + log.Println("WechatAccessToken已更新") + } return accessToken + } // PostMsg 推送消息