1.方法1:
map[persistent_code: errcode:0 errmsg:ok unionid:0hY5m7YiPiSy1tmdVsiPDaItgiEiE openid:yseuqjbn
func GetInfo(token string)(){
baseurl := "https://oapi.dingtalk.com/sns/getuserinfo?sns_token="
accessUrl := baseurl + token
responseToken,err:= http.Get(accessUrl)
if err != nil{
fmt.Println(err)
}
defer responseToken.Body.Close()//当获取到响应体时,客户端必须手动关闭链接
jsonStr,err := ioutil.ReadAll(responseToken.Body)
if err != nil{
fmt.Println(err)
}
var dat2 map[string]interface{}
if err := json.Unmarshal(jsonStr,&dat2);err == nil{
fmt.Println("userinfo")
fmt.Println(dat2)
}
persistent_code := data2["persistent_code"]
//name := dat2["user_info"].(map[string]interface{})["nick"]
//openid := dat2["user_info"].(map[string]interface{})["openid"]
}
接口请求数据的方法,返回数据是复杂的情况
map[errcode:0 errmsg:ok user_info:map[nick: unionid: dingId:$:LWCP_v1:$8MtM2lK1ewzm5QsKVHv0oA== openid:yseuqjbnBOc7BwN1ayCb
func GetInfo(token string)(){
baseurl := "https://oapi.dingtalk.com/sns/getuserinfo?sns_token="
accessUrl := baseurl + token
responseToken,err:= http.Get(accessUrl)
if err != nil{
fmt.Println(err)
}
defer responseToken.Body.Close()//当获取到响应体时,客户端必须手动关闭链接
jsonStr,err := ioutil.ReadAll(responseToken.Body)
if err != nil{
fmt.Println(err)
}
var dat2 map[string]interface{}
if err := json.Unmarshal(jsonStr,&dat2);err == nil{
fmt.Println("userinfo")
fmt.Println(dat2)
}
name := dat2["user_info"].(map[string]interface{})["nick"]
openid := dat2["user_info"].(map[string]interface{})["openid"]
}
有疑问加站长微信联系(非本文作者)