/// <summary> /// 重新获取access_token /// </summary> /// Author : 俞立钢 /// Company : 绍兴标点电子技术有限公司 /// Created : 2014-10-15 15:01:17 private void RequestAccessToken() { _baseInfo = GetBaseInfo(); string url = string.Format("https://api.weixin.qq.com/cgi-bin/token?grant_type=client_credential&appid={0}&secret={1}", _baseInfo.Appid, _baseInfo.Appsecret); string json = PublicFun.RequestGetData(url); AccessTokens tokens = json.ResolveJson(); if (tokens.access_token != null) { //获取成功,写入信息 TxtAccessToken.Text = tokens.access_token; BaseInfo info = new BaseInfo(); DateTime start = DateTime.Now; DateTime end = start.AddSeconds(Convert.ToDouble(_baseInfo.TimeSpace)); info.Id = _baseInfo.Id; info.StartDateTime = start.ToString("yyyy-MM-dd HH:mm:ss"); info.EndDateTime = end.ToString("yyyy-MM-dd HH:mm:ss"); info.AccessToken = TxtAccessToken.Text; BaseInfoDao.UpdateBaseInfo(info); //更新缓存 _cacheBaseInfo.Remove(PublicFileds.BaseInfo); _cacheBaseInfo.Insert(PublicFileds.BaseInfo, BaseInfoDao.SelectBaseInfo(info.Id)); } else { MessageBox.Show("获取失败!!!"); } }
/// <summary> /// 保存配置 /// </summary> /// Author : 俞立钢 /// Company : 绍兴标点电子技术有限公司 /// Created : 2014-10-15 09:45:11 private void BtnSave_Click(object sender, EventArgs e) { if (string.IsNullOrEmpty(TxtUrl.Text) || string.IsNullOrEmpty(TxtToken.Text) || string.IsNullOrEmpty(TxtAppId.Text) || string.IsNullOrEmpty(TxtAppSecret.Text)) { MessageBox.Show("配置不能为空!!!"); } else { _baseInfo = new BaseInfo(); _baseInfo.Id = GetBaseInfo().Id; _baseInfo.Url = TxtUrl.Text; _baseInfo.Token = TxtToken.Text; _baseInfo.Appid = TxtAppId.Text; _baseInfo.Appsecret = TxtAppSecret.Text; if (BaseInfoDao.UpdateBaseInfo(_baseInfo)) { MessageBox.Show("保存成功!"); //更新缓存 _cacheBaseInfo.Remove(PublicFileds.BaseInfo); _cacheBaseInfo.Insert(PublicFileds.BaseInfo, BaseInfoDao.SelectBaseInfo(_baseInfo.Id)); return; } MessageBox.Show("保存失败!"); } }