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.

330 lines
10 KiB
C#

using Aspose.Words.Saving;
using com.sun.org.apache.bcel.@internal.generic;
using DSWeb.Areas.CommMng.DAL;
using DSWeb.Areas.MvcShipping.Models.Message.VGM;
using DSWeb.Areas.MvcShipping.Models.MsOpSeaeBaoXian;
using DSWeb.Common.DB;
using DSWeb.MvcShipping.Helper;
using HcUtility.Comm;
using Newtonsoft.Json.Linq;
using System;
using System.Collections.Generic;
using System.Data.Entity.Core.Metadata.Edm;
using System.Data.Entity.Migrations;
using System.Diagnostics.Contracts;
using System.IO;
using System.Linq;
using System.Net.Http;
using System.Reflection;
using System.Text;
using System.Web;
using System.Web.Mvc;
using DSWeb.SoftMng.Filter;
using System.Web.Script.Serialization;
using System.Web.UI.MobileControls.Adapters;
namespace DSWeb.Areas.CommMng.Controllers
{
[JsonRequestBehavior]
public class PublicInterfaceController : Controller
{
[HttpPost]
public InterfaceResult PostInterface(InterfaceParam param) {
try {
Assembly assembly = Assembly.Load("DSWeb.Areas.CommMng.Controllers");
var type = assembly.GetType("DSWeb.Areas.CommMng.Controllers.InterfaceBase." + param.PORTNAME);
Object obj = type.Assembly.CreateInstance(type.ToString());
var doset = type.GetMethod("DoSet");
var _param = new object[]{ param};
InterfaceResult result = (InterfaceResult)doset.Invoke(obj,BindingFlags.Instance|BindingFlags.NonPublic,null, _param, null);
return result;
} catch (Exception e) {
var _r = new InterfaceResult();
_r.errCode = "1";
var msg = e.Message;
if (e.InnerException != null && e.InnerException.Message != null) {
msg += "//InnerException.Message:" + e.InnerException.Message;
}
var _rs= BasicDataRefDAL.SaveLog(msg, "", param.PORTNAME, "公开接口");
var _rr = JsonConvert.Deserialize<DBResult>(_rs.Content);
_r.errMsg = "未知错误,请联系相关人员,错误日志号【" + _rr.Data.ToString() + "】";
return _r;
}
}
/// <summary>
/// 诺诺开票回调 未完成
/// </summary>
/// <param name="param"></param>
/// <returns></returns>
[HttpPost]
public InterfaceResult NNCallBack(InterfaceParam param)
{
try
{
Assembly assembly = Assembly.Load("DSWeb.Areas.Account.Controllers");
var type = assembly.GetType("DSWeb.Areas.CommMng.Controllers.InterfaceBase." + param.PORTNAME);
Object obj = type.Assembly.CreateInstance(type.ToString());
var doset = type.GetMethod("DoSet");
var _param = new object[] { param };
InterfaceResult result = (InterfaceResult)doset.Invoke(obj, BindingFlags.Instance | BindingFlags.NonPublic, null, _param, null);
return result;
}
catch (Exception e)
{
var _r = new InterfaceResult();
_r.errCode = "1";
var msg = e.Message;
if (e.InnerException != null && e.InnerException.Message != null)
{
msg += "//InnerException.Message:" + e.InnerException.Message;
}
var _rs = BasicDataRefDAL.SaveLog(msg, "", param.PORTNAME, "公开接口");
var _rr = JsonConvert.Deserialize<DBResult>(_rs.Content);
_r.errMsg = "未知错误,请联系相关人员,错误日志号【" + _rr.Data.ToString() + "】";
return _r;
}
}
public void PublicInterface()
{
var sr = new StreamReader(Request.InputStream, Encoding.UTF8);
var strJson = sr.ReadToEnd();
var paramHead = JsonConvert.Deserialize<InterfaceParam_Base>(strJson);
try
{
//记录日志
InterfaceLog.Save("PublicInterface", strJson);
Assembly assembly = Assembly.Load("DSWeb");
var classname = "DSWeb.Areas.CommMng.PublicInterfaceDAL." + paramHead.PORTNAME;
var type = assembly.GetType(classname);
Object obj = type.Assembly.CreateInstance(type.ToString());
var doset = type.GetMethod("DoSet");
var _param = new object[] { paramHead.Param };
DBResult result = (DBResult)doset.Invoke(obj, BindingFlags.Instance | BindingFlags.NonPublic, null, _param, null);
//var str = JsonConvert.Serialize(result);
string json = JsonConvert.Serialize(result);
//Response.Clear();
Response.AddHeader("Content-type", "text/json");
Response.AddHeader("Content-type", "application/json");
Response.ContentType = "application/json";
Response.Write(json);
}
catch (Exception e)
{
//var msg = JsonConvert.Serialize(e);
//var _rs = BasicDataRefDAL.SaveLog(msg, "", "PublicInterface", "错误");
////var _rr = JsonConvert.Deserialize<DBResult>(_rs.Content);
//_r.Message = msg;
string json = JsonConvert.Serialize(e);
//Response.Clear();
Response.AddHeader("Content-type", "text/json");
Response.AddHeader("Content-type", "application/json");
Response.ContentType = "application/json";
Response.Write(json);
}
}
}
public class InterfaceResult {
public string errCode { get; set; }
public string errMsg { get; set; }
public InterfaceResult() { }
public InterfaceResult(DBResult dbresult) {
if (dbresult.Success)
{
errCode = "0";
}
else
{
errCode = "1";
}
errMsg = dbresult.Message + ";Data:" + JsonConvert.Serialize(dbresult.Data);
}
}
public class InterfaceParam {
public string PORTNAME { get; set; }
public string GID { get; set; }
public string Param { get; set; }
}
public class InterfaceParam_Base
{
public string PORTNAME { get; set; }
public string GID { get; set; }
public object Param { get; set; }
}
public static class InterfaceLog
{
public static void Save(string PORTNAME, object c)
{
var saverec = getsaverec(PORTNAME, c);
if (!string.IsNullOrWhiteSpace(saverec.Param) && !string.IsNullOrWhiteSpace(saverec.PORTNAME))
{
var cdc = new CommonDataContext();
cdc.t_PublicInterface_Log.Add(saverec);
cdc.SaveChanges();
}
}
private static t_PublicInterface_Log_md getsaverec(string PORTNAME, object c)
{
var result = new t_PublicInterface_Log_md();
try
{
result.GID = Guid.NewGuid().ToString();
result.PORTNAME = PORTNAME;
result.Param = JsonConvert.Serialize(c);
result.CreateTime = DateTime.Now;
}
catch (Exception e)
{
}
return result;
}
}
public class _Fee
{
/// <summary>
/// 单证费
/// </summary>
public string cost_name { get; set; }
/// <summary>
///
/// </summary>
public string cost_unit { get; set; }
/// <summary>
///
/// </summary>
public string cost_price { get; set; }
/// <summary>
///
/// </summary>
public string cost_count { get; set; }
/// <summary>
///
/// </summary>
public string cost_currency { get; set; }
/// <summary>
///
/// </summary>
public string cost_amount { get; set; }
}
public class _Bill
{
/// <summary>
///
/// </summary>
public string bill_no { get; set; }
/// <summary>
///
/// </summary>
public string bill_date { get; set; }
/// <summary>
/// 正本提单
/// </summary>
public string bill_type { get; set; }
/// <summary>
/// 已出单
/// </summary>
public string bill_status { get; set; }
/// <summary>
///
/// </summary>
public string bill_vessel { get; set; }
/// <summary>
///
/// </summary>
public string bill_voyage { get; set; }
/// <summary>
///
/// </summary>
public string bill_amount_usa { get; set; }
/// <summary>
///
/// </summary>
public string bill_amount_rmb { get; set; }
/// <summary>
///
/// </summary>
public string bill_container_type { get; set; }
/// <summary>
///
/// </summary>
public string bill_container_count { get; set; }
/// <summary>
///
/// </summary>
public string bill_remark { get; set; }
/// <summary>
///
/// </summary>
public List<_Fee> bill_details { get; set; }
}
public class InterfaceBase
{
public InterfaceBase() { }
public InterfaceResult DoSet(InterfaceParam param) {
return new InterfaceResult();
}
public class csCust: InterfaceBase
{
public InterfaceResult DoSet(InterfaceParam param)
{
return new InterfaceResult();
}
}
}
public class NNCallBackInfo {
public string operater { get; set; }
public string billNo { get; set; }
public NNContent content { get; set; }
}
public class NNContent {
List<NNDetail> details { get; set; }
}
public class NNDetail
{
}
}