protected void Page_Load(object sender, EventArgs e) { Id = MW.Common.LYRequest.GetInt("id", 0); if (!IsPostBack) { if (Id > 0) { model = bll.GetModel(Id); if (model != null) { string zip = model.A3; if (zip != "" && zip.EndsWith(".zip")) { bool flag = MW.Common.Utils.DecompressEx(MW.Common.Utils.GetMapPath(zip)); if (flag) { url = zip.Replace(".zip", ""); Response.Redirect(url); Response.End(); return; } } title = model.Title; time = model.CreateTime.ToString(); img = WxBase.GetResAbsUrl(model.A4); conent = WxBase.ReplacePic(MW.Common.Utils.HtmlDecode(model.Content)); base.Title = title; } } } }
public string Get(string signature, string timestamp, string nonce, string echostr) { if (string.IsNullOrEmpty(signature) || string.IsNullOrEmpty(timestamp) || string.IsNullOrEmpty(nonce)) { return(string.Empty); } if (WxBase.CheckSignature(signature, timestamp, nonce)) { return(echostr); //返回随机字符串则表示验证通过 } else { Console.WriteLine($"failed check signature:{signature} with {timestamp},{nonce}"); return(string.Empty); } }
protected void Page_Load(object sender, EventArgs e) { Id = MW.Common.LYRequest.GetInt("id", 0); if (!IsPostBack) { if (Id > 0) { model = bll.GetModel(Id); if (model != null) { title = model.Title; time = model.UpdateTime.ToString(); img = WxBase.GetResAbsUrl(model.FilePath); conent = WxBase.ReplacePic(MW.Common.Utils.HtmlDecode(model.Contents)); fj = model.fj; base.Title = title; } } } }
public async Task <ContentResult> Post(string signature, string timestamp, string nonce, string openid) { //验证微信签名 if (!WxBase.CheckSignature(signature, timestamp, nonce)) { Console.WriteLine($"receive error check signature:{signature} with {timestamp},{nonce}"); return(new ContentResult() { StatusCode = 401 }); } //初始化菜单 await WxBase.InitMenu(); using (Stream stream = Request.Body) { byte[] buffer = new byte[Request.ContentLength.Value]; await stream.ReadAsync(buffer, 0, buffer.Length); string xml = Encoding.UTF8.GetString(buffer); Console.WriteLine($"收到:{xml}"); var msg = WxTextMsg.FromXml(xml); if (msg.MsgType.Contains("text") && msg.Content.Contains("磁芯大战")) { WxUser user = null; if (await DbEntityManager.Exist <WxUser>("openid", openid)) { //get user from db user = await DbEntityManager.SelectOne <WxUser>("openid", openid); //update salt only user.ResetSalt(); await DbEntityManager.Update(user); } else { // var info = await WxBase.GetUserInfo(openid); Console.WriteLine($"获取:{info.nickname} 信息"); user = WxUser.CreateFromWxUserInfo(info); await DbEntityManager.Insert(user); } // var article = new WxArticle("MagCore - 磁芯大战", "进入房间创建游戏", HelperConfig.Current.WxInterfaceHost + "assets/images/icon.png", HelperConfig.Current.WxInterfaceHost + "pages/creator.html" + "?t=" + DateTime.Now.Ticks.ToString() + "&oid=" + openid + $"&name={user.nickname}({HashManager.Md5(openid).Substring(12, 4)})" + "&s=" + user.salt); var reply = new WxArticleMsg(msg.FromUserName, msg.ToUserName, msg.CreateTime, new WxArticle[] { article }); string text = reply.ToXml(); Console.WriteLine($"回复:{text}"); return(new ContentResult() { StatusCode = 200, Content = text }); } else { // var defaultReply = new WxTextMsg(msg.FromUserName, msg.ToUserName, msg.CreateTime, "未正确识别,磁芯大战比赛期间,其他回复暂时停止服务"); return(new ContentResult() { StatusCode = 200, Content = defaultReply.ToXml() }); } } }
public void TestWxAccessToken() { string s = WxBase.GetAccessToken(); }