/// <summary> /// 删除消息 /// </summary> /// <param name="records"></param> /// <param name="strGroupName"></param> /// <returns> /// true 成功 /// false 失败 /// </returns> bool DeleteMessage(List <MessageRecord> records) { List <MessageRecord> delete_records = new List <MessageRecord>(); foreach (MessageRecord source in records) { MessageRecord record = new MessageRecord(); // 2016-6-20 jane 不需要传group参数 record.groups = dp2WeiXinService.C_Group_PatronNotity.Split(new char[] { ',' }); record.id = source.id; delete_records.Add(record); } string strError = ""; // CancellationToken cancel_token = new CancellationToken(); try { MessageConnection connection = this.Channels.GetConnectionTaskAsync( this.Url, dp2WeiXinService.C_ConnName_TraceMessage).Result; SetMessageRequest param = new SetMessageRequest("expire", "dontNotifyMe", delete_records);//records);这里应该用delete_records吧,用records好像也没错 CancellationToken cancel_token = new CancellationToken(); SetMessageResult result = connection.SetMessageTaskAsync(param, new TimeSpan(0, 1, 0), cancel_token).Result; if (result.Value == -1) { strError = result.ErrorInfo; goto ERROR1; } } catch (AggregateException ex) { strError = MessageConnection.GetExceptionText(ex); goto ERROR1; } catch (Exception ex) { strError = ex.Message; goto ERROR1; } return(true); ERROR1: dp2WeiXinService.Instance.WriteErrorLog("DeleteMessage() error : " + strError); //this.WriteLog("DeleteMessage() error : " + strError, dp2WeiXinService.C_LogLevel_1); return(false); }
// return: // false 出错 // true 成功 bool SendMessage( MessageConnection connection, string strGroupName, string[] texts) { string strError = ""; List <MessageRecord> records = new List <MessageRecord>(); foreach (string text in texts) { MessageRecord record = new MessageRecord(); record.groups = strGroupName.Split(new char[] { ',' }); record.creator = ""; // 服务器会自己填写 record.data = text; record.format = "text"; record.type = "message"; record.thread = ""; record.expireTime = new DateTime(0); // 表示永远不失效 records.Add(record); } try { SetMessageRequest param = new SetMessageRequest("create", "", records); SetMessageResult result = connection.SetMessageTaskAsync(param, new CancellationToken()).Result; if (result.Value == -1) { strError = result.ErrorInfo; goto ERROR1; } return(true); } catch (AggregateException ex) { strError = MessageConnection.GetExceptionText(ex); goto ERROR1; } catch (Exception ex) { strError = ex.Message; goto ERROR1; } ERROR1: this.Invoke((Action)(() => MessageBox.Show(this, strError))); return(false); }
void DeleteMessage(List <MessageRecord> records, string strGroupName) { List <MessageRecord> delete_records = new List <MessageRecord>(); foreach (MessageRecord source in records) { MessageRecord record = new MessageRecord(); record.groups = strGroupName.Split(new char[] { ',' }); record.id = source.id; delete_records.Add(record); } string strError = ""; // CancellationToken cancel_token = new CancellationToken(); try { MessageConnection connection = this.Channels.GetConnectionTaskAsync( this.Url, "").Result; SetMessageRequest param = new SetMessageRequest("expire", "dontNotifyMe", records); SetMessageResult result = connection.SetMessageTaskAsync(param, new CancellationToken()).Result; if (result.Value == -1) { goto ERROR1; } } catch (AggregateException ex) { strError = MessageConnection.GetExceptionText(ex); goto ERROR1; } catch (Exception ex) { strError = ex.Message; goto ERROR1; } return; ERROR1: WriteErrorLog("DeleteMessage() error : " + strError); }