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/Account/Controllers/Chfee_PayController.cs

410 lines
20 KiB
C#

This file contains invisible Unicode characters!

This file contains invisible Unicode characters that may be processed differently from what appears below. If your use case is intentional and legitimate, you can safely ignore this warning. Use the Escape button to reveal hidden characters.

This file contains ambiguous Unicode characters that may be confused with others in your current locale. If your use case is intentional and legitimate, you can safely ignore this warning. Use the Escape button to highlight these characters.

using System;
using System.Linq;
using System.Web.Mvc;
using DSWeb.Areas.Account.DAL.Chfee_Jinzhang;
using DSWeb.Areas.Account.Models.Chfee_jinzhang;
using DSWeb.MvcShipping.Helper;
using DSWeb.MvcShipping.Comm.Cookie;
using DSWeb.Areas.CommMng.DAL;
using System.Collections.Generic;
using HcUtility.Comm;
using HcUtility.Core;
using DSWeb.EntityDA;
using DSWeb.Areas.Account.Models.Chfee_Exrate;
using System.Data;
using DSWeb.Areas.Account.Models.Chfee_Pay;
using DSWeb.Areas.Account.DAL.Chfee_bankdata;
using System.IO;
using DSWeb.Areas.Account.Models.Chfee_Invoice;
using DSWeb.Areas.Account.Models.Chfee_Settlement;
using DSWeb.SoftMng.Filter;
using DSWeb.MvcShipping.DAL.MsSysParamSet;
using javax.crypto;
using System.Security.Cryptography;
using System.Text;
using System.Collections.Specialized;
using DSWeb.MvcShipping.DAL.OP_SERVICEBILLDAL;
using DSWeb.Areas.Dispatch.Helper;
using NPOI.SS.Formula.Functions;
using DSWeb.MvcShipping.DAL.MsSeaeOrderDAL;
using DSWeb.Areas.Account.DAL.Chfee_Pay;
using DSWeb.MvcShipping.Models.MsChFee;
using DSWeb.Areas.Account.DAL.Chfee_Settlement;
using DSWeb.Areas.Account.Models.Chfee_Payapplication;
using DSWeb.Areas.Account.Models.Chfee_payapplication;
using System.Web;
using java.nio.file;
namespace DSWeb.Areas.Account.Controllers
{
[JsonRequestBehavior]
public class Chfee_PayController : Controller
{
//
// GET:
public ActionResult Index()
{
return View();
}
//
// GET: /
public ActionResult Edit()
{
return View();
}
public ActionResult StlIndex()
{
return View();
}
public ActionResult StlMateIndex()
{
return View();
}
//
// GET
#region
//[SqlKeyWordsFilter(Type = "Action")]//sql 防注入过滤器
//public ContentResult GetDataList(int start, int limit, string sort, string condition)
//{
// var dataList = ChBankdataDAL.GetDataList(condition, Convert.ToString(Session["USERID"]), CookieConfig.GetCookie_UserCode(Request), Convert.ToString(Session["COMPANYID"]), sort);
// var list = dataList.Skip(start).Take(limit);
// var json = JsonConvert.Serialize(new { Success = true, Message = "查询成功", totalCount = dataList.Count, data = list.ToList() });
// return new ContentResult() { Content = json };
//}
[SqlKeyWordsFilter(Type = "Action")]//sql 防注入过滤器
public ContentResult CreatePay(string GID)
{
DBResult result = new DBResult();
var HeadData = ChsettlementDAL.GetData("GID='" + GID + "'");
if (HeadData.PAYSTATUS == "提交支付"|| HeadData.PAYSTATUS == "支付完毕")
{
var jsonRespose = new JsonResponse { Success = false, Message = "当前状态不允许生成支付!",Data="0" };
return new ContentResult() { Content = JsonConvert.Serialize(jsonRespose) };
}
T_ALL_DA T_ALL_DA = new EntityDA.T_ALL_DA();
var CompanyName = T_ALL_DA.GetStrSQL("FULLNAME", "select FULLNAME from [company] where GID='" + Convert.ToString(Session["COMPANYID"]).ToString().Trim() + "'");
var PayCompanyList = ChPayDAL.GetDataList("", CompanyName);
if (PayCompanyList == null || PayCompanyList.Count == 0)
{
var jsonRespose = new JsonResponse { Success = false, Message = "没有注册信息无法支付!", Data = "1" };
return new ContentResult() { Content = JsonConvert.Serialize(jsonRespose) };
}
var CompanyFunName = T_ALL_DA.GetStrSQL("FULLNAME", "select [DESCRIPTION] FULLNAME from [info_client] where [SHORTNAME]='" + HeadData.CUSTOMERNAME + "'");
var newChPaymentFrom = new ChPaymentFrom();
newChPaymentFrom.Username = PayCompanyList[0].Username;
newChPaymentFrom.PayeeCompanyName = CompanyFunName;
newChPaymentFrom.PayeeCompanyAccount = HeadData.CUSTACCOUNT;
newChPaymentFrom.PayAmount = HeadData.AMOUNT;
newChPaymentFrom.PAYGID = GID;
newChPaymentFrom.PAYBILLNO = HeadData.BILLNO;
//newChPaymentFrom.SwiftCode = headData.SwiftCode;
//newChPaymentFrom.BankName = headData.BankName;
//newChPaymentFrom.BankId = headData.BankId;
//newChPaymentFrom.IsAcrossBank = headData.IsAcrossBank;
//newChPaymentFrom.IsQuickPay = headData.IsQuickPay;
//newChPaymentFrom.IsPartialPayment = headData.IsPartialPayment;
//newChPaymentFrom.IsCNYPay = headData.IsCNYPay;
//newChPaymentFrom.InvoiceFileNum = headData.InvoiceFileNum;
//newChPaymentFrom.BankBranchName = headData.BankBranchName;
//newChPaymentFrom.PayRemark = headData.PayRemark;
//newChPaymentFrom.CallBackUrl = headData.CallBackUrl;
//newChPaymentFrom.IsCNYPay = headData.IsCNYPay;
result.Success = true;
var json = JsonConvert.Serialize(new { Success = result.Success, Message = result.Message,Data= newChPaymentFrom });
return new ContentResult() { Content = json };
}
public ContentResult GetPayCityList()
{
DBResult result = new DBResult();
var Timestamp = ConvertDateTimeToInt(DateTime.Now);
var NonceStr = Guid.NewGuid().ToString().Replace("-", "");
if (NonceStr.Length > 32) NonceStr = NonceStr.Substring(0, 32);
var NewPayGet = new PayGet();
NewPayGet.AppId=MsSysParamSetDAL.GetData("PARAMNAME='DSPAYID'").PARAMVALUE;
NewPayGet.ApiSerialNo= Guid.NewGuid().ToString();
var secretKey= MsSysParamSetDAL.GetData("PARAMNAME='DSPAYKEY'").PARAMVALUE;
var payUrl = MsSysParamSetDAL.GetData("PARAMNAME='DSPAYURL'").PARAMVALUE;
var jsonstr = Newtonsoft.Json.JsonConvert.SerializeObject(NewPayGet);
var Signature = signatureGet(jsonstr, NonceStr, Timestamp.ToString(), secretKey);
Dictionary<string, string> dicData = new Dictionary<string, string>();
dicData.Add("Signature", Signature);
dicData.Add("Timestamp", Timestamp.ToString());
dicData.Add("NonceStr", NonceStr);
BasicDataRefDAL.SaveLog(jsonstr, "admin", "快付获取城市列表", "发送");
var rtn = WebRequestHelper.DoPostHead(payUrl+ "/api/GetCityList", dicData, jsonstr);
var _rd = JsonConvert.Deserialize<JosnPayGetCity>(rtn);
BasicDataRefDAL.SaveLog(rtn, "", "快付获取城市列表", "返回");
result.Success = _rd.Code == 0;
result.Message = _rd.Msg;
var CityList = _rd.Data;
var jsonRespose = new jsonresponse { success = result.Success, message = result.Message, data = CityList.ToList() };
return new ContentResult() { Content = JsonConvert.Serialize(jsonRespose) };
}
public ContentResult GetPayBankList()
{
DBResult result = new DBResult();
var Timestamp = ConvertDateTimeToInt(DateTime.Now);
var NonceStr = Guid.NewGuid().ToString().Replace("-", "");
if (NonceStr.Length > 32) NonceStr = NonceStr.Substring(0, 32);
var NewPayGet = new PayGet();
NewPayGet.AppId = MsSysParamSetDAL.GetData("PARAMNAME='DSPAYID'").PARAMVALUE;
NewPayGet.ApiSerialNo = Guid.NewGuid().ToString();
var secretKey = MsSysParamSetDAL.GetData("PARAMNAME='DSPAYKEY'").PARAMVALUE;
var payUrl = MsSysParamSetDAL.GetData("PARAMNAME='DSPAYURL'").PARAMVALUE;
var jsonstr = Newtonsoft.Json.JsonConvert.SerializeObject(NewPayGet);
var Signature = signatureGet(jsonstr, NonceStr, Timestamp.ToString(), secretKey);
Dictionary<string, string> dicData = new Dictionary<string, string>();
dicData.Add("Signature", Signature);
dicData.Add("Timestamp", Timestamp.ToString());
dicData.Add("NonceStr", NonceStr);
BasicDataRefDAL.SaveLog(jsonstr, "admin", "快付获取银行列表", "发送");
var rtn = WebRequestHelper.DoPostHead(payUrl + "/api/GetBankList", dicData, jsonstr);
var _rd = JsonConvert.Deserialize<JosnPayGetBank>(rtn);
BasicDataRefDAL.SaveLog(rtn, "", "快付获取银行列表", "返回");
result.Success = _rd.Code == 0;
result.Message = _rd.Msg;
var CityList = _rd.Data;
var jsonRespose = new jsonresponse { success = result.Success, message = result.Message, data = CityList.ToList() };
return new ContentResult() { Content = JsonConvert.Serialize(jsonRespose) };
}
public ContentResult GetCompanyIsPay()
{
DBResult result = new DBResult();
var Timestamp = ConvertDateTimeToInt(DateTime.Now);
var NonceStr = Guid.NewGuid().ToString().Replace("-", "");
if (NonceStr.Length > 32) NonceStr = NonceStr.Substring(0,32);
var NewPayGet = new PayGetCompany();
NewPayGet.AppId = MsSysParamSetDAL.GetData("PARAMNAME='DSPAYID'").PARAMVALUE;
NewPayGet.ApiSerialNo = Guid.NewGuid().ToString();
T_ALL_DA T_ALL_DA = new EntityDA.T_ALL_DA();
var CompanyName = T_ALL_DA.GetStrSQL("FULLNAME", "select FULLNAME from [company] where GID='" + Convert.ToString(Session["COMPANYID"]).ToString().Trim() + "'");
NewPayGet.CompanyName = CompanyName;
var secretKey = MsSysParamSetDAL.GetData("PARAMNAME='DSPAYKEY'").PARAMVALUE;
var payUrl = MsSysParamSetDAL.GetData("PARAMNAME='DSPAYURL'").PARAMVALUE;
var jsonstr = Newtonsoft.Json.JsonConvert.SerializeObject(NewPayGet);
var Signature = signatureGet(jsonstr, NonceStr, Timestamp.ToString(), secretKey);
Dictionary<string, string> dicData = new Dictionary<string, string>();
dicData.Add("Signature", Signature);
dicData.Add("Timestamp", Timestamp.ToString());
dicData.Add("NonceStr", NonceStr);
BasicDataRefDAL.SaveLog(jsonstr, "admin", "快付验证公司", "发送");
var rtn = WebRequestHelper.DoPostHead(payUrl + "/api/CompanyRegistered", dicData, jsonstr);
var _rd = JsonConvert.Deserialize<PayGetIsCompany>(rtn);
BasicDataRefDAL.SaveLog(rtn, "", "快付验证公司", "返回");
result.Success = _rd.Code == 0;
result.Message = _rd.Msg;
var jsonRespose = new JsonResponse { Success = result.Success, Message = result.Message };
return new ContentResult() { Content = JsonConvert.Serialize(jsonRespose) };
}
public ContentResult SendReg(string data)
{
var headData = JsonConvert.Deserialize<ChRegisterFrom>(data);
var localurl = System.Web.HttpContext.Current.Request.Url.Host;
var DSPAYUSERNAME = MsSysParamSetDAL.GetData("PARAMNAME='DSPAYUSERNAME'").PARAMVALUE;
var newPaymentFrom = new RegisterFrom();
newPaymentFrom.AppId = MsSysParamSetDAL.GetData("PARAMNAME='DSPAYID'").PARAMVALUE;
newPaymentFrom.Username = DSPAYUSERNAME;
newPaymentFrom.Password = headData.Password;
newPaymentFrom.PayPassword = headData.PayPassword;
newPaymentFrom.ContactName = headData.ContactName;
newPaymentFrom.Phone = headData.Phone;
newPaymentFrom.City = headData.City;
newPaymentFrom.CompanyName = headData.CompanyName;
newPaymentFrom.CompanyCode = headData.CompanyCode;
newPaymentFrom.CompanyAddress = headData.CompanyAddress;
newPaymentFrom.CompanyBank = headData.CompanyBank;
newPaymentFrom.CompanyAccount = headData.CompanyAccount;
newPaymentFrom.Email = headData.Email;
newPaymentFrom.LegalName = headData.LegalName;
newPaymentFrom.ValidatePassword = headData.ValidatePassword;
newPaymentFrom.ApiSerialNo = Guid.NewGuid().ToString();
DBResult result = new DBResult();
var Timestamp = ConvertDateTimeToInt(DateTime.Now);
var NonceStr = Guid.NewGuid().ToString().Replace("-", "");
if (NonceStr.Length > 32) NonceStr = NonceStr.Substring(0, 32);
T_ALL_DA T_ALL_DA = new EntityDA.T_ALL_DA();
var CompanyName = T_ALL_DA.GetStrSQL("FULLNAME", "select FULLNAME from [company] where GID='" + Convert.ToString(Session["COMPANYID"]).ToString().Trim() + "'");
var secretKey = MsSysParamSetDAL.GetData("PARAMNAME='DSPAYKEY'").PARAMVALUE;
var payUrl = MsSysParamSetDAL.GetData("PARAMNAME='DSPAYURL'").PARAMVALUE;
var jsonstr = Newtonsoft.Json.JsonConvert.SerializeObject(newPaymentFrom);
var Signature = signatureGet(jsonstr, NonceStr, Timestamp.ToString(), secretKey);
Dictionary<string, string> dicData = new Dictionary<string, string>();
dicData.Add("Signature", Signature);
dicData.Add("Timestamp", Timestamp.ToString());
dicData.Add("NonceStr", NonceStr);
BasicDataRefDAL.SaveLog(jsonstr, "admin", "快付发起支付", "发送");
var rtn = WebRequestHelper.DoPostHead(payUrl + "/api/PaymentFromApi", dicData, jsonstr);
var _rd = JsonConvert.Deserialize<PayGetIsCompany>(rtn);
BasicDataRefDAL.SaveLog(rtn, "", "快付发起支付", "返回");
result.Success = _rd.Code == 0;
result.Message = _rd.Msg;
var jsonRespose = new JsonResponse { Success = result.Success, Message = result.Message };
return new ContentResult() { Content = JsonConvert.Serialize(jsonRespose) };
}
public ContentResult SendPay(string data,string filedata)
{
var headData = JsonConvert.Deserialize<ChPaymentFrom>(data);
var filelist = JsonConvert.Deserialize<List<ChfeeFile>>(filedata);
var localurl = System.Web.HttpContext.Current.Request.Url.Host;
var DSPAYUSERNAME = MsSysParamSetDAL.GetData("PARAMNAME='DSPAYUSERNAME'").PARAMVALUE;
var InvFiles = new List<InvFiles>();
foreach (var invfile in filelist) {
var file = new InvFiles();
file.Path = localurl + "/Areas/Account/Files/" + invfile.BillNo + "/" + invfile.File_Name + "?a=23451";
file.fileExtension ="pdf";
InvFiles.Add(file);
}
var newPaymentFrom = new PaymentFrom();
newPaymentFrom.AppId = MsSysParamSetDAL.GetData("PARAMNAME='DSPAYID'").PARAMVALUE;
newPaymentFrom.Username = DSPAYUSERNAME;
newPaymentFrom.PayeeCompanyName = headData.PayeeCompanyName;
newPaymentFrom.PayeeCompanyAccount = headData.PayeeCompanyAccount;
newPaymentFrom.PaymentAmount =Convert.ToInt32(headData.PayAmount*100);
if (headData.IsAcrossBank == 0)
{
newPaymentFrom.SwiftCode ="";
newPaymentFrom.BankName ="";
newPaymentFrom.BankId =0;
}
else
{
newPaymentFrom.SwiftCode = headData.SwiftCode;
newPaymentFrom.BankName = headData.BankName;
newPaymentFrom.BankId = headData.BankId;
}
newPaymentFrom.IsAcrossBank = headData.IsAcrossBank;
newPaymentFrom.IsQuickPay = headData.IsQuickPay;
newPaymentFrom.IsPartialPayment = headData.IsPartialPayment;
newPaymentFrom.IsCNYPay = headData.IsCNYPay;
newPaymentFrom.InvoiceFileNum = filelist.Count;
newPaymentFrom.BankBranchName = headData.BankBranchName;
newPaymentFrom.PayRemark = headData.PayRemark;
newPaymentFrom.CallBackUrl = localurl+ "/Dispatch/Dispatch/PaymentCallback";
newPaymentFrom.IsCNYPay = headData.IsCNYPay;
newPaymentFrom.ApiSerialNo = Guid.NewGuid().ToString();
newPaymentFrom.Files = InvFiles;
DBResult result = new DBResult();
var Timestamp = ConvertDateTimeToInt(DateTime.Now);
var NonceStr = Guid.NewGuid().ToString().Replace("-", "");
if (NonceStr.Length > 32) NonceStr = NonceStr.Substring(0, 32);
T_ALL_DA T_ALL_DA = new EntityDA.T_ALL_DA();
var CompanyName = T_ALL_DA.GetStrSQL("FULLNAME", "select FULLNAME from [company] where GID='" + Convert.ToString(Session["COMPANYID"]).ToString().Trim() + "'");
var secretKey = MsSysParamSetDAL.GetData("PARAMNAME='DSPAYKEY'").PARAMVALUE;
var payUrl = MsSysParamSetDAL.GetData("PARAMNAME='DSPAYURL'").PARAMVALUE;
var jsonstr = Newtonsoft.Json.JsonConvert.SerializeObject(newPaymentFrom);
var Signature = signatureGet(jsonstr, NonceStr, Timestamp.ToString(), secretKey);
Dictionary<string, string> dicData = new Dictionary<string, string>();
dicData.Add("Signature", Signature);
dicData.Add("Timestamp", Timestamp.ToString());
dicData.Add("NonceStr", NonceStr);
BasicDataRefDAL.SaveLog(jsonstr, "admin", "快付发起支付", "发送");
var rtn = WebRequestHelper.DoPostHead(payUrl + "/api/PaymentFromApi", dicData, jsonstr);
var _rd = JsonConvert.Deserialize<PaymentResult>(rtn);
BasicDataRefDAL.SaveLog(rtn, "", "快付发起支付", "返回");
if (_rd.Code == 0) {
var blUpSQL = " update ch_fee_settlement set PAYID='"+ _rd.Data.SerialNo+ "',PAYSTATUS='提交付费' WHERE GID='" + headData.PAYGID+ "'";
bool bl = T_ALL_DA.GetExecuteSqlCommand(blUpSQL);
headData.GID = NonceStr;
headData.CREATETIME = DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss");
headData.CREATEUSER = Convert.ToString(Session["USERID"]).ToString().Trim();
headData.DbOperationType = DbOperationType.DbotIns;
var modb = new ModelObjectDB();
modb.Save(headData);
}
result.Success = _rd.Code == 0;
result.Message = _rd.Msg;
var jsonRespose = new JsonResponse { Success = result.Success, Message = result.Message };
return new ContentResult() { Content = JsonConvert.Serialize(jsonRespose) };
}
public static long ConvertDateTimeToInt(System.DateTime time)
{
long t = (time.Ticks - 621356256000000000) / 10000;
return t;
}
public static string signatureGet(string bodyJson, string noncestr, string timestamp, string secretKey)
{
string singature = string.Empty;
string md5str = $"{bodyJson}NonceStr={noncestr}Timestamp={timestamp}{secretKey}";
singature = MD5Encrypt32(md5str);
return singature;
}
public static string MD5Encrypt32(string password)
{
string cl = password;
string pwd = "";
MD5 md5 = MD5.Create(); //实例化一个md5对像
// 加密后是一个字节类型的数组这里要注意编码UTF8/Unicode等的选择 
byte[] s = md5.ComputeHash(Encoding.UTF8.GetBytes(cl));
// 通过使用循环,将字节类型的数组转换为字符串,此字符串是常规字符格式化所得
for (int i = 0; i < s.Length; i++)
{
// 将得到的字符串使用十六进制类型格式。格式后的字符是小写的字母如果使用大写X则格式后的字符是大写字符
pwd = pwd + s[i].ToString("x2");
}
return pwd;
}
#endregion
#region 参照部分
#endregion
}
}