private void unsubscribwexinuser(HttpContext context) { DateTime timenow = DateTime.Now; string openID = context.Request.Form["OpenID"]; if (string.IsNullOrEmpty(openID)) { LogHelper.WriteError(LogModule, "添加微信用户失败。缺少参数:OpenID", null); WebUtil.WriteJson(context, null); return; } var user = Wechat_User.GetWechat_UserByUserOpenID(openID); if (user != null) { user.UnSubscribeTime = timenow; user.SubScribe = 0; Wechat_Log log = new Wechat_Log() { OpenID = openID, OperationTime = timenow, Operation = "取消关注", }; using (SqlHelper helper = new SqlHelper()) { try { helper.BeginTransaction(); user.Save(helper); log.Save(helper); helper.Commit(); } catch (Exception ex) { helper.Rollback(); LogHelper.WriteError(LogModule, "visit: unsubscribwexinuser", ex); } } } WebUtil.WriteJson(context, "OK"); }
private void qrscenescan(HttpContext context) { string result = string.Empty; string openID = context.Request.Params["OpenID"]; string qrSceneIDStr = context.Request.Params["QrSceneID"]; int sceneID = 0; int.TryParse(qrSceneIDStr, out sceneID); if (sceneID > 0 && !string.IsNullOrEmpty(openID)) { var record = Wechat_QrScene.GetWechat_QrScene(sceneID); if (record == null) { WebUtil.WriteJson(context, null); return; } bool isChanged = false; var wUser = Wechat_User.GetWechat_UserByUserOpenID(openID); if (wUser == null) { isChanged = true; wUser = new Wechat_User(); wUser.OpenId = openID; } if (wUser.FromQrID <= 0) { wUser.FromQrID = record.ID; isChanged = true; } if (isChanged) { wUser.Save(); } string Token = context.Request.Params["accesstoken"]; result = SaveWechatProject(openID, record.ProjectID); } WebUtil.WriteJson(context, result); }
private Wechat_User CreateWechatUser(HttpContext context, out string result) { result = string.Empty; string openID = context.Request.Form["OpenID"]; string city = context.Request.Form["City"]; string country = context.Request.Form["Country"]; string nickName = context.Request.Form["NickName"]; string headImgUrl = context.Request.Form["HeadImgUrl"]; string province = context.Request.Form["Province"]; string language = context.Request.Form["Language"]; string sex = context.Request.Form["Sex"]; string subScribe = context.Request.Form["SubScribe"]; string subscribeTimeStamp = context.Request.Form["SubscribeTime"]; //todo:绑定微信粉丝来源 string qrScene = context.Request.Form["QrScene"]; string ticket = context.Request.Form["Ticket"]; DateTime subscribeTime = DateTime.Now; if (!string.IsNullOrEmpty(subscribeTimeStamp)) { subscribeTime = new DateTime(1970, 1, 1).AddSeconds(Convert.ToInt32(subscribeTimeStamp)); } if (string.IsNullOrEmpty(openID)) { LogHelper.WriteError(LogModule, "添加微信用户失败。缺少参数:OpenID", null); return(null); } if (string.IsNullOrEmpty(nickName)) { LogHelper.WriteError(LogModule, "添加微信用户失败。缺少参数:NickName", null); return(null); } var user = Wechat_User.GetWechat_UserByUserOpenID(openID); if (user == null) { user = new Foresight.DataAccess.Wechat_User() { OpenId = openID, }; } if (!string.IsNullOrEmpty(qrScene)) { int qrSceneID = 0; int.TryParse(qrScene, out qrSceneID); if (qrSceneID > 0) { var scene = Wechat_QrScene.GetWechat_QrScene(qrSceneID); if (scene != null) { if (user.FromQrID <= 0) { user.FromQrID = scene.ID; } result = SaveWechatProject(openID, scene.ProjectID); } } } user.SubScribe = int.Parse(subScribe); if (user.SubScribe != 0) { user.City = city; user.Country = country; user.NickName = nickName; user.HeadImgUrl = headImgUrl; user.Province = province; user.Sex = int.Parse(sex); user.SubscribeTime = subscribeTime; user.UnSubscribeTime = DateTime.MinValue; user.Language = language; } else { if (user.UnSubscribeTime == DateTime.MinValue) { user.UnSubscribeTime = DateTime.Now; } } if (user.FirstSubScribeTime == DateTime.MinValue) { user.FirstSubScribeTime = user.SubscribeTime; } user.Save(); return(user); }