321 lines
13 KiB
C#
321 lines
13 KiB
C#
using ExtensionMethods;
|
||
using Kingdee.BOS;
|
||
using Kingdee.BOS.Core.Report;
|
||
using Microsoft.VisualStudio.TestTools.UnitTesting;
|
||
using Newtonsoft.Json;
|
||
using SAL_OUTSTOCK.Utils;
|
||
using System;
|
||
using System.Collections.Generic;
|
||
using System.Linq;
|
||
using System.Net;
|
||
using System.Net.Sockets;
|
||
using System.Security.Cryptography;
|
||
using System.Text;
|
||
using K3CExttensionMethods;
|
||
using System.Linq.Expressions;
|
||
using Kingdee.BOS.Core.List;
|
||
using Kingdee.BOS.Util;
|
||
using Newtonsoft.Json.Linq;
|
||
using HandleUtils;
|
||
|
||
namespace UnitTestProject1
|
||
{
|
||
[TestClass]
|
||
public class UnitTest1
|
||
{
|
||
public class TestEntity
|
||
{
|
||
public TestEntity(int _id, string _name)
|
||
{
|
||
id = _id;
|
||
name = _name;
|
||
}
|
||
public int id;
|
||
public string name;
|
||
}
|
||
|
||
[TestMethod]
|
||
public void TestMethod2()
|
||
{
|
||
|
||
var json = "{\"a\":\"0\"}";
|
||
var jToken = JsonConvert.DeserializeObject<JToken>(json);
|
||
|
||
var a = jToken["a"].ToString();
|
||
string formattedValue2 = $"CD{DateTime.Now.ToString("yyMMddHHmmss")}";
|
||
int i = 0;
|
||
string itemNo = $"CD{DateTime.Now:yyMMddHHmmss}" + i++.ToString("D2");
|
||
string yearAbbreviation = DateTime.Now.Year.ToString().Substring(2, 2); // 获取年份的缩写,比如2023年的缩写为23
|
||
string formattedValue = $"CD{yearAbbreviation}{DateTime.Now.ToString("MMddHHmmss")}";
|
||
//var list = new List<TestEntity>();
|
||
//list.Add(new TestEntity(1, "ttetett"));
|
||
//list.Add(new TestEntity(1, "ttetett"));
|
||
//list.Add(new TestEntity(1, "ttetett"));
|
||
//list.Add(new TestEntity(1, "ttetett"));
|
||
//list.Add(new TestEntity(1, "ttetett"));
|
||
//list.Add(new TestEntity(1, "ttetett"));
|
||
//list.Add(new TestEntity(1, "ttetett"));
|
||
//list.Add(new TestEntity(1, "ttetett"));
|
||
//list.Add(new TestEntity(1, "ttetett"));
|
||
//list.Add(new TestEntity(1, "ttetett"));
|
||
//list.Add(new TestEntity(1, "ttetett"));
|
||
//list.Add(new TestEntity(2, "ttetett"));
|
||
//list.Add(new TestEntity(2, "ttetett"));
|
||
//list.Add(new TestEntity(2, "ttetett"));
|
||
//list.Add(new TestEntity(2, "ttetett"));
|
||
//list.Add(new TestEntity(2, "ttetett"));
|
||
//list.Add(new TestEntity(2, "ttetett"));
|
||
//list.Add(new TestEntity(2, "ttetett"));
|
||
|
||
//var ttt = list.GroupBy(x => x.id);
|
||
|
||
//var count = ttt.Count();
|
||
|
||
var tt = " ";
|
||
var b = formattedValue2.Equals(formattedValue);
|
||
//var i = tt.ToDecimal();
|
||
|
||
return;
|
||
}
|
||
|
||
[TestMethod]
|
||
public void TestMethod1()
|
||
{
|
||
|
||
string appKey = "437268ee6e1a44b6ba135eea1614f94d";
|
||
string secret = "72CD0295-2312-4B08-9A4C-2A338A0EE9BF";
|
||
// 业务参数
|
||
Dictionary<string, object> jsonMap = new Dictionary<string, object>();
|
||
jsonMap.Add("declaCode", "T00001");
|
||
jsonMap.Add("entCusCode", "4404660006");
|
||
jsonMap.Add("entCreditCode", "91440404MABRGQJR1H");
|
||
jsonMap.Add("entName", "珠海昶展物流有限公司");
|
||
jsonMap.Add("declaEntCusCode", "4404660006");
|
||
jsonMap.Add("declaEntCreditCode", "91440404MABRGQJR1H");
|
||
jsonMap.Add("declaEntName", "珠海昶展物流有限公司");
|
||
jsonMap.Add("customsCode", "5781");
|
||
jsonMap.Add("bookNum", "T5781W000004");
|
||
jsonMap.Add("compileDate", "1970-01-01 08:00:00");
|
||
jsonMap.Add("inputMan", "Test01");
|
||
jsonMap.Add("declaType", "00");
|
||
jsonMap.Add("inputDate", "1970-01-01 08:00:00");
|
||
jsonMap.Add("declaDate", "1970-01-01 08:00:00");
|
||
|
||
|
||
var auditList = new List<Dictionary<string, Object>>();
|
||
Dictionary<string, object> data = new Dictionary<string, object>();
|
||
data.Add("itemNo", "1");
|
||
data.Add("deliveryOrderNo", "2");
|
||
data.Add("productCd", "100242");
|
||
data.Add("productDesc", "喇叭");
|
||
data.Add("specificationsModels", " ");
|
||
data.Add("deliveryCnt", "80.0000000000");
|
||
data.Add("calcUnit", "Pcs");
|
||
data.Add("hscode", "8");
|
||
data.Add("inventory", "9");
|
||
data.Add("inventoryOrderNo", "10");
|
||
|
||
Dictionary<string, object> data1 = new Dictionary<string, object>();
|
||
data1.Add("itemNo", "2");
|
||
data1.Add("deliveryOrderNo", "2");
|
||
data1.Add("productCd", "100243");
|
||
data1.Add("productDesc", "听筒");
|
||
data1.Add("specificationsModels", " ");
|
||
data1.Add("deliveryCnt", "80.0000000000");
|
||
data1.Add("calcUnit", "Pcs");
|
||
data1.Add("hscode", "8");
|
||
data1.Add("inventory", "9");
|
||
data1.Add("inventoryOrderNo", "10");
|
||
|
||
|
||
auditList.Add(data);
|
||
auditList.Add(data1);
|
||
jsonMap.Add("itemList", auditList);
|
||
|
||
string json = JsonConvert.SerializeObject(jsonMap);
|
||
json = WebUnit.UrlEncode(json);
|
||
|
||
// 系统参数
|
||
Dictionary<string, object> param = new Dictionary<string, object>();
|
||
param.Add("name", "supvWarehouse.save");
|
||
param.Add("app_key", appKey);
|
||
param.Add("data", json);
|
||
param.Add("timestamp", DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss"));
|
||
param.Add("version", "");
|
||
string sign = BuildSign(param, secret);
|
||
param.Add("sign", sign);
|
||
|
||
var jsonParam = JsonConvert.SerializeObject(param);
|
||
|
||
var result = HttpWebHelper.DoPost("http://119.146.223.48:39082/api/", jsonParam);
|
||
var a = 0.00M;
|
||
var a2 = 0L;
|
||
var f = (a == a2);
|
||
return;
|
||
}
|
||
|
||
public static string BuildSign(Dictionary<string, object> paramsMap, string secret)
|
||
{
|
||
//var keySet = paramsMap.Keys;
|
||
List<string> paramNames = paramsMap.Keys.ToList();
|
||
paramNames.Sort();
|
||
StringBuilder paramNameValue = new StringBuilder();
|
||
foreach (var paramName in paramNames)
|
||
{
|
||
paramNameValue.Append(paramName).Append(paramsMap[paramName]);
|
||
}
|
||
string source = secret + paramNameValue.ToString() + secret;
|
||
return ToMD5(source);
|
||
}
|
||
|
||
public static string ToMD5(string message)
|
||
{
|
||
try
|
||
{
|
||
// 1 创建一个提供信息摘要算法的对象,初始化为md5算法对象
|
||
MD5 md5 = new MD5CryptoServiceProvider();
|
||
// 2 将消息变成byte数组
|
||
byte[] input = Encoding.UTF8.GetBytes(message);
|
||
// 3 计算后获得字节数组,这就是那128位了
|
||
byte[] buff = md5.ComputeHash(input);
|
||
// 4 把数组每一字节(一个字节占八位)换成16进制连成md5字符串
|
||
return Byte2hex(buff);
|
||
}
|
||
catch (Exception e)
|
||
{
|
||
throw e;
|
||
}
|
||
}
|
||
|
||
private static string Byte2hex(byte[] bytes)
|
||
{
|
||
//创建一个StringBuilder对象来存储最终的结果
|
||
StringBuilder sign = new StringBuilder();
|
||
//使用for循环遍历字节数组中的每个字节
|
||
for (int i = 0; i < bytes.Length; i++)
|
||
{
|
||
// 将字节强制转换为整数,并对其进行位运算,即保留后八位的值,并转换为十六进制形式的字符串
|
||
string hex = bytes[i].ToString("x2");
|
||
// 如果转换后的字符串长度为1,即只有1位,则在前面添加一个0,以保证每个字节都是两位十六进制数
|
||
if (hex.Length == 1)
|
||
{
|
||
sign.Append("0");
|
||
}
|
||
// 将转换后的字符串追加到StringBuilder对象中,并转换为大写形式
|
||
sign.Append(hex.ToUpper());
|
||
}
|
||
return sign.ToString();
|
||
}
|
||
|
||
|
||
[TestMethod]
|
||
public void TestMethod3()
|
||
{
|
||
ReportHeader header = new ReportHeader();
|
||
var _colIndex = 0;
|
||
var h1 = header.AddChild("PRODUCTTYPE", new LocaleValue("生产类型"), _colIndex++);
|
||
|
||
|
||
// Add the following directive to the file:
|
||
// using System.Linq.Expressions;
|
||
|
||
// Creating a parameter for the expression tree.
|
||
ParameterExpression param = Expression.Parameter(typeof(int));
|
||
|
||
// Creating an expression for the method call and specifying its parameter.
|
||
MethodCallExpression methodCall = Expression.Call(
|
||
typeof(Console).GetMethod("WriteLine", new Type[] { typeof(int) }),
|
||
param
|
||
);
|
||
|
||
// The following statement first creates an expression tree,
|
||
// then compiles it, and then runs it.
|
||
Expression.Lambda<Action<int>>(
|
||
methodCall,
|
||
new ParameterExpression[] { param }
|
||
).Compile()(10);
|
||
|
||
// This code example produces the following output:
|
||
//
|
||
// 10
|
||
|
||
//创建表达式参数(指定参数或变量的类型)
|
||
var param2 = Expression.Parameter(typeof(ListHeader));
|
||
|
||
//构建表达式体(类型包含指定的属性)
|
||
var body = Expression.Property(param2, "Mergeable = true");
|
||
|
||
//根据参数和表达式体构造一个Lambda表达式
|
||
var fieldExp = Expression.Lambda<Action<ListHeader>>(Expression.Convert(body, typeof(object)), param2);
|
||
|
||
|
||
h1.SetHeader(fieldExp.Compile());
|
||
return;
|
||
}
|
||
|
||
|
||
private void TTTT()
|
||
{
|
||
var list = new List<DecimalControlField>
|
||
{
|
||
new DecimalControlField("FUnitNeedQty", "LOWEST6"),
|
||
new DecimalControlField("FQTY", "LOWEST6"),
|
||
new DecimalControlField("FUnitNeedQty", "LOWEST6"),
|
||
new DecimalControlField("FBASEQTY", "LOWEST6"),
|
||
new DecimalControlField("FNEEDQTY", "LOWEST6"),
|
||
new DecimalControlField("FBASEWIPQTY", "LOWEST6"),
|
||
new DecimalControlField("FBASELACKQTY", "LOWEST6"),
|
||
new DecimalControlField("FBASEONORDERQTY", "LOWEST6"),
|
||
new DecimalControlField("FPICKEDQTY", "LOWEST6"),
|
||
new DecimalControlField("FNOPICKEDQTY", "LOWEST6"),
|
||
new DecimalControlField("FSTDQTY", "LOWEST6"),
|
||
new DecimalControlField("FMUSTQTY", "LOWEST6"),
|
||
new DecimalControlField("FLossQty", "LOWEST6"),
|
||
new DecimalControlField("FSCRAPQTY", "LOWEST6"),
|
||
new DecimalControlField("FREPICKEDQTY", "LOWEST6"),
|
||
};
|
||
}
|
||
|
||
[TestMethod]
|
||
public void TestMeThod4()
|
||
{
|
||
var appId = "271430_Rf9BQYjJ2NgUWV8JWZxLz+8t2rWa0KOK";
|
||
var dbId = "654e408a013340";
|
||
var userName = "demo";
|
||
var secret = "0ef6a61fa3d349029f8a433609bf824c";
|
||
|
||
var timeStamp = DateTimeOffset.UtcNow.ToUnixTimeMilliseconds().ToString();
|
||
var signedData = SHA1Util.GetSignature(new string[] { dbId, userName, appId, secret, timeStamp });
|
||
var json2 = @"{""dbid"":""654e408a013340"",""username"":""demo"",""appid"":""271430_Rf9BQYjJ2NgUWV8JWZxLz+8t2rWa0KOK"",""signeddata"":""{0}"",""timestamp"":""1709285538"",""lcid"":""2052"",""origintype"":""SimPas"",""entryrole"":"""",""formid"":"""",""formtype"":"""",""pkid"":"""",""otherargs"":""|{'permitcount':'0'}"",""openmode"":null,""loginthen"":""""}";
|
||
var json = $@"{{""dbid"":""{dbId}"",""username"":""{userName}"",""appid"":""{appId}"",""signeddata"":""{signedData}"",""timestamp"":""{timeStamp}"",""lcid"":""2052"",""origintype"":""SimPas"",""entryrole"": """",""formid"":""PUR_PurchaseOrder"",""formtype"":"""",""pkid"":""100001"",""otherargs"":""|{{'permitcount':'0'}}"",""openmode"":null,""loginthen"":""""}}";
|
||
var jToken = JsonConvert.DeserializeObject<JToken>(json);
|
||
//json = string.Format(json2, signedData);
|
||
var base64Str = Base64Helper.Base64Encode(json);
|
||
var url = "http://localhost/K3Cloud/html5/index.aspx?ud=";
|
||
url = url + base64Str;
|
||
return;
|
||
}
|
||
|
||
//public string GetSignature(string[] arr)
|
||
//{
|
||
// //1. 将数组进行排序
|
||
// //2. 将数组拼接成一个字符串进行sha1加密
|
||
// arr = arr.OrderBy(z => z).ToArray();
|
||
// var arrString = string.Join("", arr);
|
||
// var sha1 = SHA1.Create();
|
||
// var sha1Arr = sha1.ComputeHash(Encoding.UTF8.GetBytes(arrString));
|
||
// StringBuilder enText = new StringBuilder();
|
||
// foreach (var b in sha1Arr)
|
||
// {
|
||
// enText.AppendFormat("{0:x2}", b);
|
||
|
||
// }
|
||
// return enText.ToString();
|
||
//}
|
||
}
|
||
|
||
|
||
|
||
|
||
}
|