static void Main(string[] args) { CommUtil.LOG_PRINT_CONSOLE = false; CommUtil.LOG_PRINT_FILE = true; //CommUtil.LOG_PRINT_FILE_BUFFER = false; log = SzLogger.getLogger(); Console.WriteLine("准备好测试了请敲回车"); Console.ReadLine(); List <System.Threading.Thread> ths = new List <System.Threading.Thread>(); long time = TimeUtil.CurrentTimeMillis(); for (int k = 0; k < 5; k++) { /*5个线程*/ System.Threading.Thread t = new System.Threading.Thread(() => { /*每个线程 10万 条日志*/ for (int i = 0; i < 1000000; i++) { Program.log.Error(i + " ssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssss我测ssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssss"); } }); t.Start(); ths.Add(t); } ths.ForEach((t) => t.Join()); Console.WriteLine("并发结束,等待写入结束" + (TimeUtil.CurrentTimeMillis() - time)); while (Program.log.Count > 0) { } Console.WriteLine("500万条日志并发写入结束" + (TimeUtil.CurrentTimeMillis() - time)); Console.ReadLine(); }
/// <summary> /// 发送视频消息 /// </summary> /// <param name="host"></param> /// <param name="account"></param> /// <param name="toUserNameId"></param> /// <param name="mediaId"></param> /// <returns></returns> /// https://wx.qq.com/cgi-bin/mmwebwx-bin/webwxsendvideomsg?fun=async&f=json&pass_ticket=%252FX8NCpFJfNmU%252Be%252FgE2dwRCN2D8Y8EBSKunfckAJmPfCeVD4YaubkaS2e767qiyAO /// https://wx.qq.com/cgi-bin/mmwebwx-bin/webwxsendvideomsg?fun=async&f=json&lang=zh_CN&pass_ticket=KwMEOlgC57Dc1AwBwr7oaHekXX0P8fJE%252Bl0cLVocIrxdWNr%252F9URPGCAEmf%252FzfjEK public static HttpTaskParams GetSendVideoMsg(string host, WxAccount account, string toUserNameId, string mediaId) { string url = string.Format("{0}?fun=async&f=json&lang=zh_CN&pass_ticket={1}", WxHttpApi.GetCommonUrl(host, WxHttpApi.URL_WX_SEND_VIDEO_MSG), encoding(account.PassTicket)); HttpTaskParams htp = HttpTaskParams.NewPost(url); htp.ContentType = "application/json;charset=UTF-8"; WxSendMsgReq req = new WxSendMsgReq(); req.BaseRequest = WxReqUtil.GetIdentifyReq(account); req.Scene = 0; WxSendMediaMsg msg = new WxSendMediaMsg(); msg.Type = 43;//视频 msg.MediaId = mediaId; msg.FromUserName = account.UserName; msg.ToUserName = toUserNameId; string msgId = TimeUtil.CurrentTimeMillis() + TextUtil.RandomNumber(4); msg.LocalID = msgId; msg.ClientMsgId = msgId; msg.Content = string.Empty; req.Msg = msg; htp.CustomStringContentBody = JsonConvert.SerializeObject(req); return(htp); }
public RequestMessage(int msgId, int identiy, byte[] datas) { this.msgId = msgId; this.identiy = identiy; this.datas = datas; this.time = TimeUtil.CurrentTimeMillis(); }
/// <summary> /// 消息处理 /// </summary> public void UpdateReciveMessage() { lock (this.responseQueue) { while (this.responseQueue.Count > 0) { PackageData package = (PackageData)responseQueue.Dequeue(); if (package.msgId == MSG_HEART_ID) { if (heartStartTime == 0) { heartStartTime = TimeUtil.CurrentTimeMillis(); } long endTime = TimeUtil.CurrentTimeMillis(); long useTime = endTime - heartStartTime; heartStartTime = endTime; Debugger.Log("Received heart! time==" + useTime); continue; } //call lua socket LuaHelper.CallLuaFunction(GNETWORK_MODULE, GNETWORK_FUNC_RECEIVE_MESSAGE, package.msgId, package.buffer); } } }
/// <summary> /// 加入任务 /// </summary> /// <param name="t"></param> public virtual void AddTask(TaskModel t) { t.CreateTime = TimeUtil.CurrentTimeMillis(); taskQueue.Enqueue(t); //防止线程正在阻塞时添加进入了新任务 are.Set(); }
/// <summary> /// 线程处理器 /// </summary> protected virtual void Run() { while (!this.IsDelete) { while ((taskQueue.Count > 0)) { TaskModel task = null; /*获取并移除当前任务*/ if (!taskQueue.TryDequeue(out task)) { break; } /* 执行任务 */ long submitTime = TimeUtil.CurrentTimeMillis(); try { if (!task.Cancel) { task.Run(); } } catch (Exception e) { if (log.IsErrorEnabled()) { log.Error(System.Threading.Thread.CurrentThread.Name + " 执行任务:" + task.GetType().FullName + " 遇到错误", e); } } if (task is TimerTaskModel) { ((TimerTaskModel)task).LastRun = true; } long timeL1 = TimeUtil.CurrentTimeMillis() - submitTime; if (!task.GetType().FullName.StartsWith("Net.Sz.Framework")) { if (timeL1 > 10) { if (log.IsDebugEnabled()) { log.Debug(System.Threading.Thread.CurrentThread.Name + " 完成了任务:" + task.GetType().FullName + " 执行耗时:" + timeL1); } } } task = null; } are.Reset(); /*队列为空等待200毫秒继续*/ are.WaitOne(200); } if (log.IsErrorEnabled()) { log.Error(DateTime.Now.NowString() + " " + System.Threading.Thread.CurrentThread.Name + " Destroying"); } }
/// <summary> /// 获取微信所有联系人 /// </summary> /// <param name="wxAccount"></param> /// <returns></returns> /// https://wx2.qq.com/cgi-bin/mmwebwx-bin/webwxgetcontact /// ?lang=zh_CN /// &pass_ticket=9%252FuIrFpoM6CCrYsAV7mzDF0aFkHiXGlotDlmHbQokhM%253D /// &r=1501480039623 /// &seq=0 /// &skey=@crypt_77e833b9_e705acd2a3250d78bdbb1137d87afad5 public static HttpTaskParams GetContactAllParams(string host, WxAccount wxAccount) { string url = string.Format("{0}?lang=zh_CN&pass_ticket={1}&r={2}&seq=0&skey={3}", WxHttpApi.GetCommonUrl(host, WxHttpApi.URL_WX_CONTACT_ALL), encoding(wxAccount.PassTicket), TimeUtil.CurrentTimeMillis(), encoding(wxAccount.Skey)); return(HttpTaskParams.NewGet(url)); }
/// <summary> /// 获取登录uid相关请求参数 /// </summary> /// <returns></returns> /// url->https://login.wx.qq.com/jslogin /// ?appid=wx782c26e4c19acffb /// &redirect_uri=https%3A%2F%2Fwx.qq.com%2Fcgi-bin%2Fmmwebwx-bin%2Fwebwxnewloginpage /// &fun=new /// &lang=zh_CN /// &_=1499308667244 public static HttpTaskParams GetLoginUidParams() { HttpTaskParams htp = HttpTaskParams.NewGet(WxHttpApi.GetLoginUrl(WxHttpApi.URL_LOGIN_UID)); htp.AddStringParam("appid", "wx782c26e4c19acffb"); htp.AddStringParam("fun", "new"); htp.AddStringParam("lang", "zh_CN"); htp.AddStringParam("_", TimeUtil.CurrentTimeMillis().ToString()); htp.AddStringParam("redirect_uri", WxHttpApi.URL_WX_JS_LOGIN_REDIRECT_URI); return(htp); }
/// <summary> /// 获取二维码扫描结果请求 /// </summary> /// <param name="uid"></param> /// <param name="tip"></param> /// <returns></returns> /// url->https://login.wx.qq.com/cgi-bin/mmwebwx-bin/login /// ?loginicon=true /// &uuid=Ifv-J92fbw== /// &tip=0& /// r=-366287686& /// _=1499309823465 public static HttpTaskParams GetLoginScanParams(string uid, string tip) { HttpTaskParams htp = HttpTaskParams.NewGet(WxHttpApi.GetLoginUrl(WxHttpApi.URL_LOGIN_QRCODE_SCAN_CHECK)); htp.AddStringParam("uuid", uid); htp.AddStringParam("tip", tip); htp.AddStringParam("loginicon", "true"); long millis = TimeUtil.CurrentTimeMillis(); htp.AddStringParam("r", ((millis / 1000)).ToString());//时间戳取反 htp.AddStringParam("_", millis.ToString()); return(htp); }
/// <summary> /// 获取同步检查参数 /// </summary> /// <param name="account"></param> /// <param name="deviceId"></param> /// <param name="wxSyncKey"></param> /// <returns></returns> /// https://webpush.wx2.qq.com/cgi-bin/mmwebwx-bin/synccheck /// ?r=1501480039641 /// &skey=%40crypt_77e833b9_e705acd2a3250d78bdbb1137d87afad5&sid=TlG7spFxhWig3TpY /// &uin=243082945 /// &deviceid=e835949820036438 /// &synckey=1_653730215%7C2_653730255%7C3_653730169%7C1000_1501462441 /// &_=1501479916949 public static HttpTaskParams GetSyncCheckParams(string host, WxAccount wxAccount, WxSyncKey wxSyncKey) { HttpTaskParams htp = HttpTaskParams.NewGet(WxHttpApi.GetWebPushUrl(host, WxHttpApi.URL_WX_MSG_CHECK)); htp.AddStringParam("skey", wxAccount.Skey); htp.AddStringParam("uin", wxAccount.Uin); htp.AddStringParam("sid", wxAccount.Sid); htp.AddStringParam("deviceid", wxAccount.DeviceId); htp.AddStringParam("synckey", WxReqUtil.GetSyncKey2String(wxSyncKey)); long millis = TimeUtil.CurrentTimeMillis(); htp.AddStringParam("r", millis.ToString()); htp.AddStringParam("_", (millis / 1000).ToString());//时间戳取反 return(htp); }
/// <summary> /// 获取微信登录初始化接口 /// </summary> /// <param name="result"></param> /// <returns></returns> /// demo:https://wx.qq.com/cgi-bin/mmwebwx-bin/webwxinit /// ?r=665841145 /// &lang=zh_CN /// &pass_ticket=zXbwZhRifdRRNcPjsjxyemYskxzSRQOxZF6T3HJuTpsdgPENMSMXylIlmsnrEZ5s public static HttpTaskParams GetLoginInitParams(string host, WxLoginIdsResult result, string deviceId) { //r时间戳取反 string url = string.Format("{0}?r={1}&lang={2}&pass_ticket={3}", WxHttpApi.GetCommonUrl(host, WxHttpApi.URL_WX_INIT), (TimeUtil.CurrentTimeMillis() / 1000), "zh_CN", encoding(result.PassTicket)); HttpTaskParams htp = HttpTaskParams.NewPost(url); htp.ContentType = "application/json;charset=utf-8"; htp.CustomStringContentBody = JsonConvert.SerializeObject(WxReqUtil.GetBaseReq(result, deviceId)); #if Debug Console.WriteLine("init content body = " + htp.CustomStringContentBody); #endif return(htp); }
/// <summary> /// 批量获取联系人,包含个人和组 /// </summary> /// <param name="wxAccount"></param> /// <param name="groupUserNames"></param> /// <returns></returns> /// //https://wx.qq.com/cgi-bin/mmwebwx-bin/webwxbatchgetcontact /// ?type=ex /// &r=1498291861743 /// &lang=zh_CN /// &pass_ticket=ga8bxGb9YQJLWhU6RA6FMamJy0wqnD7QuWP9k%252F9tlTb8O1uUkgcZ7YbjNg3bEkYH public static HttpTaskParams GetBatchContactParams(string host, WxAccount wxAccount, List <string> groupUserNameIds) { string url = string.Format("{0}?type=ex&r={1}&lang=zh_CN&pass_ticket={2}", WxHttpApi.GetCommonUrl(host, WxHttpApi.URL_WX_CONTACT_BATCH), TimeUtil.CurrentTimeMillis(), encoding(wxAccount.PassTicket)); HttpTaskParams htp = HttpTaskParams.NewPost(url); htp.ContentType = "application/json;charset=utf-8"; WxBatchContactReq req = new WxBatchContactReq(); req.BaseRequest = WxReqUtil.GetIdentifyReq(wxAccount); req.Count = CollectionUtil.Size(groupUserNameIds); req.List = WxReqUtil.GetBatchContactItemList(groupUserNameIds); htp.CustomStringContentBody = JsonConvert.SerializeObject(req); return(htp); }
/// <summary> /// 同步获取更新消息 /// </summary> /// <param name="account"></param> /// <param name="syncKey"></param> /// <returns></returns> /// https://wx.qq.com/cgi-bin/mmwebwx-bin/webwxsync /// ?sid=XbUcBWzGt6NPu5jO /// &skey=@crypt_55085584_cf738edf865a9c101021022d1c732ae6 /// &lang=zh_CN /// &pass_ticket=lBIvUtbeb5e%252BMIDHLr5QVehuJDPbW3NEgMSh87ILAOv3ue1HdLtSV%252B8AK0ULznEL public static HttpTaskParams GetSyncMsgParams(string host, WxAccount account, WxSyncKey syncKey) { string url = string.Format("{0}?sid={1}&skey={2}&pass_ticket={3}&lang={4}", WxHttpApi.GetCommonUrl(host, WxHttpApi.URL_WX_MSG_PULL), encoding(account.Sid), encoding(account.Skey), encoding(account.PassTicket), "zh_CN"); HttpTaskParams htp = HttpTaskParams.NewPost(url); htp.ContentType = "application/json;charset=UTF-8"; WxWebSyncReq req = new WxWebSyncReq(); req.BaseRequest = WxReqUtil.GetIdentifyReq(account); req.SyncKey = syncKey; req.rr = (~(TimeUtil.CurrentTimeMillis() / 1000)).ToString();//时间戳取反 htp.CustomStringContentBody = JsonConvert.SerializeObject(req); return(htp); }
private string createPackage(string methodName, string[] parameterTypes, object[] parameters) { //RegistryParam registryParam = new RegistryParam //{ // registGroup = "EXECUTOR", // registryKey = executorappname, // registryValue = $"{executorip}:{executorPort}" //}; RpcRequest rpcRequest = new RpcRequest { accessToken = accessToken, className = "com.xxl.job.core.biz.AdminBiz", createMillisTime = TimeUtil.CurrentTimeMillis(), methodName = methodName,// "registry", parameters = parameters, parameterTypes = parameterTypes, serverAddress = this.address + MAPPING, }; var str = Newtonsoft.Json.JsonConvert.SerializeObject(rpcRequest); return(str); }