//获取微信人员信息 public ActionResult GetWxUserInfo() { string wxid = Request["WXID"]; var temp = WXXUserInfoService.LoadEntities(x => x.WXID == wxid).FirstOrDefault(); return(Json(temp, JsonRequestBehavior.AllowGet)); }
//微信小程序登录积分 public ActionResult AddScoreNum() { string wxid = Request["WXID"]; var temp = WXXUserInfoService.LoadEntities(x => x.WXID == wxid).FirstOrDefault(); if (temp != null) { var dateDay = temp.EditScoreTime.GetValueOrDefault().ToLongDateString(); if (dateDay == DateTime.Now.ToLongDateString()) { return(Json(new { ret = "no", msg = "您今日已签过到了~" }, JsonRequestBehavior.AllowGet)); } var score = T_BoolItemService.LoadEntities(x => x.ThisItem == 0).First().@int; temp.ScoreNum = temp.ScoreNum + score; temp.EditScoreTime = DateTime.Now; if (WXXUserInfoService.EditEntity(temp)) { return(Json(new { ret = "ok" }, JsonRequestBehavior.AllowGet)); } else { return(Json(new { ret = "no", msg = "签到失败!请联系客服" }, JsonRequestBehavior.AllowGet)); } } else { return(Json(new { ret = "no", msg = "我此微信用户登录信息" }, JsonRequestBehavior.AllowGet)); } }
public string SendTempletMessge(long uid, string TsText) { //var user = UserInfoService.LoadEntities(x => x.ID == uid).FirstOrDefault(); var rtmp = WXXUserInfoService.LoadEntities(x => x.UID == uid).FirstOrDefault(); if (rtmp == null) { return(null); } string strReturn = string.Empty; try { #region 获取access_token string apiurl = "https://api.weixin.qq.com/cgi-bin/token?grant_type=client_credential&appid=wxc67a3c17709458e5&secret=34a9647b2c1120e443cdf14b1a0d6b46"; WebRequest request = WebRequest.Create(@apiurl); request.Method = "POST"; WebResponse response = request.GetResponse(); Stream stream = response.GetResponseStream(); Encoding encode = Encoding.UTF8; StreamReader reader = new StreamReader(stream, encode); string detail = reader.ReadToEnd(); var jd = JsonConvert.DeserializeObject <WXApi>(detail); string token = (String)jd.access_token; DateTime dtime = MvcApplication.GetT_time(); var wxx = WXX_FormIDService.LoadEntities(x => x.AddUserID == uid && x.StopTime > dtime).DefaultIfEmpty(); WXX_FormID Minwxx = new WXX_FormID(); if (wxx.ToList()[0] != null) { Minwxx = wxx.OrderBy(x => x.StopTime).FirstOrDefault(); } else { return(null); } #endregion #region 组装信息推送,并返回结果(其它模版消息于此类似) string url = "https://api.weixin.qq.com/cgi-bin/message/wxopen/template/send?access_token=" + token; string temp = "{\"touser\": \"" + rtmp.WXID + "\"," + "\"template_id\": \"3zN541eDUYsMVVZnqf6GEuZr7KDdOC1jamBsgEKHXY0\", " + "\"topcolor\": \"#FF0000\", " + "\"form_id\": \"" + Minwxx.FormID + "\"," + "\"data\": " + "{\"first\": {\"value\": \"您好,您有一条咨询通知信息\"}," + "\"keyword1\": { \"value\": \"" + TsText + "\"}," + "\"remark\": {\"value\": \"\" }}}"; #endregion //核心代码 GetResponseData(temp, @url); strReturn = "推送成功"; //删除使用过的formid WXX_FormIDService.DeleteEntity(Minwxx); } catch (Exception ex) { strReturn = ex.Message; } return(strReturn); }
//获取微信用户列表 public ActionResult GetWxUserList() { var temp = WXXUserInfoService.LoadEntities(x => x.ID > 0).DefaultIfEmpty(); var rtmp = from a in temp select new { ID = a.ID, Name = a.PersonName }; return(Json(rtmp, JsonRequestBehavior.AllowGet)); }
//获取充值历史纪录 public ActionResult GetOrderHistory() { string wxid = Request["WXID"]; var uid = WXXUserInfoService.LoadEntities(x => x.WXID == wxid).First().ID; var temp = OrderHistoryService.LoadEntities(x => x.Del == false && x.Uid == uid).DefaultIfEmpty().ToList(); if (temp != null && temp[0] != null) { return(Json(new { ret = "ok", rows = temp }, JsonRequestBehavior.AllowGet)); } else { return(Json(new { ret = "no" }, JsonRequestBehavior.AllowGet)); } }
//查找ID public ActionResult SechFromId() { string wxid = Request["WXID"]; long uid = WXXUserInfoService.LoadEntities(x => x.WXID == wxid).First().ID; DateTime dtime = MvcApplication.GetT_time(); var wxx = WXX_FormIDService.LoadEntities(x => x.AddUserID == uid && x.StopTime > dtime).DefaultIfEmpty(); if (wxx.ToList()[0] != null) { var Minwxx = wxx.OrderBy(x => x.StopTime).FirstOrDefault(); return(Json(new { ret = "ok", Minwx = Minwxx }, JsonRequestBehavior.AllowGet)); } else { return(Json(new { ret = "no", str = "查询信息空~" }, JsonRequestBehavior.AllowGet)); } }
//获取消息并推送 public ActionResult ToTsMessage() { var uid = Request["BeiTsPerson"] == null?0:Convert.ToInt64(Request["BeiTsPerson"]); var text = Request["TsText"]; string Message = ""; if (uid == 0) { var temp = WXXUserInfoService.LoadEntities(x => x.ID > 0).DefaultIfEmpty().ToList(); if (temp != null && temp[0] != null) { foreach (var a in temp) { Message = SendTempletMessge(a.ID, text); } if (Message == "推送成功") { WXXTsMessage wtm = new WXXTsMessage(); wtm.Message = text; wtm.ToAllUser = true; wtm.AddTime = DateTime.Now; WXXTsMessageService.AddEntity(wtm); return(Json(new { ret = "ok", msg = Message }, JsonRequestBehavior.AllowGet)); } } return(Json(new { ret = "no" }, JsonRequestBehavior.AllowGet)); } else { Message = SendTempletMessge(uid, text); if (Message == "推送成功") { WXXTsMessage wtm = new WXXTsMessage(); wtm.Message = text; wtm.ToAllUser = false; wtm.ToOneUser = WXXUserInfoService.LoadEntities(x => x.ID == uid).FirstOrDefault().WXID; wtm.AddTime = DateTime.Now; WXXTsMessageService.AddEntity(wtm); return(Json(new { ret = "ok", msg = Message }, JsonRequestBehavior.AllowGet)); } } return(Json(new { ret = "no" }, JsonRequestBehavior.AllowGet)); }
public ActionResult CheckLogin() { string wxid = Request["WXID"]; var temp = WXXUserInfoService.LoadEntities(x => x.WXID == wxid).FirstOrDefault(); if (temp != null) { int state = 0; if (temp.PersonName != Request["nickName"]) { temp.PersonName = Request["nickName"]; state = 1; } if (temp.Gender != Convert.ToInt32(Request["gender"])) { temp.Gender = Convert.ToInt32(Request["gender"]); state = 1; } if (temp.Photo != Request["avatarUrl"]) { temp.Photo = Request["avatarUrl"]; state = 1; } if (state == 1) { WXXUserInfoService.EditEntity(temp); } return(Json(new { ret = "ok", msg = "登陆成功!!", userInfo = temp }, JsonRequestBehavior.AllowGet)); } else { WXXUserInfo wui = new WXXUserInfo(); wui.WXID = wxid; wui.PersonName = Request["nickName"]; wui.Gender = Convert.ToInt32(Request["gender"]); wui.Photo = Request["avatarUrl"]; wui.ScoreNum = 0; wui.DEL = 0; WXXUserInfo wxxui = WXXUserInfoService.AddEntity(wui); return(Json(new { ret = "ok", msg = "登陆成功!", userInfo = wxxui }, JsonRequestBehavior.AllowGet)); } }
//创建ID public ActionResult AddFromId() { string wxid = Request["WXID"]; long uid = WXXUserInfoService.LoadEntities(x => x.WXID == wxid).First().ID; WXX_FormID wfm = new WXX_FormID(); wfm.FormID = Request["FromID"].ToString(); wfm.AddTime = MvcApplication.GetT_time(); wfm.AddUserID = uid; wfm.CanUse = 0; wfm.StopTime = wfm.AddTime.AddDays(7); try { WXX_FormIDService.AddEntity(wfm); return(Json(new { ret = "ok" }, JsonRequestBehavior.AllowGet)); } catch (Exception e) { return(Json(new { ret = "err", str = e.ToString() }, JsonRequestBehavior.AllowGet)); } }