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; using DSWeb.MvcShipping.DAL.MsSysThirdPartyAccount; using DSWeb.Areas.Account.Models.Chfee_payapplication; using DSWeb.Areas.Account.DAL.Chfee_payapplication; 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;//测试cognitionurl; static string UrlHead = 正式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(); 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 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(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" } { "appid": "v7JNCMbkEnmDm5OwtwsUbmD93s", "secret": "qHOPMT3dkHnQFLXHk1gbUWmKhcUFan" } appid=xSsjHYkzkAsoy53FtGCoPRFNAZ secret=BlpdbnRssCNR5hlAEgN3f9jfc9c3vy 响应示例 {'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(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 dic = null) { var _res = new ResultResponse(); try { GetUrl(); var rtn = WebRequestHelper.DoGet_Param(Url, dic); rtn = rtn.Replace("\"PO NO\"", "\"PONO\""); _res = JsonConvert.Deserialize(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 箱型箱量 { /// /// /// public string 箱量 { get; set; } /// /// /// public string 箱型 { get; set; } } public class CommitResult { /// /// 山东恩威国际货运代理有限公司 /// public string 委托公司 { get; set; } /// /// 恩威小李 /// public string 联系人 { get; set; } /// /// /// //public int? proofreadUsedTime { get; set; } /// /// /// public string 电话 { get; set; } /// /// /// public string 运输条款 { get; set; } /// /// /// public string 发货人 { get; set; } /// /// /// public string 客户委托编码 { get; set; } /// /// 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有特殊要求,请及时通知我司 /// public string 备注 { get; set; } /// /// /// public string templateId { get; set; } /// /// /// public string 换列控制符 { get; set; } /// /// /// public int? recordId { get; set; } /// /// /// public string 邮箱 { get; set; } /// /// /// public string 收货地 { get; set; } /// /// /// public string 目的港 { get; set; } /// /// /// public string 运费条款 { get; set; } /// /// /// public string 货描 { get; set; } /// /// /// public string proofreadFrom { get; set; } /// /// /// public string 毛重 { get; set; } /// /// /// public string commitType { get; set; } /// /// /// public string 包装种类 { get; set; } /// /// /// public string 收货人 { get; set; } /// /// /// public string 通知人 { get; set; } /// /// /// public string 船名 { get; set; } /// /// /// public string 贸易条款 { get; set; } /// /// (请务必填写中文品名)\n4 X20' 80 MT NET TOLUENE DIISOCYANATE\nTOLUENE DIISOCYANATE,\nCASNO.26471-62-5 /// public string 品名 { get; set; } /// /// /// public string 航次 { get; set; } /// /// /// public string 卸货港 { get; set; } /// /// /// public List<箱型箱量> 箱型箱量 { get; set; } /// /// /// public string 起运港 { get; set; } /// /// /// public string 唛头 { get; set; } /// /// /// public string 件数 { get; set; } /// /// /// public DateTime? ETD { get; set; } /// /// 海运托书 /// public string templateName { get; set; } /// /// /// public string 交货地 { get; set; } /// /// /// public long? createTime { get; set; } /// /// /// public string 船公司 { get; set; } /// /// /// public string 体积 { get; set; } /// /// /// public string HSCODE { get; set; } /// /// /// public int? proofreadUser { get; set; } /// /// /// public string _id { get; set; } /// /// /// 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 { /// /// /// public string templateId { get; set; } /// /// /// public int recordId { get; set; } /// /// /// public string name { get; set; } /// /// /// public string recogType { get; set; } /// /// /// public string proofreadType { get; set; } /// /// /// public CommitResult commitResult { get; set; } /// /// /// 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) { //将识别数据与现有数据合并 //如识别数据有内容 则用其代替现有字段内容 if (data != null && data.commitResult != null) { var _result = data.commitResult; if (!string.IsNullOrWhiteSpace(_result.发货人)) { //headdata. } //发货人 SHIPPER PropNameList = new Dictionary { { "委托公司", "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" } }; var oldCustomerName= headdata.CUSTOMERNAME; 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 = ""; headdata.CUSTOMERNAME = oldCustomerName; } else { headdata.CUSTOMERNAME = _tempinfoclient.SHORTNAME; } } } } private Dictionary PropNameList { get; set; } = new Dictionary(); } } #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; /// /// 公钥加密 /// /// 加密内容 /// 公钥(Base64编码后的) /// 返回Base64内容 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; } /// /// RSA公钥格式转换,.net->java /// /// .net生成的公钥 /// 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); } /// /// RSA私钥格式转换,java->.net /// /// java生成的RSA私钥 /// public static string RSAPrivateKeyJava2DotNet(string privateKey) { RsaPrivateCrtKeyParameters privateKeyParam = (RsaPrivateCrtKeyParameters)PrivateKeyFactory.CreateKey(Convert.FromBase64String(privateKey)); return string.Format("{0}{1}

{2}

{3}{4}{5}{6}{7}
", 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())); } 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; } = ""; private static bool locked { get; set; } = false; private static string token { get; set; } = ""; private static DateTime? tokenEndTime { get; set; } = null; const string URLHead = "http://117.78.44.211"; //获取secret public static void GetRSAKEY() { var rsakey = GetKey(); CPK = rsakey.PublicKey; } public static void GetSecret() { APPID= MsSysParamSetDAL.GetSysParamValue("FanWei_appid"); //v7JNCMbkEnmDm5OwtwsUbmD93s SPK = MsSysParamSetDAL.GetSysParamValue("FanWei_SPK"); SECRET = MsSysParamSetDAL.GetSysParamValue("FanWei_SECRET"); if (!string.IsNullOrWhiteSpace(SPK) && !string.IsNullOrWhiteSpace(SECRET)) { return; } GetRSAKEY(); var appparam = new { appid = APPID, cpk = CPK }; var paramdic = new Dictionary { { "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(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); } } public static void GetToken() { if (locked) return; locked = true; try { GetSecret(); //token过期时间30分钟 //所以获取时记录获取后的25分钟为过期时间 如过期则重新获取 if (!(tokenEndTime == null || tokenEndTime <= DateTime.Now || string.IsNullOrWhiteSpace(token))) { return; } var secret = EncryptByPublicKey(SECRET,SPK); var paramdic = new Dictionary { { "appid", APPID }, { "secret", secret } }; var securl = URLHead + "/api/ec/dev/auth/applytoken"; var data = WebRequestHelper.DoPost_Header(securl, paramdic); if (data != null) { var r = JsonConvert.Deserialize(data); token = r.token; tokenEndTime = DateTime.Now.AddMinutes(25); //MsSysParamSetDAL.SaveSysParamValue("FanWei_TOKEN", "泛微TOKEN", token); } } catch (Exception e) { } finally { locked = false; } } public static DBResult PostApplication( ChPayapplication headdata, string userid, string username, string companyid) { GetToken(); var result = new DBResult(); try { var hp = new GetResult(); result = hp.DoGet(headdata, userid, username, companyid); } 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 = URLHead; return baseurl; } public abstract string GetUrl(); public 泛微Response DoGet(Dictionary dic=null) { GetUrl(); var rtn = WebRequestHelper.DoGet(Url); //临时替换 由于.在识别时报错 临时改为## //rtn = rtn.Replace(".", "##"); response = JsonConvert.Deserialize<泛微Response>(rtn); return response; } } public class SecretResponse : 泛微Response { public string secret { get; set; } public string spk { get; set; } } public class TokenResponse: 泛微Response { public string token { get; set; } } public class fj { public string filePath { get; set; } public string fileName { get; set; } public fj() { } public fj(ChfeeFile chfeefile) { //系统参数 var paramset = MsSysParamSetDAL.GetDataByName("DS7URL"); if (!string.IsNullOrWhiteSpace(chfeefile.File_Path) && chfeefile.File_Path.IndexOf("\\Areas\\") >= 0) { var oldfilePath = chfeefile.File_Path.Substring(chfeefile.File_Path.IndexOf("\\Areas\\"), chfeefile.File_Path.Length - chfeefile.File_Path.IndexOf("\\Areas\\")).Replace("\\","/"); filePath = (paramset.PARAMVALUE + "/" + oldfilePath).Replace("//Areas", "/Areas"); filePath = filePath.Replace("//Areas", "/Areas"); fileName = chfeefile.File_Name; } } } public static List GetFileList(string billno) { var filelist= ChfeeFileDal.GetFileList(billno); var result=new List(); if (filelist != null && filelist.Count > 0) { foreach (var item in filelist) { result.Add(new fj(item)); } } return result; } public class Field { public string fieldName { get; set; } public string fieldValue { get; set; } public Field() { } public Field(string _fieldname, string _fieldvalue) { fieldName=_fieldname; fieldValue=_fieldvalue; } public Field(string _fieldname, decimal? _fieldvalue) { fieldName = _fieldname; fieldValue = _fieldvalue==null?"0": _fieldvalue.ToString(); } } public class FileField { public string fieldName { get; set; } public List fieldValue { get; set; } public FileField(string _fieldname, List _fieldvalue) { fieldName = _fieldname; fieldValue = _fieldvalue; } } public static ArrayList GetMainData(ChPayapplication headdata, string userid,int deptid, view_xdf_md fkdx) { var result = new ArrayList(); result.add(new Field("sqr", userid));//申请人 改用ID result.add(new Field("sqbm", deptid.ToString()));//申请部门 改用申请人部门ID var applytimestr = headdata.APPLYTIME == null ? DateTime.Now.ToString("yyyy-MM-dd") : ((DateTime)(headdata.APPLYTIME)).ToString("yyyy-MM-dd"); result.add(new Field("sqrq", applytimestr));//申请日期 result.add(new Field("lcbh", headdata.BILLNO));//流程编号 用付费申请单号 result.add(new Field("bz", headdata.REMARK));//备注 result.add(new Field("fkdx", fkdx.id.ToString()));//headdata.CUSTOMERNAME 付款对象 需使用泛微的一个ID号 var cdc = new CommonDataContext(); //var yxzh = ""; //var khx = ""; //if (!string.IsNullOrWhiteSpace(headdata.CUSTACCOUNTGID)) { // var custbank = cdc.info_client_bank.FirstOrDefault(x => x.GID == headdata.CUSTACCOUNTGID); // yxzh = custbank.ACCOUNT; // khx = custbank.BANKNAME; //} result.add(new Field("yxzh", fkdx.yxzh));//银行账号 result.add(new Field("khx", fkdx.khx));//开户行 result.add(new Field("wtdw", headdata.BS_CUSTOMERNAME));//委托单位 文本 result.add(new Field("jehj", Math.Round(headdata.AMOUNTRMB,2)));//金额合计 result.add(new Field("jehjdx", Math.Round(headdata.AMOUNTRMB,2)));//金额合计大写 //result.add(new Field("jehjdx", BasicDataRefDAL.ConvertToChineseMoney2( (double)headdata.AMOUNTRMB))); result.add(new Field("jehjmj", Math.Round(headdata.AMOUNTUSD,2)));//金额合计美金 result.add(new Field("jehjdxmj", Math.Round(headdata.AMOUNTUSD,2)));//金额合计大写美金 //result.add(new Field("jehjmjdx", BasicDataRefDAL.ConvertToChineseMoney2((double)headdata.AMOUNTUSD))); //附件fj字段的值: [{ "filePath":"上传的附件地址或者base64","fileName":"附件名称(包含附件类型)"}] var fjlist = GetFileList(headdata.BILLNO); //var fjliststr = JsonConvert.Serialize(fjlist); result.add(new FileField("fj", fjlist));//金额合计大写美金 var bsnolist = cdc.ch_fee_do.Where(x=>x.BILLNO ==headdata.BILLNO).Select(s=>s.BSNO).Distinct().ToList(); var vopbsMblnoList = cdc.v_op_bs.Where(x => bsnolist.Contains(x.BSNO)).Select(s => s.MBLNO).Distinct().ToList(); var bodymblnostr = ""; if (vopbsMblnoList != null && vopbsMblnoList.Count > 0) { bodymblnostr = string.Join(" , ", vopbsMblnoList); } result.add(new Field("tdh", bodymblnostr));//提单号 依据付款申请的ch_fee_do的bsno关联v_op_bs的MBLNO return result; } public static List GetDetailData(ChPayapplication headdata) { var resultlist = new List(); var result = new detailData(); result.workflowRequestTableRecords = new List(); 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(); var oplbdic = new Dictionary { {"海运进口" ,"0"}, {"海运出口" ,"1"}, {"空运进口" ,"2"}, {"空运出口" ,"3"} }; 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)); if (headdata.CURR=="RMB" || item.CURRENCY == "RMB") { newline.workflowRequestTableFields.Add(new Field("fyje", item.ORIGAMOUNT * item.EXCHANGERATE)); } else { newline.workflowRequestTableFields.Add(new Field("fyje",0)); //newline.workflowRequestTableFields.Add(new Field("fyje", item.ORIGAMOUNT*item.EXCHANGERATE)); } newline.workflowRequestTableFields.Add(new Field("wtdw", bs.CUSTOMERNAME)); var oplbstr = "4"; //4 海运进出口 5空运进出口 6铁路进口 7铁路出口 if (oplbdic.ContainsKey(bs.OPLBNAME)) oplbstr = oplbdic[bs.OPLBNAME]; newline.workflowRequestTableFields.Add(new Field("yslx", oplbstr)); newline.workflowRequestTableFields.Add(new Field("tdh", bs.MBLNO)); newline.workflowRequestTableFields.Add(new Field("xxxl", bs.CNTRTOTAL)); var fyjemj = "0"; if (headdata.CURR !="RMB" && item.CURRENCY == "USD") fyjemj = item.ORIGAMOUNT==null?"0": item.ORIGAMOUNT.ToString(); newline.workflowRequestTableFields.Add(new Field("fyjemj", fyjemj)); result.workflowRequestTableRecords.Add(newline); } resultlist.Add(result); return resultlist; } public class detailBody { public int recordOrder { get; set; } = 0; public List workflowRequestTableFields { get; set; } public detailBody() { workflowRequestTableFields = new List(); } } public class detailData { //测试表:formtable_main_120 明细:formtable_main_120_dt1 //正式表:formtable_main_77 明细:formtable_main_77_dt1 //public string tableDBName { get; set; } = "formtable_main_120_dt1"; public string tableDBName { get; set; } = "formtable_main_77_dt1"; public List workflowRequestTableRecords { get; set; } } public class GetResult : API_URL { public override string GetUrl() { //获取appid和secret Url = GetBaseUrl() + "/api/workflow/paService/doCreateRequest"; return Url; } public DBResult DoGet(ChPayapplication headdata , string userid, string username, string companyid) { var result = new DBResult(); var _res = new SuccessResponse(); var _res2 = new FailResponse(); try { GetUrl(); var cdc = new CommonDataContext(); var _user = cdc.VW_user.FirstOrDefault(x => x.USERID == userid); #region 正式获取userid的逻辑 var _userid = "0"; var fanweiconnstr = MsSysParamSetDAL.GetData("PARAMNAME='FanWei_DBCONN'").PARAMVALUE; var FanWeidc = new OtherDB(fanweiconnstr); var oaname = _user.SHOWNAME.Trim().Replace(" ", ""); var fwuser = FanWeidc.view_hrmresource.Where(x => x.lastname == oaname).ToList(); //var fwuser = FanWeidc.view_hrmresource.Where(x => x.lastname == "宫喜芬").ToList(); if (fwuser == null || fwuser.Count <= 0) { result.SetErrorInfo($"用户[{oaname}]在OA系统中不存在"); return result; } else { _userid = fwuser[0].id.ToString(); } var _userid_m = EncryptByPublicKey(_userid, SPK); #endregion //var _userid_m = EncryptByPublicKey("49", SPK); var dic = new Dictionary { { "token", token }, { "appid", APPID}, { "userid", _userid_m } }; var 付费申请付款对象 = cdc.info_client.First(x => x.SHORTNAME == headdata.CUSTOMERNAME); var fxdxlist = FanWeidc.view_xdf.Where(x => x.gyskhmc == 付费申请付款对象.DESCRIPTION).ToList(); if (fxdxlist == null || fxdxlist.Count <= 0) { result.SetErrorInfo($"客户[{付费申请付款对象.DESCRIPTION}]在OA系统中不存在"); return result; } var fxdx = fxdxlist[0]; var maindata = GetMainData(headdata, _userid, fwuser[0].departmentid, fxdx); var detaildata = GetDetailData(headdata); //var sendobj = new //{ // detailData = detaildata, // mainData = maindata, // otherParams = new { isnextflow = "1" }, // remark = "", // requestLevel = "", // requestName = "业务类供应商付款申请-票结", // workflowId = "117" //}; var valuedic = new Dictionary { { "mainData", JsonConvert.Serialize(maindata) }, { "detailData", JsonConvert.Serialize(detaildata)}, { "otherParams", JsonConvert.Serialize(new { isnextflow = "1" }) }, { "requestName", "业务类供应商付款申请-票结-"+ _user.SHOWNAME+"-"+headdata.BILLNO}, //{ "workflowId", "117" } { "workflowId", "79" } }; //var jsonstr=JsonConvert.Serialize(sendobj).Replace("\r\n",""); BasicDataRefDAL.SaveLog("url:" + Url + ";dic:" + JsonConvert.Serialize(dic) + ";valuedic:" + JsonConvert.Serialize(valuedic) ,"","泛微OA","发送" ); var rtn = WebRequestHelper.DoPost_Header(Url, dic, valuedic); BasicDataRefDAL.SaveLog(rtn , "", "泛微OA", "返回" ); try { _res = JsonConvert.Deserialize(rtn); if (_res.code.Contains("ERROR")) { var bottom= Regex.Replace(_res.reqFailMsg.msgInfo.bottom, @"\<[^\<]*\>", ""); var detail = Regex.Replace(_res.reqFailMsg.msgInfo.detail, @"\<[^\<]*\>", ""); result.SetErrorInfo(JsonConvert.Serialize( _res.reqFailMsg.msgInfo.title+":" + bottom + "\r\n\r\n" + detail)); } else { result.Data = _res.data.requestid; result.OK("发送成功"); } //要记录requestid //var logicdic = new Dictionary { // { "requestid", _res.data.requestid } //}; //BasicDataRefDAL.SaveLogicInfo(headdata.GID, "泛微审批", logicdic); } catch (Exception e) { _res2 = JsonConvert.Deserialize(rtn); result.SetErrorInfo("发送失败:"+ _res2.errMsg.ToString()); } return result; } catch (Exception e) { return result.SetErrorInfo(e.Message); } finally { } //return _res; } } public class 泛微Response { /// /// /// public string code { get; set; } /// /// /// public string data { get; set; } /// /// /// public string errMsg { get; set; } } public class SuccessResponse : 泛微Response { public string code { get; set; } /// /// /// public Data data { get; set; } /// /// /// public ErrMsg errMsg { get; set; } /// /// /// public ReqFailMsg reqFailMsg { get; set; } } public class FailResponse : 泛微Response { /// /// /// public ErrMsg errMsg { get; set; } } public class Data { /// /// /// public int requestid { get; set; } } public class ErrMsg { } public class KeyParameters { } public class MsgInfo { public string prompttype { get; set; } public string bottom { get; set; } public string detail { get; set; } public string title { get; set; } } public class OtherParams { /// /// /// public string doAutoApprove { get; set; } } public class ReqFailMsg { /// /// /// public KeyParameters keyParameters { get; set; } /// /// /// public MsgInfo msgInfo { get; set; } /// /// /// public OtherParams otherParams { get; set; } } } #endregion } }