Você não pode selecionar mais de 25 tópicos Os tópicos devem começar com uma letra ou um número, podem incluir traços ('-') e podem ter até 35 caracteres.
 
 
 
 
 
 

220 linhas
9.0 KiB

  1. using System;
  2. using Learun.Application.Organization;
  3. using Learun.Application.TwoDevelopment.EducationalAdministration;
  4. using Learun.Application.TwoDevelopment.EvaluationTeach;
  5. using Learun.Util;
  6. using Nancy;
  7. using System.Collections.Generic;
  8. using System.Drawing;
  9. using System.IO;
  10. using System.Linq;
  11. using System.Security.Cryptography;
  12. using System.Text;
  13. using System.Web;
  14. using System.Web.Mvc;
  15. using Learun.Application.Base.SystemModule;
  16. using Learun.Application.TwoDevelopment.Ask;
  17. using Learun.Application.TwoDevelopment.ReceiveSendFeeManagement;
  18. using Newtonsoft.Json;
  19. using ThoughtWorks.QRCode.Codec;
  20. namespace Learun.Application.WebApi.Modules
  21. {
  22. /// <summary>
  23. /// 版 本 Learun-ADMS V7.0.0 数字化智慧校园
  24. /// Copyright (c) 2013-2018 北京泉江科技有限公司
  25. /// 创建人:数字化智慧校园-框架开发组
  26. /// 日 期:2018.01.04
  27. /// 描 述:部门管理
  28. /// </summary>
  29. public class StuFreshPayFeeApi : BaseApi
  30. {
  31. public StuFreshPayFeeApi()
  32. : base("/learun/freshpayfee")
  33. {
  34. Get["/getpayfeelist"] = GetPayfeeList;// 获取缴费列表
  35. Get["/getpayfeeinfo"] = GetPayfeeInfo;//获取缴费明细
  36. Post["/generateqrcode"] = PayFeeQRCode;//生成缴费二维码
  37. Get["/getinvoice"] = GetInvoice;//获取发票
  38. }
  39. private StuInfoFreshIBLL stuInfoFreshIBLL = new StuInfoFreshBLL();
  40. private FinaChargesStandardIBLL finaChargesStandardIBLL = new FinaChargesStandardBLL();
  41. public Response GetInvoice(dynamic _)
  42. {
  43. string keyValue = Request.Query["keyValue"];
  44. var list = stuInfoFreshIBLL.GetStuEnrollFeeOrder(keyValue, true);
  45. return Success(list);
  46. }
  47. public Response GetPayfeeList(dynamic _)
  48. {
  49. ReqPageParam parameter = this.GetReqData<ReqPageParam>();
  50. var data = stuInfoFreshIBLL.GetPageList(parameter.pagination, parameter.queryJson);
  51. var jsonData = new
  52. {
  53. rows = data,
  54. total = parameter.pagination.total,
  55. page = parameter.pagination.page,
  56. records = parameter.pagination.records
  57. };
  58. return Success(jsonData);
  59. }
  60. public Response GetPayfeeInfo(dynamic _)
  61. {
  62. string keyValue = Request.Query["keyValue"];
  63. int jiaoFeiYear = DateTime.Now.Year;
  64. var StuInfoFreshData = stuInfoFreshIBLL.GetStuInfoFreshEntity(keyValue);
  65. var stuInfoFreshFamily = stuInfoFreshIBLL.GetStuInfoFreshFamilyList(keyValue);
  66. //当前年度缴费记录
  67. var FeeOrderList = stuInfoFreshIBLL.GetFeeOrderList(StuInfoFreshData.StuNo, jiaoFeiYear);
  68. var FinaChargesStandardList = new List<FinaChargesStandardEntity>();
  69. FinaChargesStandardList = finaChargesStandardIBLL.GetFinaChargesStandardListByYongYou(StuInfoFreshData.StuNo, jiaoFeiYear).ToList();
  70. var PayFeeTotal = FinaChargesStandardList.Select(x => x.Standard).Sum();
  71. var jsonData = new
  72. {
  73. StuInfoFreshData = StuInfoFreshData,
  74. FinaChargesStandardList = FinaChargesStandardList,
  75. StuInfoFreshFamilyList = stuInfoFreshFamily,
  76. PayFeeTotal = PayFeeTotal,
  77. YJAmount = FeeOrderList.Sum(x => x.SJAmount)
  78. };
  79. return Success(jsonData);
  80. }
  81. public class PayfeeRequest
  82. {
  83. public string strEntity { get; set; }
  84. public string detailList { get; set; }
  85. }
  86. /// <summary>
  87. /// 生成缴费二维码
  88. /// </summary>
  89. /// <returns></returns>
  90. public Response PayFeeQRCode(dynamic _)
  91. {
  92. string keyValue = Request.Query["keyValue"];
  93. PayfeeRequest parameter = this.GetReqData<PayfeeRequest>();
  94. StuInfoFreshEntity entity = parameter.strEntity.ToObject<StuInfoFreshEntity>();
  95. List<StuEnrollFeeOrderDetailEntity> list = parameter.detailList.ToObject<List<StuEnrollFeeOrderDetailEntity>>();
  96. var model = stuInfoFreshIBLL.GetStuInfoFreshEntity(keyValue);
  97. var imgUrl = "";
  98. Random ran = new Random();
  99. string merchantid = "105000082201406";//商户号
  100. string posid = "043724806";//商户柜台代码
  101. string branchid = "510000000";//分行代码
  102. string orderid = DateTime.Now.ToString("yyyyMMddhhmmss") + ran.Next(0, 100000);
  103. string payment = entity.PayMoney.ToString();
  104. string curcode = "01";
  105. string txcode = "530550";
  106. string remark1 = model.StuNo;
  107. string remark2 = "20" + model.Grade;
  108. string returntype = "3";
  109. string timeout = DateTime.Now.AddMinutes(10).ToString("yyyyMMddHHmmss");
  110. string pub32tr2 = "40d987faa793a0a27e7a86ef020111";
  111. string bankURL = "https://ibsbjstar.ccb.com.cn/CCBIS/ccbMain?CCB_IBSVersion=V6";
  112. string tmp = "MERCHANTID=" + merchantid + "&POSID=" + posid + "&BRANCHID=" + branchid + "&ORDERID=" + orderid;
  113. tmp += "&PAYMENT=" + payment + "&CURCODE=" + curcode + "&TXCODE=" + txcode + "&REMARK1=" + remark1;
  114. tmp += "&REMARK2=" + remark2 + "&RETURNTYPE=" + returntype + "&TIMEOUT=" + timeout;
  115. MD5 md5 = MD5.Create();
  116. string tmp1 = tmp;
  117. tmp += "&PUB=" + pub32tr2;
  118. byte[] buffer = Encoding.Default.GetBytes(tmp);
  119. byte[] md5Buffer = md5.ComputeHash(buffer);
  120. string strMd5 = "";
  121. //hdnOrderId.Value = orderid;
  122. foreach (byte item in md5Buffer)
  123. {
  124. strMd5 += item.ToString("x2");
  125. }
  126. string url = bankURL + "&" + tmp1 + "&MAC=" + strMd5;
  127. string reJson = HttpMethods.Post(url);
  128. LogEntity logEntity = new LogEntity();
  129. logEntity.F_CategoryId = 121;
  130. logEntity.F_ExecuteResultJson = reJson;
  131. logEntity.WriteLog();
  132. //HttpConnect conn = new HttpConnect();
  133. //string reJson = conn.Post(url, "");
  134. JsonBean MemberInfoList = JsonConvert.DeserializeObject<JsonBean>(reJson);
  135. if (MemberInfoList.SUCCESS.Equals("true"))
  136. {
  137. string imgCode = HttpMethods.Post(MemberInfoList.PAYURL);
  138. logEntity.F_CategoryId = 121;
  139. logEntity.F_ExecuteResultJson = imgCode;
  140. logEntity.WriteLog();
  141. MemberInfoList = JsonConvert.DeserializeObject<JsonBean>(imgCode);
  142. if (MemberInfoList.SUCCESS.Equals("true"))
  143. {
  144. imgUrl = CreateQRImg(MemberInfoList.QRURL, orderid);
  145. }
  146. }
  147. if (!string.IsNullOrEmpty(imgUrl))
  148. {
  149. // model.PayFeeDetail = entity.PayFeeDetail;
  150. // model.PayMoney = entity.PayMoney;
  151. model.LoanMoney = entity.LoanMoney;
  152. model.orderid = orderid;
  153. stuInfoFreshIBLL.SaveFeeData(keyValue, model, list);
  154. }
  155. var backimgUrl = new { imgUrl };
  156. return Success(backimgUrl);
  157. }
  158. public class JsonBean
  159. {
  160. /// <summary>
  161. ///
  162. /// </summary>
  163. public string SUCCESS { get; set; }
  164. public string PAYURL { get; set; }
  165. public string QRURL { get; set; }
  166. }
  167. /// <summary>
  168. /// 生成并保存二维码图片的方法
  169. /// </summary>
  170. /// <param name="str">输入的内容</param>
  171. public string CreateQRImg(string str, string orderId)
  172. {
  173. string QRCodeFile = Config.GetValue("QRCodeFile");
  174. Random ran = new Random();
  175. Bitmap bt;
  176. str = HttpUtility.UrlDecode(str);
  177. string enCodeString = str;
  178. //生成设置编码实例
  179. QRCodeEncoder qrCodeEncoder = new QRCodeEncoder();
  180. //设置二维码的规模,默认4
  181. qrCodeEncoder.QRCodeScale = 3;
  182. //设置二维码的版本,默认7
  183. qrCodeEncoder.QRCodeVersion = 7;
  184. //设置错误校验级别,默认中等
  185. qrCodeEncoder.QRCodeErrorCorrect = QRCodeEncoder.ERROR_CORRECTION.M;
  186. //生成二维码图片
  187. bt = qrCodeEncoder.Encode(enCodeString, Encoding.UTF8);
  188. //二维码图片的名称
  189. string filename = orderId;
  190. if (!DirFileHelper.IsExistFile(QRCodeFile + "/Content/images/QRCode/"))
  191. {
  192. Directory.CreateDirectory(QRCodeFile + "/Content/images/QRCode/");
  193. }
  194. var path = QRCodeFile + "/Content/images/QRCode/" + filename + ".jpg";
  195. //保存二维码图片在photos路径下
  196. try
  197. {
  198. bt.Save(path);
  199. }
  200. catch (Exception ex)
  201. {
  202. return "";
  203. }
  204. //图片控件要显示的二维码图片路径
  205. return "/Content/images/QRCode/" + filename + ".jpg";
  206. }
  207. }
  208. }