protected override void OnActionExecuting(ActionExecutingContext filterContext) { //判断是否登录,如果没有登录跳转登录页 //if (User_Shop.IsLogin() == false) //{ // string url = ""; // //如果是微信登录跳转到授权页面 // if (Url_Mobile.IsWechat()) // { // url = Url_Mobile.GetLogin() + "/auth"; // } // else // { // url = Url_Mobile.GetLogin(); // } // url += "?redirecturl=" + ReqHelper.req.Url.AbsolutePath; // if (string.IsNullOrEmpty(url) == false) // filterContext.Result = new RedirectResult(url); //} if (User_Shop.IsLogin() == false) { string url = ""; url = Url_Mobile.GetLogin(); //url += "?redirecturl=" + ReqHelper.req.Url.AbsolutePath; if (string.IsNullOrEmpty(url) == false) { filterContext.Result = new RedirectResult(url); } } }
/// <summary> /// 商城首页 /// </summary> /// <returns></returns> public ActionResult Index() { //跳转处理 //if (Url_Mobile.IsMobile()) //{ return(Redirect(Url_Mobile.GetIndex())); //} //return View(); }
/// <summary> /// 绑定微信 /// </summary> /// <returns></returns> public ActionResult Auth() { ConfigInfo config = ConfigInfo.GetInfo(); OAuthManage _oauth = new OAuthManage(config.AppID, config.AppSecret, new LinkManage().GetUserOAthHandle()); string wxUrl = _oauth.GetCodeUrl(); string redirecturl = Url_Shop.GetRecirectUrl(); wxUrl += "?redirecturl=" + redirecturl; if (Url_Mobile.IsWechat()) { return(Redirect(wxUrl)); } ViewBag.wxUrl = wxUrl; return(View()); }
public PartialViewResult GetBrand() { bool IsMySelf = Url_Mobile.IsSelf(); //国际大品牌 List <ShopBrand> brand1 = DB.ShopBrand.Where(q => q.IsWorld).OrderByDescending(q => q.Sort) .ToList(); //推荐品牌 List <ShopBrand> brand2 = DB.ShopBrand.Where(q => q.IsRecommend).OrderByDescending(q => q.IsRecommend) .ToList(); //国货精品 List <ShopBrand> brand3 = DB.ShopBrand.Where(q => q.IsWorld == false).OrderByDescending(q => q.IsWorld == false) .ToList(); ViewBag.brand1 = brand1; ViewBag.brand2 = brand2; ViewBag.brand3 = brand3; return(PartialView()); }
public ActionResult OAuthHandle() { ConfigInfo config = ConfigInfo.GetInfo(); OAuthManage _oauth = new OAuthManage(config.AppID, config.AppSecret, new LinkManage().GetUserOAthHandle()); string recirecturl = Url_Shop.GetRecirectUrl(); LogHelper.Debug("OAuthHandle-redirecturl:" + recirecturl); string result = ""; try { //注册事件处理 _oauth.OnError = (e) => { string msg = ""; Exception inner = e; while (inner != null) { msg += inner.Message; inner = inner.InnerException; } result = msg; LogOperate.Write(msg); }; _oauth.OnGetTokenSuccess = (token) => { result += "<br/>"; result += token.ToJsonString(); LogOperate.Write("获取token成功:" + result); }; //特别处理获取用户信息成功 _oauth.OnGetUserInfoSuccess = (user) => { result += "<br/>"; result += user.ToJsonString(); CookieHelper.SetCookie("openid", user.openid, 1); CookieHelper.SetCookie("nickname", user.nickname, 1); CookieHelper.SetCookie("headimgurl", user.headimgurl, 1); //判断openid的用户是否存在 Member_Info model = DB.Member_Info.GetModelByOpenID(user.openid); if (model != null) { //保存信息到客户端同步登录 User_Shop.SetUser(model); } else { if (model == null) { //如果是游客,返回登录 if (string.IsNullOrEmpty(recirecturl)) { recirecturl = $"http://{Request.Url.Host}/mobile/login"; } } else { model.OpenID = user.openid; if (string.IsNullOrEmpty(model.NickName)) { model.NickName = user.nickname; } model.Photo = user.headimgurl; DB.Member_Info.Update(model); //保存信息到客户端同步登录 User_Shop.SetUser(model); recirecturl = Url_Mobile.GetUserCenter(); } } }; //第二步 _oauth.GetAccess_Token(); //第三步 _oauth.GetUserInfo(); //显示结果 ViewBag.msg = result; if (string.IsNullOrEmpty(recirecturl)) { recirecturl = $"http://{Request.Url.Host}/mobile"; } return(Redirect(recirecturl)); } catch (Exception ex) { string msg = ""; Exception inner = ex; while (inner != null) { msg += inner.Message; inner = inner.InnerException; } return(Content(result + "----->" + msg + "<br />" + ex.StackTrace)); } }
public ActionResult Save(decimal scores, decimal amount, int id = 0) { //1.添加充值记录 ScoreRecord record = null; Member_Info curUser = DB.Member_Info.FindEntity(CurrentUser.Id); if (id == 0) { Xml_Site config = DB.XmlConfig.XmlSite; if (amount <= 0) { return(Content("充值金额要大于0")); } if (scores % config.ScoreMultiple != 0) { return(Content("充值数量要是" + config.ScoreMultiple + "的数量")); } record = new ScoreRecord(); record.CreateTime = DateTime.Now; record.Scores = scores; record.Amount = amount; record.State = Enums.ScoreState.待付款.GetHashCode(); record.MemberID = curUser.MemberId; record.MemberCode = curUser.Code; record.MemberName = curUser.NickName; DB.ScoreRecord.Insert(record); } else { record = DB.ScoreRecord.FindEntity(id); } //判断是否是微信端 if (Url_Mobile.IsWechat() && string.IsNullOrEmpty(curUser.OpenID) == false) { Xml_Site config = DB.XmlConfig.XmlSite; JsonHelp json = new JsonHelp(true); try { //使用微信api 下订单 PayManage _manage = new PayManage(); string tradetype = Url_Mobile.IsWechat() ? "JSAPI" : "NATIVE"; _manage.OnCreateOrderSuccess += (result) => { json.Msg = result.Prepay_ID; json.ReUrl = result.Code_Url; //二维码地址 //签名处理 Dictionary <string, string> dic = new Dictionary <string, string>(); int timeStamp = AccessTokenManage.TimeStamp; dic.Add("appId", result.APPID); dic.Add("timeStamp", timeStamp.ToString()); dic.Add("nonceStr", timeStamp.ToString()); dic.Add("package", $"prepay_id={result.Prepay_ID}"); dic.Add("signType", "MD5"); json.Data = new { appId = result.APPID, timeStamp = timeStamp.ToString(), nonceStr = timeStamp.ToString(), package = $"prepay_id={result.Prepay_ID}", signType = "MD5", paySign = ConfigInfo.GetPaySign(dic) }; }; _manage.BackHandleUrl = $"http://{Request.Url.Host}/ajax/ScoreWX";//指定回调地址 _manage.CreateOrder(DateTime.Now.ToString("MMddms") + "_" + record.ID, config.GetAmount(amount), curUser.OpenID, tradetype, "竹笛商城积分充值"); } catch (Exception ex) { json.IsSuccess = false; json.Msg = ex.Message; Common.LogHelper.Debug("积分充值微信端出错:" + ex.Message); Common.LogHelper.Debug(ex.StackTrace); } return(Json(json)); } else { //2.获取充值地址 //string url = PayHelper.GetPayUrl(DateTime.Now.ToString("MMddms") + "_" + record.ID, amount, "积分充值", true); //return Redirect(url); return(Redirect("支付接口申请中....")); } }