// GET: Me public ActionResult Index(string openid) { if (!string.IsNullOrEmpty(openid)) { WxUserDao userDao = new WxUserDao(); //1 查询是否已经存在ticket和nickname信息 WxUser user = userDao.Find(openid); bool isExist = user != null; //2 如果没有nickname需获取用户信息 if (user == null || string.IsNullOrEmpty(user.headimgurl) || string.IsNullOrEmpty(user.nickname)) { var userinfo = Common.HttpUtility.HttpGet($"https://api.weixin.qq.com/cgi-bin/user/info?access_token={AccessTokenHelper.GetAccessToken()}&openid={openid}&lang=zh_CN", "", "utf-8"); JObject jobect = (JObject)JsonConvert.DeserializeObject(userinfo); if ((string)jobect["subscribe"] == "0") { return(View("Error", new { message = "未关注" })); } user = new WxUser(); user.openid = openid; user.headimgurl = (string)jobect["headimgurl"]; user.nickname = (string)jobect["nickname"]; user.ticket = WeixinHelper.CreateTempQRCode(openid); user.ticketcreatedatetime = DateTime.Now; if (!isExist) { userDao.Add(user); } else { userDao.Update(user); } } return(View(user)); } else { return(View("Error")); } }
public ActionResult Wallet(string openid) { if (!string.IsNullOrEmpty(openid)) { WxUserDao userDao = new WxUserDao(); WxUser user = userDao.Find(openid); if (user == null) { return(View("Error")); } return(View(user)); } else { return(View("Error")); } }