From ef39b91982e51ff3585df27dece53f29b49b5dca Mon Sep 17 00:00:00 2001
From: shanj <18996038927@163.com>
Date: Fri, 1 Apr 2022 05:28:28 +0800
Subject: [PATCH] =?UTF-8?q?=E6=8A=93=E6=89=8B=E6=9C=BA=E5=8F=B7?=
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit
---
BBWY.Client/APIServices/OrderService.cs | 3 +-
BBWY.Client/BBWY.Client.csproj | 3 +-
BBWY.Client/ViewModels/MainViewModel.cs | 72 ++-
.../ViewModels/Order/OrderListViewModel.cs | 7 +-
BBWY.Client/Views/MainWindow.xaml | 6 +
BBWY.Client/Views/MainWindow.xaml.cs | 16 -
BBWY.Client/Views/Order/GrabJDMibole.xaml | 16 +
BBWY.Client/Views/Order/GrabJDMibole.xaml.cs | 98 ++++
BBWY.Common/Http/HttpDownloader.cs | 456 ++++++++++++++++++
BBWY.Server.Business/Order/OrderBusiness.cs | 10 +-
.../Request/Order/DecryptConsigneeRequest.cs | 5 +
11 files changed, 669 insertions(+), 23 deletions(-)
create mode 100644 BBWY.Client/Views/Order/GrabJDMibole.xaml
create mode 100644 BBWY.Client/Views/Order/GrabJDMibole.xaml.cs
create mode 100644 BBWY.Common/Http/HttpDownloader.cs
diff --git a/BBWY.Client/APIServices/OrderService.cs b/BBWY.Client/APIServices/OrderService.cs
index 67e0c489..259247fa 100644
--- a/BBWY.Client/APIServices/OrderService.cs
+++ b/BBWY.Client/APIServices/OrderService.cs
@@ -63,7 +63,7 @@ namespace BBWY.Client.APIServices
///
///
///
- public ApiResponse DecodeConsignee(string orderId)
+ public ApiResponse DecodeConsignee(string orderId, string plaintextMobile)
{
return SendRequest(globalContext.BBYWApiHost, "Api/Order/DecryptConsignee", new
{
@@ -73,6 +73,7 @@ namespace BBWY.Client.APIServices
globalContext.User.Shop.AppToken,
saveResponseLog = true,
orderId,
+ plaintextMobile,
saveDb = true
}, null, HttpMethod.Post);
}
diff --git a/BBWY.Client/BBWY.Client.csproj b/BBWY.Client/BBWY.Client.csproj
index da12e8d8..a3c67933 100644
--- a/BBWY.Client/BBWY.Client.csproj
+++ b/BBWY.Client/BBWY.Client.csproj
@@ -1,7 +1,7 @@
- WinExe
+ Exe
netcoreapp3.1
true
Resources\Images\bbwylogo.ico
@@ -40,6 +40,7 @@
+
diff --git a/BBWY.Client/ViewModels/MainViewModel.cs b/BBWY.Client/ViewModels/MainViewModel.cs
index c1685673..1e3a2aec 100644
--- a/BBWY.Client/ViewModels/MainViewModel.cs
+++ b/BBWY.Client/ViewModels/MainViewModel.cs
@@ -1,13 +1,16 @@
using BBWY.Client.APIServices;
using BBWY.Client.Models;
using BBWY.Common.Extensions;
+using BBWY.Common.Http;
using BBWY.Common.Models;
using GalaSoft.MvvmLight.Command;
using Jd.Api;
using Jd.Api.Request;
+using Microsoft.Web.WebView2.Core;
using System;
using System.Collections.Generic;
using System.Collections.ObjectModel;
+using System.Net.Http;
using System.Threading;
using System.Threading.Tasks;
using System.Windows;
@@ -18,10 +21,13 @@ namespace BBWY.Client.ViewModels
public class MainViewModel : BaseVM, IDenpendency
{
#region Properties
+ private IHttpClientFactory httpClientFactory;
private MdsApiService mdsApiService;
private LogisticsService logisticsService;
private MenuModel selectedMenuModel;
private bool showShopChoosePanel;
+ private bool showWB2RuntimeDownloadPanel;
+ private double wb2DownloadProgress;
public GlobalContext GlobalContext { get; set; }
public IList MenuList { get; set; }
@@ -51,6 +57,16 @@ namespace BBWY.Client.ViewModels
/// 是否显示店铺选择列表
///
public bool ShowShopChoosePanel { get => showShopChoosePanel; set { Set(ref showShopChoosePanel, value); } }
+
+ ///
+ /// 是否显示webview2 runtime下载面板
+ ///
+ public bool ShowWB2RuntimeDownloadPanel { get => showWB2RuntimeDownloadPanel; set { Set(ref showWB2RuntimeDownloadPanel, value); } }
+
+ ///
+ /// webview2 runtime下载进度
+ ///
+ public double Wb2DownloadProgress { get => wb2DownloadProgress; set { Set(ref wb2DownloadProgress, value); } }
#endregion
#region Commands
@@ -60,8 +76,9 @@ namespace BBWY.Client.ViewModels
#endregion
#region Methods
- public MainViewModel(GlobalContext globalContext, MdsApiService mdsApiService, LogisticsService logisticsService)
+ public MainViewModel(GlobalContext globalContext, MdsApiService mdsApiService, LogisticsService logisticsService, IHttpClientFactory httpClientFactory)
{
+ this.httpClientFactory = httpClientFactory;
this.mdsApiService = mdsApiService;
this.logisticsService = logisticsService;
ClosingCommand = new RelayCommand(Exit);
@@ -88,6 +105,12 @@ namespace BBWY.Client.ViewModels
}
};
Task.Factory.StartNew(Login);
+
+ if (!CheckWebview2Runtime())
+ {
+ //下载webview2 runtime
+ Task.Factory.StartNew(DownloadWebview2Runtime);
+ }
}
private void Exit(System.ComponentModel.CancelEventArgs e)
@@ -185,6 +208,53 @@ namespace BBWY.Client.ViewModels
}
GlobalContext.LogisticsResponseList = response.Data;
}
+
+ private bool CheckWebview2Runtime()
+ {
+ bool isInstall = false;
+ try
+ {
+ isInstall = !string.IsNullOrEmpty(CoreWebView2Environment.GetAvailableBrowserVersionString());
+ }
+ catch (Exception ex)
+ {
+ Console.WriteLine(ex.Message);
+ }
+ return isInstall;
+ }
+
+ private void DownloadWebview2Runtime()
+ {
+ ShowWB2RuntimeDownloadPanel = true;
+ var dw = new HttpDownloader(httpClientFactory, null);
+ dw.OnDownloadProgressChanged += Dw_OnDownloadProgressChanged;
+ dw.OnDownloadComplated += Dw_OnDownloadComplated;
+ var url = "https://msedge.sf.dl.delivery.mp.microsoft.com/filestreamingservice/files/116652c9-fae0-4d10-9c67-8bc4f24064e0/MicrosoftEdgeWebView2RuntimeInstallerX64.exe";
+ dw.DownloadFile(url, System.IO.Path.GetTempPath(), "MicrosoftEdgeWebView2RuntimeInstallerX64.exe", null);
+ dw.OnDownloadProgressChanged -= Dw_OnDownloadProgressChanged;
+ dw.OnDownloadComplated -= Dw_OnDownloadComplated;
+ }
+
+ private void Dw_OnDownloadComplated(object sender, DownloadCompletedEventArgs e)
+ {
+ try
+ {
+ if (e.Error == null)
+ {
+ System.Diagnostics.Process.Start(System.IO.Path.Combine(System.IO.Path.GetTempPath(), "MicrosoftEdgeWebView2RuntimeInstallerX64.exe"));
+ ShowWB2RuntimeDownloadPanel = false;
+ }
+ }
+ catch (Exception ex)
+ {
+ MessageBox.Show(ex.Message);
+ }
+ }
+
+ private void Dw_OnDownloadProgressChanged(object sender, DownloadProgressChangedEventArgs e)
+ {
+ Wb2DownloadProgress = e.ProgressPercentage;
+ }
#endregion
}
}
diff --git a/BBWY.Client/ViewModels/Order/OrderListViewModel.cs b/BBWY.Client/ViewModels/Order/OrderListViewModel.cs
index 8dad0bda..edfce75a 100644
--- a/BBWY.Client/ViewModels/Order/OrderListViewModel.cs
+++ b/BBWY.Client/ViewModels/Order/OrderListViewModel.cs
@@ -247,8 +247,13 @@ namespace BBWY.Client.ViewModels
private void DecodeConsignee(Order order)
{
+ var plaintextMobile = string.Empty;
+ var grab = new GrabJDMibole(order.Id);
+ if (grab.ShowDialog() == true)
+ plaintextMobile = grab.Tag.ToString();
+ return;
IsLoading = true;
- Task.Factory.StartNew(() => orderService.DecodeConsignee(order.Id)).ContinueWith(t =>
+ Task.Factory.StartNew(() => orderService.DecodeConsignee(order.Id, plaintextMobile)).ContinueWith(t =>
{
var response = t.Result;
IsLoading = false;
diff --git a/BBWY.Client/Views/MainWindow.xaml b/BBWY.Client/Views/MainWindow.xaml
index 3f377f2f..07ea6fc3 100644
--- a/BBWY.Client/Views/MainWindow.xaml
+++ b/BBWY.Client/Views/MainWindow.xaml
@@ -99,6 +99,12 @@
+
+
+
+
diff --git a/BBWY.Client/Views/MainWindow.xaml.cs b/BBWY.Client/Views/MainWindow.xaml.cs
index 54c5fe27..99ed5b44 100644
--- a/BBWY.Client/Views/MainWindow.xaml.cs
+++ b/BBWY.Client/Views/MainWindow.xaml.cs
@@ -23,23 +23,7 @@ namespace BBWY.Client.Views
private void MainWindow_Loaded(object sender, RoutedEventArgs e)
{
-
- //var appkey = "120EA9EC65AB017567D78CC1139EEEA5";
- //var appsecret = "866a9877f5f24b03b537483b4defe75d";
- //var token = "00f28ca8917948aea46e9f534090817a5mdb";
- //
- //IJdClient client = new DefaultJdClient("https://api.jd.com/routerjson", appkey, appsecret);
- //
- //WareReadSearchWare4ValidRequest req = new WareReadSearchWare4ValidRequest();
- //req.orderField = "modified";
- //req.orderType = "desc";
- //req.pageSize = 50;
- //req.field = "images,logo";
- //
- //WareReadSearchWare4ValidResponse response = client.Execute(req, token, DateTime.Now.ToLocalTime());
- //
- //Console.WriteLine(response.Body);
}
private void frame_Navigated(object sender, System.Windows.Navigation.NavigationEventArgs e)
diff --git a/BBWY.Client/Views/Order/GrabJDMibole.xaml b/BBWY.Client/Views/Order/GrabJDMibole.xaml
new file mode 100644
index 00000000..bc6bc2e1
--- /dev/null
+++ b/BBWY.Client/Views/Order/GrabJDMibole.xaml
@@ -0,0 +1,16 @@
+
+
+
+
+
+
+
+
diff --git a/BBWY.Client/Views/Order/GrabJDMibole.xaml.cs b/BBWY.Client/Views/Order/GrabJDMibole.xaml.cs
new file mode 100644
index 00000000..c80bf746
--- /dev/null
+++ b/BBWY.Client/Views/Order/GrabJDMibole.xaml.cs
@@ -0,0 +1,98 @@
+using Microsoft.Web.WebView2.Core;
+using Microsoft.Web.WebView2.Wpf;
+using System;
+using System.Collections.Generic;
+using System.Diagnostics;
+using System.Reflection;
+using System.Text;
+using System.Windows;
+using System.Windows.Controls;
+using System.Windows.Data;
+using System.Windows.Documents;
+using System.Windows.Input;
+using System.Windows.Media;
+using System.Windows.Media.Imaging;
+using System.Windows.Shapes;
+using io = System.IO;
+
+namespace BBWY.Client.Views.Order
+{
+ ///
+ /// GrabJDMibole.xaml 的交互逻辑
+ ///
+ public partial class GrabJDMibole : Window
+ {
+ private WebView2 wb2;
+ //private Stopwatch sw;
+ private string orderId;
+
+ public GrabJDMibole(string orderId)
+ {
+ InitializeComponent();
+ this.orderId = orderId;
+ this.Loaded += GrabJDMibole_Loaded;
+ this.Unloaded += GrabJDMibole_Unloaded;
+ }
+
+ private void GrabJDMibole_Unloaded(object sender, RoutedEventArgs e)
+ {
+ this.Unloaded -= GrabJDMibole_Unloaded;
+ if (wb2 != null && wb2.CoreWebView2 != null)
+ {
+ wb2.CoreWebView2InitializationCompleted -= Wb2_CoreWebView2InitializationCompleted;
+ wb2.NavigationCompleted -= Wb2_NavigationCompleted;
+ wb2.WebMessageReceived -= CoreWebView2_WebMessageReceived;
+ //wb2.Dispose();
+ Console.WriteLine("wb2 Disposed");
+ }
+ }
+
+ private void GrabJDMibole_Loaded(object sender, RoutedEventArgs e)
+ {
+ //sw = new Stopwatch();
+ wb2 = new WebView2();
+ grid.Children.Add(wb2);
+ //sw.Start();
+ var wb2Setting = CoreWebView2Environment.CreateAsync(userDataFolder: io.Path.Combine(io.Path.GetDirectoryName(Assembly.GetExecutingAssembly().Location), "WebView2UserData")).Result;
+ wb2.EnsureCoreWebView2Async(wb2Setting);
+ wb2.CoreWebView2InitializationCompleted += Wb2_CoreWebView2InitializationCompleted;
+ wb2.NavigationCompleted += Wb2_NavigationCompleted;
+ wb2.WebMessageReceived += CoreWebView2_WebMessageReceived;
+ }
+ private void Wb2_CoreWebView2InitializationCompleted(object sender, Microsoft.Web.WebView2.Core.CoreWebView2InitializationCompletedEventArgs e)
+ {
+ //sw.Stop();
+ //Console.WriteLine(sw.ElapsedMilliseconds);
+ wb2.CoreWebView2.Navigate($"https://neworder.shop.jd.com/order/orderDetail?orderId={orderId}");
+ }
+
+ private async void Wb2_NavigationCompleted(object sender, CoreWebView2NavigationCompletedEventArgs e)
+ {
+ //Console.WriteLine(wb2.CoreWebView2.Source);
+ //Console.WriteLine(wb2.Source);
+ if (wb2.CoreWebView2.Source.StartsWith("https://passport.shop.jd.com/login"))
+ {
+ //首次打开需要登录
+ await wb2.CoreWebView2.ExecuteScriptAsync("window.scrollTo(790,150)");
+ await wb2.CoreWebView2.ExecuteScriptAsync("document.querySelector(\"div[data-tab-id='form']\").click()");
+ }
+ else if (wb2.CoreWebView2.Source.StartsWith("https://neworder.shop.jd.com/order/orderDetail"))
+ {
+ //进入订单详情页面,触发点击查看手机号
+ Console.WriteLine("触发查看手机号");
+ var js = @"var mobileNode = document.getElementById('mobile');
+ mobileNode.addEventListener('DOMNodeInserted',function(e){ var m=mobileNode.innerText; window.chrome.webview.postMessage(m);});
+ document.getElementById('viewOrderMobile').click();";
+ _ = await wb2.CoreWebView2.ExecuteScriptAsync(js);
+ }
+ }
+
+ private void CoreWebView2_WebMessageReceived(object sender, CoreWebView2WebMessageReceivedEventArgs e)
+ {
+ var mobole = e.TryGetWebMessageAsString();
+ this.Tag = mobole;
+ this.DialogResult = true;
+ this.Close();
+ }
+ }
+}
diff --git a/BBWY.Common/Http/HttpDownloader.cs b/BBWY.Common/Http/HttpDownloader.cs
new file mode 100644
index 00000000..665bdaf3
--- /dev/null
+++ b/BBWY.Common/Http/HttpDownloader.cs
@@ -0,0 +1,456 @@
+using System;
+using System.IO;
+using System.Net;
+using System.Net.Http;
+using System.Threading;
+
+namespace BBWY.Common.Http
+{
+ ///
+ /// Http下载器
+ ///
+ public class HttpDownloader
+ {
+
+ private IHttpClientFactory httpClientFactory;
+
+ public HttpDownloader(IHttpClientFactory httpClientFactory, DownloadSetting dwSetting = null)
+ {
+ this.httpClientFactory = httpClientFactory;
+ complateArgs = new DownloadCompletedEventArgs();
+ changeArgs = new DownloadProgressChangedEventArgs();
+ if (dwSetting == null)
+ dwSetting = new DownloadSetting();
+ downloadSetting = dwSetting;
+ buffer = new byte[downloadSetting.BufferSize];
+ }
+
+ ~HttpDownloader()
+ {
+ this.buffer = null;
+ this.downloadSetting = null;
+ this.complateArgs.Error = null;
+ this.complateArgs = null;
+ this.changeArgs = null;
+ }
+
+ #region Property
+
+ ///
+ /// 下载进度变化参数
+ ///
+ private DownloadProgressChangedEventArgs changeArgs;
+
+ ///
+ /// 下载完成参数
+ ///
+ private DownloadCompletedEventArgs complateArgs;
+
+ ///
+ /// 下载参数配置类
+ ///
+ private DownloadSetting downloadSetting;
+
+ ///
+ /// 下载缓冲区
+ ///
+ private byte[] buffer;
+
+ #endregion
+
+ #region Delegate
+ public delegate void DownloadProgressChangedEventHandler(object sender, DownloadProgressChangedEventArgs e);
+
+ public delegate void DownloadCompletedEventHandler(object sender, DownloadCompletedEventArgs e);
+
+ public delegate void ReDownloadEventHandler(object sender, DownloadCompletedEventArgs e);
+ #endregion
+
+ #region Event
+ ///
+ /// 下载进度变化事件
+ ///
+ public event DownloadProgressChangedEventHandler OnDownloadProgressChanged;
+
+ ///
+ /// 下载完成事件
+ ///
+ public event DownloadCompletedEventHandler OnDownloadComplated;
+
+ ///
+ /// 自动重下事件
+ ///
+ public event ReDownloadEventHandler OnReDownload;
+ #endregion
+
+ #region Method
+ ///
+ /// 设置下载参数
+ ///
+ ///
+ public void SetDownloadSetting(DownloadSetting dwSetting)
+ {
+ if (dwSetting != null)
+ downloadSetting = dwSetting;
+ }
+
+ private void DoProcessChangedEvent(DownloadProgressChangedEventArgs args)
+ {
+ OnDownloadProgressChanged?.Invoke(this, args);
+ }
+
+ private void DoCompletedEvent(DownloadCompletedEventArgs args)
+ {
+ OnDownloadComplated?.Invoke(this, args);
+ }
+
+ private void DoReDownloadEvent(DownloadCompletedEventArgs args)
+ {
+ OnReDownload?.Invoke(this, args);
+ }
+
+ private void ArgsInit()
+ {
+ changeArgs.Cancel = false;
+ complateArgs.Cancelled = false;
+ complateArgs.Error = null;
+ }
+
+ ///
+ /// 获取文件总大小
+ ///
+ ///
+ ///
+ public long GetTotalLength(string url)
+ {
+ long length = 0;
+ try
+ {
+ using (var httpClient = httpClientFactory.CreateClient())
+ {
+ var requestMessage = new HttpRequestMessage(HttpMethod.Head, url);
+ var httpResponse = httpClient.SendAsync(requestMessage, HttpCompletionOption.ResponseHeadersRead).Result;
+ if (httpResponse.IsSuccessStatusCode)
+ length = httpResponse.Content.Headers.ContentLength ?? 0;
+ }
+
+ //var req = (HttpWebRequest)WebRequest.Create(new Uri(url));
+ //req.Method = "HEAD";
+ //req.Timeout = 5000;
+ //var res = (HttpWebResponse)req.GetResponse();
+ //if (res.StatusCode == HttpStatusCode.OK)
+ //{
+ // length = res.ContentLength;
+ //}
+ //res.Close();
+ return length;
+ }
+ catch (WebException wex)
+ {
+ throw wex;
+ }
+ }
+
+
+ private bool DownloadFile(string url, string savePath, long startPosition, long totalSize)
+ {
+ long currentReadSize = 0; //当前已经读取的字节数
+ if (startPosition != 0)
+ currentReadSize = startPosition;
+ using (var httpClient = httpClientFactory.CreateClient())
+ {
+ try
+ {
+ httpClient.Timeout = new TimeSpan(0, 0, 20);
+ if (currentReadSize != 0 && currentReadSize == totalSize)
+ {
+ changeArgs.CurrentSize = changeArgs.TotalSize = totalSize;
+ return true;
+ }
+ if (currentReadSize != 0)
+ {
+ try
+ {
+ httpClient.DefaultRequestHeaders.Range = new System.Net.Http.Headers.RangeHeaderValue(currentReadSize, totalSize);
+ }
+ catch (Exception ex)
+ {
+ //http 416
+ currentReadSize = 0;
+ }
+ }
+
+ using (var response = httpClient.GetAsync(url, HttpCompletionOption.ResponseHeadersRead).Result)
+ {
+ using (var responseStream = response.Content.ReadAsStreamAsync().Result)
+ {
+ changeArgs.TotalSize = totalSize;
+ using (var fs = new FileStream(savePath, currentReadSize == 0 ? FileMode.Create : FileMode.Append, FileAccess.Write))
+ {
+ //判断服务器是否支持断点续下
+ if (currentReadSize != 0 &&
+ response.StatusCode == HttpStatusCode.PartialContent &&
+ response.Content.Headers.ContentLength != totalSize)
+ fs.Seek(startPosition, SeekOrigin.Begin); //支持,从本地文件流末尾进行写入
+ else
+ currentReadSize = 0; //不支持,从本地文件流开始进行写入
+
+ if (buffer.Length != downloadSetting.BufferSize)
+ buffer = new byte[downloadSetting.BufferSize];
+ int size = responseStream.Read(buffer, 0, buffer.Length);
+ while (size != 0)
+ {
+ fs.Write(buffer, 0, size);
+ if (buffer.Length != downloadSetting.BufferSize)
+ buffer = new byte[downloadSetting.BufferSize];
+ size = responseStream.Read(buffer, 0, buffer.Length);
+ currentReadSize += size; //累计下载大小
+ //执行下载进度变化事件
+ changeArgs.CurrentSize = currentReadSize;
+ DoProcessChangedEvent(changeArgs);
+ //判断挂起状态
+ if (changeArgs.Cancel)
+ return true;
+ }
+
+ //执行下载进度变化事件
+ changeArgs.CurrentSize = changeArgs.TotalSize;
+ DoProcessChangedEvent(changeArgs);
+ fs.Flush(true);
+ }
+
+ //验证远程服务器文件字节数和本地文件字节数是否一致
+ long localFileSize = 0;
+ try
+ {
+ localFileSize = new FileInfo(savePath).Length;
+ }
+ catch (Exception ex)
+ {
+ localFileSize = changeArgs.CurrentSize;
+ }
+
+ if (totalSize != localFileSize)
+ {
+ complateArgs.Error = new Exception(string.Format("远程文件字节:[{0}]与本地文件字节:[{1}]不一致", totalSize, localFileSize));
+ }
+ }
+ }
+ }
+ catch (IOException ex)
+ {
+ complateArgs.Error = ex;
+ }
+ catch (WebException ex)
+ {
+ complateArgs.Error = ex;
+ }
+ catch (Exception ex)
+ {
+ complateArgs.Error = ex;
+ }
+ }
+ return complateArgs.Error == null;
+ }
+
+
+ public bool DownloadFile(string url, string saveFolderPath, string saveFileName, long? totalSize)
+ {
+ ArgsInit();
+ var result = false;
+ //验证文件夹
+ try
+ {
+ if (!Directory.Exists(saveFolderPath))
+ Directory.CreateDirectory(saveFolderPath);
+ }
+ catch (Exception ex)
+ {
+ complateArgs.Error = ex;
+ DoCompletedEvent(complateArgs);
+ return result;
+ }
+
+ if (totalSize == null || totalSize.Value == 0)
+ {
+ try
+ {
+ totalSize = GetTotalLength(url);
+ }
+ catch (Exception ex)
+ {
+ Console.WriteLine("获取远程服务器字节数失败 {0}", ex.Message);
+ complateArgs.Error = ex;
+ DoCompletedEvent(complateArgs);
+ return result;
+ }
+ }
+
+ string saveFilePath = Path.Combine(saveFolderPath, saveFileName);
+ long startPosition = 0;
+ for (var i = 1; i <= downloadSetting.TryCount; i++)
+ {
+ if (File.Exists(saveFilePath))
+ {
+ try
+ {
+ startPosition = new FileInfo(saveFilePath).Length;
+ }
+ catch
+ {
+ startPosition = 0;
+ }
+ }
+
+ result = DownloadFile(url, saveFilePath, startPosition, totalSize.Value);
+ if (result)
+ {
+ break;
+ }
+ else
+ {
+ if (i != downloadSetting.TryCount)
+ {
+ complateArgs.TryCount = i + 1;
+ DoReDownloadEvent(complateArgs);
+ Thread.Sleep(downloadSetting.SleepTime);
+ if (complateArgs.Cancelled)
+ break;
+ ArgsInit();
+ }
+ }
+ if (complateArgs.Cancelled)
+ break;
+ }
+ DoCompletedEvent(complateArgs);
+ return result;
+ }
+
+ public byte[] DwonloadBytes(string url)
+ {
+ ArgsInit();
+ using (var httpClient = httpClientFactory.CreateClient())
+ {
+ return httpClient.GetByteArrayAsync(url).Result;
+ }
+
+ }
+
+ ///
+ /// 取消/暂停下载
+ ///
+ public void CancelDownload()
+ {
+ this.changeArgs.Cancel = true;
+ this.complateArgs.Cancelled = true;
+ }
+ #endregion
+ }
+
+
+ ///
+ /// 下载进度变化参数
+ ///
+ public class DownloadProgressChangedEventArgs
+ {
+ public DownloadProgressChangedEventArgs()
+ {
+ ProgressPercentage = 0.0;
+ Cancel = false;
+ }
+ ///
+ /// 下载进度百分比
+ ///
+ public double ProgressPercentage;
+
+
+ private long currentSize;
+
+ ///
+ /// 当前下载总大小
+ ///
+ public long CurrentSize
+ {
+ get { return currentSize; }
+ set
+ {
+ currentSize = value;
+ this.ProgressPercentage = Math.Round((CurrentSize * 1.0 / TotalSize) * 100, 2);
+ }
+ }
+
+ ///
+ /// 文件总大小
+ ///
+ public long TotalSize;
+
+ ///
+ /// 取消状态
+ ///
+ public bool Cancel;
+ }
+
+ ///
+ /// 下载完成参数
+ ///
+ public class DownloadCompletedEventArgs
+ {
+ public DownloadCompletedEventArgs()
+ {
+ Cancelled = false;
+ Error = null;
+ }
+ ///
+ /// 下载异常
+ ///
+ public Exception Error;
+
+ ///
+ /// 重试次数
+ ///
+ public int TryCount;
+
+ ///
+ /// 下载操作是否被取消 【取消则为true;默认false】
+ ///
+ public bool Cancelled;
+ }
+
+ public class DownloadSetting
+ {
+ public DownloadSetting()
+ {
+ this.BufferSize = 1024 * 1024 * 1;
+ this.TryCount = 5;
+ this.SleepTime = 5000;
+ }
+
+ ///
+ ///
+ ///
+ ///
+ ///
+ /// 毫秒
+ public DownloadSetting(int bufferSize, int tryCount, int sleepTime)
+ {
+ this.BufferSize = bufferSize;
+ this.TryCount = tryCount;
+ this.SleepTime = sleepTime;
+ }
+
+ ///
+ /// 下载缓冲区大小
+ ///
+ public int BufferSize;
+
+ ///
+ /// 重试次数
+ ///
+ public int TryCount;
+
+ ///
+ /// 自动重下休眠时间, 毫秒
+ ///
+ public int SleepTime;
+ }
+}
diff --git a/BBWY.Server.Business/Order/OrderBusiness.cs b/BBWY.Server.Business/Order/OrderBusiness.cs
index 1c21b342..1a3a7cd4 100644
--- a/BBWY.Server.Business/Order/OrderBusiness.cs
+++ b/BBWY.Server.Business/Order/OrderBusiness.cs
@@ -256,15 +256,19 @@ namespace BBWY.Server.Business
if (!response.Success)
throw new BusinessException(response.Msg) { Code = response.Code };
+ if (!string.IsNullOrEmpty(decryptConsigneeRequest.PlaintextMobile))
+ response.Data.Mobile = decryptConsigneeRequest.PlaintextMobile;
+
//将解密后的收货人信息存至数据库
if (decryptConsigneeRequest.SaveDb)
+ {
fsql.Update(decryptConsigneeRequest.OrderId).Set(oc => oc.ContactName, response.Data.ContactName)
.Set(oc => oc.Address, response.Data.Address)
- .Set(oc => oc.Mobile, response.Data.Mobile)
- .Set(oc => oc.TelePhone, response.Data.TelePhone)
+ .SetIf(!string.IsNullOrEmpty(response.Data.Mobile), oc => oc.Mobile, response.Data.Mobile)
+ .SetIf(!string.IsNullOrEmpty(response.Data.TelePhone), oc => oc.TelePhone, response.Data.TelePhone)
.Set(oc => oc.IsDecode, true)
.ExecuteAffrows();
-
+ }
return response.Data;
}
diff --git a/BBWY.Server.Model/Dto/Request/Order/DecryptConsigneeRequest.cs b/BBWY.Server.Model/Dto/Request/Order/DecryptConsigneeRequest.cs
index 5eb02cdd..a1919b4f 100644
--- a/BBWY.Server.Model/Dto/Request/Order/DecryptConsigneeRequest.cs
+++ b/BBWY.Server.Model/Dto/Request/Order/DecryptConsigneeRequest.cs
@@ -7,6 +7,11 @@
{
public string OrderId { get; set; }
+ ///
+ /// 手机号明文
+ ///
+ public string PlaintextMobile { get; set; }
+
///
/// 保存至数据库
///