public MpUser UpdateUserInfo(string OpenId, string token) { MpUser currUser = this.GetByOpenID(OpenId); if (currUser != null && currUser.IsSubscribe) { if (!string.IsNullOrEmpty(token)) { try { UserInfoJson info = Senparc.Weixin.MP.AdvancedAPIs.User.Info(token, OpenId); if (info != null) { currUser.City = info.city; currUser.Country = info.country; currUser.HeadImgUrl = info.headimgurl; currUser.Language = info.language; currUser.NickName = info.nickname; currUser.Province = info.province; currUser.Sex = info.sex; this.Update(currUser); } } catch (Exception e) { Log4NetImpl.Write("UpdateUserInfo失败:" + e.Message); } } } return(currUser); }
public string GetAccessToken() { MpCenter mp = MpCenterService.GetALL().FirstOrDefault(); try { if (mp != null && !string.IsNullOrEmpty(mp.AppID) && !string.IsNullOrEmpty(mp.AppSecret)) { var timespan = DateTime.Now - mp.GetTokenDate.Value; if (timespan.TotalMinutes > 15 || string.IsNullOrEmpty(mp.AccessToken)) { AccessTokenResult token = CommonApi.GetToken(mp.AppID, mp.AppSecret); if (token != null && !string.IsNullOrEmpty(token.access_token)) { Log4NetImpl.Write("GetAccessToken更新:not null"); mp.GetTokenDate = DateTime.Now; mp.AccessToken = token.access_token; MpCenterService.ExcuteSql("update MpCenter set GetTokenDate='" + DateTime.Now + "',AccessToken='" + token.access_token + "' where Id='" + mp.Id.ToString() + "'"); MpCenter mpCache = _cacheManager.Get <MpCenter>("MpCenter"); mpCache = mp; } } } } catch (Exception e) { Log4NetImpl.Write("GetAccessToken失败:" + e.Message); return(""); } return(mp.AccessToken); }
public string GetAccessToken() { MpCenter mp = MpCenterCache; try { if (mp != null && !string.IsNullOrEmpty(mp.AppID) && !string.IsNullOrEmpty(mp.AppSecret)) { var timespan = DateTime.Now - mp.GetTokenDate.Value; if (timespan.TotalMinutes > 15 || string.IsNullOrEmpty(mp.AccessToken)) { AccessTokenResult token = CommonApi.GetToken(mp.AppID, mp.AppSecret); if (token != null && !string.IsNullOrEmpty(token.access_token)) { mp.GetTokenDate = DateTime.Now; mp.AccessToken = token.access_token; _mpCenterService.Update(mp); MpCenterCache = mp; } } } } catch (Exception e) { Log4NetImpl.Write("GetAccessToken失败:" + e.Message); return(""); } return(mp.AccessToken); }
public void Application_Error(object sender, EventArgs e) { //在出现未处理的错误时运行的代码 //错误日志 Exception exception = Server.GetLastError(); if (exception == null) { return; } if (exception.InnerException != null) { exception = exception.InnerException; } if (exception.Message.Contains("禁止路径")) { return; } if (exception.Message.Contains("服务器") || exception.Message.Contains("超时") || exception.Message.Contains("登录失败")) { Log4NetImpl.Write(exception.Message, Log4NetImpl.ErrorLevel.Error); } else if (exception.Message.Contains("最大池大小")) { Log4NetImpl.Write("超出最大池大小:重启进程", Log4NetImpl.ErrorLevel.Error); HttpRuntime.UnloadAppDomain(); } else { Log4NetImpl.Write(exception.Message, Log4NetImpl.ErrorLevel.Error); } }
/// <summary> /// 发送消息 /// </summary> /// <param name="OpenId">OpenId</param> /// <param name="content">发送的内容</param> /// <param name="token">不填则自动获取</param> /// <returns></returns> public bool SendMessage(string OpenId, string content, string token = "") { if (string.IsNullOrEmpty(token)) { token = GetAccessToken(); } if (!string.IsNullOrEmpty(token)) { try { WxJsonResult errorResult = Custom.SendText(token, OpenId, content); if (errorResult.errcode != ReturnCode.请求成功) { return(false); } } catch (Exception e) { Log4NetImpl.Write("SendMessage:失败" + e.Message); return(false); } return(true); } return(false); }
public ActionResult MpQrCodeDelete(Guid id) { if (id != Guid.Empty) { MpQrScene qr = MpQrSceneService.GetById(id); try { if (qr != null) { MpQrSceneService.BeginTransaction(); MpQrSceneService.ExcuteSql("update MpUser set SceneId=0 where SceneId>0 and SceneId=" + qr.SceneId.ToString()); MpQrSceneService.Delete(qr); MpQrSceneService.Commit(); } } catch (Exception ex) { if (qr != null) { MpQrSceneService.Rollback(); } Log4NetImpl.Write("delete qrcode:" + ex.ToString()); return(JsonMessage(false, "删除失败")); } } return(JsonMessage(true)); }
/// <summary> /// 获取二维码(不需要AccessToken) /// 错误情况下(如ticket非法)返回HTTP错误码404。 /// </summary> /// <param name="ticket"></param> /// <returns></returns> public static string ShowQrCode(string ticket) { var urlFormat = "https://mp.weixin.qq.com/cgi-bin/showqrcode?ticket={0}"; Log4NetImpl.Write(string.Format(urlFormat, ticket)); return(string.Format(urlFormat, ticket)); }
public bool DelMaterial(Guid id) { try { this.BeginTransaction(); MpMaterial mp = this.GetById(id); if (mp != null) { var param = new Dictionary <string, object>(); param.Add("Id", mp.MpMaterialItems.Select(l => l.Id).ToArray()); MpMaterialItemService.Delete(param); var param1 = new Dictionary <string, object>(); Guid[] guidArr = MpReplyService.GetALL(x => x.MaterialID == mp.Id).Select(l => l.Id).ToArray(); if (guidArr != null && guidArr.Length > 0) { param1.Add("Id", MpReplyService.GetALL(x => x.MaterialID == mp.Id).Select(l => l.Id).ToArray()); MpReplyService.Delete(param1); } this.Delete("delete from MpMaterial where Id='" + id + "'"); } this.Commit(); return(true); } catch (Exception e) { Log4NetImpl.Write("DelMaterial失败:" + e.Message); this.Rollback(); return(false); } }
public JsonResult DelReply(Guid id) { try { MpReplyService.BeginTransaction(); MpReply reply = MpReplyService.GetALL(x => x.Id == id).FirstOrDefault(); if (reply != null) { if (reply.MpMaterial.TypeName == "text") { MpMaterialItemService.Delete(reply.MpMaterial.MpMaterialItems.FirstOrDefault()); MpMaterialService.Delete(reply.MpMaterial); } MpReplyService.Delete(reply); } MpReplyService.Commit(); return(JsonMessage(true, "")); } catch (Exception e) { Log4NetImpl.Write("DelReply失败:" + e.Message); MpReplyService.Rollback(); return(JsonMessage(false, "")); } }
public ActionResult PluginsLotteryResult(Guid Id) { try { if (Id == Guid.Empty) { Log4NetImpl.Write("PluginsLottery:参数有误"); throw new OceanException("参数有误,请检查!"); } //页面上的Plugins IList <Plugin> plugins = _pluginService.GetALL(); ViewBag.ContentPlugins = plugins; Plugin curPlugin = plugins.Where(p => p.Name.Contains("仙游")).FirstOrDefault(); ViewBag.CurPlugin = curPlugin; if (curPlugin == null) { throw new OceanException("对不起,不存在该插件或未开通,请检查!"); } ViewBag.Title = curPlugin.RPluginBase.Name; OceanDynamicList <object> list = _pluginSceneResultService.GetPageDynamicList(Id); ViewBag.PluginResultList = list; return(View("LotteryResult")); } catch (Exception ex) { Log4NetImpl.Write("PluginsLotteryResult:" + ex.Message); throw new OceanException(ex.Message, ex); } }
/// <summary> /// 订阅(关注)事件 /// </summary> /// <returns></returns> public override IResponseMessageBase OnEvent_SubscribeRequest(RequestMessageEvent_Subscribe requestMessage) { Log4NetImpl.Write("关注事件触发:"); MpUser fromUser = MpUserService.GetByOpenID(requestMessage.FromUserName); if (fromUser != null) { Log4NetImpl.Write("EventKey:" + requestMessage.EventKey); fromUser.IsSubscribe = true; if (!string.IsNullOrEmpty(requestMessage.EventKey)) { fromUser.SceneId = Convert.ToInt32(requestMessage.EventKey.Replace("qrscene_", "")); Log4NetImpl.Write("OnEvent_SubscribeRequest:" + fromUser.SceneId.ToString()); } fromUser.LastVisitDate = DateTime.Now; MpUserService.Update(fromUser); } var responseMessage = ResponseMessageBase.CreateFromRequestMessage <ResponseMessageText>(requestMessage); MpReply reply = MpReplyService.GetALL(k => k.Action == "beadded").FirstOrDefault(); if (reply != null) { return(ResponseMsg(reply.MpMaterial)); } return(responseMessage); }
public ActionResult SafeIPEditProvide() { List <string> list = new List <string>(); list.Add("安全IP|" + ConfigurationEnum.Config_SafeIP + "|" + RQuery["SafeIP"]); //事务 try { foreach (string config in list) { string[] arrConfig = config.Split('|'); if (arrConfig.Length != 3) { return(JsonMessage(false, "格式错误")); } _configurationService.UpdateConfiguration(arrConfig[1], arrConfig[2].Trim()); } //更新配置缓存 ConfigurationCache.Instance.RemoveCache(); base.AddLog(string.Format("更新安全IP成功"), AdminLoggerModuleEnum.Configuration); return(JsonMessage(true, "保存成功")); } catch (Exception ex) { Log4NetImpl.Write(ex.Message, Log4NetImpl.ErrorLevel.Error); return(JsonMessage(false, ex.Message)); } }
public ActionResult PluginScratch(Guid Id) { try { Log4NetImpl.Write("PluginScratch:MpUserID" + MpUserID); if (MpUserID == Guid.Empty) { string rawUrl = "http://wx.ssrcb.com/pluginsScene/PluginScratch?id=" + WebHelper.GetGuid("Id", Guid.Empty); if (string.IsNullOrEmpty(RQuery["openid"])) { Log4NetImpl.Write("open.weixin.qq.com"); string redirectURL = "http://wx.ssrcb.com/mpuser/autologin?refUrl=" + rawUrl; //return Redirect(redirectURL); //return RedirectToRoute(new { controller = "mpuser", action = "AutoLogin2", refUrl = rawUrl, guid = Id.ToString() }); //return Json(new { isLogin = true, message = string.Format("https://open.weixin.qq.com/connect/oauth2/authorize?appid={0}&redirect_uri=http://wx.ssrcb.com/mpuser/autologin?refUrl={1}&response_type=code&scope=snsapi_base&state=STATE#wechat_redirect", MpCenterCache.AppID, rawUrl) }); string refUrl = string.Format("https://open.weixin.qq.com/connect/oauth2/authorize?appid={0}&redirect_uri=http://wx.ssrcb.com/mpuser/autologin?refUrl={1}&response_type=code&scope=snsapi_base&state=STATE#wechat_redirect", MpCenterCache.AppID, rawUrl); Response.Redirect(refUrl); } } if (MpUserID == Guid.Empty) { return(Json(new { message = "您没有相关的权限,具体请联系总行相关部门!" })); } Log4NetImpl.Write("PluginScratch:plugins-"); //页面上的Plugins IList <Plugin> plugins = _pluginService.GetALL(); ViewBag.ContentPlugins = plugins; Plugin curPlugin = plugins.Where(p => p.Id == Id).FirstOrDefault(); ViewBag.CurPlugin = curPlugin; if (curPlugin == null) { Log4NetImpl.Write("PluginScratch:对不起,不存在该插件或未开通,请检查!"); throw new OceanException("对不起,不存在该插件或未开通,请检查!"); } ViewBag.Title = curPlugin.RPluginBase.Name + "_石狮农商银行"; PluginSceneApllyCodeAllower pluginSceneApllyCodeAllower = _pluginSceneApllyCodeAllowerService.GetUnique("from SceneApllyCodeAllower where MpUserId='" + this.MpUserID.ToString() + "'"); if (pluginSceneApllyCodeAllower == null) { return(Json(new { message = "您没有相关的权限,具体请联系总行相关部门!" })); } IList <PluginSceneVerifyCodeDetail> verifyCodeList = _pluginSceneVerifyCodeDetailService.GetList("select * from SceneVerifyCodeDetail where GYH = '" + pluginSceneApllyCodeAllower.GYH + "' ORDER BY CreateDate DESC"); ViewBag.GYH = pluginSceneApllyCodeAllower.GYH; ViewBag.GYHName = pluginSceneApllyCodeAllower.Name; ViewBag.MpUserArr = this.MpUserArr; ViewBag.MpUserID = this.MpUserID; ViewBag.VerifyCodeList = verifyCodeList; return(View("PluginScratch")); } catch (Exception ex) { Log4NetImpl.Write("PluginScratch:" + ex.Message); throw new OceanException(ex.Message, ex); } }
public OceanException(string msg, Exception ex) : base(msg) { if (ex != null) { Log4NetImpl.Write(msg + ":" + ex.ToString(), Log4NetImpl.ErrorLevel.Debug); } }
/// <summary></summary> /// 获取指定页面的Stream /// <param name="url">指定页面的路径 /// <param name="postData">回发的数据 /// <param name="isPost">是否以post方式发送请求 /// <param name="cookieCollection">Cookie集合 /// <returns></returns> public static Stream GetStream(string url, string myCookie = "") { //Thread.Sleep(delay); currentTry++; HttpWebRequest httpWebRequest = null; HttpWebResponse httpWebResponse = null; try { httpWebRequest = (HttpWebRequest)HttpWebRequest.Create(url); //httpWebRequest.CookieContainer = cookieContainer; ServicePointManager.SecurityProtocol = SecurityProtocolType.Ssl3; httpWebRequest.ContentType = contentType; httpWebRequest.ServicePoint.ConnectionLimit = maxTry; httpWebRequest.Referer = url; httpWebRequest.Accept = accept; httpWebRequest.UserAgent = userAgent; httpWebRequest.Method = "GET"; httpWebRequest.Headers.Add("Cookie", myCookie); httpWebResponse = (HttpWebResponse)httpWebRequest.GetResponse(); Stream responseStream = httpWebResponse.GetResponseStream(); currentTry--; //httpWebRequest.Abort(); //httpWebResponse.Close(); return(responseStream); } catch (Exception e) { Log4NetImpl.Write("MpQrCodeEditProvide失败:" + e.Message); Console.ForegroundColor = ConsoleColor.Red; Console.WriteLine(DateTime.Now.ToString("HH:mm:ss ") + e.Message); Console.ForegroundColor = ConsoleColor.White; if (currentTry <= maxTry) { //GetHtml(url, cookieContainer); } currentTry--; if (httpWebRequest != null) { httpWebRequest.Abort(); } if (httpWebResponse != null) { httpWebResponse.Close(); } return(null); } }
/// <summary> /// [开始会话(等待客服接入)] /// </summary> public static CommunicationObject StartKfMeeting(Guid sendUserId) { Log4NetImpl.Write("等待客服接入"); HttpRequests httpRequests = new HttpRequests(); string url = string.Format("{0}{1}", CommunicationPostUrl, "StartKfMeeting"); string strPostData = httpRequests.Analysis(new string[] { "SendUserId", "token" }, new string[] { sendUserId.ToString(), token }); string jsonText = httpRequests.DownloadHtml(url, strPostData); //反序列化JSON字符串 return(JsonConvert.DeserializeObject <CommunicationObject>(jsonText)); }
/// <summary> /// 实现自己的任务逻辑 /// </summary> public void Execute() { if (DateTime.Now.Hour == 1) { Log4NetImpl.Write("执行任务!" + DateTime.Now); Dictionary <string, object> parms = new Dictionary <string, object>(); parms.Add("dbname", "ocean"); parms.Add("bkpath", "D:\\Db\\"); parms.Add("bkfname", "db_\\DATE\\_db.bak"); _mpUserService.ExcuteProc <int>("p_backupdb", parms); } }
public bool SaveMaterial(string data = "") { try { this.BeginTransaction(); MpMaterial material = JsonConvert.DeserializeObject <MpMaterial>(data); IList <MpMaterialItem> newItems = material.MpMaterialItems.ToList(); if (material.Id == Guid.Empty) { foreach (var item in newItems) { if (item.Id == Guid.Empty) { MpMaterialItemService.Insert(item); } } this.Insert(material); } else { IList <MpMaterialItem> orginMaterialItems = MpMaterialItemService.GetALL(m => m.MaterialID == material.Id); foreach (var item in newItems) { if (item.Id == Guid.Empty) { MpMaterialItemService.Insert(item); } else { MpMaterialItemService.Update(item); } } foreach (var item in orginMaterialItems) { if (newItems.Where(i => i.Id == item.Id).Count() == 0) { MpMaterialItemService.Delete(item); } } material.UpateDate = DateTime.Now; this.Update(material); } this.Commit(); return(true); } catch (Exception e) { Log4NetImpl.Write("SaveMaterial失败:" + e.Message); this.Rollback(); return(false); } }
public ActionResult Post(string signature, string timestamp, string nonce, string echostr) { if (!CheckSignature.Check(signature, timestamp, nonce, Token)) { Log4NetImpl.Write("WeixinController-Post失败:参数错误"); return(Content("参数错误!")); } //v4.2.2之后的版本,可以设置每个人上下文消息储存的最大数量,防止内存占用过多,如果该参数小于等于0,则不限制 var maxRecordCount = 3; //自定义MessageHandler,对微信请求的详细判断操作都在这里面。 var messageHandler = new CustomMessageHandler(Request.InputStream, maxRecordCount); try { //测试时可开启此记录,帮助跟踪数据,使用前请确保App_Data文件夹存在,且有读写权限。 //messageHandler.RequestDocument.Save(Server.MapPath("~/App_Data/" + DateTime.Now.Ticks + "_Request_" + messageHandler.RequestMessage.FromUserName + ".txt")); //执行微信处理过程 AysnUser(messageHandler.RequestMessage.FromUserName); messageHandler.Execute(); //测试时可开启,帮助跟踪数据 //messageHandler.ResponseDocument.Save(Server.MapPath("~/App_Data/" + DateTime.Now.Ticks + "_Response_" + messageHandler.ResponseMessage.ToUserName + ".txt")); //return Content(messageHandler.ResponseDocument.ToString());//v0.7- if (messageHandler.ResponseDocument == null) { return(Content("")); } //return new FixWeixinBugWeixinResult(messageHandler);//为了解决官方微信5.0软件换行bug暂时添加的方法,平时用下面一个方法即可 return(new WeixinResult(messageHandler));//v0.8+ } catch (Exception ex) { //using (TextWriter tw = new StreamWriter(Server.MapPath("~/App_Data/Error_" + DateTime.Now.Ticks + ".txt"))) //{ // tw.WriteLine("ExecptionMessage:" + ex.Message); // tw.WriteLine(ex.Source); // tw.WriteLine(ex.StackTrace); // //tw.WriteLine("InnerExecptionMessage:" + ex.InnerException.Message); // if (messageHandler.ResponseDocument != null) // { // tw.WriteLine(messageHandler.ResponseDocument.ToString()); // } // tw.Flush(); // tw.Close(); //} Log4NetImpl.Write("Post失败:" + ex.Message); return(Content("")); } }
public ActionResult AutoLogin2() { string code = RQuery["code"]; string state = RQuery["state"]; string refUrl = RQuery["refUrl"]; string openid = RQuery["openid"]; string gid = RQuery["guid"]; Log4NetImpl.Write("refUrl:" + refUrl); if (string.IsNullOrEmpty(openid)) { OAuthAccessTokenResult authResult = OAuth.GetAccessToken(MpCenterCache.AppID, MpCenterCache.AppSecret, code); openid = authResult.openid; } if (!string.IsNullOrEmpty(openid)) { Log4NetImpl.Write("currUser:"******"默认分组").Id; currUser.IsSubscribe = true; currUser.LastVisitDate = DateTime.Now; currUser.OpenID = openid; currUser.OrginID = MpCenterCache.OriginID; currUser.UserState = 0; MpUserService.Insert(currUser); } if (currUser != null) { Log4NetImpl.Write("oAuth:" + currUser.OpenID); WriteMpUserCookie(currUser); } if (string.IsNullOrEmpty(OpenID)) { Log4NetImpl.Write("用户未识别:" + currUser.OpenID); return(Content("用户未识别")); } if (!string.IsNullOrEmpty(refUrl)) { Log4NetImpl.Write("跳转回来!"); //Response.Redirect(refUrl); return(RedirectToRoute(new { controller = "PluginsScene", action = "PluginScratch", id = gid })); } } return(Content("请联系管理员")); }
/// <summary> /// 获取二维码(不需要AccessToken) /// 错误情况下(如ticket非法)返回HTTP错误码404。 /// </summary> /// <param name="ticket"></param> /// <param name="stream"></param> public static void ShowQrCode(string ticket, Stream stream, string path = "") { var urlFormat = "https://mp.weixin.qq.com/cgi-bin/showqrcode?ticket={0}"; stream = HttpHelper.GetStream(string.Format(urlFormat, ticket)); Log4NetImpl.Write(string.Format(urlFormat, ticket)); if (stream != null) { System.Drawing.Image img = new Bitmap(stream); img.Save(path); } //HttpUtility.Get.Download(string.Format(urlFormat, ticket), stream,path); }
public ActionResult PluginScratch(Guid Id) { try { TempData["OpenID"] = ""; if (TempData["OpenID"].ToString() == "") { string code = RQuery["code"]; string state = RQuery["state"]; string refUrl = RQuery["refUrl"]; string openid = RQuery["openid"]; if (code == "") { Log4NetImpl.Write("PluginScratch:redirectUrl"); string redirectUrl = "http://wx.ssrcb.com/xyplugins/PluginScratch?id=" + Id.ToString(); string reUrl = (OAuth.GetAuthorizeUrl(MpCenterCache.AppID, redirectUrl, "STATE", OAuthScope.snsapi_base)); Response.Redirect(reUrl); return(View("Scratch")); } if (string.IsNullOrEmpty(openid) || openid == "") { OAuthAccessTokenResult authResult = OAuth.GetAccessToken(MpCenterCache.AppID, MpCenterCache.AppSecret, code); openid = authResult.openid; } TempData["OpenID"] = openid; } ViewBag.OpenID = TempData["OpenID"].ToString(); //页面上的Plugins IList <Plugin> plugins = _pluginService.GetALL(); ViewBag.ContentPlugins = plugins; Plugin curPlugin = plugins.Where(p => p.Id == Id).FirstOrDefault(); ViewBag.CurPlugin = curPlugin; if (curPlugin == null) { throw new OceanException("对不起,不存在该插件或未开通,请检查!"); } ViewBag.Title = curPlugin.RPluginBase.Name + ""; XmlDocument xmlDoc = new XmlDocument(); xmlDoc.LoadXml(curPlugin.Value); XmlNode pluginNode = xmlDoc.SelectSingleNode("plugin"); GetDataToViewData(pluginNode); return(View("Scratch")); } catch (Exception ex) { throw new OceanException(ex.Message, ex); } }
/// <summary> /// 执行发送请求 /// </summary> public bool Execute(SendSmsRequest request, ref string message) { if (APIClientOcean.SmsReturnCode != SmsReturnCode.操作成功) { message = APIClientOcean.SmsReturnCode.ToString(); return(false); } SmsReturnCode smsReturnCode = SmsReturnCode.未知错误; //发送短信 if (request.SendTime.HasValue && request.SrcID.HasValue) { smsReturnCode = (SmsReturnCode)APIClientOcean.APIClient.sendSM( request.Mobiles.ToArray <string>(), request.Message, ((DateTime)request.SendTime).ToString("yyyy-MM-dd HH:mm:ss"), request.SMID, (long)request.SrcID); } else if ((!request.SendTime.HasValue) && request.SrcID.HasValue) { smsReturnCode = (SmsReturnCode)APIClientOcean.APIClient.sendSM( request.Mobiles.ToArray <string>(), request.Message, request.SMID, (long)request.SrcID); } else if (request.SendTime.HasValue && (!request.SrcID.HasValue)) { smsReturnCode = (SmsReturnCode)APIClientOcean.APIClient.sendSM( request.Mobiles.ToArray <string>(), request.Message, ((DateTime)request.SendTime).ToString("yyyy-MM-dd HH:mm:ss"), request.SMID, 0); } else if ((!request.SendTime.HasValue) && (!request.SrcID.HasValue)) { smsReturnCode = (SmsReturnCode)APIClientOcean.APIClient.sendSM( request.Mobiles.ToArray <string>(), request.Message, request.SMID); } else { message = "参数错误"; return(false); } Log4NetImpl.Write("MAS服务器返回:" + smsReturnCode.ToString()); if (smsReturnCode != SmsReturnCode.操作成功) { message = smsReturnCode.ToString(); return(false); } return(true); }
/// <summary> /// 订阅(关注)事件 /// </summary> /// <returns></returns> public override IResponseMessageBase OnEvent_ScanRequest(RequestMessageEvent_Scan requestMessage) { Log4NetImpl.Write("Scan关注事件触发:"); MpUser fromUser = MpUserService.GetByOpenID(requestMessage.FromUserName); if (fromUser != null) { if (!string.IsNullOrEmpty(requestMessage.EventKey)) { fromUser.SceneId = Convert.ToInt32(requestMessage.EventKey); Log4NetImpl.Write("OnEvent_ScanRequest:" + fromUser.SceneId.ToString()); } fromUser.LastVisitDate = DateTime.Now; MpUserService.Update(fromUser); } return(null); }
/// <summary> /// Event事件类型请求 /// </summary> public virtual IResponseMessageBase OnEventRequest(RequestMessageEventBase requestMessage) { var strongRequestMessage = RequestMessage as IRequestMessageEventBase; IResponseMessageBase responseMessage = null; switch (strongRequestMessage.Event) { case Event.ENTER: responseMessage = OnEvent_EnterRequest(RequestMessage as RequestMessageEvent_Enter); break; case Event.LOCATION: responseMessage = OnEvent_LocationRequest(RequestMessage as RequestMessageEvent_Location); //目前实际无效 break; case Event.SCAN: case Event.scan: //二维码 Log4NetImpl.Write("scan关注事件"); responseMessage = OnEvent_ScanRequest(RequestMessage as RequestMessageEvent_Scan); break; case Event.subscribe: //订阅 responseMessage = OnEvent_SubscribeRequest(RequestMessage as RequestMessageEvent_Subscribe); break; case Event.unsubscribe: //退订 responseMessage = OnEvent_UnsubscribeRequest(RequestMessage as RequestMessageEvent_Unsubscribe); break; case Event.CLICK: //菜单点击 responseMessage = OnEvent_ClickRequest(RequestMessage as RequestMessageEvent_Click); break; case Event.VIEW: //URL跳转(view视图) responseMessage = OnEvent_ViewRequest(RequestMessage as RequestMessageEvent_View); break; default: throw new UnknownRequestMsgTypeException("未知的Event下属请求信息", null); } return(responseMessage); }
public ActionResult MpQrCodeEditProvide() { Ocean.Entity.MpQrScene mp = new Entity.MpQrScene(); TryUpdateModel <MpQrScene>(mp); if (mp.Id.ToString().StartsWith("0000")) { string token = GetAccessToken(); int iTemp = MpQrSceneService.GetMaxSceneId(mp.ActionName) + 1; try { if (mp.ActionName == 0) { mp.TimeoutTicks = 1800; mp.SceneId = iTemp; CreateQrCodeResult result = QrCode.Create(token, 1800, iTemp); //QrCode.ShowQrCode(result.ticket, new MemoryStream(), WebHelper.MapPaths("~/images/Qrimg/Qr_" + iTemp.ToString() + ".jpg")); //mp.ImgUrl = GlobalConfig.GetConfig()["ResourceDomain"] + "/Qrimg/Qr_" + iTemp.ToString() + ".jpg"; mp.ImgUrl = QrCode.ShowQrCode(result.ticket); } else { mp.TimeoutTicks = 0; mp.SceneId = iTemp; CreateQrCodeResult result = QrCode.Create(token, 0, iTemp); //QrCode.ShowQrCode(result.ticket, new MemoryStream(), WebHelper.MapPaths("~/images/Qrimg/Qr_" + iTemp.ToString() + ".jpg")); //mp.ImgUrl = GlobalConfig.GetConfig()["ResourceDomain"] + "/Qrimg/Qr_" + iTemp.ToString() + ".jpg"; mp.ImgUrl = QrCode.ShowQrCode(result.ticket); } MpQrSceneService.Insert(mp); return(JsonMessage(true, "生成二维码成功")); } catch (Exception e) { Log4NetImpl.Write("MpQrCodeEditProvide失败:" + e.Message); return(JsonMessage(false, "生成二维码失败")); } } else { } return(JsonMessage(false, "生成二维码失败")); }
/// <summary> /// Executes the task /// </summary> public void Execute() { this._isRunning = true; try { var task = this.CreateTask(); if (task != null) { this._lastStartUtc = DateTime.UtcNow; task.Execute(); this._lastEndUtc = this._lastSuccessUtc = DateTime.UtcNow; } } catch (Exception ex) { this._enabled = !this.StopOnError; this._lastEndUtc = DateTime.UtcNow; //log error Log4NetImpl.Write(string.Format("Error while running the '{0}' schedule task. {1}", this._name, ex.Message), Log4NetImpl.ErrorLevel.Error); } try { //find current schedule task var scheduleTaskService = EngineContext.Current.Resolve <IScheduleTaskService>(); var scheduleTask = scheduleTaskService.GetTaskByType(this._type); if (scheduleTask != null) { scheduleTask.LastStartUtc = this.LastStartUtc; scheduleTask.LastEndUtc = this.LastEndUtc; scheduleTask.LastSuccessUtc = this.LastSuccessUtc; scheduleTaskService.UpdateTask(scheduleTask); } } catch (Exception exc) { Debug.WriteLine(string.Format("Error saving schedule task datetimes. Exception: {0}", exc)); } this._isRunning = false; }
public ActionResult PluginLottery(Guid Id) { try { if (Id == Guid.Empty) { throw new OceanException("参数有误,请检查!"); } //if (MpUserID == Guid.Empty) //{ // string rawUrl = "http://wx.ssrcb.com/ScoreSys/PluginLottery?id=" + TempData["Id"]; // if (string.IsNullOrEmpty(RQuery["openid"])) // { // return Json(new { isOK = false, isLogin = true, error_code = "ERR_NotLogin", message = string.Format("https://open.weixin.qq.com/connect/oauth2/authorize?appid={0}&redirect_uri=http://wx.ssrcb.com/mpuser/autologin?refUrl={1}&response_type=code&scope=snsapi_base&state=STATE#wechat_redirect", MpCenterCache.AppID, rawUrl) }); // } //} ViewBag.Score_Plugin_Title = TempData["Score_Plugin_Title"]; ViewBag.Score_Plugin_StartDate = TempData["Score_Plugin_StartDate"]; ViewBag.Score_Plugin_EndDate = TempData["Score_Plugin_EndDate"]; ViewBag.Score_Plugin_Summary = TempData["Score_Plugin_Summary"]; ViewBag.Score_Plugin_ZeroPrize = TempData["Score_Plugin_ZeroPrize"]; ViewBag.Score_Plugin_UsePoint = TempData["Score_Plugin_UsePoint"]; ViewBag.Score_Plugin_FailsTimes = TempData["Score_Plugin_FailsTimes"]; ViewBag.Score_Plugin_FailsAddOdds = TempData["Score_Plugin_FailsAddOdds"]; IList <ScorePluginResult> scorePluginResultList = _scorePluginResultService.GetList("from ScorePluginResult where PluginId='" + Id.ToString() + "'"); ViewBag.ScorePluginResultList = scorePluginResultList; if (scorePluginResultList != null) { IEnumerable <ScorePluginResult> myplugin_SubmitList = _scorePluginResultService.GetList("from ScorePluginResult where PluginId='" + Id.ToString() + "' and MpUserId='" + this.MpUserID + "' order by CreateDate desc"); ViewBag.MyPlugin_SubmitList = myplugin_SubmitList; } } catch (System.Exception ex) { Log4NetImpl.Write("ScoreSys_PluginLottery:" + ex.Message); return(View("Index")); } return(View("Lottery")); }
protected override void OnActionExecuting(ActionExecutingContext filterContext) { base.OnActionExecuting(filterContext); try { if (!string.IsNullOrEmpty(this.OpenID)) { CurrentFunongbao = _funongbaoService.GetFunongbaoByOpenid(this.OpenID); Log4NetImpl.Write("CurrentFunongbao:"); if (CurrentFunongbao == null || CurrentFunongbao.IsAuth == 0) { filterContext.Result = new RedirectResult("/IdentAuth/Index?refUrl=" + this.Request.Url); } else { Log4NetImpl.Write("ViewBag.UserName:"******"MpUser:"******"先生" : "女士"); } Log4NetImpl.Write("MpUser: end"); } Log4NetImpl.Write("CurrentFunongbao:"); } } } catch (Exception ex) { Log4NetImpl.Write(ex.ToString()); throw new OceanException(ex.Message); } }
/// <summary> /// 实现自己的任务逻辑 /// </summary> public void Execute() { ////测试 //FunongbaoApply apply = _funongbaoApplyService.GetUnique(f => f.Id == new Guid("9A904BD7-5556-4EB2-A493-6C3DC85CB4BD") && f.NoticeStatus == 0); //if (apply != null) //{ // _mpUserService.SendMessage(apply.RFunongbao.OpenId, "尊敬的" + apply.RFunongbao.Name + ",您本季度有新的额度可供调整。\r\n" + "<a href=\"" + BaseConfigs.GetConfig().WebUrl + "/funongbao/apply\">点击这里,立即申请</a>");//"点击菜单->福农宝->调额申请"); // apply.NoticeStatus = 1; // _funongbaoApplyService.Update(apply); //} //尊敬的**,您本季度有新的额度可供调整。 //点击这里,立即申请 if (DateRuleList.DateRules.Where(d => d.ApplyMonth == DateTime.Now.Month).Count() > 0 && DateTime.Now.Day == DateRule.ApplyStartDay) { Log4NetImpl.Write("执行任务!" + DateTime.Now); //PagedList<FunongbaoApply> applys = _funongbaoApplyService.GetForTaskUserList(1, 100); //if (applys != null) //{ // foreach (FunongbaoApply apply in applys) // { // apply.NoticeStatus = 1; // _mpUserService.SendMessage(apply.RFunongbao.OpenId, "尊敬的" + apply.RFunongbao.Name + ",您本季度有新的额度可供调整。\r\n" + "点击菜单->福农宝->调额申请");//"<a href=\"" + BaseConfigs.GetConfig().WebUrl + "/funongbao/apply\">点击这里,立即申请</a>"); // _funongbaoApplyService.Update(apply); // } //} //for (int i = 1; i < applys.TotalPageCount; i++) //{ // applys = _funongbaoApplyService.GetForTaskUserList((i + 1), 100); // if (applys != null) // { // foreach (FunongbaoApply apply1 in applys) // { // apply1.NoticeStatus = 1; // _mpUserService.SendMessage(apply1.RFunongbao.OpenId, "尊敬的" + apply1.RFunongbao.Name + ",您本季度有新的额度可供调整。\r\n" + "点击菜单->福农宝->调额申请");//"<a href=\"" + BaseConfigs.GetConfig().WebUrl + "/funongbao/apply\">点击这里,立即申请</a>"); // _funongbaoApplyService.Update(apply1); // } // } //} } }