SVN-Revision: r278
This commit is contained in:
tdx
2025-02-21 03:57:02 +00:00
parent d11c1d200c
commit ba85d23227
@@ -7,8 +7,10 @@ using Lskj.Core;
using Lskj.Model; using Lskj.Model;
using Lskj.Util; using Lskj.Util;
using Microsoft.WindowsAPICodePack.Shell; using Microsoft.WindowsAPICodePack.Shell;
using Newtonsoft.Json;
using Newtonsoft.Json.Linq; using Newtonsoft.Json.Linq;
using System; using System;
using System.Collections.Generic;
using System.Data; using System.Data;
using System.IO; using System.IO;
using System.Net; using System.Net;
@@ -322,15 +324,42 @@ namespace Lskj.PubArtworkDynamic.Control
string fileStream = Convert.ToBase64String(fileBytes); string fileStream = Convert.ToBase64String(fileBytes);
string userId = ERPInfo.Instance.UserId; string userId = ERPInfo.Instance.UserId;
DateTime uploadTime = DateTime.Now; DateTime uploadTime = DateTime.Now;
//上传文件到服务器目录 //上传文件到服务器目录
postUrl = "{0}Api/FileUploadApi.ashx?moduleId={1}&idValue={2}&folder={3}&totsize={4}&position={5}&filename={6}&method={7}"; postUrl = "{0}Api/FileUploadApi.ashx?moduleId={1}&idValue={2}&folder={3}&totsize={4}&position={5}&filename={6}&method={7}";
if (!string.IsNullOrEmpty(leftTopGridIdValue)) if (!string.IsNullOrEmpty(leftTopGridIdValue))
{
string token = "";
string loginUrl = $"{SystemInfo.Instance.OAUrl}/Api/SysUserAjaxApi.ashx";
HttpTools.setting("application/x-www-form-urlencoded", null, null, HttpTools.Encode.UTF8);
Dictionary<string, string> loginPmsDic = new Dictionary<string, string>();
loginPmsDic.Add("method", "Login");
loginPmsDic.Add("username", ERPInfo.Instance.UserName);
loginPmsDic.Add("password", ERPInfo.Instance.InPassWord);
HttpWebResponse loginResponse = HttpTools.Post(loginUrl, "", loginPmsDic, HttpTools.Method.POST, out CookieCollection loginCookie, out string loginResult);
if (loginResponse != null && !string.IsNullOrEmpty(loginResult))
{
JObject jObject = JsonConvert.DeserializeObject<JObject>(loginResult);
if (jObject.ContainsKey("success"))
{
if ((jObject["success"] + "").Equals("True"))
{
if (jObject.ContainsKey("token"))
{
token = jObject["token"] + "";
}
}
}
}
if (!string.IsNullOrEmpty(token))
{ {
postUrl = string.Format(postUrl, SystemInfo.Instance.OAUrl, this.MainViewModel.SysModel.ModuleCode, leftTopGridIdValue, "UploadFilesTemp", fileBytes.Length, 0, name, "DoWebUpload"); postUrl = string.Format(postUrl, SystemInfo.Instance.OAUrl, this.MainViewModel.SysModel.ModuleCode, leftTopGridIdValue, "UploadFilesTemp", fileBytes.Length, 0, name, "DoWebUpload");
HttpTools.setting("application/x-www-form-urlencoded", null, null); HttpTools.setting("application/x-www-form-urlencoded", null, null);
string result = ""; string result = "";
CookieCollection cookieCollection = null; CookieCollection cookieCollection = null;
HttpWebResponse webResponse = HttpTools.Post(postUrl, fileStream, null, HttpTools.Method.POST, out cookieCollection, out result); Dictionary<string, string> headerDic = new Dictionary<string, string>();
headerDic.Add("Authorization", $"Bearer {token}");
HttpWebResponse webResponse = HttpTools.Post(postUrl, fileStream, null, headerDic, HttpTools.Method.POST, out cookieCollection, out result);
if (webResponse != null && !string.IsNullOrEmpty(result)) if (webResponse != null && !string.IsNullOrEmpty(result))
{ {
JObject jsonObject = (JObject)Newtonsoft.Json.JsonConvert.DeserializeObject(result); JObject jsonObject = (JObject)Newtonsoft.Json.JsonConvert.DeserializeObject(result);
@@ -361,6 +390,12 @@ namespace Lskj.PubArtworkDynamic.Control
} }
} }
else else
{
returnMsg = loginResult;
isUpload = false;
}
}
else
{ {
returnMsg = "上传节点值不能为空"; returnMsg = "上传节点值不能为空";
isUpload = false; isUpload = false;
@@ -442,38 +477,4 @@ namespace Lskj.PubArtworkDynamic.Control
/// 附件转换byte[] /// 附件转换byte[]
/// </summary> /// </summary>
/// <param name="filePath">附件路径</param> /// <param name="filePath">附件路径</param>
/// <returns>二进制</returns> /// <returns>二进制</retur
private byte[] ConvertFileToBytes(string filePath)
{
byte[] bytContent = null;
System.IO.FileStream fs = null;
System.IO.BinaryReader br = null;
try
{
fs = new FileStream(filePath, System.IO.FileMode.Open);
}
catch (Exception)
{
throw;
}
finally
{
if (fs != null)
br = new BinaryReader((Stream)fs);
if (br != null)
bytContent = br.ReadBytes((Int32)fs.Length);
if (fs != null)
fs.Dispose();
}
return bytContent;
}
/// <summary>
/// 右键菜单回调
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
private void OnRightMenuCallBack(object sender, EventArgs e)
{
}
}
}