Ejemplo n.º 1
0
        /// <summary>
        /// 通过回调OAuth地址所得code及agentid参数,获取请求的weixinid
        /// </summary>
        /// <param name="code"></param>
        /// <param name="agentid"></param>
        private string GetWeixinidByAPI(string code, int agentid)
        {
            //参数检查
            if (string.IsNullOrEmpty(code) || agentid < 1)
            {
                return(string.Empty);
            }

            //目标:只获取OpenID
            Senparc.Weixin.QY.AdvancedAPIs.OAuth2.GetUserIdResult result;
            try
            {
                result = Senparc.Weixin.QY.AdvancedAPIs.OAuth2.OAuth2Api.GetUserId(WeiXinSDKExtension.GetCurrentAccessTokenQY(), code, agentid);
            }
            catch (Exception ex)
            {
                //如果获取不到,返回NULL,外部进行错误处理。
                return(string.Empty);
            }

            if (result != null)
            {
                //SessionHelper.Add(ConstStr.SESSION_CURRENT_USERID, result.UserId);
                //返回结果
                return(result.UserId);
            }
            else
            {
                return(string.Empty);
            }

            //SessionHelper.Add(ConstStr.SESSION_CURRENT_USERID, code + agentid);
            //return code + agentid;
        }
Ejemplo n.º 2
0
        //---Private:

        #region 获取AccessToken

        /// <summary>
        /// 获取 当前公众号对应的AccessToken
        /// </summary>
        /// <returns></returns>
        private static string GetAccessToken()
        {
            return(WeiXinSDKExtension.GetCurrentAccessToken());
        }