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; using System.Net.Http; namespace Learun.Application.WebApi.Modules { /// /// 版 本 Learun-ADMS V7.0.0 数字化智慧校园 /// Copyright (c) 2013-2018 北京泉江科技有限公司 /// 创建人:数字化智慧校园-框架开发组 /// 日 期:2018.01.04 /// 描 述: /// public class FinaChargeStuYearApi : BaseApi { private FinaChargeStuYearIBLL finaChargeStuYearIBLL = new FinaChargeStuYearBLL(); private FinaChargeStuOrderIBLL finaChargeStuOrderIbll = new FinaChargeStuOrderBLL(); private TeachSwitchIBLL teachSwitchIbll = new TeachSwitchBLL(); public FinaChargeStuYearApi() : base("/ReceiveSendFeeManagement/FinaChargeStuYearApi") { Get["/getpayfeelist"] = GetPayfeeList;// 获取缴费列表 Get["/getpayfeeinfo"] = GetPayfeeInfo;//获取缴费明细 Post["/generateqrcode"] = PayFeeQRCode;//生成缴费二维码 Get["/getinvoice"] = GetInvoice;//获取发票 } public Response GetInvoice(dynamic _) { string keyValue = Request.Query["keyValue"]; var list = finaChargeStuYearIBLL.GetStuInvoice(keyValue); return Success(list); } public Response GetPayfeeList(dynamic _) { var eastatus = teachSwitchIbll.GetFirst("jf"); if (eastatus != null && eastatus.status == "1") { ReqPageParam parameter = this.GetReqData(); var data = finaChargeStuYearIBLL.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); } else { return Fail("当前不在缴费时间范围"); } } public Response GetPayfeeInfo(dynamic _) { string keyValue = Request.Query["keyValue"]; //学生基础信息 var FinaChargeStuYearData = finaChargeStuYearIBLL.GetFinaChargeStuYearEntity(keyValue); //学生缴费明细 var FinaChargeStuItemList = finaChargeStuYearIBLL.GetFinaChargeStuItemList(keyValue); var jsonData = new { StuInfoFreshData = FinaChargeStuYearData, FinaChargesStandardList = FinaChargeStuItemList, PayFeeTotal =FinaChargeStuYearData.NeedToPay, SJAmount = FinaChargeStuYearData.SJAmount }; return Success(jsonData); } public class PayfeeRequest { public string strEntity { get; set; } public string detailList { get; set; } } /// /// 生成缴费二维码 /// /// public Response PayFeeQRCode(dynamic _) { PayfeeRequest parameter = this.GetReqData(); FinaChargeStuYearEntity entity = parameter.strEntity.ToObject(); List list = parameter.detailList.ToObject>(); var imgUrl = ""; //访问学校财务服务器 string payresulturl = Config.GetValue("payresulturl"); string par = "requestXml="; Encoding encoding = Encoding.GetEncoding("gb2312"); byte[] payload = encoding.GetBytes(par); HttpClient httpClient = new HttpClient(); HttpContent content = new ByteArrayContent(payload); try { var result = httpClient.PostAsync(payresulturl, content); //LogEntity logEntity2 = new LogEntity(); //logEntity2.F_CategoryId = 121; //logEntity2.F_SourceObjectId = "preaccess"; //logEntity2.F_SourceContentJson = "成功"; //logEntity2.F_ExecuteResultJson = result.ToString(); //logEntity2.WriteLog(); try { 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 = entity.StuNo; string remark2 = entity.FSYear.ToString(); 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_SourceObjectId = "qrcode"; logEntity.F_SourceContentJson = "成功"; 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_SourceObjectId = "qrcode"; logEntity.F_SourceContentJson = "成功"; logEntity.F_ExecuteResultJson = imgCode; logEntity.WriteLog(); MemberInfoList = JsonConvert.DeserializeObject(imgCode); if (MemberInfoList.SUCCESS.Equals("true")) { imgUrl = CreateQRImg(MemberInfoList.QRURL, orderid); } } if (!string.IsNullOrEmpty(imgUrl)) { entity.orderid = orderid; finaChargeStuOrderIbll.SaveOrderData(entity, list); } } catch (Exception e) { LogEntity logEntity = new LogEntity(); logEntity.F_CategoryId = 121; logEntity.F_SourceObjectId = "qrcode"; logEntity.F_SourceContentJson = "失败"; logEntity.F_ExecuteResultJson = e.Message; logEntity.WriteLog(); } } catch (Exception e) { LogEntity logEntity = new LogEntity(); logEntity.F_CategoryId = 121; logEntity.F_SourceObjectId = "preaccess"; logEntity.F_SourceContentJson = "失败"; logEntity.F_ExecuteResultJson = e.Message; logEntity.WriteLog(); return Fail("缴费机器暂停缴费!"); } var backimgUrl = new { imgUrl }; return Success(backimgUrl); } 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 "/Content/images/QRCode/" + filename + ".jpg"; } } }