Exemple #1
0
        public ActionResult Post(string signature, string timestamp, string nonce, string echostr)
        {
            try
            {
                var appid     = "";
                var appsecret = "";
                if (CheckSignature(out appid, out appsecret))
                {
                    WeixinMessage message = null;
                    string        msgBody = "";
                    Stream        s       = System.Web.HttpContext.Current.Request.InputStream;
                    byte[]        b       = new byte[s.Length];
                    s.Read(b, 0, (int)s.Length);
                    msgBody = Encoding.UTF8.GetString(b);
                    if (string.IsNullOrWhiteSpace(msgBody))
                    {
                        _log.AddLog(new Log()
                        {
                            Msg = "lkpost过来的数据包:空" + msgBody.Length + DateTime.Now.ToString(), CreateTime = DateTime.Now, Ret = 0
                        });

                        return(null);
                    }
                    _log.AddLog(new Log()
                    {
                        Msg = "msgBody:" + msgBody.Length, CreateTime = DateTime.Now, Ret = 0
                    });

                    message = AcceptMessageAPI.Parse(msgBody);
                    WeiXinSdkTask _sdk     = new WeiXinSdkTask(appid, appsecret);
                    var           response = _sdk.Execute(message);//处理接收到的信息
                    _log.AddLog(new Log()
                    {
                        Msg = "response:" + response, CreateTime = DateTime.Now, Ret = 0
                    });
                    return(new ContentResult
                    {
                        Content = response,
                        ContentType = "text/xml",
                        ContentEncoding = System.Text.UTF8Encoding.UTF8
                    });
                }
                else
                {
                    _log.AddLog(new Log()
                    {
                        Msg = "lk消息真实性效验,不通过", CreateTime = DateTime.Now, Ret = 0
                    });
                }
            }
            catch (Exception ex)
            {
                _log.AddLog(new Log()
                {
                    Msg = "lk出错:" + ex.Message + DateTime.Now.ToString(), CreateTime = DateTime.Now, Ret = 0
                });
            }

            return(Content("")); //返回空串表示有响应
        }
        public ActionResult Testsql(string openid)
        {
            var _user = new WeiXinUserTask();

            for (var i = 0; i < 1000; i++)
            {
                var user = _user.GetByOpenId(openid);
                _log.AddLog(new Log()
                {
                    Ret = 2018, CreateTime = DateTime.Now, Msg = JsonConvert.SerializeObject(user)
                });
            }
            return(Content("ok"));
        }
Exemple #3
0
        public void Execute(IJobExecutionContext context)
        {
            var msg        = "";
            var _log       = new LogTask();
            var _wxconfig  = new WeiXinConfigTask();
            var configList = _wxconfig.GetListConfig();

            foreach (var item in configList)
            {
                var config = _wxconfig.GetConfig(item.WeiXinId);
                if (config != null)
                {
                    try
                    {
                        item.AccessToken     = BasicAPI.GetAccessToken(item.AppId, item.Appsecret).access_token;
                        item.JsApiToken      = JSAPI.GetTickect(item.AccessToken).ticket;
                        item.TokenUpdateTime = DateTime.Now;
                        msg = _wxconfig.UpdateToken(item).Msg;
                    }
                    catch (Exception e)
                    {
                        var log = new Log()
                        {
                            CreateTime = DateTime.Now, Msg = "公众号token更新错误:" + e.Message + ";时间:" + DateTime.Now, Ret = 0
                        };
                        _log.AddLog(log);
                    }
                }

                var log1 = new Log()
                {
                    CreateTime = DateTime.Now, Msg = "公众号token更新:" + item.WeiXinId + "执行:" + msg + ";时间:" + DateTime.Now, Ret = 0
                };
                _log.AddLog(log1);
            }
        }
        public void ThreadTest_1(object num)
        {
            var _logtask = new LogTask();
            var number   = (int)num;

            for (var i = 0; i < number; i++)
            {
                var log = new Log()
                {
                    CreateTime = DateTime.Now,
                    Msg        = num + "No:" + i,
                    Ret        = 89,
                };
                _logtask.AddLog(log);
                Thread.Sleep(1000 * number);
            }
        }
        //执行代理请求
        public void GoProxy(object obj)
        {
            var list     = (List <IpProxy>)obj;
            var errornum = 0;
            var oknum    = 0;
            var newtime  = DateTime.Now;

            foreach (var item in list)
            {
                var res = Services.Utility.WebUtils.DoGetProxy("http://baidu.com", item.Host, Convert.ToInt32(item.Port));
                if (res != "OK")
                {
                    _ipProxyTask.DelIpProxy(item.Host);
                }
                else
                {
                    item.Serve = item.Serve + res;
                    _ipProxyTask.UpdateIpProxy(item);
                    foreach (var url in _urlList)
                    {
                        res = Services.Utility.WebUtils.DoGetProxy(url, item.Host, Convert.ToInt32(item.Port));
                        if (res != "OK")
                        {
                            errornum++;
                        }
                        else
                        {
                            oknum++;
                        }
                    }
                }
            }
            var _logtask = new LogTask();
            var log      = new Log()
            {
                CreateTime = DateTime.Now,
                Msg        = "newtime:" + newtime + ";oknum:" + oknum + ";errornum:" + errornum,
                Ret        = 88,
            };

            _logtask.AddLog(log);
        }
        public ActionResult Index(HttpPostedFileBase filebase)
        {
            try
            {
                HttpPostedFileBase file = Request.Files["files"];
                var error    = "";
                var savePath = NpoiSdk.GetSavePath(file, out error);
                if (string.IsNullOrWhiteSpace(savePath))
                {
                    ViewBag.error = error;
                }
                DataTable table = NpoiSdk.ExcelToDataTable(savePath);


                //引用事务机制,出错时,事物回滚
                using (TransactionScope transaction = new TransactionScope())
                {
                    for (int i = 0; i < table.Rows.Count; i++)
                    {
                        string msg   = table.Rows[i][0].ToString();
                        var    ret   = table.Rows[i][1];
                        var    model = new Log()
                        {
                            Ret        = Convert.ToInt32(ret),
                            Msg        = msg,
                            CreateTime = DateTime.Now
                        };
                        _log.AddLog(model);
                        //此处写录入数据库代码;
                    }
                    transaction.Complete();
                }
                ViewBag.error = "导入成功";
            }
            catch (Exception e)
            {
                ViewBag.error = "导入失败:" + e.Message;
            }
            System.Threading.Thread.Sleep(2000);
            return(View());
        }