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)); }
public static accessTokenInfo GetAccessTokenInfo(string getAccessTokenUrl, string appID, string appsecret, string code) { string accessurl = string.Format(getAccessTokenUrl, appID, appsecret, code); string result = WebHelper.GetRequestData(accessurl, "get", ""); if (result.Contains("errmsg")) { return(null); } try { accessTokenInfo tokenInfo = JsonHelper.DeserializeJsonToObject <accessTokenInfo>(result); return(tokenInfo); } catch (Exception e) { return(null); } }
public ActionResult ServiceEval(string code = "", string state = "") { Core.ServiceEvalInfo model = new Core.ServiceEvalInfo() { EvalProduct = 3, EvalLogistics = 3, EvalService = 3, State = 0 }; 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/ServiceEval"; 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.Name = wechatInfo.nickname; model.WeChatOpenId = wechatInfo.openid; model.WeChatName = wechatInfo.nickname; model.Province = wechatInfo.province; model.City = wechatInfo.city; } } List <SelectListItem> selList = new List <SelectListItem>(); selList.Add(new SelectListItem() { Text = "01", Value = "01" }); selList.Add(new SelectListItem() { Text = "02", Value = "02" }); selList.Add(new SelectListItem() { Text = "03", Value = "03" }); selList.Add(new SelectListItem() { Text = "04", Value = "04" }); ViewData["selList"] = selList; } return(View(model)); }