public string GetCardApi(string token) { string Cardapi_ticket = ""; CardApiTicket at = new CardApiTicket(); IHmjMemberService _hmjMember = new HmjMemberService(); at = _hmjMember.GetModelCardApi(); if (at == null) { at = new CardApiTicket(); } if (at.Cardapi_Ticket != "" && at.Cardapi_Ticket != null && (at.GetTicketTime == null ? DateTime.Now.AddHours(-3) : at.GetTicketTime.Value).AddHours(2) > DateTime.Now) //不为空,并且获取时间没有超过2小时 { return(at.Cardapi_Ticket); } else { Cardapi_ticket = at.Cardapi_Ticket; string url = "https://api.weixin.qq.com/cgi-bin/ticket/getticket?access_token=" + token + "&type=wx_card"; string b = PostRequest(url); CardApi ticket = JsonConvert.DeserializeObject <CardApi>(b); if (ticket.errcode == 0) //正确 { at.Cardapi_Ticket = ticket.ticket; at.GetTicketTime = DateTime.Now; _hmjMember.AddCardApi(at); return(at.Cardapi_Ticket); } return(""); } }
public AccessResponse SendTmps(BCJ_TMP_DETAIL_EX request) { ILog _loginfo = LogManager.GetLogger("loginfo"); string ip = String.Empty; //服务端获取IP地址 ip = HttpContext.Current.Request.ServerVariables["HTTP_X_FORWARDED_FOR"]; if (null == ip || ip == String.Empty) { ip = HttpContext.Current.Request.ServerVariables["REMOTE_ADDR"]; } if (null == ip || ip == String.Empty) { ip = HttpContext.Current.Request.UserHostAddress; } //ILog _logerror = LogManager.GetLogger("logerror"); //_loginfo.Info("IP:"+ip); //string ip = this.Context.Request.UserHostAddress; //HttpRequest.UserHostAddress.ToString() //BCJ_TMP_DETAIL tmp_detail = JsonConvert.DeserializeObject<BCJ_TMP_DETAIL>(request); AccessResponse response = new AccessResponse(); string json = ""; string key = FormsAuthentication.HashPasswordForStoringInConfigFile(ip, "SHA1"); if (System.Configuration.ConfigurationManager.AppSettings.Get("AuthSecret") == null) { _loginfo.Info("发送模板消息接口 IP:" + ip + " 验证不通过:服务没有配置白名单"); response.Wv_Return = "N"; response.Message = "服务没有配置白名单"; response.Member_Group = "0"; return(response); } if (!System.Configuration.ConfigurationManager.AppSettings.Get("AuthSecret").Split(',').Contains <string>(key)) { _loginfo.Info("发送模板消息接口 IP:" + ip + " 验证不通过:当前ip" + ip + "不在没权限访问"); response.Wv_Return = "N"; response.Message = "当前ip" + ip + "不在没权限访问"; response.Member_Group = "0"; return(response); } int successCnt = 0; try { if (string.IsNullOrWhiteSpace(request.IsRealTime)) { _loginfo.Info("发送模板消息接口 IP:" + ip + " 验证不通过:请提供是否实时参数信息"); response.Wv_Return = "N"; response.Message = "请提供是否实时参数信息"; response.Member_Group = "0"; return(response); } if (string.IsNullOrWhiteSpace(request.Invoke_Time)) { _loginfo.Info("发送模板消息接口 IP:" + ip + " 验证不通过:调用时间参数异常"); response.Wv_Return = "N"; response.Message = "调用时间参数异常"; response.Member_Group = "0"; return(response); } try { DateTime Invoke_Time = DateTime.Parse(request.Invoke_Time); } catch { _loginfo.Info("发送模板消息接口 IP:" + ip + " 验证不通过:调用时间格式不正确"); response.Wv_Return = "N"; response.Message = "调用时间格式不正确"; response.Member_Group = "0"; return(response); } if (request.Templates.Count <= 0) { _loginfo.Info("发送模板消息接口 IP:" + ip + " 验证不通过:请至少提供一个消息模版信息"); response.Wv_Return = "N"; response.Message = "请至少提供一个消息模版信息"; response.Member_Group = "0"; return(response); } if (request.Template_Params.Count <= 0) { _loginfo.Info("发送模板消息接口 IP:" + ip + " 验证不通过:请至少提供一个会员目标组信息"); response.Wv_Return = "N"; response.Message = "请至少提供一个会员目标组信息"; response.Member_Group = "0"; return(response); } string resmsg = NetHelper.HttpRequest(AppConfig.BeautyChinaWebApp, "", "GET", 2000, Encoding.UTF8, "application/json"); TokeRes toke = JsonHelper.DeserializeObject <TokeRes>(resmsg); HmjMemberService _hmjMember = new HmjMemberService(); string errorMessage = ""; string requestStr = JsonHelper.SerializeObject(request); //添加日志: ip+请求参数 _loginfo.Info("发送模板消息接口 IP:" + ip + " 请求参数:" + requestStr); int str = _hmjMember.SendTmpEx(request, toke.Access_Token, ref successCnt, ref errorMessage); if (str == -1) { _loginfo.Info("发送模板消息接口 IP:" + ip + " 返回结果失败:" + "[成功数]" + successCnt + " [错误信息]" + errorMessage); response.Wv_Return = "N"; response.Message = errorMessage; response.Member_Group = successCnt.ToString(); return(response); } _loginfo.Info("发送模板消息接口 IP:" + ip + " 返回结果成功:[成功数]" + successCnt); response.Wv_Return = "Y"; response.Message = "OK"; response.Member_Group = successCnt.ToString(); return(response); } catch (Exception ex) { _loginfo.Info("发送模板消息接口 IP:" + ip + " 返回结果异常:[成功数]" + successCnt); WriteLog("发送模板消息", ex); //return ResponseJsonError(false, error_message, ex); response.Wv_Return = "N"; response.Message = ex.Message; response.Member_Group = successCnt.ToString(); return(response); } }