3 Star 5 Fork 0

Rick/wechat-backend

加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
克隆/下载
token.go 855 Bytes
一键复制 编辑 原始数据 按行查看 历史
Zhao Xiaojie 提交于 2019-05-30 11:18 . change the github org
package main
import (
"encoding/json"
"log"
"net/http"
"strings"
"github.com/jenkins-zh/wechat-backend/pkg/config"
)
//https://api.weixin.qq.com/cgi-bin/token?grant_type=client_credential&appid=APPID&secret=APPSECRET
type AccessToken struct {
AccessToken string `json:"access_token"`
Expires int `json:"expires_in"`
}
func getAccessToken(config *config.WeChatConfig) string {
resp, err := http.Get(strings.Join([]string{"https://api.weixin.qq.com/cgi-bin/token?grant_type=client_credential",
"&appid=", config.AppID, "&secret=", config.AppSecret}, ""))
if err != nil {
return ""
}
if resp.StatusCode != http.StatusOK {
log.Printf("search query failed: %s\n", resp.Status)
return ""
}
var result AccessToken
if err := json.NewDecoder(resp.Body).Decode(&result); err != nil {
return ""
}
return result.AccessToken
}
马建仓 AI 助手
尝试更多
代码解读
代码找茬
代码优化
Go
1
https://gitee.com/linuxsuren/wechat-backend.git
git@gitee.com:linuxsuren/wechat-backend.git
linuxsuren
wechat-backend
wechat-backend
master

搜索帮助