protected T_ProductUserTokenEntity GetProductUserToken() { var result = _productUserTokenBll.Value.GetByResourceOwner(CurrentUser.ResourceOwner); if (null == result) { throw new Exception($"用户{CurrentUser.ResourceOwner}令牌信息不存在"); } if (result.UpdateTime.AddSeconds(result.ExpiresIn) > DateTime.Now.AddSeconds(-120)) { return(result); } //更新令牌 GetTokenResultModel getToken = null; if (result.RefreshTokenTimeout.AddDays(-30) < DateTime.Now) { RPoney.Log.LoggerManager.Debug(GetType().Name, "更新刷新令牌"); getToken = ApiCommon.GetToken(AppConfigBll.AppConfig.AppKey, AppConfigBll.AppConfig.AppSecrect, result.RefreshToken, result.AccessToken); } else { RPoney.Log.LoggerManager.Debug(GetType().Name, "使用刷新令牌换取accesstoken"); getToken = ApiCommon.GetTokenByRefreshToKen(AppConfigBll.AppConfig.AppKey, AppConfigBll.AppConfig.AppSecrect, result.RefreshToken); } var productUserToken = new T_ProductUserTokenEntity { AliId = getToken.AliId, MemberId = getToken.MemberId, ResourceOwner = getToken.ResourceOwner, AccessToken = getToken.AccessToken, RefreshToken = getToken.RefreshToken, ExpiresIn = getToken.ExpiresIn.CInt(0, false), RefreshTokenTimeout = getToken.RefreshTokenTimeout.GetDateTimeFromUtc(DateTime.MinValue), UpdateTime = DateTime.Now }; if (_productUserTokenBll.Value.Save(productUserToken)) { return(productUserToken); } return(null); }
/// <summary> /// 查询景点列表 /// </summary> /// <param name="pq"></param> /// <returns></returns> public sceneryList QueryScenery(QueryScenery pq) { string request = ""; PropertyInfo[] pInfos = typeof(QueryScenery).GetProperties(); foreach (var pInfo in pInfos) { //if(typeof(f).is) if (pInfo.GetValue(pq, null) != null) { request += "<" + pInfo.Name + ">" + pInfo.GetValue(pq, null) + "</" + pInfo.Name + ">"; } } string rs = ApiCommon.GetResult(request, "GetSceneryList", "http://tcopenapi.17usoft.com/handlers/scenery/queryhandler.ashx").Replace("&", "&"); rs = GetJQRs(rs); var model = rs.XmlToEntity <sceneryList>(); return(model); }
/// <summary> /// 执行函数 /// </summary> private APIResault DoMethods(HttpListenerRequest request) { ServiceRequest req = new ServiceRequest(); req.Load(request); string arg = req.GetArgString(); string method = req.MethodName; string url = request.Url.AbsolutePath; string ip = LanUnit.GetHostAddress(request); if (_lanUnit != null && _lanUnit.IsAllowIP(ip)) { return(ApiCommon.GetException(new System.Net.WebException("调用IP:" + ip + "不在白名单内"))); } if (string.IsNullOrWhiteSpace(method)) { return(ApiCommon.GetFault("函数MethodName不能为空")); } try { APIResault con = RunMethod(url, method, arg, request); if (_message != null && _message.ShowLog) { string mess = con.Message; _message.Log(mess); } return(con); } catch (Exception ex) { if (OnException != null) { OnException(ex); } return(ApiCommon.GetException(ex)); } }
/// <summary> /// 检查数据包ID /// </summary> /// <param name="curTick"></param> /// <param name="tick"></param> /// <returns></returns> private APIResault CheckPacket(long curTick, string name, long tick) { long left = Math.Abs(curTick - tick); if (left > PacketTimeout) { return(ApiCommon.GetFault("请求已过期")); } StringBuilder sbKey = new StringBuilder(); sbKey.Append(PackIDHead); sbKey.Append(name); sbKey.Append("."); sbKey.Append(curTick.ToString("X")); string key = sbKey.ToString(); bool isSet = _cache.SetValue <int>(key, 1, SetValueType.AddNew, 30); if (!isSet) { return(ApiCommon.GetFault("重复请求")); } return(ApiCommon.GetSuccess()); }
private void DoRequest(object objhttpListenerContext) { try { HttpListenerContext context = objhttpListenerContext as HttpListenerContext; if (context == null) { return; } HttpListenerRequest request = context.Request; APIResault res = DoMethods(request); //取得响应对象 HttpListenerResponse response = context.Response; string responseBody = null; if (res == null) { res = ApiCommon.GetFault("请求错误"); } responseBody = res.ToJson(); //设置响应头部内容,长度及编码 response.ContentLength64 = System.Text.Encoding.UTF8.GetByteCount(responseBody); response.ContentType = "application/json; Charset=UTF-8"; using (StreamWriter sw = new StreamWriter(response.OutputStream)) { sw.Write(responseBody); } } catch (Exception ex) { if (OnException != null) { OnException(ex); } } }
public APIResault UpdateAddress(string args, HttpListenerRequest request) { string remoteIP = GetIP(request); string blockkey = KeyHead + remoteIP; long curTick = (long)CommonMethods.ConvertDateTimeInt(DateTime.Now, true, true); APIResault res = CheckBlockIP(blockkey, remoteIP, curTick); if (!res.IsSuccess) { return(res); } ArgValues arg = ApiCommon.GetArgs(args); long tick = arg.GetDataValue <long>("Tick"); string name = arg.GetDataValue <string>("Name"); string sign = arg.GetDataValue <string>("Sign"); res = CheckPacket(curTick, name, tick); if (!res.IsSuccess) { return(res); } FWUser user = _userMan.GetUser(name); if (user == null) { return(ApiCommon.GetFault("找不到用户:" + name)); } string cntkey = KeyCntHead + remoteIP; string cursign = user.GetSign(tick); if (!string.Equals(cursign, sign, StringComparison.CurrentCultureIgnoreCase)) { int times = _cache.GetValue <int>(cntkey); times++; string err = null; if (times >= BlockTimes) { _cache.SetValue <long>(blockkey, curTick, SetValueType.Set, BlockSecond); _cache.DeleteValue(cntkey); err = "效验错误,IP被屏蔽:" + remoteIP; } else { _cache.SetValue <int>(cntkey, times, SetValueType.Set, BlockSecond); err = "效验错误,错误次数:" + times; } return(ApiCommon.GetFault(err)); } _cache.DeleteValue(cntkey); if (!user.UpdateIP(remoteIP)) { return(ApiCommon.GetSuccess()); } _userMan.RefreashFirewall(); _userMan.SaveConfig(); _form.OnUserUpdate(); if (_message != null && _message.ShowLog) { _message.Log("用户:" + name + ",的IP更新为:" + remoteIP); } return(ApiCommon.GetSuccess()); }
public string GetCountyListByCityId(int cid) { string rs = ApiCommon.GetResult("<cityId>" + cid + "</cityId>", "GetCountyListByCityId", "http://tcopenapi.17usoft.com/Handlers/General/AdministrativeDivisionsHandler.ashx"); return(rs); }
/// <summary> /// 根据省份获取同程网城市信息 /// </summary> /// <param name="Pid"></param> /// <returns></returns> public string GetCityListByProvinceId(int Pid) { string rs = ApiCommon.GetResult("<provinceId>" + Pid + "</provinceId>", "GetCityListByProvinceId", "http://tcopenapi.17usoft.com/Handlers/General/AdministrativeDivisionsHandler.ashx"); return(rs); }
/// <summary> /// 获取同程网省份信息 /// </summary> /// <returns></returns> public string GetProvinceList() { string rs = ApiCommon.GetResult("", "GetProvinceList", "http://tcopenapi.17usoft.com/Handlers/General/AdministrativeDivisionsHandler.ashx"); return(rs); }