using BBWY.Client.Helpers; using Newtonsoft.Json.Linq; using System; using System.Collections.Concurrent; using System.Linq; using System.Threading.Tasks; using System.Windows; namespace BBWY.Client.ViewModels { public partial class OrderListViewModel { private PipeHelper pipeHelper; private ConcurrentDictionary dongdongBuyerDictionary; public void InitDongDong() { dongdongBuyerDictionary = new ConcurrentDictionary(); pipeHelper.ServerReceiveCallback = OnDongDongSendMessage; pipeHelper.CreateServer("bbwyPipeServer"); } private void OnDongDongSendMessage(string msg) { if (string.IsNullOrEmpty(msg)) return; try { var j = JObject.Parse(msg); var buyerAccount = j.Value("user"); var phone = j.Value("phone"); if (!string.IsNullOrEmpty(buyerAccount) && !string.IsNullOrEmpty(phone)) { var key = $"{buyerAccount}_{phone}"; if (!dongdongBuyerDictionary.TryAdd(key, phone)) return; } var order = OrderList.FirstOrDefault(o => !string.IsNullOrEmpty(o.BuyerAccount) && o.BuyerAccount == buyerAccount); if (order != null && order.Consignee != null && order.Consignee.IsDecode) return; //已经解密过 Task.Factory.StartNew(() => orderService.DecodeConsignee(order.Id, phone)).ContinueWith(t => { var response = t.Result; IsLoading = false; if (!response.Success) { App.Current.Dispatcher.Invoke(() => MessageBox.Show(response.Msg, "解密失败")); return; } order.Consignee.ContactName = response.Data.ContactName; order.Consignee.Address = response.Data.Address; order.Consignee.Mobile = response.Data.Mobile; order.Consignee.IsDecode = true; }); } catch (Exception ex) { } } } }