コード例 #1
0
        /// <summary>
        /// 设置用户默认公众号
        /// </summary>
        /// <param name="userID">用户ID</param>
        /// <param name="projectInfoID">公众号ID</param>
        public void SetDefaultMp(string userID, string mpID)
        {
            var t         = SysBool.T.ToString();
            var f         = SysBool.F.ToString();
            var defaultMp = entities.MpAccountUserRelation.Where(d => d.UserID == userID && d.MpID == mpID).OrderByDescending(d => d.ID).FirstOrDefault();

            if (defaultMp != null)
            {
                defaultMp.IsDefault = t;
                defaultMp.IsUsed    = t;
            }
            else
            {
                var dm = new MpAccountUserRelation();
                dm.ID        = FormulaHelper.CreateGuid();
                dm.UserID    = userID;
                dm.MpID      = mpID;
                dm.IsDefault = t;
                dm.IsUsed    = t;
                entities.MpAccountUserRelation.Add(dm);
            }
            var notdefault = entities.MpAccountUserRelation.Where(d => d.UserID == userID && d.MpID != mpID).ToList();

            for (int i = 0; i < notdefault.Count(); i++)
            {
                notdefault[i].IsDefault = f;
            }

            entities.SaveChanges();
        }
コード例 #2
0
ファイル: WxFO.cs プロジェクト: Luyingjin/Qy
        /// <summary>
        /// 获取公众号认证令牌
        /// </summary>
        /// <param name="QyID"></param>
        /// <returns></returns>
        public string GetAccessToken(string QyID, bool GetNewToken = false)
        {
            var token = "";

            //LogWriter.Info(string.Format("qyid为{0}的静默授权在通过code获取token时异常,原因:{1}", corpid, result.errmsg));
            LogWriter.Info("GetAccessToken:1");
            var account = CacheHelper.Get(string.Format("WxAccount{0}", QyID)) as QyAccount;

            if (account == null)
            {
                LogWriter.Info("GetAccessToken:2");
                account = entities.QyAccount.Where(c => c.ID == QyID && c.IsDelete == 0).FirstOrDefault();
                CacheHelper.Set(string.Format("WxAccount{0}", QyID), account);
            }
            if (account != null)
            {
                LogWriter.Info(GetNewToken + "-GetAccessToken:3-" + account.CorpID + "@" + account.CorpSecret);
                if (!AccessTokenContainer.CheckRegistered(account.CorpID + "@" + account.CorpSecret) || GetNewToken)
                {
                    LogWriter.Info("GetAccessToken:4");
                    AccessTokenContainer.Register(account.CorpID, account.CorpSecret);
                }
                var result = AccessTokenContainer.GetTokenResult(account.CorpID + "@" + account.CorpSecret, GetNewToken);
                LogWriter.Info("key=" + account.CorpID + "@" + account.CorpSecret + GetNewToken + "GetAccessToken:5-" + JsonHelper.ToJson(result));
                if (result.access_token != account.AccessToken)
                {
                    LogWriter.Info("GetAccessToken:6");
                    account                       = entities.QyAccount.Where(c => c.ID == QyID && c.IsDelete == 0).FirstOrDefault();
                    account.AccessToken           = result.access_token;
                    account.AccessTokenExpireTime = DateTime.Now.AddSeconds(result.expires_in);
                    account.ModifyDate            = DateTime.Now;
                    entities.SaveChanges();
                    CacheHelper.Set(string.Format("WxAccount{0}", QyID), account);
                }
                token = account.AccessToken;
            }
            return(token);
        }