/// <summary> /// 刷新会话令牌 /// </summary> /// <param name="_Mechant"></param> public void freshToken(yy_Platforms _Mechant) { #region 如果商家Access_token过期就刷新,调用接口需要用这个 if (String.IsNullOrEmpty(_Mechant.Access_token) || _Mechant.Access_token_Expires_in < DateTime.Now) { var _res = new WebClient().DownloadString( String.Format("https://api.weixin.qq.com/cgi-bin/token?grant_type=client_credential&appid={0}&secret={1}", _Mechant.APPKey, _Mechant.APPSecret)); var _resObj = JsonConvert.DeserializeObject<JObject>(_res); if (_resObj["access_token"] != null) { _Mechant.Access_token = _resObj["access_token"].Value<String>(); _Mechant.Access_token_Expires_in = DateTime.Now.AddSeconds(_resObj["expires_in"].Value<int>()); DB.SaveChanges(); } } #endregion #region 如果商家jsapi_ticket过期就刷新,网页里用jsAPi需要用这个 if (String.IsNullOrEmpty(_Mechant.jsapi_ticket) || _Mechant.jsapi_ticket_Expires_in < DateTime.Now) { var _res = new WebClient().DownloadString(String.Format("https://api.weixin.qq.com/cgi-bin/ticket/getticket?access_token={0}&type=jsapi", _Mechant.Access_token)); var _resObj = JsonConvert.DeserializeObject<JObject>(_res); if (_resObj["ticket"] != null) { _Mechant.jsapi_ticket = _resObj["ticket"].Value<String>(); _Mechant.jsapi_ticket_Expires_in = DateTime.Now.AddSeconds(_resObj["expires_in"].Value<int>()); DB.SaveChanges(); } } #endregion #region 如果商家api_ticket过期就刷新,网页里用js发券,做签名时需要用到这个 if (String.IsNullOrEmpty(_Mechant.api_ticket) || _Mechant.api_ticket_Expires_in < DateTime.Now) { var _res = new WebClient().DownloadString(String.Format("https://api.weixin.qq.com/cgi-bin/ticket/getticket?access_token={0}&type=wx_card", _Mechant.Access_token)); var _resObj = JsonConvert.DeserializeObject<JObject>(_res); if (_resObj["ticket"] != null) { _Mechant.api_ticket = _resObj["ticket"].Value<String>(); _Mechant.api_ticket_Expires_in = DateTime.Now.AddSeconds(_resObj["expires_in"].Value<int>()); DB.SaveChanges(); } } #endregion }
public ResponseItem Put(yy_Platforms value) { if (value == null) { return new ResponseItem(1, "传入了空数据,无法继续。"); } var _Entity = DB.yy_Platforms.Find(value.ID); if (_Entity != null) { _Entity.Access_token = value.Access_token; _Entity.Image = value.Image; _Entity.jsapi_ticket = value.jsapi_ticket; _Entity.jsapi_ticket_Expires_in = value.jsapi_ticket_Expires_in; _Entity.JSSDK = value.JSSDK; _Entity.Code = value.Code; _Entity.Access_token_Expires_in = value.Access_token_Expires_in; _Entity.api_ticket = value.api_ticket; _Entity.api_ticket_Expires_in = value.api_ticket_Expires_in; _Entity.APPAdminID = value.APPAdminID; _Entity.APPID = value.APPID; _Entity.APPKey = value.APPKey; _Entity.APPName = value.APPName; _Entity.APPNumber = value.APPNumber; _Entity.APPPayCert = value.APPPayCert; _Entity.APPPayID = value.APPPayID; _Entity.APPPayKey = value.APPPayKey; _Entity.APPSecret = value.APPSecret; _Entity.Link = value.Link; _Entity.Name = value.Name; _Entity.PlatformConfig = value.PlatformConfig; _Entity.QRCode = value.QRCode; _Entity.RecallUrl = value.RecallUrl; _Entity.Refresh_token = value.Refresh_token; _Entity.Remark = value.Remark; DB.SaveChanges(); return new ResponseItem(0, ""); } else { DB.yy_Platforms.Add(value); DB.SaveChanges(); return new ResponseItem(0, ""); } }