public ActionResult ProductFeedBacks(Core.ProductFeedbacksInfo model, string code = "", string state = "") { model.State = 0; if (ModelState.IsValid) { model.CreateTime = DateTime.Now; if (Services.ProductFeedBacks.Create(model) > 0) { return(RedirectToAction("ProductFeedBacksSuccess")); } else { return(Content("提交失败")); } } else { foreach (var s in ModelState.Values) { foreach (var p in s.Errors) { new LogHelper().Write(p.ErrorMessage); } } } return(View(model)); }
public ActionResult ProductFeedBacks(string code = "", string state = "") { Core.ProductFeedbacksInfo model = new Core.ProductFeedbacksInfo(); string useragent = Request.UserAgent; if (useragent.ToLower().Contains("micromessenger")) { //1.不包含code和state的情况下,转去微信认证 if (string.IsNullOrEmpty(code) && string.IsNullOrEmpty(state)) { //转向微信认证 string url = "http://www.kingsdown.com.cn/Plugins/ProductFeedBacks"; string requestUrl = string.Format(getCodeUrl, appID, System.Web.HttpUtility.UrlEncode(url), Guid.NewGuid().ToString()); return(Redirect(requestUrl)); } //2.在有code和state的情况下,获取access_token accessTokenInfo tokenInfo = GetAccessTokenInfo(getAccessTokenUrl, appID, appsecret, code); if (tokenInfo != null) { new LogHelper().Write(tokenInfo.access_token); weChatUserInfo wechatInfo = GetWeChatUserInfo(getUserInfoUrl, tokenInfo.access_token, tokenInfo.openid); if (wechatInfo != null) { model.CustomerName = wechatInfo.nickname; model.WeChatOpenId = wechatInfo.openid; model.WeChatName = wechatInfo.nickname; model.CityName = wechatInfo.city; } } } return(View(model)); }