protected void GetHeadImg(M_UserInfo mu) { if (mu == null || mu.IsNull || mu.UserID < 1) { } else { uappMod = uappBll.SelModelByUid(mu.UserID, "wechat"); M_WX_User wuserMod = new M_WX_User(); if (uappMod != null) { try { wuserMod = wxapi.GetWxUserModel(uappMod.OpenID); } catch (Exception ex) { wxapi.GetToken(); wuserMod = wxapi.GetWxUserModel(uappMod.OpenID); throw ex; } if (wuserMod != null) { Response.Write("{\"nickname\":\"" + wuserMod.Name + "\",\"headimgurl\":\"" + wuserMod.HeadImgUrl + "\"}"); } } } }
public IActionResult WXUser_API() { WxAPI api = WxAPI.Code_Get(AppId); string action = GetParam("action"); string result = ""; switch (action) { case "update": string openid = GetParam("openid"); M_WX_User oldmod = wxuserBll.SelForOpenid(openid); if (oldmod != null && oldmod.ID > 0) { M_WX_User usermod = api.GetWxUserModel(openid); usermod.ID = oldmod.ID; usermod.CDate = DateTime.Now; usermod.AppId = AppId; wxuserBll.UpdateByID(usermod); result = JsonConvert.SerializeObject(usermod); } else { result = "-1"; } break; default: break; } return(Content(result)); }
/// <summary> /// 系统事件,如订阅等处理 /// </summary> public void WxEventHandler(M_WxTextMsg reqMod) { M_WX_User userMod = null; errmsg += ",事件:" + reqMod.Event; switch (reqMod.Event) { case "subscribe": userMod = api.GetWxUserModel(reqMod.FromUserName); userMod.CDate = DateTime.Now; userMod.AppId = api.AppId.ID; wxuserBll.Insert(userMod); M_WxImgMsg msgmod = JsonConvert.DeserializeObject <M_WxImgMsg>(api.AppId.WelStr); msgmod.ToUserName = reqMod.FromUserName; msgmod.FromUserName = reqMod.ToUserName; if (string.IsNullOrEmpty(msgmod.Articles[0].PicUrl)) //如未设置图片则以纯文本格式发送,纯文本支持内置超链接 { M_WxTextMsg textMod = ImageToText(msgmod); RepToClient(textMod.ToXML()); } else { RepToClient(msgmod.ToXML()); } break; case "unsubscribe": wxuserBll.DelByOpenid(api.AppId.ID, reqMod.FromUserName); break; default: break; } }
protected void Page_Init(object sender, EventArgs e) { M_UserInfo mu1 = buser.GetLogin(); if (mu1 == null || mu1.IsNull || mu1.UserID < 1) { Response.Redirect("/wxpromo.aspx?appid=2&r=/User/Default2.aspx"); } else if (mu1.Status != 0) { function.WriteErrMsg("你的帐户未通过验证或被锁定,请与网站管理员联系", "/wxpromo.aspx?appid=2&r=/User/Default2.aspx"); } if (buser.CheckLogin()) { uappMod = uappBll.SelModelByUid(mu1.UserID, "wechat"); if (uappMod != null) { M_WX_User wxuserMod = wxuserBll.SelForOpenid(2, uappMod.OpenID); if (wxuserMod == null) { WxAPI wxapi = WxAPI.Code_Get(2); string apiurl = "https://api.weixin.qq.com/cgi-bin/"; string result = APIHelper.GetWebResult(apiurl + "user/info?access_token=" + wxapi.AccessToken + "&openid=" + uappMod.OpenID); JObject obj = JsonConvert.DeserializeObject <JObject>(result); if (obj["errcode"].ToString() == "40003") { buser.ClearCookie(); Response.Redirect("/wxpromo.aspx?appid=2&r=/User/Default2.aspx"); } } } } else if (badmin.CheckLogin()) { M_AdminInfo adminMod = badmin.GetAdminLogin(); M_UserInfo mu = buser.GetUserByName(adminMod.AdminName, adminMod.AdminPassword); if (mu == null || mu.IsNull || mu.UserID < 1) { Response.Redirect("/User/Login.aspx"); } else if (mu.Status != 0) { function.WriteErrMsg("你的帐户未通过验证或被锁定,请与网站管理员联系", "/wxpromo.aspx?appid=2&r=/User/Default2.aspx"); } else { buser.SetLoginState(mu); } } else { B_User.CheckIsLogged(Request.RawUrl); } }
//用户文件信息处理 public string UserTextDeal(M_WxTextMsg reqMod) { M_WX_ReplyMsg rpMod = rpBll.SelByFileAndDef(appBll.GetAppByWxNo(reqMod.ToUserName).ID, reqMod.Content); M_WxImgMsg msgMod = new M_WxImgMsg(); msgMod.ToUserName = reqMod.FromUserName; msgMod.FromUserName = reqMod.ToUserName; //如果未匹配到则直接返回 string result = ""; if (rpMod == null) { M_WxImgMsg msgmod1 = new M_WxImgMsg(); msgmod1.ToUserName = reqMod.FromUserName; msgmod1.FromUserName = reqMod.ToUserName; M_WX_ReplyMsg rpMod1 = new M_WX_ReplyMsg(); rpMod1 = rpBll.SelByFileAndDef(appBll.GetAppByWxNo(reqMod.ToUserName).ID, "头图"); if (rpMod1 != null) { M_WXImgItem item = JsonConvert.DeserializeObject <M_WXImgItem>(rpMod1.Content); msgmod1.Articles.Add(new M_WXImgItem() { Title = item.Title, Url = item.Url, Description = item.Description, PicUrl = item.PicUrl }); } RepToClient(msgmod1.ToXML()); } else//如果匹配到 { M_WXImgItem item = JsonConvert.DeserializeObject <M_WXImgItem>(rpMod.Content); if (item.Description.Contains("{$UserName}")) { M_WX_User wuserMod = api.GetWxUserModel(reqMod.FromUserName); item.PicUrl = wuserMod.HeadImgUrl; item.Description = item.Description.Replace("{$UserName}", wuserMod.Name); } msgMod.Articles.Add(item); switch (rpMod.MsgType) { case "0": M_WxTextMsg textMod = ImageToText(msgMod); result = textMod.ToXML(); break; case "1": result = msgMod.ToXML(); break; } } return(result); }
protected void Page_Load(object sender, EventArgs e) { if (!IsPostBack) { M_UserInfo mu = buser.GetLogin(); int appid = DataConverter.CLng(Request.QueryString["appid"]); if (mu != null && mu.UserID > 0) { try { TimeSpan ts = DateTime.UtcNow - new DateTime(1970, 1, 1, 0, 0, 0, 0); timestr = Convert.ToInt64(ts.TotalSeconds).ToString(); if (appid == 0) { appid = 1; } WxAPI wxapi = WxAPI.Code_Get(appid); appMod = appBll.SelReturnModel(appid); uappMod = uappBll.SelModelByUid(mu.UserID, "wechat"); wuserMod = wxapi.GetWxUserModel(uappMod.OpenID); userface.Src = wuserMod.HeadImgUrl; userface.Alt = wuserMod.Name; NickName.Text = wuserMod.Name; string jsapi_ticket = APIHelper.GetWebResult("https://api.weixin.qq.com/cgi-bin/ticket/getticket?access_token=" + wxapi.AccessToken + "&type=jsapi"); JObject jsapi_obj = (JObject)JsonConvert.DeserializeObject(jsapi_ticket); string stringA = "jsapi_ticket=" + jsapi_obj["ticket"].ToString() + "&noncestr=" + nonceStr + "×tamp=" + timestr + "&url=" + Request.Url.AbsoluteUri; paySign = EncryptHelper.SHA1(stringA).ToLower(); string jsapi_ticket1 = APIHelper.GetWebResult("https://api.weixin.qq.com/cgi-bin/qrcode/create?access_token=" + wxapi.AccessToken + "&type=jsapi", "POST", "{\"action_name\":\"QR_LIMIT_STR_SCENE\",\"action_info\":{\"scene\":{\"scene_str\":\"" + mu.UserID + "\"}}}"); if (jsapi_ticket1 != "") { JObject jsapi_obj1 = (JObject)JsonConvert.DeserializeObject(jsapi_ticket1); Image1.ImageUrl = "https://mp.weixin.qq.com/cgi-bin/showqrcode?ticket=" + jsapi_obj1["ticket"]; } } catch (Exception ex) { } } else { Response.Redirect("/wxpromo.aspx?r=/User"); } } }
protected void Page_Load(object sender, EventArgs e) { if (!IsPostBack) { WxAPI wxapi = WxAPI.Code_Get(); string code = Request.QueryString["code"] ?? ""; if (string.IsNullOrEmpty(code)) { return; } string result = APIHelper.GetWebResult("https://api.weixin.qq.com/sns/oauth2/access_token?appid=" + wxapi.AppId.APPID + "&secret=" + wxapi.AppId.Secret + "&code=" + code + "&grant_type=authorization_code"); JObject obj = (JObject)JsonConvert.DeserializeObject(result); string openid = obj["openid"].ToString(); Appinfo umod = appBll.SelModelByOpenID(openid, "wechat"); M_UserInfo mu = new M_UserInfo(); if (umod == null) { umod = new Appinfo(); M_WX_User wuMod = wxuserBll.SelForOpenid(wxapi.AppId.ID, openid); if (wuMod == null) { wuMod = wxapi.GetWxUserModel(openid); wxuserBll.Insert(wuMod); } mu.UserName = "******" + DateTime.Now.ToString("yyyyMMddHHmmss") + function.GetRandomString(2).ToLower(); mu.UserPwd = StringHelper.MD5(function.GetRandomString(6)); mu.Email = function.GetRandomString(10) + "@random.com"; mu.HoneyName = wuMod.Name; mu.TrueName = wuMod.Name; mu.UserID = buser.Add(mu); umod.UserID = mu.UserID; umod.SourcePlat = "wechat"; umod.OpenID = wuMod.OpenID; appBll.Insert(umod); M_Uinfo mubase = new M_Uinfo(); mubase.UserId = mu.UserID; buser.AddBase(mubase); } else { mu = buser.SelReturnModel(umod.UserID); } //设置为登录状态 buser.SetLoginState(mu); Response.Redirect(RUrl); } }
protected void Page_Load(object sender, EventArgs e) { ExHelper.CheckUserAuth("wechat"); M_CommonData storeMod = ExHelper.Store2_User(); if (DataConverter.CLng(storeMod.SpecialID) < 1) { function.WriteErrMsg("尚未绑定微信号", "/Extend/WX/WXConfig.aspx"); } AppId = Convert.ToInt32(storeMod.SpecialID); api = WxAPI.Code_Get(AppId); if (function.isAjax()) { string action = Request.Form["action"]; string result = ""; switch (action) { case "update": M_WX_User oldmod = wxuserBll.SelForOpenid(Request.Form["openid"]); if (oldmod != null && oldmod.ID > 0) { M_WX_User usermod = api.GetWxUserModel(Request.Form["openid"]); usermod.ID = oldmod.ID; usermod.CDate = DateTime.Now; usermod.AppId = api.AppId.ID; wxuserBll.UpdateByID(usermod); result = JsonConvert.SerializeObject(usermod); } else { result = "-1"; } break; default: break; } Response.Write(result); Response.Flush(); Response.End(); } if (!IsPostBack) { MyBind(); } }
protected void GetHeadImg(M_UserInfo mu) { int appid = 1; if (AppID > 0) { appid = AppID; } WxAPI wxapi = WxAPI.Code_Get(appid); if (mu == null || mu.IsNull || mu.UserID < 1) { } else { uappMod = uappBll.SelModelByUid(mu.UserID, "wechat"); M_WX_User wuserMod = new M_WX_User(); if (uappMod != null) { try { wuserMod = wxapi.GetWxUserModel(uappMod.OpenID); if (string.IsNullOrEmpty(wuserMod.Name)) { wxapi.GetToken(); wuserMod = wxapi.GetWxUserModel(uappMod.OpenID); } } catch (Exception ex) { wxapi.GetToken(); wuserMod = wxapi.GetWxUserModel(uappMod.OpenID); throw ex; } if (wuserMod != null) { Response.Write("{\"nickname\":\"" + wuserMod.Name + "\",\"headimgurl\":\"" + wuserMod.HeadImgUrl + "\"}"); } } } }
/// <summary> /// 获取粉丝信息模型,该接口需要公众号已认证,否则无法获取粉丝信息 /// </summary> public M_WX_User GetWxUserModel(string openid) { M_WX_User userMod = new M_WX_User(); userMod.OpenID = openid; string result = APIHelper.GetWebResult(apiurl + "user/info?access_token=" + AccessToken + "&openid=" + openid); JObject obj = JsonConvert.DeserializeObject <JObject>(result); try { userMod.Name = obj["nickname"].ToString(); userMod.Sex = DataConverter.CLng(obj["sex"]); userMod.City = obj["city"].ToString(); userMod.Province = obj["province"].ToString(); userMod.Country = obj["country"].ToString(); userMod.HeadImgUrl = obj["headimgurl"].ToString(); userMod.Groupid = DataConverter.CLng(obj["groupid"]); } catch (Exception ex) { ZLLog.L("GetWxUserModel出错,原因:" + ex.Message + ",返回:" + result); } return(userMod); }
/// <summary> /// 系统事件,如订阅等处理 /// </summary> public void WxEventHandler(M_WxTextMsg reqMod) { M_WX_User userMod = null; errmsg += ",事件:" + reqMod.Event; switch (reqMod.Event.ToLower()) { case "subscribe": userMod = api.GetWxUserModel(reqMod.FromUserName); userMod.CDate = DateTime.Now; userMod.AppId = api.AppId.ID; wxuserBll.Insert(userMod); M_WxImgMsg msgmod = JsonConvert.DeserializeObject <M_WxImgMsg>(api.AppId.WelStr); msgmod.ToUserName = reqMod.FromUserName; msgmod.FromUserName = reqMod.ToUserName; if (string.IsNullOrEmpty(msgmod.Articles[0].PicUrl)) //如未设置图片则以纯文本格式发送,纯文本支持内置超链接 { M_WxTextMsg textMod = ImageToText(msgmod); RepToClient(textMod.ToXML()); } else { RepToClient(msgmod.ToXML()); } //关注时发送多条信息 //System.Threading.ThreadPool.QueueUserWorkItem(new System.Threading.WaitCallback(SendMsg), reqMod); break; case "unsubscribe": wxuserBll.DelByOpenid(api.AppId.ID, reqMod.FromUserName); break; case "location": //用户进入公众号(包含定位信息) break; default: break; } }
protected void Page_Load(object sender, EventArgs e) { if (!IsPostBack) { M_Design_Album albumMod = albumBll.SelReturnModel(Mid); M_UserInfo mu = buser.GetSelect(albumMod.UserID); string username = mu.UserName; appMod = appBll.SelModelByUid(mu.UserID, "wechat"); if (appMod != null) { wxMod = wxBll.SelForOpenid(1, appMod.OpenID); if (wxMod != null) { username = wxMod.Name; } } albumMod.AlbumName += "-来自[" + username + "]的动力逐浪微相册"; string html = SafeSC.ReadFileStr("/design/album/tlps/" + albumMod.UseTlp + "/photo.html"); html = html.Replace("\"{album}\"", JsonConvert.SerializeObject(albumMod)); Response.Clear(); Response.Write(html); Response.End(); } }
protected void Page_Init(object sender, EventArgs e) { if (buser.CheckLogin()) { M_UserInfo mu = buser.GetLogin(); if (mu == null || mu.IsNull || mu.UserID < 1) { Response.Redirect("/wxpromo.aspx?r=" + Request.RawUrl); //Response.Redirect("/User/Login.aspx"); } else if (mu.Status != 0) { function.WriteErrMsg("你的帐户未通过验证或被锁定,请与网站管理员联系", "/User/Login.aspx"); } uappMod = uappBll.SelModelByUid(mu.UserID, "wechat"); if (uappMod != null) { M_WX_User wxuserMod1 = wxuserBll.SelForOpenid(1, uappMod.OpenID); M_WX_User wxuserMod2 = wxuserBll.SelForOpenid(2, uappMod.OpenID); if (wxuserMod1 != null) { footer_div1.Visible = true; } if (wxuserMod2 != null) { footer_div2.Visible = true; } if (wxuserMod1 == null && wxuserMod2 == null) { footer_div1.Visible = true; } } } else { B_User.CheckIsLogged(Request.RawUrl); } }
protected void Page_Load(object sender, EventArgs e) { api = WxAPI.Code_Get(AppId); if (function.isAjax()) { string action = Request.Form["action"]; string result = ""; switch (action) { case "update": M_WX_User oldmod = wxuserBll.SelForOpenid(AppId, Request.Form["openid"]); if (oldmod != null && oldmod.ID > 0) { M_WX_User usermod = api.GetWxUserModel(Request.Form["openid"]); usermod.ID = oldmod.ID; usermod.CDate = DateTime.Now; usermod.AppId = AppId; wxuserBll.UpdateByID(usermod); result = JsonConvert.SerializeObject(usermod); } else { result = "-1"; } break; default: break; } Response.Write(result); Response.Flush(); Response.End(); } if (!IsPostBack) { MyBind(); string alias = " [公众号:" + api.AppId.Alias + "]"; Call.SetBreadCrumb(Master, "<li><a href='" + CustomerPageAction.customPath2 + "Main.aspx'>工作台</a></li><li><a href='" + CustomerPageAction.customPath2 + "WeiXin/Home.aspx'>移动微信</a></li><li class='active'>粉丝管理" + alias + "</li>"); } }
public void MyBind() { DataTable dt = new DataTable(); M_UserInfo mu = buser.GetLogin(); switch (SType) { case 0: //订单 orderMod = orderBll.SelModelByOrderNo(OrderNo); //Total_L.Text = orderMod.Balance_price.ToString("f2") + "+" + orderMod.Freight.ToString("f2") + "=" + orderMod.Ordersamount.ToString("f2") + "元 (金额+运费)"; labelmoney01.Text = orderMod.Receivablesamount.ToString("f2"); ExpressNum_T.Text = orderMod.ExpressNum; ExpressDelivery_T.Text = orderMod.ExpressDelivery; if (orderMod == null || orderMod.id == 0) { function.WriteErrMsg("订单不存在"); } if (orderMod.Userid != mu.UserID) { function.WriteErrMsg("该订单不属于你,无法查看"); } dt = SelByOrderID(orderMod.id); price = orderMod.Balance_price; fare = orderMod.Freight; allamount = orderMod.Ordersamount; DataTable dt1 = SqlHelper.ExecuteTable("select * from ZL_Payment where PaymentNum='" + orderMod.OrderNo + "' order by PayTime DESC"); if (dt1.Rows.Count > 0) { payMod = payBll.SelModelByPayNo(dt1.Rows[0]["PayNo"].ToString()); allamount = (double)payMod.MoneyPay; arrive = payMod.ArriveMoney; point = payMod.UsePoint; } Total_L.Text = price.ToString("f2") + " + " + fare.ToString("f2") + " - " + arrive.ToString("f2") + "-" + (point * 0.01).ToString("f2") + "(" + point + ")" + " = " + allamount.ToString("f2"); Total_L.Text = Total_L.Text + " (商品总价+运费-优惠券-积分兑换=总额)"; break; case 1: //购物车 dt = cartBll.GetCarProList(OrderNo); break; } if (orderMod.Paymentstatus != (int)M_OrderList.PayEnum.HasPayed) { PayUrl_A.Visible = true; DataTable dt1 = SqlHelper.ExecuteTable("select * from ZL_Payment where PaymentNum='" + orderMod.OrderNo + "' order by PayTime DESC"); string payurl = "&OrderCode=" + orderMod.OrderNo; if (dt1.Rows.Count > 0) { payurl = "&PayNo=" + dt1.Rows[0]["PayNo"]; } uappMod = uappBll.SelModelByUid(buser.GetLogin().UserID, "wechat"); if (uappMod != null) { M_WX_User wxuserMod1 = wxuserBll.SelForOpenid(1, uappMod.OpenID); M_WX_User wxuserMod2 = wxuserBll.SelForOpenid(2, uappMod.OpenID); if (wxuserMod1 != null && wxuserMod2 == null) { PayUrl_A.HRef = "/PayOnline/OrderPay.aspx?appid=1" + payurl; } else if (wxuserMod2 != null && wxuserMod1 == null) { PayUrl_A.HRef = "/PayOnline/OrderPay.aspx?appid=2" + payurl; } else if (wxuserMod1 == null && wxuserMod2 == null) { PayUrl_A.HRef = "/PayOnline/OrderPay.aspx?" + payurl; } } else { PayUrl_A.HRef = "/PayOnline/OrderPay.aspx?" + payurl; } } if (dt.Rows.Count > 0 && !string.IsNullOrEmpty(dt.Rows[0]["Additional"].ToString())) { User_Div.Visible = true; M_Cart_Travel model = JsonConvert.DeserializeObject <M_Cart_Travel>(dt.Rows[0]["Additional"].ToString()); List <M_Cart_Contract> modelList = new List <M_Cart_Contract>(); modelList.AddRange(model.Guest); modelList.AddRange(model.Contract); UserRPT.DataSource = modelList; UserRPT.DataBind(); } pronum = dt.Rows.Count; RPT.DataSource = dt; RPT.DataBind(); }
/// <summary> /// 系统事件,如订阅等处理 /// </summary> public void WxEventHandler(M_WxTextMsg reqMod) { M_WX_User userMod = null; errmsg += ",事件:" + reqMod.Event; switch (reqMod.Event.ToLower()) { case "subscribe": userMod = api.GetWxUserModel(reqMod.FromUserName); userMod.CDate = DateTime.Now; userMod.AppId = api.AppId.ID; wxuserBll.Insert(userMod); M_WxImgMsg msgmod = JsonConvert.DeserializeObject <M_WxImgMsg>(api.AppId.WelStr); msgmod.ToUserName = reqMod.FromUserName; msgmod.FromUserName = reqMod.ToUserName; int pid = DataConvert.CLng(reqMod.EventKey.Replace("qrscene_", "")); M_UserAPP uappMod1 = new M_UserAPP(); M_UserInfo mu1 = new M_UserInfo(); M_WX_User wuserMod = new M_WX_User(); M_Uinfo mubase = new M_Uinfo(); uappMod1 = uappBll.SelModelByOpenID(reqMod.FromUserName, "wechat"); wuserMod = api.GetWxUserModel(reqMod.FromUserName); if (uappMod1 != null) { mu1 = buser.GetUserByUserID(uappMod1.UserID); if (mu1 != null && mu1.UserID > 0) { mu1.TrueName = wuserMod.Name; try { string vpath = SiteConfig.SiteOption.UploadDir + "User/" + mu1.UserName + mu1.UserID + "/wxheadimg.jpg"; HttpHelper.DownFile(wuserMod.HeadImgUrl, vpath); mu1.UserFace = vpath; } catch (Exception ex) { ZLLog.L("微信更新头像错误,原因:" + ex.Message); } mu1.GroupID = 1; buser.UpdateByID(mu1); } else { mu1.UserName = "******" + DateTime.Now.ToString("yyyyMMddHHmmss") + function.GetRandomString(2).ToLower(); mu1.UserPwd = StringHelper.MD5(function.GetRandomString(6)); mu1.Email = function.GetRandomString(10) + "@wx.com"; mu1.Question = function.GetRandomString(5); mu1.Answer = function.GetRandomString(5); mu1.TrueName = wuserMod.Name; mu1.GroupID = 1; try { string vpath = SiteConfig.SiteOption.UploadDir + "User/" + mu1.UserName + mu1.UserID + "/wxheadimg.jpg"; HttpHelper.DownFile(wuserMod.HeadImgUrl, vpath); mu1.UserFace = vpath; } catch (Exception ex) { ZLLog.L("微信更新头像错误,原因:" + ex.Message); } mu1.UserID = buser.Add(mu1); uappMod1.UserID = mu1.UserID; uappMod1.SourcePlat = "wechat"; uappMod1.OpenID = reqMod.FromUserName; uappBll.UpdateByID(uappMod1); mubase.UserId = mu1.UserID; buser.AddBase(mubase); } } else { uappMod1 = new M_UserAPP(); mu1.UserName = "******" + DateTime.Now.ToString("yyyyMMddHHmmss") + function.GetRandomString(2).ToLower(); mu1.UserPwd = StringHelper.MD5(function.GetRandomString(6)); mu1.Email = function.GetRandomString(10) + "@wx.com"; mu1.Question = function.GetRandomString(5); mu1.Answer = function.GetRandomString(5); mu1.TrueName = wuserMod.Name; mu1.GroupID = 1; try { string vpath = SiteConfig.SiteOption.UploadDir + "User/" + mu1.UserName + mu1.UserID + "/wxheadimg.jpg"; HttpHelper.DownFile(wuserMod.HeadImgUrl, vpath); mu1.UserFace = vpath; } catch (Exception ex) { ZLLog.L("微信更新头像错误,原因:" + ex.Message); } mu1.UserID = buser.Add(mu1); uappMod1.UserID = mu1.UserID; uappMod1.SourcePlat = "wechat"; uappMod1.OpenID = reqMod.FromUserName; uappBll.Insert(uappMod1); mubase.UserId = mu1.UserID; buser.AddBase(mubase); } if (string.IsNullOrEmpty(msgmod.Articles[0].PicUrl)) //如未设置图片则以纯文本格式发送,纯文本支持内置超链接 { M_WxTextMsg textMod = ImageToText(msgmod); RepToClient(textMod.ToXML()); } else { RepToClient(msgmod.ToXML()); } //关注时发送多条信息 if (pid > 0) { System.Threading.ThreadPool.QueueUserWorkItem(new System.Threading.WaitCallback(SendMsg), reqMod); } //关注时发送多条信息 //System.Threading.ThreadPool.QueueUserWorkItem(new System.Threading.WaitCallback(SendMsg), reqMod); break; case "unsubscribe": wxuserBll.DelByOpenid(api.AppId.ID, reqMod.FromUserName); break; case "location": //用户进入公众号(包含定位信息) break; case "scan": M_UserAPP uappMod = new M_UserAPP(); M_UserInfo mu = new M_UserInfo(); M_WxTextMsg textMod2 = new M_WxTextMsg(); M_WX_User wuserMod1 = api.GetWxUserModel(reqMod.FromUserName); M_Uinfo mubase1 = new M_Uinfo(); textMod2.FromUserName = reqMod.ToUserName; textMod2.ToUserName = reqMod.FromUserName; textMod2.MsgType = "text"; textMod2.Content = ""; uappMod = uappBll.SelModelByOpenID(reqMod.FromUserName, "wechat"); if (uappMod != null) { mu = buser.GetUserByUserID(uappMod.UserID); M_UserInfo pmu = buser.GetUserByUserID(DataConvert.CLng(reqMod.EventKey)); if (mu != null && mu.UserID > 0) { if (DataConvert.CLng(mu.ParentUserID) > 0) { textMod2.Content = "您已绑定了推荐人不能重复绑定!"; RepToClient(textMod2.ToXML()); } else { if (mu.UserID == DataConvert.CLng(reqMod.EventKey)) { textMod2.Content = "您扫描的是您自己的二维码!"; } else { mu.ParentUserID = DataConvert.CLng(reqMod.EventKey).ToString(); if (pmu != null && pmu.UserID > 0) { string err = ""; try { if (CheckParentUser(pmu.UserID, mu.UserID, ref err)) { mu.ParentUserID = pmu.UserID.ToString(); if (buser.UpdateByID(mu)) { textMod2.Content = "您成功绑定了推荐人:" + pmu.TrueName + "!"; } else { textMod2.Content = "绑定推荐人失败!"; } } else { textMod2.Content = "绑定推荐失败,错误信息:" + err; } } catch (Exception ex) { textMod2.Content = "绑定推荐失败,错误信息:" + pmu.TrueName + "的推荐关系有循环!"; } } else { textMod2.Content = "绑定推荐失败,推荐人不存在!"; } } RepToClient(textMod2.ToXML()); } } } else { uappMod1 = new M_UserAPP(); mu.UserName = "******" + DateTime.Now.ToString("yyyyMMddHHmmss") + function.GetRandomString(2).ToLower(); mu.UserPwd = StringHelper.MD5(function.GetRandomString(6)); mu.Email = function.GetRandomString(10) + "@wx.com"; mu.Question = function.GetRandomString(5); mu.Answer = function.GetRandomString(5); mu.TrueName = wuserMod1.Name; mu.GroupID = 1; try { string vpath = SiteConfig.SiteOption.UploadDir + "User/" + mu.UserName + mu.UserID + "/wxheadimg.jpg"; HttpHelper.DownFile(wuserMod1.HeadImgUrl, vpath); mu.UserFace = vpath; } catch (Exception ex) { ZLLog.L("微信更新头像错误,原因:" + ex.Message); } M_UserInfo pmu = buser.GetUserByUserID(DataConvert.CLng(reqMod.EventKey)); if (pmu != null && pmu.UserID > 0) { mu.ParentUserID = reqMod.EventKey; } mu.UserID = buser.Add(mu); uappMod1.UserID = mu.UserID; uappMod1.SourcePlat = "wechat"; uappMod1.OpenID = reqMod.FromUserName; uappBll.Insert(uappMod1); mubase1.UserId = mu.UserID; buser.AddBase(mubase1); if (pmu != null && pmu.UserID > 0) { textMod2.Content = "您成功绑定了推荐人:" + pmu.TrueName + "!"; RepToClient(textMod2.ToXML()); } } break; default: break; } }
//获取订单操作按钮,分为已下单(未付款),已下单(已付款),已完结(显示) public string Getoperator(DataRowView dr) { M_OrderList orderMod = new M_OrderList(); string result = ""; int orderStatus = DataConverter.CLng(dr["OrderStatus"]); int payStatus = DataConverter.CLng(dr["Paymentstatus"]); int oid = Convert.ToInt32(dr["ID"]); int aside = Convert.ToInt32(dr["Aside"]); string orderNo = dr["OrderNo"].ToString(); //----------如果已经删除,则不执行其余的判断 if (aside != 0)//如果已删除,则不进行其余的判断 { result += "<div><a href='javascript:;' data-oid='" + oid + "' onclick='ConfirmAction(this,\"reconver\");'>还原订单</a></div>"; result += "<div><a href='javascript:;' data-oid='" + oid + "' onclick='ConfirmAction(this,\"realdel\");'>彻底删除</a></div>"; return(result); } if (payStatus == (int)M_OrderList.PayEnum.NoPay)//未付款,显示倒计时和付款链接 { bool isnormal = true; //订单过期判断 if (SiteConfig.ShopConfig.OrderExpired > 0) { int seconds = GetOrderUnix(dr); if (seconds <= 0) { result += "<span class='gray9'>订单关闭</span>"; isnormal = false; } else { result += "<span class='ordertime' data-time='" + seconds + "'></span>"; } } DataTable dt = SqlHelper.ExecuteTable("select * from ZL_Payment where PaymentNum='" + orderNo + "' order by PayTime DESC"); string payurl = "&OrderCode=" + orderNo; if (dt.Rows.Count > 0) { payurl = "&PayNo=" + dt.Rows[0]["PayNo"]; } //订单未完成,且为正常状态,显示付款 if (isnormal && OrderHelper.IsCanPay(dr.Row)) { uappMod = uappBll.SelModelByUid(buser.GetLogin().UserID, "wechat"); if (uappMod != null) { M_WX_User wxuserMod1 = wxuserBll.SelForOpenid(1, uappMod.OpenID); M_WX_User wxuserMod2 = wxuserBll.SelForOpenid(2, uappMod.OpenID); if (wxuserMod1 != null && wxuserMod2 == null) { result += "<br/><a href='/Payonline/OrderPay.aspx?appid=1" + payurl + "' class='btn btn-danger btn-sm'> 前往付款</a> "; } else if (wxuserMod2 != null && wxuserMod1 == null) { result += "<br/><a href='/Payonline/OrderPay.aspx?appid=2" + payurl + "' class='btn btn-danger btn-sm'> 前往付款</a> "; } else if (wxuserMod1 == null && wxuserMod2 == null) { result += "<br/><a href='/Payonline/OrderPay.aspx?" + payurl + "' class='btn btn-danger btn-sm'> 前往付款</a> "; } } else { result += "<br/><a href='/Payonline/OrderPay.aspx?" + payurl + "' class='btn btn-danger btn-sm'> 前往付款</a> "; } //DataTable dt = SqlHelper.ExecuteTable(CommandType.Text, "select * from ZL_Payment where PaymentNum='" + orderNo + "'", null); //if (dt.Rows.Count > 0) //{ // string redirect_uri = HttpUtility.UrlEncode("http://www.wodian8.com/Payonline/wxpayonline.aspx?PayNo=" + dt.Rows[0]["PayNo"].ToString()); // string url = "https://open.weixin.qq.com/connect/oauth2/authorize?appid=wx8c5c2dc7b10a36f3&redirect_uri=" + redirect_uri + "&response_type=code&scope=snsapi_userinfo&state=STATE#wechat_redirect"; // result += "<br/><a href='" + url + "' class='btn btn-danger btn-sm'> 前往付款</a> "; //} //else // result += "<br/><a href='/Payonline/OrderPay.aspx?OrderCode=" + orderNo + "' class='btn btn-danger btn-sm'> 前往付款</a> "; } result += "<span><a href='javascript:;' data-oid='" + oid + "' class='btn btn-warning btn-sm' onclick='ConfirmAction(this,\"del\");'><i class='fa fa-close'></i> 取消订单</a></span>"; } else { //---物流 switch (Convert.ToInt32(dr["StateLogistics"])) { case 1: result += "<div><a href='javascript:;' class='btn btn-primary' data-oid='" + oid + "' onclick='ConfirmAction(this,\"receive\");'>确认收货</a></div>"; break; } //已付款,但处理申请退款等状态 if (orderStatus < (int)M_OrderList.StatusEnum.Normal) { //result += "<a href='AddShare.aspx?CartID=" + dr["CartID"] + "'>取消退款</a><br />"; } //已付款未完结,可申请退款 if (orderStatus >= (int)M_OrderList.StatusEnum.Normal && orderStatus < (int)M_OrderList.StatusEnum.OrderFinish) { result += "<a href='javascript:;' onclick='ShowDrawback(" + oid + ");'>取消订单</a>"; } //已付款已完结,可评价晒单 if (orderStatus >= (int)M_OrderList.StatusEnum.OrderFinish)//已完结 { if (!(dr["AddStatus"].ToString().Contains("comment"))) { result += "<a href='AddShare.aspx?OrderID=" + dr["ID"] + "'><i class='fa fa-edit'></i> 评价晒单</a>"; } //result += "<a href='/Shop/" + dr["ProID"] + ".aspx' target='_blank' class='btn btn-primary'>立即购买</a>"; } } return(result); }
/// <summary> /// 系统事件,如订阅等处理 /// </summary> public void WxEventHandler(M_WxTextMsg reqMod) { M_WX_User userMod = null; switch (reqMod.Event.ToLower()) { case "subscribe": userMod = api.GetWxUserModel(reqMod.FromUserName); userMod.CDate = DateTime.Now; userMod.AppId = api.AppId.ID; wxuserBll.Insert(userMod); M_WxImgMsg msgmod = JsonConvert.DeserializeObject <M_WxImgMsg>(api.AppId.WelStr); msgmod.ToUserName = reqMod.FromUserName; msgmod.FromUserName = reqMod.ToUserName; int pid = DataConvert.CLng(reqMod.EventKey.Replace("qrscene_", "")); Appinfo uappMod1 = new Appinfo(); B_UserAPP uappBll1 = new B_UserAPP(); M_UserInfo mu1 = new M_UserInfo(); M_WX_User wuserMod = new M_WX_User(); M_Uinfo mubase = new M_Uinfo(); uappMod1 = uappBll1.SelModelByOpenID(reqMod.FromUserName, "wechat"); wuserMod = api.GetWxUserModel(reqMod.FromUserName); if (uappMod1 != null) { mu1 = buser.GetUserByUserID(uappMod1.UserID); if (mu1 != null && mu1.UserID > 0) { mu1.TrueName = wuserMod.Name; mu1.GroupID = 1; buser.UpdateByID(mu1); } else { mu1.UserName = "******" + DateTime.Now.ToString("yyyyMMddHHmmss") + function.GetRandomString(2).ToLower(); mu1.UserPwd = StringHelper.MD5(function.GetRandomString(6)); mu1.Email = function.GetRandomString(10) + "@wx.com"; mu1.Question = function.GetRandomString(5); mu1.Answer = function.GetRandomString(5); mu1.TrueName = wuserMod.Name; mu1.GroupID = 1; mu1.UserID = buser.Add(mu1); uappMod1.UserID = mu1.UserID; uappMod1.SourcePlat = "wechat"; uappMod1.OpenID = reqMod.FromUserName; uappBll1.UpdateByID(uappMod1); mubase.UserId = mu1.UserID; buser.AddBase(mubase); } } else { uappMod1 = new Appinfo(); mu1.UserName = "******" + DateTime.Now.ToString("yyyyMMddHHmmss") + function.GetRandomString(2).ToLower(); mu1.UserPwd = StringHelper.MD5(function.GetRandomString(6)); mu1.Email = function.GetRandomString(10) + "@wx.com"; mu1.Question = function.GetRandomString(5); mu1.Answer = function.GetRandomString(5); mu1.TrueName = wuserMod.Name; mu1.GroupID = 1; mu1.UserID = buser.Add(mu1); uappMod1.UserID = mu1.UserID; uappMod1.SourcePlat = "wechat"; uappMod1.OpenID = reqMod.FromUserName; uappBll1.Insert(uappMod1); mubase.UserId = mu1.UserID; buser.AddBase(mubase); } if (string.IsNullOrEmpty(msgmod.Articles[0].PicUrl)) //如未设置图片则以纯文本格式发送,纯文本支持内置超链接 { M_WxTextMsg textMod = ImageToText(msgmod); RepToClient(textMod.ToXML()); } else { RepToClient(msgmod.ToXML()); } //关注时发送多条信息 if (pid > 0) { System.Threading.ThreadPool.QueueUserWorkItem(new System.Threading.WaitCallback(SendMsg), reqMod); } //关注时发送多条信息 //System.Threading.ThreadPool.QueueUserWorkItem(new System.Threading.WaitCallback(SendMsg), reqMod); break; case "unsubscribe": wxuserBll.DelByOpenid(api.AppId.ID, reqMod.FromUserName); break; case "location": //用户进入公众号(包含定位信息) M_WxImgMsg msgmod1 = new M_WxImgMsg(); msgmod1.ToUserName = reqMod.FromUserName; msgmod1.FromUserName = reqMod.ToUserName; M_WX_ReplyMsg rpMod = new M_WX_ReplyMsg(); rpMod = rpBll.SelByFileAndDef(appBll.GetAppByWxNo(reqMod.ToUserName).ID, "头图"); if (rpMod != null) { M_WXImgItem item = JsonConvert.DeserializeObject <M_WXImgItem>(rpMod.Content); msgmod1.Articles.Add(new M_WXImgItem() { Title = item.Title, Url = item.Url, Description = item.Description, PicUrl = item.PicUrl }); } // rpMod = rpBll.SelByFileAndDef(appBll.GetAppByWxNo(reqMod.ToUserName).ID, "推送1"); // { // M_WXImgItem item = JsonConvert.DeserializeObject<M_WXImgItem>(rpMod.Content); // msgmod1.Articles.Add(new M_WXImgItem() { Title = item.Title, Url = item.Url, Description = item.Description, PicUrl = item.PicUrl }); // } // rpMod = rpBll.SelByFileAndDef(appBll.GetAppByWxNo(reqMod.ToUserName).ID, "推送2"); // { // M_WXImgItem item = JsonConvert.DeserializeObject<M_WXImgItem>(rpMod.Content); // msgmod1.Articles.Add(new M_WXImgItem() { Title = item.Title, Url = item.Url, Description = item.Description, PicUrl = item.PicUrl }); // } // rpMod = rpBll.SelByFileAndDef(appBll.GetAppByWxNo(reqMod.ToUserName).ID, "推送3"); // { // M_WXImgItem item = JsonConvert.DeserializeObject<M_WXImgItem>(rpMod.Content); // msgmod1.Articles.Add(new M_WXImgItem() { Title = item.Title, Url = item.Url, Description = item.Description, PicUrl = item.PicUrl }); // } // rpMod = rpBll.SelByFileAndDef(appBll.GetAppByWxNo(reqMod.ToUserName).ID, "推送4"); // { // M_WXImgItem item = JsonConvert.DeserializeObject<M_WXImgItem>(rpMod.Content); // msgmod1.Articles.Add(new M_WXImgItem() { Title = item.Title, Url = item.Url, Description = item.Description, PicUrl = item.PicUrl }); // } RepToClient(msgmod1.ToXML()); break; case "scan": Appinfo uappMod = new Appinfo(); B_UserAPP uappBll = new B_UserAPP(); M_UserInfo mu = new M_UserInfo(); M_WxTextMsg textMod2 = new M_WxTextMsg(); textMod2.FromUserName = reqMod.ToUserName; textMod2.ToUserName = reqMod.FromUserName; textMod2.MsgType = "text"; textMod2.Content = ""; uappMod = uappBll.SelModelByOpenID(reqMod.FromUserName, "wechat"); if (uappMod != null) { mu = buser.GetUserByUserID(uappMod.UserID); M_UserInfo pmu = buser.GetUserByUserID(DataConvert.CLng(reqMod.EventKey)); if (mu != null && mu.UserID > 0) { if (DataConvert.CLng(mu.ParentUserID) > 0) { textMod2.Content = "您已绑定了推荐人不能重复绑定!"; RepToClient(textMod2.ToXML()); } else { if (mu.UserID == DataConvert.CLng(reqMod.EventKey)) { textMod2.Content = "您扫描的是您自己的二维码!"; } else { mu.ParentUserID = DataConvert.CLng(reqMod.EventKey).ToString(); if (pmu != null && pmu.UserID > 0) { string err = ""; if (CheckParentUser(pmu.UserID, mu.UserID, ref err)) { mu.ParentUserID = pmu.UserID.ToString(); if (buser.UpdateByID(mu)) { textMod2.Content = "您成功绑定了推荐人:" + pmu.TrueName + "!"; } else { textMod2.Content = "绑定推荐人失败!"; } } else { textMod2.Content = "绑定推荐失败,错误信息:" + err; } } else { textMod2.Content = "绑定推荐失败,推荐人不存在!"; } } RepToClient(textMod2.ToXML()); } } } break; default: break; } }
/// <summary> /// 系统事件,如订阅等处理 /// </summary> public void WxEventHandler(M_WxTextMsg reqMod) { M_WX_User userMod = null; errmsg += ",事件:" + reqMod.Event; switch (reqMod.Event.ToLower()) { case "subscribe": userMod = api.GetWxUserModel(reqMod.FromUserName); userMod.CDate = DateTime.Now; userMod.AppId = api.AppId.ID; wxuserBll.Insert(userMod); M_WxImgMsg msgmod = new M_WxImgMsg(); msgmod.ToUserName = reqMod.FromUserName; msgmod.FromUserName = reqMod.ToUserName; M_WX_ReplyMsg rpMod1 = new M_WX_ReplyMsg(); rpMod1 = rpBll.SelByFileAndDef(appBll.GetAppByWxNo(reqMod.ToUserName).ID, "头图"); if (rpMod1 != null) { M_WXImgItem item = JsonConvert.DeserializeObject <M_WXImgItem>(rpMod1.Content); msgmod.Articles.Add(new M_WXImgItem() { Title = item.Title, Url = item.Url, Description = item.Description, PicUrl = item.PicUrl }); } rpMod1 = rpBll.SelByFileAndDef(appBll.GetAppByWxNo(reqMod.ToUserName).ID, "推送1"); { M_WXImgItem item = JsonConvert.DeserializeObject <M_WXImgItem>(rpMod1.Content); msgmod.Articles.Add(new M_WXImgItem() { Title = item.Title, Url = item.Url, Description = item.Description, PicUrl = item.PicUrl }); } rpMod1 = rpBll.SelByFileAndDef(appBll.GetAppByWxNo(reqMod.ToUserName).ID, "推送2"); { M_WXImgItem item = JsonConvert.DeserializeObject <M_WXImgItem>(rpMod1.Content); msgmod.Articles.Add(new M_WXImgItem() { Title = item.Title, Url = item.Url, Description = item.Description, PicUrl = item.PicUrl }); } rpMod1 = rpBll.SelByFileAndDef(appBll.GetAppByWxNo(reqMod.ToUserName).ID, "推送3"); { M_WXImgItem item = JsonConvert.DeserializeObject <M_WXImgItem>(rpMod1.Content); msgmod.Articles.Add(new M_WXImgItem() { Title = item.Title, Url = item.Url, Description = item.Description, PicUrl = item.PicUrl }); } rpMod1 = rpBll.SelByFileAndDef(appBll.GetAppByWxNo(reqMod.ToUserName).ID, "推送4"); { M_WXImgItem item = JsonConvert.DeserializeObject <M_WXImgItem>(rpMod1.Content); msgmod.Articles.Add(new M_WXImgItem() { Title = item.Title, Url = item.Url, Description = item.Description, PicUrl = item.PicUrl }); } rpMod1 = rpBll.SelByFileAndDef(appBll.GetAppByWxNo(reqMod.ToUserName).ID, "推送5"); { M_WXImgItem item = JsonConvert.DeserializeObject <M_WXImgItem>(rpMod1.Content); msgmod.Articles.Add(new M_WXImgItem() { Title = item.Title, Url = item.Url, Description = item.Description, PicUrl = item.PicUrl }); } RepToClient(msgmod.ToXML()); System.Threading.ThreadPool.QueueUserWorkItem(new System.Threading.WaitCallback(SendMsg), reqMod); break; case "unsubscribe": { userMod = wxuserBll.SelForOpenid(reqMod.FromUserName); if (userMod != null) { wxuserBll.Del(userMod.ID); } } break; case "location": //用户进入公众号(包含定位信息) break; case "scan": //带参数的二维码扫描进入(关注事件在上方处理) M_UserAPP uappMod = new M_UserAPP(); B_UserAPP uappBll = new B_UserAPP(); M_UserInfo mu = new M_UserInfo(); M_WxTextMsg textMod2 = new M_WxTextMsg(); textMod2.FromUserName = reqMod.ToUserName; textMod2.ToUserName = reqMod.FromUserName; textMod2.MsgType = "text"; textMod2.Content = ""; uappMod = uappBll.SelModelByOpenID(reqMod.FromUserName, "wechat"); if (uappMod != null) { mu = buser.GetUserByUserID(uappMod.UserID); M_UserInfo pmu = buser.GetUserByUserID(DataConvert.CLng(reqMod.EventKey)); if (mu != null && mu.UserID > 0) { if (DataConvert.CLng(mu.ParentUserID) > 0) { textMod2.Content = "您已绑定了推荐人不能重复绑定!"; RepToClient(textMod2.ToXML()); } else { if (mu.UserID == DataConvert.CLng(reqMod.EventKey)) { textMod2.Content = "您扫描的是您自己的二维码!"; } else { mu.ParentUserID = DataConvert.CLng(reqMod.EventKey).ToString(); if (pmu != null && pmu.UserID > 0) { string err = ""; if (CheckParentUser(pmu.UserID, mu.UserID, ref err)) { mu.ParentUserID = pmu.UserID.ToString(); if (buser.UpdateByID(mu)) { textMod2.Content = "您成功绑定了推荐人:" + pmu.TrueName + "!"; } else { textMod2.Content = "绑定推荐人失败!"; } } else { textMod2.Content = "绑定推荐失败,错误信息:" + err; } } else { textMod2.Content = "绑定推荐失败,推荐人不存在!"; } } RepToClient(textMod2.ToXML()); } } } break; default: break; } }