2023-12-08 23:53:07 +08:00
|
|
|
|
using ExtensionMethods;
|
|
|
|
|
|
using Microsoft.VisualStudio.TestTools.UnitTesting;
|
2023-12-20 22:26:30 +08:00
|
|
|
|
using Newtonsoft.Json;
|
|
|
|
|
|
using SAL_OUTSTOCK.Utils;
|
2023-12-08 23:53:07 +08:00
|
|
|
|
using System;
|
2023-12-20 22:26:30 +08:00
|
|
|
|
using System.Collections.Generic;
|
|
|
|
|
|
using System.Linq;
|
|
|
|
|
|
using System.Net;
|
|
|
|
|
|
using System.Net.Sockets;
|
|
|
|
|
|
using System.Security.Cryptography;
|
|
|
|
|
|
using System.Text;
|
2023-12-08 23:53:07 +08:00
|
|
|
|
|
|
|
|
|
|
namespace UnitTestProject1
|
|
|
|
|
|
{
|
|
|
|
|
|
[TestClass]
|
|
|
|
|
|
public class UnitTest1
|
|
|
|
|
|
{
|
2023-12-26 10:44:19 +08:00
|
|
|
|
public class TestEntity
|
|
|
|
|
|
{
|
|
|
|
|
|
public TestEntity(int _id, string _name)
|
|
|
|
|
|
{
|
|
|
|
|
|
id = _id;
|
|
|
|
|
|
name = _name;
|
|
|
|
|
|
}
|
|
|
|
|
|
public int id;
|
|
|
|
|
|
public string name;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
[TestMethod]
|
|
|
|
|
|
public void TestMethod2()
|
|
|
|
|
|
{
|
|
|
|
|
|
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();
|
|
|
|
|
|
|
|
|
|
|
|
return;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2023-12-08 23:53:07 +08:00
|
|
|
|
[TestMethod]
|
|
|
|
|
|
public void TestMethod1()
|
|
|
|
|
|
{
|
|
|
|
|
|
|
2023-12-20 22:26:30 +08:00
|
|
|
|
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");
|
2023-12-08 23:53:07 +08:00
|
|
|
|
|
2023-12-15 09:08:09 +08:00
|
|
|
|
|
2023-12-20 22:26:30 +08: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);
|
2023-12-26 10:44:19 +08:00
|
|
|
|
auditList.Add(data1);
|
2023-12-20 22:26:30 +08:00
|
|
|
|
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);
|
2023-12-26 10:44:19 +08:00
|
|
|
|
param.Add("timestamp", DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss"));
|
2023-12-20 22:26:30 +08:00
|
|
|
|
param.Add("version", "");
|
|
|
|
|
|
string sign = BuildSign(param, secret);
|
|
|
|
|
|
param.Add("sign", sign);
|
|
|
|
|
|
|
2023-12-26 10:44:19 +08:00
|
|
|
|
var jsonParam = JsonConvert.SerializeObject(param);
|
2023-12-20 22:26:30 +08:00
|
|
|
|
|
2023-12-26 10:44:19 +08:00
|
|
|
|
var result = HttpWebHelper.DoPost("http://119.146.223.48:39082/api/", jsonParam);
|
2023-12-15 09:08:09 +08:00
|
|
|
|
var a = 0.00M;
|
|
|
|
|
|
var a2 = 0L;
|
|
|
|
|
|
var f = (a == a2);
|
2023-12-08 23:53:07 +08:00
|
|
|
|
return;
|
|
|
|
|
|
}
|
2023-12-20 22:26:30 +08:00
|
|
|
|
|
|
|
|
|
|
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();
|
|
|
|
|
|
}
|
2023-12-08 23:53:07 +08:00
|
|
|
|
}
|
2023-12-26 10:44:19 +08:00
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
2023-12-08 23:53:07 +08:00
|
|
|
|
}
|