98 lines
3.2 KiB
C#
98 lines
3.2 KiB
C#
using System;
|
|
using System.Collections.Generic;
|
|
using System.Linq;
|
|
using System.Net.Http;
|
|
using System.Net.Http.Headers;
|
|
using System.Net.Mime;
|
|
using System.Text;
|
|
using System.Threading.Tasks;
|
|
using YLErp.Modules.ApiModule;
|
|
|
|
namespace YLErp.Modules.CompanyModules.ZheQi
|
|
{
|
|
[TestClass]
|
|
public class SealTaskTest
|
|
{
|
|
[TestMethod]
|
|
public void TestUploadApi()
|
|
{
|
|
InnerTestUploadApi().Wait();
|
|
}
|
|
|
|
public async Task InnerTestUploadApi()
|
|
{
|
|
var hclient = Program.GetService<IHttpClientFactory>().CreateClient();
|
|
hclient.BaseAddress = new Uri("http://122.224.170.3:13472");
|
|
var _httpClient = new HttpClientWrap(hclient);
|
|
|
|
var res = await _httpClient.PostMultipartFormDataAsync("es/v1/getToken", new Dictionary<string, HttpContent>
|
|
{
|
|
["appid"] = new StringContent("zqsy_api_yl"),
|
|
["secretkey"] = new StringContent("8PyrLMVxT1=WzTmr")
|
|
}, null);
|
|
|
|
var tokenModel = JsonHelper.Deserialize<ZQTokenApiResponseModel>(res);
|
|
|
|
Assert.IsTrue(tokenModel.success, "请求用印接口token失败");
|
|
|
|
var token = tokenModel.data.token;
|
|
|
|
using var fs = new FileStream("D:\\360极速浏览器X下载\\浙江永武资本管理有限公司CW20160001OP221229002Q20221230.pdf", FileMode.Open, FileAccess.Read);
|
|
|
|
var fileBytes = new byte[fs.Length];
|
|
|
|
fs.Read(fileBytes, 0, fileBytes.Length);
|
|
|
|
var postData = new Dictionary<string, HttpContent>
|
|
{
|
|
["file"] = new ByteArrayContent(fileBytes)
|
|
{
|
|
Headers =
|
|
{
|
|
ContentDisposition = new ContentDispositionHeaderValue("form-data")
|
|
{
|
|
Name = "file",
|
|
FileName = "CW20160001OP221229002Q20221230.pdf",
|
|
}
|
|
}
|
|
},
|
|
["typeCode"] = new StringContent("MM"),
|
|
//{
|
|
// Headers =
|
|
// {
|
|
// ContentDisposition = new ContentDispositionHeaderValue("form-data")
|
|
// {
|
|
// Name = "typeCode",
|
|
// }
|
|
// }
|
|
//},
|
|
//["keywords"] = new StringContent("甲方:")
|
|
//{
|
|
// Headers =
|
|
// {
|
|
// ContentDisposition = new ContentDispositionHeaderValue("form-data")
|
|
// {
|
|
// Name = "keywords",
|
|
// }
|
|
// }
|
|
//},
|
|
};
|
|
|
|
res = await _httpClient.PostMultipartFormDataAsync("es/v1/sign", postData, req =>
|
|
{
|
|
req.Headers.Add("token", token);
|
|
});
|
|
|
|
var sealModel = JsonHelper.Deserialize<ZQSealApiResponseModel>(res);
|
|
|
|
var fileBytesStr = "";
|
|
|
|
Assert.IsTrue(sealModel.success, sealModel.msg);
|
|
|
|
fileBytesStr = sealModel.data.fileByte;
|
|
|
|
Assert.IsTrue(fileBytesStr != null);
|
|
}
|
|
}
|
|
}
|