Пример #1
0
    //得到accesstoken 如果文件里时间 超时则重新获取
    private string getAccessToken()
    {
        // access_token 应该全局存储与更新,以下代码以写入到文件中做示例
        string access_token = "";

        Jnwf.Model.tb_AccessTokenEntity model = Jnwf.BLL.tb_AccessTokenBLL.GetInstance().GetModel(weixincode);
        if (model != null)
        {
            if (model.AddTime.AddHours(1) <= DateTime.Now)
            {
                access_token = GetCurrentAccessToken(appId, appSecret);

                model.AccessToken = access_token;
                model.AddTime     = DateTime.Now;

                Jnwf.BLL.tb_AccessTokenBLL.GetInstance().Update(model);
            }
            else
            {
                access_token = model.AccessToken;
            }
        }


        return(access_token);
    }
Пример #2
0
    public string GetToken()
    {
        string token      = "";
        string appid      = Jnwf.Utils.Config.ConfigurationUtil.GetAppSettingValue("appid");
        string secret     = Jnwf.Utils.Config.ConfigurationUtil.GetAppSettingValue("secret");
        string weixincode = Jnwf.Utils.Config.ConfigurationUtil.GetAppSettingValue("weixincode");

        Jnwf.Model.tb_AccessTokenEntity temp = Jnwf.BLL.tb_AccessTokenBLL.GetInstance().GetModel(weixincode);
        if (temp != null)
        {
            if (temp.AddTime.AddHours(1) <= DateTime.Now)
            {
                token            = GetAccessToken(appid, secret);
                temp.AccessToken = token;
                temp.AddTime     = DateTime.Now;

                Jnwf.BLL.tb_AccessTokenBLL.GetInstance().Update(temp);
            }
            else
            {
                token = temp.AccessToken;
            }
        }
        return(token);
    }