193 lines
7.1 KiB
C#
193 lines
7.1 KiB
C#
using ExtensionMethods;
|
||
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;
|
||
|
||
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 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;
|
||
}
|
||
|
||
[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();
|
||
}
|
||
}
|
||
|
||
|
||
|
||
|
||
}
|