You cannot select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
DS7/DSWeb/Areas/CommMng/DAL/PublicAPIDAL.cs

1260 lines
43 KiB
C#

2 years ago
using DSWeb.Areas.CommMng.Models;
using DSWeb.Areas.OA.Models.WorkFlow;
using DSWeb.Common.DB;
using DSWeb.EntityDA;
using DSWeb.MvcShipping.DAL.MsInfoClient;
using DSWeb.MvcShipping.DAL.MsSysParamSet;
using DSWeb.MvcShipping.Helper;
using DSWeb.MvcShipping.Models.MsCtExplan;
using DSWeb.MvcShipping.Models.MsInfoClient;
using DSWeb.SoftMng.BLL;
using DSWeb.SoftMng.Models.MsInfoClass;
using DSWeb.SoftMng.Models.MsInfoClientItem;
using DSWeb.TruckMng.Helper.Repository;
using HcUtility.Comm;
using HcUtility.Core;
using Microsoft.Practices.EnterpriseLibrary.Data;
using NPOI.HSSF.UserModel;
using NPOI.SS.UserModel;
using NPOI.XSSF.UserModel;
using Spire.Pdf;
using System;
using System.Collections.Generic;
using System.Data;
using System.Data.SqlClient;//使用sqlcomm
using System.IO;//用于向数据库中存取图片
using System.Linq;
using System.Net;
using System.Text;
using System.Text.RegularExpressions;
using System.Web;
using System.Web.Mvc;
using System.Security.Cryptography;
using System.Threading;
using DSWeb.Areas.Dispatch.Helper;
using DSWeb.MvcShipping.Models.MsOpBillYj;
using NPOI.SS.Formula.Functions;
using javax.xml.crypto;
using NPOI.OpenXmlFormats.Dml;
using sun.security.jgss;
using Quartz.Util;
using Baidu.Aip;
using AlibabaCloud.SDK.Dingtalkokr_1_0.Models;
using sun.nio.cs.ext;
using System.Xml;
using Org.BouncyCastle.Crypto.Parameters;
using Org.BouncyCastle.Asn1.X509;
using Org.BouncyCastle.X509;
using static DSWeb.Areas.CommMng.DAL.PublicAPIDAL.Helper;
using static DSWeb.Areas.CommMng.DAL.PublicAPIDAL.OAHelper;
using Org.BouncyCastle.Math;
using Org.BouncyCastle.Pkcs;
using Org.BouncyCastle.Crypto.Generators;
using Org.BouncyCastle.Crypto;
using Org.BouncyCastle.Asn1.Pkcs;
using Org.BouncyCastle.Asn1;
using Org.BouncyCastle.Bcpg;
using Org.BouncyCastle.Security;
using Org.BouncyCastle.Crypto.Encodings;
using Org.BouncyCastle.Crypto.Engines;
using System.ServiceModel.Configuration;
using java.util;
using DSWeb.Areas.Account.Models.Chfee_Payapplication;
2 years ago
namespace DSWeb.Areas.CommMng.DAL
{
public class PublicAPIDAL
{
#region 壹沓科技 ocr识别功能
public static class Helper
{
private static bool locked { get; set; } = false;
private static string token { get; set; } = "";
private static DateTime? tokentime { get; set; } = null;
//获取新token
public static void GetNewToken()
{
if (locked) return;
locked = true;
//获取token
try
{
GetBackUrl_gettoken hp = new GetBackUrl_gettoken();
var rp = hp.DoGet();
var data = rp.data;
token = data.accessToken;
tokentime = DateTime.Now.AddSeconds((double)data.expiresIn);
}
catch (Exception e)
{
}
finally { locked = false; }
}
//获取token
public static void GetToken()
{
//if (string.IsNullOrWhiteSpace(token) || DateTime.Now.AddMinutes(3) > tokentime)
//{
// GetNewToken();
//}
//return token;
GetBackUrl_gettokenByPort hp = new GetBackUrl_gettokenByPort();
var rp = hp.DoGet();
token = rp.data;
//tokentime = DateTime.Now.AddSeconds((double)data.expiresIn);
}
//获取前端接入参数
const string cognitionurl = "https://ocr-beta.1datatech.net";
const string cognitionurl = "https://ocr.1datatech.net";
const string UrlHead = "https://jinshique-web-beta.1datatech.net/erpRecog/recordid";
const string UrlHead = " https://jinshique.1datatech.net/erpRecog/recordid";//{}
static string cognitionurl = cognitionurl;
static string UrlHead = UrlHead;
public static string GetUrl_front(string CUSTOMERNAME, string recordId = "")
{
var baseurl = UrlHead;
//var baseurl = 正式UrlHead;
if (string.IsNullOrWhiteSpace(recordId))
{
baseurl = baseurl.Replace("/recordid", "");
}
else
{
baseurl = baseurl.Replace("recordid", recordId);
}
/*
erpCustomSign string ERP
ERP
sceneId string ERP
shpping_order
redirectUrl string
( JS
encodeURIComponent )
beacon json ERP ERP
ID( JS
encodeURIComponent )
token string token
*/
GetToken();
var url = baseurl + $"?erpCustomSign={CUSTOMERNAME}&sceneId={"shipping_order"}&redirectUrl&beacon&token={token}";
return url;
}
public static ResultResponse GetOcrResult(string recordId)
{
//GetToken();
var result = new ResultResponse();
try
{
var hp = new GetResult();
var dic = new Dictionary<string, string>();
if (string.IsNullOrEmpty(token))
{
GetToken();
}
dic.Add("recordId", recordId);
dic.Add("access_token", token);
result = hp.DoGet(dic);
}
catch (Exception e)
{
}
return result;
}
public abstract class API_URL
{
public string Url { get; set; } = "";
public Response response { get; set; }
public static string GetBaseUrl()
{
var baseurl = cognitionurl;
return baseurl;
}
public abstract string GetUrl();
public Response DoGet(Dictionary<string, string> dic = null)
{
GetUrl();
var rtn = WebRequestHelper.DoGet(Url);
//临时替换 由于.在识别时报错 临时改为##
//rtn = rtn.Replace(".", "##");
response = JsonConvert.Deserialize<Response>(rtn);
return response;
}
}
public class GetBackUrl_gettoken : API_URL
{
public override string GetUrl()
{
//获取appid和secret
var appid = MsSysParamSetDAL.GetSysParamValue("JinShiQueAppid");
var secret = MsSysParamSetDAL.GetSysParamValue("JinShiQueSecret");
Url = GetBaseUrl() + $"/oauth/1.0/token?grant_type=client_credential&appid={appid}&secret={secret}";
return Url;
}
public TokenResponse DoGet()
{
GetUrl();
var rtn = WebRequestHelper.DoGet(Url);
//临时替换 由于.在识别时报错 临时改为##
//rtn = rtn.Replace(".", "##");
var _res = JsonConvert.Deserialize<TokenResponse>(rtn);
return _res;
}
}
public class GetBackUrl_gettokenByPort : API_URL
{
//20221208 改为使用吴广的接口
/*
url: http://118.190.106.151:5678/v1/ydkj/token
: post
, json
{
"appid": "RXJXMteB",
"secret": "60cdbead4f05233d5e4fe8638a5178129665fda5"
}
{'code': 200, 'data': '[token]', 'msg': 'ok', 'request': 'POST /v1/ydkj/token'}
{'code': 1000, 'data': [], 'msg': 'Invalid access key', 'request': 'POST /v1/ydkj/token'}
*/
public override string GetUrl()
{
Url = "http://118.190.106.151:5678/v1/ydkj/token";
return Url;
}
public TokenResponseByPort DoGet()
{
GetUrl();
//获取appid和secret
var appid = MsSysParamSetDAL.GetSysParamValue("JinShiQueAppid");
var secret = MsSysParamSetDAL.GetSysParamValue("JinShiQueSecret");
var appparam = new
{
appid = appid,
secret = secret
};
var rtn = WebRequestHelper.DoPost_Json(Url, appparam);
//临时替换 由于.在识别时报错 临时改为##
//rtn = rtn.Replace(".", "##");
var _res = JsonConvert.Deserialize<TokenResponseByPort>(rtn);
return _res;
}
}
public class GetResult : API_URL
{
public override string GetUrl()
{
//获取appid和secret
Url = GetBaseUrl() + "/api/recog/v1/proofread/result";
return Url;
}
public ResultResponse DoGet(Dictionary<string, string> dic = null)
{
var _res = new ResultResponse();
try
{
GetUrl();
var rtn = WebRequestHelper.DoGet_Param(Url, dic);
rtn = rtn.Replace("\"PO NO\"", "\"PONO\"");
_res = JsonConvert.Deserialize<ResultResponse>(rtn);
return _res;
}
catch (Exception e)
{
return _res;
}
finally { }
return _res;
}
}
public class Response
{
public int code { get; set; }
public string message { get; set; }
public string data { get; set; }
}
public class TokenData
{
public string accessToken { get; set; }
public long? expiresIn { get; set; }
}
public class TokenResponse : Response
{
//public string accessToken { get; internal set; }
public new TokenData data { get; set; }
}
public class TokenResponseByPort : Response
{
}
public class
{
/// <summary>
///
/// </summary>
public string { get; set; }
/// <summary>
///
/// </summary>
public string { get; set; }
}
public class CommitResult
{
/// <summary>
/// 山东恩威国际货运代理有限公司
/// </summary>
public string { get; set; }
/// <summary>
/// 恩威小李
/// </summary>
public string { get; set; }
/// <summary>
///
/// </summary>
//public int? proofreadUsedTime { get; set; }
/// <summary>
///
/// </summary>
public string { get; set; }
/// <summary>
///
/// </summary>
public string { get; set; }
/// <summary>
///
/// </summary>
public string { get; set; }
/// <summary>
///
/// </summary>
public string { get; set; }
/// <summary>
/// TO: 青岛捷丰储运\nTO泛海华航FM:恩威小李 0535-6233091\n船期CMA 10月 12日\n约号QQGD065967\n提单上显示目的港代理信息,电放提单\n申请目的港14天免费箱使\n甲苯二异氰酸酯 CLASS:6.1 UN NO:2078(无海污)\nHS CODE:29291010\n无副危 闪点:137℃ PGII EMS:F-A,S-A\n我司订舱货物若港口显示船期转运条款\n航程挂港运价等与我司要求不符或船公司\n有特殊要求请及时通知我司
/// </summary>
public string { get; set; }
/// <summary>
///
/// </summary>
public string templateId { get; set; }
/// <summary>
///
/// </summary>
public string { get; set; }
/// <summary>
///
/// </summary>
public int? recordId { get; set; }
/// <summary>
///
/// </summary>
public string { get; set; }
/// <summary>
///
/// </summary>
public string { get; set; }
/// <summary>
///
/// </summary>
public string { get; set; }
/// <summary>
///
/// </summary>
public string { get; set; }
/// <summary>
///
/// </summary>
public string { get; set; }
/// <summary>
///
/// </summary>
public string proofreadFrom { get; set; }
/// <summary>
///
/// </summary>
public string { get; set; }
/// <summary>
///
/// </summary>
public string commitType { get; set; }
/// <summary>
///
/// </summary>
public string { get; set; }
/// <summary>
///
/// </summary>
public string { get; set; }
/// <summary>
///
/// </summary>
public string { get; set; }
/// <summary>
///
/// </summary>
public string { get; set; }
/// <summary>
///
/// </summary>
public string { get; set; }
/// <summary>
/// (请务必填写中文品名)\n4 X20' 80 MT NET TOLUENE DIISOCYANATE\nTOLUENE DIISOCYANATE,\nCASNO.26471-62-5
/// </summary>
public string { get; set; }
/// <summary>
///
/// </summary>
public string { get; set; }
/// <summary>
///
/// </summary>
public string { get; set; }
/// <summary>
///
/// </summary>
public List<> { get; set; }
/// <summary>
///
/// </summary>
public string { get; set; }
/// <summary>
///
/// </summary>
public string { get; set; }
/// <summary>
///
/// </summary>
public string { get; set; }
/// <summary>
///
/// </summary>
public DateTime ETD { get; set; }
/// <summary>
/// 海运托书
/// </summary>
public string templateName { get; set; }
/// <summary>
///
/// </summary>
public string { get; set; }
/// <summary>
///
/// </summary>
public long? createTime { get; set; }
/// <summary>
///
/// </summary>
public string { get; set; }
/// <summary>
///
/// </summary>
public string { get; set; }
/// <summary>
///
/// </summary>
public string HSCODE { get; set; }
/// <summary>
///
/// </summary>
public int? proofreadUser { get; set; }
/// <summary>
///
/// </summary>
public string _id { get; set; }
/// <summary>
///
/// </summary>
public int? cid { get; set; }
public string GetCntrtotal()
{
var result = "";
if ( != null && .Count > 0)
{
foreach (var item in )
{
if (result != "") result += " ";
result += item. + "*" + item.;
}
}
return result;
}
}
public class ResultData
{
/// <summary>
///
/// </summary>
public string templateId { get; set; }
/// <summary>
///
/// </summary>
public int recordId { get; set; }
/// <summary>
///
/// </summary>
public string name { get; set; }
/// <summary>
///
/// </summary>
public string recogType { get; set; }
/// <summary>
///
/// </summary>
public string proofreadType { get; set; }
/// <summary>
///
/// </summary>
public CommitResult commitResult { get; set; }
/// <summary>
///
/// </summary>
public string beacon { get; set; }
}
public class ResultResponse : Response
{
//public string accessToken { get; internal set; }
public new ResultData data
{
get;
set;
}
public void SetData(ref DSWeb.MvcShipping.Models.MsOpSeae.MsOpSeae headdata)
{ //将识别数据与现有数据合并
//如识别数据有内容 则用其代替现有字段内容
var _result = data.commitResult;
if (!string.IsNullOrWhiteSpace(_result.))
{
//headdata.
}
//发货人 SHIPPER
PropNameList = new Dictionary<string, string>
{
{ "委托公司", "CUSTOMERNAME" },
{ "联系人", "ATTN" },
{ "电话", "ATTNTEL" },
{ "发货人", "SHIPPER" },
{ "客户委托编码", "CUSTNO" },
{ "备注", "REMARK" },
{ "邮箱", "ATTNEMAIL" },
{ "收货地", "PLACERECEIPT" },
{ "目的港", "DESTINATION" },
//{ "运费条款", "SHIPPER" },
{ "货描", "DESCRIPTION" },
{ "毛重", "KGS" },
{ "包装种类", "KINDPKGS" },
{ "收货人", "CONSIGNEE" },
{ "通知人", "NOTIFYPARTY" },
{ "运输条款", "SERVICE" },
{ "船公司", "CARRIER" },
{ "船名", "VESSEL" },
{ "航次", "VOYNO" },
{ "贸易条款", "TRADETERM" },
{ "品名", "GOODSNAME" },
{ "起运港", "PODLOAD" },
{ "卸货港", "PORTDISCHARGE" },
{ "交货地", "PLACEDELIVERY" },
{ "ETD", "ETD" },
{ "唛头", "MARKS" },
{ "件数", "NOPKGS" },
{ "体积", "CBM" },
{ "HSCODE", "HSCODE" }
};
foreach (var item in PropNameList)
{
//var value = _result.GetType().GetProperty("发货人").GetValue(_result, null);
//headdata.SetPropertyValue("")
var value = _result.GetType().GetProperty(item.Key).GetValue(_result, null);
if (value != null && !string.IsNullOrWhiteSpace(value.ToString()))
{
headdata.SetPropertyValue(item.Value, value.ToString());
}
}
//不规则的数据
var cdc = new CommonDataContext();
headdata.CNTRTOTAL = _result.GetCntrtotal();
var _customername = headdata.CUSTOMERNAME;
//如果CUSTOMERNAME在info_client.SHORTNAME当中不存在 则尝试用info_client.FULLNAME对应后修改之
var _infoclient = cdc.info_client.FirstOrDefault(x => x.SHORTNAME == _customername);
if (_infoclient == null || string.IsNullOrWhiteSpace(_infoclient.SHORTNAME))
{
var _tempinfoclient = cdc.info_client.FirstOrDefault(x => x.EnFullName == _customername || x.DESCRIPTION == _customername);
if (_tempinfoclient == null || string.IsNullOrWhiteSpace(_tempinfoclient.SHORTNAME))
{
headdata.CUSTOMERNAME = _tempinfoclient.SHORTNAME;
}
}
}
private Dictionary<string, string> PropNameList { get; set; } = new Dictionary<string, string>();
}
}
#endregion
#region 泛微
public struct RSAKEY
{
public string PublicKey
{
get;
set;
}
public string PrivateKey
{
get;
set;
}
}
public static RSAKEY GetKey()
{
//RSA密钥对的构造器
RsaKeyPairGenerator keyGenerator = new RsaKeyPairGenerator();
//RSA密钥构造器的参数
RsaKeyGenerationParameters param = new RsaKeyGenerationParameters(
Org.BouncyCastle.Math.BigInteger.ValueOf(3),
new Org.BouncyCastle.Security.SecureRandom(),
1024, //密钥长度
25);
//用参数初始化密钥构造器
keyGenerator.Init(param);
//产生密钥对
AsymmetricCipherKeyPair keyPair = keyGenerator.GenerateKeyPair();
//获取公钥和密钥
AsymmetricKeyParameter publicKey = keyPair.Public;
AsymmetricKeyParameter privateKey = keyPair.Private;
SubjectPublicKeyInfo subjectPublicKeyInfo = SubjectPublicKeyInfoFactory.CreateSubjectPublicKeyInfo(publicKey);
PrivateKeyInfo privateKeyInfo = PrivateKeyInfoFactory.CreatePrivateKeyInfo(privateKey);
Asn1Object asn1ObjectPublic = subjectPublicKeyInfo.ToAsn1Object();
byte[] publicInfoByte = asn1ObjectPublic.GetEncoded("UTF-8");
Asn1Object asn1ObjectPrivate = privateKeyInfo.ToAsn1Object();
byte[] privateInfoByte = asn1ObjectPrivate.GetEncoded("UTF-8");
RSAKEY item = new RSAKEY()
{
PublicKey = Convert.ToBase64String(publicInfoByte),
PrivateKey = Convert.ToBase64String(privateInfoByte)
};
return item;
}
private static Encoding Encoding_UTF8 = Encoding.UTF8;
/// <summary>
/// 公钥加密
/// </summary>
/// <param name="data">加密内容</param>
/// <param name="publicKey">公钥Base64编码后的</param>
/// <returns>返回Base64内容</returns>
public static string EncryptByPublicKey(string data, string publicKey)
{
//非对称加密算法,加解密用
IAsymmetricBlockCipher engine = new Pkcs1Encoding(new RsaEngine());
//加密
try
{
engine.Init(true, GetPublicKeyParameter(publicKey));
byte[] byteData = Encoding_UTF8.GetBytes(data);
var ResultData = engine.ProcessBlock(byteData, 0, byteData.Length);
return Convert.ToBase64String(ResultData);
}
catch (Exception ex)
{
throw ex;
}
}
private static AsymmetricKeyParameter GetPublicKeyParameter(string keyBase64)
{
keyBase64 = keyBase64.Replace("\r", "").Replace("\n", "").Replace(" ", "");
byte[] publicInfoByte = Convert.FromBase64String(keyBase64);
Asn1Object pubKeyObj = Asn1Object.FromByteArray(publicInfoByte);//这里也可以从流中读取,从本地导入
AsymmetricKeyParameter pubKey = PublicKeyFactory.CreateKey(publicInfoByte);
return pubKey;
}
/// <summary>
/// RSA公钥格式转换.net->java
/// </summary>
/// <param name="publicKey">.net生成的公钥</param>
/// <returns></returns>
public static string RSAPublicKeyDotNet2Java(string publicKey)
{
XmlDocument doc = new XmlDocument();
doc.LoadXml(publicKey);
BigInteger m = new BigInteger(1, Convert.FromBase64String(doc.DocumentElement.GetElementsByTagName("Modulus")[0].InnerText));
BigInteger p = new BigInteger(1, Convert.FromBase64String(doc.DocumentElement.GetElementsByTagName("Exponent")[0].InnerText));
RsaKeyParameters pub = new RsaKeyParameters(false, m, p);
SubjectPublicKeyInfo publicKeyInfo = SubjectPublicKeyInfoFactory.CreateSubjectPublicKeyInfo(pub);
byte[] serializedPublicBytes = publicKeyInfo.ToAsn1Object().GetDerEncoded();
return Convert.ToBase64String(serializedPublicBytes);
}
/// <summary>
/// RSA私钥格式转换java->.net
/// </summary>
/// <param name="privateKey">java生成的RSA私钥</param>
/// <returns></returns>
public static string RSAPrivateKeyJava2DotNet(string privateKey)
{
RsaPrivateCrtKeyParameters privateKeyParam = (RsaPrivateCrtKeyParameters)PrivateKeyFactory.CreateKey(Convert.FromBase64String(privateKey));
return string.Format("<RSAKeyValue><Modulus>{0}</Modulus><Exponent>{1}</Exponent><P>{2}</P><Q>{3}</Q><DP>{4}</DP><DQ>{5}</DQ><InverseQ>{6}</InverseQ><D>{7}</D></RSAKeyValue>",
Convert.ToBase64String(privateKeyParam.Modulus.ToByteArrayUnsigned()),
Convert.ToBase64String(privateKeyParam.PublicExponent.ToByteArrayUnsigned()),
Convert.ToBase64String(privateKeyParam.P.ToByteArrayUnsigned()),
Convert.ToBase64String(privateKeyParam.Q.ToByteArrayUnsigned()),
Convert.ToBase64String(privateKeyParam.DP.ToByteArrayUnsigned()),
Convert.ToBase64String(privateKeyParam.DQ.ToByteArrayUnsigned()),
Convert.ToBase64String(privateKeyParam.QInv.ToByteArrayUnsigned()),
Convert.ToBase64String(privateKeyParam.Exponent.ToByteArrayUnsigned()));
}
2 years ago
public static class OAHelper
{
private static string APPID { get; set; } = "";
private static string CPK { get; set; } = "";
private static string SPK { get; set; } = "";
private static string SECRET { get; set; } = "";
2 years ago
private static bool locked { get; set; } = false;
private static string token { get; set; } = "";
private static DateTime? tokenEndTime { get; set; } = null;
2 years ago
const string URLHead = "http://117.78.44.211";
//获取secret
public static void GetRSAKEY()
2 years ago
{
var rsakey = GetKey();
CPK = rsakey.PublicKey;
}
2 years ago
public static void GetSecret() {
2 years ago
APPID= MsSysParamSetDAL.GetSysParamValue("FanWei_appid");
SPK = MsSysParamSetDAL.GetSysParamValue("FanWei_SPK");
SECRET = MsSysParamSetDAL.GetSysParamValue("FanWei_SECRET");
2 years ago
if (!string.IsNullOrWhiteSpace(SPK) && !string.IsNullOrWhiteSpace(SECRET))
{
return;
2 years ago
}
GetRSAKEY();
var appparam = new
2 years ago
{
appid = APPID,
cpk = CPK
};
2 years ago
var paramdic = new Dictionary<string, string>
{
{ "appid", APPID },
{ "cpk", CPK }
};
var securl = URLHead + "/api/ec/dev/auth/regist";
var data = WebRequestHelper.DoPost_Header(securl, paramdic);
if (data != null)
{
//JSONObject result = JSON.parseObject(data);
//if ("true".equals(result.getString("status")))
//{
// this.SPK = result.getString("spk");
// this.SECRET = result.getString("secrit");
//}
var cpkresult = JsonConvert.Deserialize<SecretResponse>(data);
//从返回值中解析出SPK
SPK = cpkresult.spk;
//SPK = RSAPrivateKeyJava2DotNet(cpkresult.spk);
SECRET = cpkresult.secret;
//将CPK记录至
MsSysParamSetDAL.SaveSysParamValue("FanWei_SPK", "泛微SPK", SPK);
MsSysParamSetDAL.SaveSysParamValue("FanWei_SECRET", "泛微SECRET", SECRET);
2 years ago
}
2 years ago
}
2 years ago
public static void GetToken()
{
if (locked) return;
locked = true;
try
{
GetSecret();
2 years ago
//token过期时间30分钟
//所以获取时记录获取后的25分钟为过期时间 如过期则重新获取
2 years ago
if (!(tokenEndTime == null || tokenEndTime <= DateTime.Now || string.IsNullOrWhiteSpace(token))) {
return;
}
2 years ago
var secret = EncryptByPublicKey(SECRET,SPK);
2 years ago
var paramdic = new Dictionary<string, string>
{
{ "appid", APPID },
{ "secret", secret }
};
2 years ago
var securl = URLHead + "/api/ec/dev/auth/applytoken";
2 years ago
var data = WebRequestHelper.DoPost_Header(securl, paramdic);
2 years ago
if (data != null)
{
var r = JsonConvert.Deserialize<TokenResponse>(data);
2 years ago
token = r.token;
tokenEndTime = DateTime.Now.AddMinutes(25);
//MsSysParamSetDAL.SaveSysParamValue("FanWei_TOKEN", "泛微TOKEN", token);
}
2 years ago
}
catch (Exception e) {
2 years ago
}
finally { locked = false; }
}
2 years ago
public static ResultResponse PostApplication( ChPayapplication headdata, string userid, string username, string companyid)
2 years ago
{
GetToken();
2 years ago
var result = new ResultResponse();
try
{
var hp = new GetResult();
result = hp.DoGet(headdata, userid, username, companyid);
2 years ago
}
catch (Exception e)
{
}
return result;
}
public abstract class API_URL
{
public string Url { get; set; } = "";
public Response response { get; set; }
2 years ago
public static string GetBaseUrl()
{
var baseurl = URLHead;
2 years ago
return baseurl;
}
public abstract string GetUrl();
public Response DoGet(Dictionary<string,string> dic=null)
2 years ago
{
GetUrl();
var rtn = WebRequestHelper.DoGet(Url);
//临时替换 由于.在识别时报错 临时改为##
//rtn = rtn.Replace(".", "##");
response = JsonConvert.Deserialize<Response>(rtn);
2 years ago
return response;
}
}
public class SecretResponse : Response
2 years ago
{
public string secret { get; set; }
public string spk { get; set; }
}
public class TokenResponse: Response
{
public string token { get; set; }
}
2 years ago
public class Field {
public string fieldName { get; set; }
public string fieldValue { get; set; }
public Field()
2 years ago
{
}
public Field(string _fieldname, string _fieldvalue) {
fieldName=_fieldname;
fieldValue=_fieldvalue;
}
public Field(string _fieldname, decimal? _fieldvalue)
{
fieldName = _fieldname;
fieldValue = _fieldvalue==null?"0": _fieldvalue.ToString();
}
}
2 years ago
public class FileField : Field {
public List<Field> fieldValue { get; set; }
}
2 years ago
public static ArrayList GetMainData(ChPayapplication headdata, string userid, string username, string compoanyid) {
var result = new ArrayList();
2 years ago
result.add(new Field("sqr", headdata.APPLICANTNAME));
result.add(new Field("sqbm", headdata.APPLICANTDEPT));
var applytimestr = headdata.APPLYTIME == null ? "" : ((DateTime)(headdata.APPLYTIME)).ToString("yyyy-MM-dd HH:mm:ss");
result.add(new Field("lcbh", headdata.BILLNO));
result.add(new Field("bz", headdata.REMARK));
result.add(new Field("fkdx", headdata.CUSTOMERNAME));
var yxzh = "";
var khx = "";
var cdc = new CommonDataContext();
if (!string.IsNullOrWhiteSpace(headdata.CUSTACCOUNTGID)) {
var custbank = cdc.info_client_bank.FirstOrDefault(x => x.GID == headdata.CUSTACCOUNTGID);
yxzh = custbank.ACCOUNT;
khx = custbank.BANKNAME;
2 years ago
}
result.add(new Field("yxzh", yxzh));
result.add(new Field("khx", khx));
result.add(new Field("wtdw", headdata.BS_CUSTOMERNAME));
2 years ago
result.add(new Field("jehj", headdata.AMOUNTRMB));
result.add(new Field("jehjdx", BasicDataRefDAL.ConvertToChineseMoney( (double)headdata.AMOUNTRMB)));
result.add(new Field("jehjmj", headdata.AMOUNTUSD));
result.add(new Field("jehjmjdx", BasicDataRefDAL.ConvertToChineseMoney((double)headdata.AMOUNTUSD)));
2 years ago
var bodymblnolist = cdc.ch_fee_do.Where(x=>x.BILLNO ==headdata.BILLNO).Select(s=>s.MBLNO).Distinct().ToList();
var bodymblnostr = "";
if (bodymblnolist != null && bodymblnolist.Count > 0) {
bodymblnostr = string.Join(" , ", bodymblnolist);
}
result.add(new Field("tdh", bodymblnostr));
2 years ago
return result;
}
public static List<detailData> GetDetailData(ChPayapplication headdata) {
var resultlist = new List<detailData>();
var result = new detailData();
result.workflowRequestTableRecords = new List<detailBody>();
var cdc = new CommonDataContext();
var bodylist = cdc.ch_fee_do.Where(x => x.BILLNO == headdata.BILLNO).ToList();
var bsnolist = bodylist.Select(s => s.BSNO).ToList();
var vopbsList = cdc.v_op_bs.Where(x => bsnolist.Contains(x.BSNO)).ToList();
foreach (var item in bodylist) {
var newline = new detailBody();
var bs = vopbsList.First(x => x.BSNO == item.BSNO);
newline.workflowRequestTableFields.Add(new Field("fymc",item.FEENAME));
newline.workflowRequestTableFields.Add(new Field("fyje", item.ORIGAMOUNT*item.EXCHANGERATE));
newline.workflowRequestTableFields.Add(new Field("wtdw", bs.CUSTOMERNAME));
newline.workflowRequestTableFields.Add(new Field("yslx", bs.OPLBNAME));
newline.workflowRequestTableFields.Add(new Field("tdh", bs.MBLNO));
newline.workflowRequestTableFields.Add(new Field("xxxl", bs.CNTRTOTAL));
var fyjemj = "0";
if (item.CURRENCY == "USD") fyjemj = item.ORIGAMOUNT==null?"0": item.ORIGAMOUNT.ToString();
newline.workflowRequestTableFields.Add(new Field("fyjemj", fyjemj));
result.workflowRequestTableRecords.Add(newline);
2 years ago
}
resultlist.Add(result);
2 years ago
return resultlist;
}
2 years ago
public class detailBody {
public int recordOrder { get; set; } = 0;
public List<Field> workflowRequestTableFields { get; set; }
2 years ago
public detailBody() {
workflowRequestTableFields = new List<Field>();
}
}
2 years ago
public class detailData {
public string tableDBName { get; set; } = "formtable_main_1356_dt1";
public List<detailBody> workflowRequestTableRecords { get; set; }
2 years ago
}
2 years ago
public class GetResult : API_URL
{
public override string GetUrl()
{
//获取appid和secret
Url = GetBaseUrl() + "/api/workflow/paService/doCreateRequest";
2 years ago
return Url;
}
public ResultResponse DoGet(ChPayapplication headdata , string userid, string username, string companyid)
2 years ago
{
var _res = new ResultResponse();
try
{
GetUrl();
//String secretUserid = rsa.encrypt(null, userid, null, "utf-8", spk, false);
//heads.put("userid", secretUserid);
//userid将会填在user.wechetaccount里面
var _userid = EncryptByPublicKey("cs1", SPK);
2 years ago
var dic = new Dictionary<string, string> {
{ "token", token },
{ "appid", APPID},
{ "userid", _userid }
};
var maindata = GetMainData(headdata, userid, username, companyid);
var detaildata = GetDetailData(headdata);
var sendobj = new
{
detailData = detaildata,
mainData = maindata,
otherParams = new { isnextflow = "1" },
remark = "",
requestLevel = "",
requestName = "业务类供应商付款申请-票结",
workflowId = "117"
};
var jsonstr=JsonConvert.Serialize(sendobj);
var rtn = WebRequestHelper.DoPost_Header(Url, dic, jsonstr);
2 years ago
_res = JsonConvert.Deserialize<ResultResponse>(rtn);
return _res;
}
catch (Exception e) {
return _res;
}
finally { }
//return _res;
2 years ago
}
}
public class Response
2 years ago
{
/// <summary>
///
/// </summary>
public string code { get; set; }
public bool status { get; set; }
/// <summary>
///
/// </summary>
2 years ago
public string data { get; set; }
/// <summary>
///
/// </summary>
public string errMsg { get; set; }
2 years ago
}
public class ResultData
2 years ago
{
/// <summary>
///
/// </summary>
public string code { get; set; }
2 years ago
/// <summary>
///
/// </summary>
public string data { get; set; }
2 years ago
/// <summary>
///
/// </summary>
public string errMsg { get; set; }
2 years ago
}
public class ResultResponse : Response
2 years ago
{
//public string accessToken { get; internal set; }
public new ResultData data {
get;
set;
}
}
}
#endregion
}
}