/// <summary> /// 业务处理 /// </summary> private void MainPushSms() { try { threadLst = new List <Thread>(); threadStateLst = new List <Thread_State>(); IList <MsgBase> msgLst = GetMsg(); IList <Msg> numList = GetNumList(msgLst, 20); if (numList != null && numList.Count > 0) { int total_count = numList.Count; int thread_count = THREAD_COUNT; int take_count = total_count / thread_count + (total_count % thread_count > 0 ? 1 : 0); for (int x = 0; x < thread_count; x++) { Thread_Param para = new Thread_Param(); para.thread_id = x; para.msgLst = numList.Skip(x * take_count).Take(take_count).ToList <Msg>(); //处理数据 Thread t = new Thread(new ParameterizedThreadStart(PushSms)); t.IsBackground = true; t.Start(para); threadLst.Add(t); } } } catch (Exception e) { string msg = string.Format("[MainPushSms] err={0}", e.Message); WriteLog(msg, "Sms-Log"); service_log_add(0, "Sms", msg); } }
/// <summary> /// 发送消息 /// </summary> /// <param name="obj"></param> private void PushSms(object obj) { JPushClient client = new JPushClient(app_key, master_secret); Thread_Param para = obj as Thread_Param; foreach (Msg msg in para.msgLst) { try { PushPayload payload = PushObject_ios_audienceMore_messageWithExtras(msg); client.SendPush(payload); //var result = client.SendPush(payload); ////由于统计数据并非非是即时的,所以等待一小段时间再执行下面的获取结果方法 //System.Threading.Thread.Sleep(10000); ////如需查询上次推送结果执行下面的代码 //var apiResult = client.getReceivedApi(result.msg_id.ToString()); //var apiResultv3 = client.getReceivedApi_v3(result.msg_id.ToString()); ////如需查询某个messageid的推送结果执行下面的代码 //var queryResultWithV2 = client.getReceivedApi("1739302794"); //var querResultWithV3 = client.getReceivedApi_v3("1739302794"); } catch (APIRequestException e) { //Console.WriteLine("Error response from JPush server. Should review and fix it. "); //Console.WriteLine("HTTP Status: " + e.Status); //Console.WriteLine("Error Code: " + e.ErrorCode); //Console.WriteLine("Error Message: " + e.ErrorMessage); string err = string.Format("[PushSms] Error response from JPush server. HTTP Status:{0},Error Code:{1},Error Message:{2}", e.Status, e.ErrorCode, e.Message); WriteLog(err, "Sms-Log"); service_log_add(msg.msg_id, "Sms", err); } catch (APIConnectionException e) { //Console.WriteLine(e.Message); string err = string.Format("[PushSms] Error Message:{0}", e.Message); WriteLog(err, "Sms-Log"); service_log_add(msg.msg_id, "Sms", err); } } }