using System; using Learun.Application.Organization; using Learun.Application.TwoDevelopment.EducationalAdministration; using Learun.Application.TwoDevelopment.EvaluationTeach; using Learun.Util; using Nancy; using System.Collections.Generic; using System.Drawing; using System.IO; using System.Linq; using System.Security.Cryptography; using System.Text; using System.Web; using System.Web.Mvc; using Learun.Application.Base.SystemModule; using Learun.Application.TwoDevelopment.Ask; using Learun.Application.TwoDevelopment.ReceiveSendFeeManagement; using Newtonsoft.Json; using ThoughtWorks.QRCode.Codec; namespace Learun.Application.WebApi.Modules { /// /// 版 本 Learun-ADMS V7.0.0 数字化智慧校园 /// Copyright (c) 2013-2018 北京泉江科技有限公司 /// 创建人:数字化智慧校园-框架开发组 /// 日 期:2018.01.04 /// 描 述:部门管理 /// public class StuFreshPayFeeApi : BaseApi { public StuFreshPayFeeApi() : base("/learun/freshpayfee") { Get["/getpayfeelist"] = GetPayfeeList;// 获取缴费列表 Get["/getpayfeeinfo"] = GetPayfeeInfo;//获取缴费明细 Post["/generateqrcode"] = PayFeeQRCode;//生成缴费二维码 Get["/getinvoice"] = GetInvoice;//获取发票 } private StuInfoFreshIBLL stuInfoFreshIBLL = new StuInfoFreshBLL(); private FinaChargesStandardIBLL finaChargesStandardIBLL = new FinaChargesStandardBLL(); public Response GetInvoice(dynamic _) { string keyValue = Request.Query["keyValue"]; var list = stuInfoFreshIBLL.GetStuEnrollFeeOrder(keyValue, true); return Success(list); } public Response GetPayfeeList(dynamic _) { ReqPageParam parameter = this.GetReqData(); var data = stuInfoFreshIBLL.GetPageList(parameter.pagination, parameter.queryJson); var jsonData = new { rows = data, total = parameter.pagination.total, page = parameter.pagination.page, records = parameter.pagination.records }; return Success(jsonData); } public Response GetPayfeeInfo(dynamic _) { string keyValue = Request.Query["keyValue"]; int jiaoFeiYear = DateTime.Now.Year; var StuInfoFreshData = stuInfoFreshIBLL.GetStuInfoFreshEntity(keyValue); var stuInfoFreshFamily = stuInfoFreshIBLL.GetStuInfoFreshFamilyList(keyValue); //当前年度缴费记录 var FeeOrderList = stuInfoFreshIBLL.GetFeeOrderList(StuInfoFreshData.StuNo, jiaoFeiYear); var FinaChargesStandardList = new List(); FinaChargesStandardList = finaChargesStandardIBLL.GetFinaChargesStandardListByYongYou(StuInfoFreshData.StuNo, jiaoFeiYear).ToList(); var PayFeeTotal = FinaChargesStandardList.Select(x => x.Standard).Sum(); var jsonData = new { StuInfoFreshData = StuInfoFreshData, FinaChargesStandardList = FinaChargesStandardList, StuInfoFreshFamilyList = stuInfoFreshFamily, PayFeeTotal = PayFeeTotal, YJAmount = FeeOrderList.Sum(x => x.SJAmount) }; return Success(jsonData); } public class PayfeeRequest { public string strEntity { get; set; } public string detailList { get; set; } } /// /// 生成缴费二维码 /// /// public Response PayFeeQRCode(dynamic _) { string keyValue = Request.Query["keyValue"]; PayfeeRequest parameter = this.GetReqData(); StuInfoFreshEntity entity = parameter.strEntity.ToObject(); List list = parameter.detailList.ToObject>(); var model = stuInfoFreshIBLL.GetStuInfoFreshEntity(keyValue); var imgUrl = ""; Random ran = new Random(); string merchantid = "105000082201406";//商户号 string posid = "043724806";//商户柜台代码 string branchid = "510000000";//分行代码 string orderid = DateTime.Now.ToString("yyyyMMddhhmmss") + ran.Next(0, 100000); string payment = entity.PayMoney.ToString(); string curcode = "01"; string txcode = "530550"; string remark1 = model.StuNo; string remark2 = "20" + model.Grade; string returntype = "3"; string timeout = DateTime.Now.AddMinutes(10).ToString("yyyyMMddHHmmss"); string pub32tr2 = "40d987faa793a0a27e7a86ef020111"; string bankURL = "https://ibsbjstar.ccb.com.cn/CCBIS/ccbMain?CCB_IBSVersion=V6"; string tmp = "MERCHANTID=" + merchantid + "&POSID=" + posid + "&BRANCHID=" + branchid + "&ORDERID=" + orderid; tmp += "&PAYMENT=" + payment + "&CURCODE=" + curcode + "&TXCODE=" + txcode + "&REMARK1=" + remark1; tmp += "&REMARK2=" + remark2 + "&RETURNTYPE=" + returntype + "&TIMEOUT=" + timeout; MD5 md5 = MD5.Create(); string tmp1 = tmp; tmp += "&PUB=" + pub32tr2; byte[] buffer = Encoding.Default.GetBytes(tmp); byte[] md5Buffer = md5.ComputeHash(buffer); string strMd5 = ""; //hdnOrderId.Value = orderid; foreach (byte item in md5Buffer) { strMd5 += item.ToString("x2"); } string url = bankURL + "&" + tmp1 + "&MAC=" + strMd5; string reJson = HttpMethods.Post(url); LogEntity logEntity = new LogEntity(); logEntity.F_CategoryId = 121; logEntity.F_ExecuteResultJson = reJson; logEntity.WriteLog(); //HttpConnect conn = new HttpConnect(); //string reJson = conn.Post(url, ""); JsonBean MemberInfoList = JsonConvert.DeserializeObject(reJson); if (MemberInfoList.SUCCESS.Equals("true")) { string imgCode = HttpMethods.Post(MemberInfoList.PAYURL); logEntity.F_CategoryId = 121; logEntity.F_ExecuteResultJson = imgCode; logEntity.WriteLog(); MemberInfoList = JsonConvert.DeserializeObject(imgCode); if (MemberInfoList.SUCCESS.Equals("true")) { imgUrl = CreateQRImg(MemberInfoList.QRURL, orderid); } } if (!string.IsNullOrEmpty(imgUrl)) { // model.PayFeeDetail = entity.PayFeeDetail; // model.PayMoney = entity.PayMoney; model.LoanMoney = entity.LoanMoney; model.orderid = orderid; stuInfoFreshIBLL.SaveFeeData(keyValue, model, list); } return Success(imgUrl); } public class JsonBean { /// /// /// public string SUCCESS { get; set; } public string PAYURL { get; set; } public string QRURL { get; set; } } /// /// 生成并保存二维码图片的方法 /// /// 输入的内容 public string CreateQRImg(string str, string orderId) { string QRCodeFile = Config.GetValue("QRCodeFile"); Random ran = new Random(); Bitmap bt; str = HttpUtility.UrlDecode(str); string enCodeString = str; //生成设置编码实例 QRCodeEncoder qrCodeEncoder = new QRCodeEncoder(); //设置二维码的规模,默认4 qrCodeEncoder.QRCodeScale = 3; //设置二维码的版本,默认7 qrCodeEncoder.QRCodeVersion = 7; //设置错误校验级别,默认中等 qrCodeEncoder.QRCodeErrorCorrect = QRCodeEncoder.ERROR_CORRECTION.M; //生成二维码图片 bt = qrCodeEncoder.Encode(enCodeString, Encoding.UTF8); //二维码图片的名称 string filename = orderId; if (!DirFileHelper.IsExistFile(QRCodeFile + "/Content/images/QRCode/")) { Directory.CreateDirectory(QRCodeFile + "/Content/images/QRCode/"); } var path = QRCodeFile + "/Content/images/QRCode/" + filename + ".jpg"; //保存二维码图片在photos路径下 try { bt.Save(path); } catch (Exception ex) { return ""; } //图片控件要显示的二维码图片路径 return QRCodeFile + "/Content/images/QRCode/" + filename + ".jpg"; } } }