Beispiel #1
0
 public override void GetUserInfo(Action <WechatUserInfoResponseData> onComplete)
 {
     GetAccessToken((data) =>
     {
         if (data.errcode == 0)
         {
             GetUserInfo(data.openid, data.access_token, onComplete);
         }
         else
         {
             Debug.Log($"ErrCode:{data.errcode},ErrMsg:{data.errmsg}");
             wechatUserInfoResponseData         = new WechatUserInfoResponseData();
             wechatUserInfoResponseData.errcode = data.errcode;
             wechatUserInfoResponseData.errmsg  = data.errmsg;
             onComplete?.Invoke(wechatUserInfoResponseData);
         }
     });
 }
        protected static async Task GetUserInfoWebRequest(string openId, string accessToken)
        {
            string          requestStr = $"?openid={openId}&access_token={accessToken}&lang=zh_CN";
            string          url        = "https://api.weixin.qq.com/sns/userinfo" + requestStr;
            UnityWebRequest webRequest = UnityWebRequest.Get(url);
            await webRequest.SendWebRequest();

            if (webRequest.isNetworkError || webRequest.isHttpError)
            {
                Debug.LogError(webRequest.error);
            }
            else
            {
                Debug.Log(webRequest.downloadHandler.text);
                wechatUserInfoResponseData = JsonUtility.FromJson <WechatUserInfoResponseData>(webRequest.downloadHandler.text);
                onObtainUserInfoComplete?.Invoke(wechatUserInfoResponseData);
            }
        }
Beispiel #3
0
 public override void GetUserInfo(string openId, string accessToken, Action <WechatUserInfoResponseData> onComplete)
 {
     wechatUserInfoResponseData = new WechatUserInfoResponseData();
     onObtainUserInfoComplete   = onComplete;
     if (wechatAccessTokenResponseData != null &&
         !string.IsNullOrEmpty(wechatAccessTokenResponseData.access_token) &&
         !string.IsNullOrEmpty(wechatAccessTokenResponseData.openid))
     {
         if (isWebRequest)
         {
             _ = GetUserInfoWebRequest(openId, accessToken);
         }
         else
         {
             ObtainUserInfo(openId, accessToken, CallBackUserInfo);
         }
     }
     else
     {
         Debug.LogError("Please obtain access token first!");
         wechatUserInfoResponseData.errcode = -1;
         onComplete?.Invoke(wechatUserInfoResponseData);
     }
 }