Skip to content

Commit

Permalink
fix newRefreshToken
Browse files Browse the repository at this point in the history
  • Loading branch information
iyear committed Jul 5, 2020
1 parent c4e44d7 commit e15e57d
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 8 deletions.
3 changes: 2 additions & 1 deletion control.go
Original file line number Diff line number Diff line change
Expand Up @@ -104,7 +104,7 @@ func SignTask() {
//签到任务
for _, u := range data {
pre := "您的账户: " + u.alias + "\n在任务执行时出现了错误!\n错误:"
access, err := MSGetToken(u.refreshToken, u.clientId, u.clientSecret)
access, newRefreshToken, err := MSGetToken(u.refreshToken, u.clientId, u.clientSecret)
chat, _ := bot.ChatByID(strconv.FormatInt(u.tgId, 10))

//生成解绑按钮
Expand All @@ -130,6 +130,7 @@ func SignTask() {
continue
}
u.uptime = time.Now().Unix()
u.refreshToken = newRefreshToken
if ok, err := UpdateData(u); !ok {
logger.Println(u.msId+" ", err)
bot.Send(chat, pre+err.Error(), tmpBtn)
Expand Down
14 changes: 7 additions & 7 deletions outlook.go
Original file line number Diff line number Diff line change
Expand Up @@ -60,8 +60,8 @@ func MSFirGetToken(code, cid, cse string) (access string, refresh string, Error
return "", "", errors.New(string(content))
}

//return access_token
func MSGetToken(refreshtoken, cid, cse string) (access string, Error error) {
//return access_token and new refresh token
func MSGetToken(refreshtoken, cid, cse string) (access string, newRefreshToken string, Error error) {
var r http.Request
client := &http.Client{}
r.ParseForm()
Expand All @@ -76,25 +76,25 @@ func MSGetToken(refreshtoken, cid, cse string) (access string, Error error) {
req, err := http.NewRequest("POST", MsApiUrl+"/common/oauth2/v2.0/token", body)
if err != nil {
logger.Println(err)
return "", err
return "", "", err
}
resp, err := client.Do(req)
if err != nil {
logger.Println(err)
return "", err
return "", "", err
}
defer resp.Body.Close()
content, err := ioutil.ReadAll(resp.Body)
if err != nil {
logger.Println(err)
return "", err
return "", "", err
}
//fmt.Println(string(content))
//fmt.Println(gjson.Get(string(content), "access_token").String())
if gjson.Get(string(content), "token_type").String() == "Bearer" {
return gjson.Get(string(content), "access_token").String(), nil
return gjson.Get(string(content), "access_token").String(), gjson.Get(string(content), "refresh_token").String(), nil
}
return "", errors.New(string(content))
return "", "", errors.New(string(content))
}

//Get User's Information
Expand Down

0 comments on commit e15e57d

Please sign in to comment.