Exemple #1
0
        /// <summary>
        /// 从微信服务端同步用户的个人基本信息
        /// </summary>
        /// <param name="wechatAuthentManager"></param>
        public void SynchronWechatUserInfo(IWechatAuthentManager wechatAuthentManager)
        {
            if (string.IsNullOrEmpty(m_openId))
            {
                LogHelper.Logger.Error("OpenId为空,用户可能不是从合法的途径进入到该站点!");
                throw new Exception("OpenId不能为空,请从合法的途径进入该站点");
            }
            var userInfoResult = CommonApi.GetUserInfo(wechatAuthentManager.GetAccessToken(), m_openId);

            if (userInfoResult.errcode != ReturnCode.请求成功)
            {
                LogHelper.Logger.Error("请求用户的基本信息失败,原因:" + userInfoResult.errcode);
                throw new Exception("请求用户的基本信息失败,原因:" + userInfoResult.errcode);
            }
            UserWechatInfo = userInfoResult.MapTo <WechatAccount>();
        }
Exemple #2
0
        public bool CreateWechatMenu(out string msg)
        {
            var accessToken = _wechatAuthentManager.GetAccessToken();

            if (!string.IsNullOrEmpty(accessToken))
            {
                var wechatMenu = _wechatMenuProvider.GetWechatMenu();

                try
                {
                    var result = CommonApi.CreateMenu(accessToken, wechatMenu);
                    msg = result.errmsg;
                    return(result.errcode == ReturnCode.请求成功);
                }
                catch (Exception e)
                {
                    LogHelper.Logger.Error(e.Message, e);
                    msg = e.Message;
                }
                return(false);
            }
            msg = "获取AcessToken失败";
            return(false);
        }