public async Task <ActionResult> Entry(PostModel model)
        {
            //这里总是较验不通过,不知道为什么。
            //if (CheckSignature.Check(model.Signature, model.Timestamp, model.Nonce, token))
            //{
            //    LogHelper.SaveLog("weixin", JsonConvert.SerializeObject(model));
            //    return Content("参数错误!");
            //}

            LogHelper.SaveLog("weixin", JsonConvert.SerializeObject(model));

            try
            {
                StreamReader  reader    = new StreamReader(Request.Body);
                string        xml       = reader.ReadToEnd();
                DataSet       ds        = new DataSet();
                StringReader  stream    = new StringReader(xml);
                XmlTextReader readerXml = new XmlTextReader(stream);
                ds.ReadXml(readerXml);

                DataRow dr     = ds.Tables[0].Rows[0];
                string  openId = dr["FromUserName"].ToString();

                //这里写接收后业务处理
                //WeixinMPService.SendText(SSOClient.UserId, "您的openId是:" + openId);
                BitNoticeMessage message = new BitNoticeMessage()
                {
                    Sender      = "weixin",
                    Receiver    = "5eeea4ce-71ab-4464-b72f-17f5163ee944",
                    Content     = "<h4 class=\"spop-title\">公众号关注通知</h4>你关注了微信公众号;<br />你的OpenId是:<br />" + openId,
                    MessageType = "notice"
                };
                await BitNoticeService.SendStringAsync(message);

                return(Content("success"));
            }
            catch (Exception ex)
            {
                LogHelper.SaveLog(ex);
                return(Content("服务器异常!"));
            }
        }
Esempio n. 2
0
        /// <summary>
        /// 向本服务器用户发送消息
        /// </summary>
        /// <returns></returns>
        public async Task <ActionResult> SendWebSocketString()
        {
            try
            {
                using (StreamReader reader = new StreamReader(Request.Body, Encoding.Default, true, 1024, true))
                {
                    var text = reader.ReadToEnd();
                    LogHelper.SaveLog("SendWebSocketString", text);
                    var msg = JsonConvert.DeserializeObject <BitNoticeMessage>(text);
                    await BitNoticeService.SendStringAsync(msg, true);

                    return(Json(true));
                }
            }
            catch (Exception ex)
            {
                LogHelper.SaveLog(ex);
                return(Json(new { Code = 1, Msg = "服务器异常,请联系管理员!" }));
            }
        }
Esempio n. 3
0
        public async Task <JsonResult> NoticWebSocket()
        {
            try
            {
                BitNoticeMessage message = new BitNoticeMessage()
                {
                    Sender      = "readme",
                    Receiver    = SSOClient.UserId.ToString(),
                    Content     = "<h4 class=\"spop-title\">系统通知示例</h4><img src=\"../../qrcode/encode/user\" width=\"100\" height=\"100\" /><br />生成二维码;今天是" + DateTime.Now.WeekName(),
                    MessageType = "notice"
                };
                //仅是一个推送通知示例,顺带个二维码示例
                await BitNoticeService.SendStringAsync(message);

                return(Json(new { Code = 0 }));
            }
            catch (Exception ex)
            {
                LogHelper.SaveLog(ex);
                return(Json(new { Code = 1, Msg = "服务器异常,请联系管理员!" }));
            }
        }
Esempio n. 4
0
        public async Task <JsonResult> Apk()
        {
            try
            {
                string apps = Path.Combine(AppDomain.CurrentDomain.BaseDirectory, "apps");
                Dictionary <string, string> vers = new Dictionary <string, string>();
                foreach (var file in Directory.GetFiles(apps))
                {
                    var    path = Path.GetFileNameWithoutExtension(file).Split("_");
                    string key  = "";
                    foreach (var v in path[path.Length - 1].Split("."))
                    {
                        key += v.PadLeft(5, '0');
                    }
                    vers.Add(key, file);
                }
                var    ver = vers.Keys.Max();
                string url = string.Format("{0}://{1}/apps/{2}", Request.Scheme, Request.Host, Path.GetFileName(vers[ver]));


                BitNoticeMessage message = new BitNoticeMessage()
                {
                    Sender      = "readme",
                    Receiver    = SSOClient.UserId.ToString(),
                    Content     = "<h4 class=\"spop-title\">扫码下载框架APP示例</h4><img src=\"../../qrcode/encode?msg=" + HttpUtility.UrlEncode(url) + "\" width=\"100\" height=\"100\" /><br />",
                    MessageType = "notice"
                };
                await BitNoticeService.SendStringAsync(message);

                return(Json(new { Code = 0 }));
            }
            catch (Exception ex)
            {
                LogHelper.SaveLog(ex);
                return(Json(new { Code = 1, Msg = "服务器异常,请联系管理员!" }));
            }
        }