平台返回数据结构修改
This commit is contained in:
@@ -2,7 +2,9 @@ package tribally
|
|||||||
|
|
||||||
import (
|
import (
|
||||||
"encoding/json"
|
"encoding/json"
|
||||||
|
"errors"
|
||||||
"fmt"
|
"fmt"
|
||||||
|
"github.com/zeromicro/go-zero/core/logx"
|
||||||
"io"
|
"io"
|
||||||
"net/http"
|
"net/http"
|
||||||
"strings"
|
"strings"
|
||||||
@@ -26,25 +28,28 @@ func BindTribally(apiKey, userId string) (string, error) {
|
|||||||
}
|
}
|
||||||
defer res.Body.Close()
|
defer res.Body.Close()
|
||||||
|
|
||||||
|
if res.StatusCode != http.StatusOK {
|
||||||
|
return "", errors.New(res.Status)
|
||||||
|
}
|
||||||
|
|
||||||
body, err := io.ReadAll(res.Body)
|
body, err := io.ReadAll(res.Body)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return "", err
|
return "", err
|
||||||
}
|
}
|
||||||
result := struct {
|
result := struct {
|
||||||
Error string `json:"error"`
|
Error string `json:"error"`
|
||||||
Code string `json:"code"`
|
Code string `json:"code"`
|
||||||
Data struct {
|
AuthURL string `json:"authUrl"`
|
||||||
AuthURL string `json:"authUrl"`
|
|
||||||
} `json:"data"`
|
|
||||||
}{}
|
}{}
|
||||||
err = json.Unmarshal(body, &result)
|
err = json.Unmarshal(body, &result)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return "", err
|
return "", err
|
||||||
}
|
}
|
||||||
|
logx.Errorw("============", logx.Field("body", string(body)))
|
||||||
if result.Error != "" {
|
if result.Error != "" {
|
||||||
return "", fmt.Errorf("error: %s, code: %s", result.Error, result.Code)
|
return "", fmt.Errorf("error: %s, code: %s", result.Error, result.Code)
|
||||||
}
|
}
|
||||||
return result.Data.AuthURL, nil
|
return result.AuthURL, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func VerifyTribally(token string) error {
|
func VerifyTribally(token string) error {
|
||||||
|
|||||||
Reference in New Issue
Block a user