Exemple #1
0
        /// <summary>
        /// 刷新jsapi_ticket,数据库更新
        /// </summary>
        /// <param name="accessToken"></param>
        /// <param name="mpInfo"></param>
        /// <param name="errMsg">错误信息</param>
        /// <returns></returns>
        private string RefreshJsApiTicket(string accessToken, WeixinMPInfo mpInfo, out string errMsg)
        {
            string ticket = WeixinTokenBuildHelper.BuildJsApiTickets(accessToken, out errMsg);

            if (ticket == "")
            {
                return("");
            }
            //尝试更新,没有就新增
            WxTokensModel model = WxTokensBLL.Instance.GetModel((int)HQEnums.WxTokenTypeOptions.Jsticket);

            if (model == null)
            {
                WxTokensBLL.Instance.Add(new WxTokensModel()
                {
                    BuildTime = DateTime.Now,
                    Token     = ticket,
                    TypeKey   = (int)HQEnums.WxTokenTypeOptions.Jsticket
                });
            }
            else
            {
                model.Token     = ticket;
                model.BuildTime = DateTime.Now;
                WxTokensBLL.Instance.Update(model);
            }
            return(ticket);
        }
Exemple #2
0
        /// <summary>
        /// 刷新accessToken,数据库更新
        /// </summary>
        /// <param name="mpInfo">公众账号APPID等信息</param>
        /// <param name="errMsg">错误信息</param>
        /// <returns></returns>
        private string RefreshAccessToken(WeixinMPInfo mpInfo, out string errMsg)
        {
            string accessToken = WeixinTokenBuildHelper.BuildAccessToken(mpInfo.AppId, mpInfo.AppSecret, out errMsg);

            if (accessToken == "")
            {
                return("");
            }
            //尝试更新,没有就新增
            WxTokensModel model = WxTokensBLL.Instance.GetModel((int)HQEnums.WxTokenTypeOptions.Accesstoken);

            if (model == null)
            {
                WxTokensBLL.Instance.Add(new WxTokensModel()
                {
                    BuildTime = DateTime.Now,
                    Token     = accessToken,
                    TypeKey   = (int)HQEnums.WxTokenTypeOptions.Accesstoken
                });
            }
            else
            {
                model.Token     = accessToken;
                model.BuildTime = DateTime.Now;
                WxTokensBLL.Instance.Update(model);
            }
            return(accessToken);
        }