From 39d714ab26d84ff711a1fa3360b5536f88a2d3eb Mon Sep 17 00:00:00 2001 From: Rosbit Xu Date: Wed, 6 May 2020 10:17:44 +0800 Subject: [PATCH] sns-api updated --- router.go | 20 +++++++++----------- 1 file changed, 9 insertions(+), 11 deletions(-) diff --git a/router.go b/router.go index ae43688..73a0e35 100644 --- a/router.go +++ b/router.go @@ -234,24 +234,22 @@ func snsAPI(w http.ResponseWriter, r *http.Request) { writeError(w, http.StatusInternalServerError, err.Error()) return } + + var userInfo map[string]interface{} if scope == "base" { - writeJson(w, http.StatusOK, map[string]interface{}{ - "code": http.StatusOK, - "msg": "OK", - "openId": openId, - }) - return + userInfo, err = wxUser.GetInfoByAccessToken() + } else { + if err = wxUser.GetInfo(); err == nil { + userInfo = wxUser.UserInfo + } } - userInfo, err := wxUser.GetInfoByAccessToken() - if err != nil { - writeError(w, http.StatusInternalServerError, err.Error()) - return - } writeJson(w, http.StatusOK, map[string]interface{}{ "code": http.StatusOK, "msg": "OK", + "openId": openId, "userInfo": userInfo, + "error": err.Error(), }) }