OutApiController.cs 12 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262
  1. using Microsoft.AspNetCore.Mvc;
  2. using Microsoft.AspNetCore.Http;
  3. using Microsoft.Extensions.Logging;
  4. using Microsoft.Extensions.Options;
  5. using System.Collections.Generic;
  6. using LitJson;
  7. using Library;
  8. using System.Linq;
  9. using System;
  10. using MySystem.MainModels;
  11. using System.IO;
  12. using System.Text;
  13. using Aliyun.OSS;
  14. using System.Security.Cryptography;
  15. namespace MySystem.Areas.Api.Controllers.v1
  16. {
  17. public class OutApiController : BaseController
  18. {
  19. public OutApiController(IHttpContextAccessor accessor, ILogger<BaseController> logger, IOptions<Setting> setting) : base(accessor, logger, setting)
  20. {
  21. }
  22. #region 设置服务费
  23. [Route("/api/v1/deposit/set")]
  24. public JsonResult SetDeposit()
  25. {
  26. StreamReader sr = new StreamReader(Request.Body);
  27. string requestMes = sr.ReadToEnd();
  28. JsonData data = JsonMapper.ToObject(requestMes);
  29. Dictionary<string, object> req = new Dictionary<string, object>();
  30. string PosSn = data["posSn"].ToString();
  31. req.Add("PosSn", PosSn);
  32. req.Add("BrandId", data["brandId"].ToString());
  33. req.Add("Deposit", data["deposit"].ToString());
  34. string UserId = "0";
  35. if(requestMes.Contains("\"userId\""))
  36. {
  37. UserId = data["userId"].ToString();
  38. }
  39. req.Add("UserId", UserId);
  40. string CallBackUrl = "";
  41. if(requestMes.Contains("\"callBackUrl\""))
  42. {
  43. CallBackUrl = data["callBackUrl"].ToString();
  44. }
  45. req.Add("CallBackUrl", CallBackUrl);
  46. RedisDbconn.Instance.AddList("ChangePosFeeQueue", Newtonsoft.Json.JsonConvert.SerializeObject(req));
  47. return Json(new AppResultJson() { Status = "1", Info = "" });
  48. }
  49. #endregion
  50. #region 设置费率
  51. [Route("/api/v1/fee/set")]
  52. public JsonResult SetFee()
  53. {
  54. StreamReader sr = new StreamReader(Request.Body);
  55. string requestMes = sr.ReadToEnd();
  56. JsonData data = JsonMapper.ToObject(requestMes);
  57. string PosSn = data["posSn"].ToString();
  58. string MerNo = data["mchNo"].ToString();
  59. int BrandId = int.Parse(data["brandId"].ToString());
  60. decimal FeeRate = decimal.Parse(data["feeRate"].ToString());
  61. int FeeExtra = int.Parse(data["feeExtra"].ToString());
  62. string CallBackUrl = "";
  63. if(requestMes.Contains("\"callBackUrl\""))
  64. {
  65. CallBackUrl = data["callBackUrl"].ToString();
  66. }
  67. int ChangeKind = 0;
  68. if(FeeRate == 0.63M && FeeExtra == 3)
  69. {
  70. ChangeKind = 1;
  71. }
  72. else if(FeeRate == 0.63M && FeeExtra == 0)
  73. {
  74. ChangeKind = 2;
  75. }
  76. else if(FeeRate == 0.6M && FeeExtra == 0)
  77. {
  78. ChangeKind = 3;
  79. }
  80. // PosId:机具Id
  81. // Kind:1或2,1为费率0.63+3,2为费率0.63,3为费率0.6
  82. // OpMan:操作人,app传创客编号,后台传SysUserName
  83. string info = "{\"RecordId\":\"0\",\"PosSn\":\"" + PosSn + "\",\"MerNo\":\"" + MerNo + "\",\"BrandId\":\"" + BrandId + "\",\"Fee\": \"" + FeeRate.ToString().TrimEnd('0') + "\",\"Kind\": \"" + ChangeKind + "\",\"OpMan\": \"接口\",\"CallBackUrl\":\"" + CallBackUrl + "\"}";
  84. RedisDbconn.Instance.AddList("SetDepositPostQueue", info);
  85. return Json(new AppResultJson() { Status = "1", Info = "" });
  86. }
  87. #endregion
  88. #region WIFI解绑
  89. [HttpPost]
  90. [Route("/kxs/unbind/wifi")]
  91. public Dictionary<string, object> UnBindWifi()
  92. {
  93. StreamReader sr = new StreamReader(Request.Body);
  94. string requestMes = sr.ReadToEnd();
  95. if (string.IsNullOrEmpty(requestMes))
  96. {
  97. return new Dictionary<string, object>();
  98. }
  99. string content = Newtonsoft.Json.JsonConvert.SerializeObject(Request.Headers) + "#cut#" + requestMes;
  100. Utils.WriteLog(content, "WIFI解绑推送消息");
  101. string fileName = function.MD5_16(Guid.NewGuid().ToString());
  102. RedisDbconn.Instance.AddList("kxs_unbindwifi_list", content + "#cut#" + fileName);
  103. Dictionary<string, object> obj = new Dictionary<string, object>();
  104. obj.Add("resCode", 200);
  105. obj.Add("resMsg", "success");
  106. return obj;
  107. }
  108. #endregion
  109. #region WIFI换绑
  110. [HttpPost]
  111. [Route("/kxs/changebind/wifi")]
  112. public Dictionary<string, object> ChangeBindWifi()
  113. {
  114. StreamReader sr = new StreamReader(Request.Body);
  115. string requestMes = sr.ReadToEnd();
  116. if (string.IsNullOrEmpty(requestMes))
  117. {
  118. return new Dictionary<string, object>();
  119. }
  120. string content = Newtonsoft.Json.JsonConvert.SerializeObject(Request.Headers) + "#cut#" + requestMes;
  121. Utils.WriteLog(content, "WIFI换绑推送消息");
  122. string fileName = function.MD5_16(Guid.NewGuid().ToString());
  123. RedisDbconn.Instance.AddList("kxs_changebindwifi_list", content + "#cut#" + fileName);
  124. Dictionary<string, object> obj = new Dictionary<string, object>();
  125. obj.Add("resCode", 200);
  126. obj.Add("resMsg", "success");
  127. return obj;
  128. }
  129. #endregion
  130. #region 同行奖同步
  131. [Route("/leader/prize/do/{month:minlength(6)}")]
  132. public string LeaderPrize(string month)
  133. {
  134. if(RedisDbconn.Instance.Get<string>("LeaderTxjPrizeFlag" + month) == "1")
  135. {
  136. return "请勿频繁操作";
  137. }
  138. RedisDbconn.Instance.Set("LeaderTxjPrizeFlag" + month, "1");
  139. RedisDbconn.Instance.SetExpire("LeaderTxjPrizeFlag" + month, 60);
  140. RedisDbconn.Instance.AddList("TxjQueue", month);
  141. return "ok";
  142. }
  143. #endregion
  144. #region 获取更新过期身份证链接
  145. [Route("/api/v1/ls/idcardurl")]
  146. public JsonResult LsIdCardUrl()
  147. {
  148. StreamReader sr = new StreamReader(Request.Body);
  149. string requestMes = sr.ReadToEnd();
  150. requestMes = requestMes.Replace("\"", "");
  151. Utils.WriteLog(requestMes, "获取更新过期身份证链接");
  152. requestMes = PublicImportDataService.Instance.AesDecryptForIv(requestMes);
  153. Utils.WriteLog(requestMes + "\n\n", "获取更新过期身份证链接");
  154. JsonData data = JsonMapper.ToObject(requestMes);
  155. string merNo = data["merNo"].ToString();
  156. string content = PublicImportDataService.Instance.LePassGetExpiredIdCardUrl(merNo);
  157. JsonData jsonObj = JsonMapper.ToObject(content);
  158. if(jsonObj["error_code"].ToString() == "0")
  159. {
  160. return Json(new AppResultJson() { Status = "1", Info = jsonObj["error_msg"].ToString(), Data = jsonObj["data"].ToString() });
  161. }
  162. return Json(new AppResultJson() { Status = "-1", Info = jsonObj["error_msg"].ToString() });
  163. }
  164. #endregion
  165. #region 更新小程序版本
  166. [Route("/api/v1/mini/addver")]
  167. public string MiniAddVesion(string id)
  168. {
  169. RedisDbconn.Instance.AddList("MiniSetVersionQueue", id);
  170. return "ok";
  171. }
  172. #endregion
  173. #region 前端上传oss返回参数
  174. [Route("/api/oss/uploadinfo")]
  175. public JsonResult OssInfo(string value)
  176. {
  177. value = AesDecrypt(value);
  178. JsonData data = JsonMapper.ToObject(value);
  179. string dir = data["dir"].ToString(); //文件上传路径
  180. if (string.IsNullOrEmpty(data["dir"].ToString()))
  181. {
  182. return Json(new AppResultJson() { Status = "1", Info = "文件上传路径不能为空" });
  183. }
  184. Dictionary<string, object> Obj = new Dictionary<string, object>();
  185. var OssUrl = "https://laikeba.oss-cn-chengdu.aliyuncs.com";
  186. var AccessKeyId = "LTAI5tJsPaNzqCSMCPwb8zfz";
  187. var AccessKeySecret = "efM31Up75fQcgZ32U6xvAciagceQae";
  188. var endpoint = "https://oss-cn-chengdu.aliyuncs.com";
  189. // "OSSKey": "LTAI5tJsPaNzqCSMCPwb8zfz",
  190. // "OSSSecret": "efM31Up75fQcgZ32U6xvAciagceQae",
  191. // "OSSEndpoint": "oss-cn-chengdu.aliyuncs.com",
  192. // "OSSBucketName": "laikeba",
  193. // 构造OssClient实例。 endpoint 格式:https://oss-cn-beijing.aliyuncs.com
  194. var ossClient = new OssClient(endpoint, AccessKeyId, AccessKeySecret);
  195. var config = new PolicyConditions();
  196. config.AddConditionItem(PolicyConditions.CondContentLengthRange, 1, 1024L * 1024 * 1024 * 5);// 文件大小范围:单位byte
  197. config.AddConditionItem(MatchMode.StartWith, PolicyConditions.CondKey, dir);
  198. var expire = DateTimeOffset.Now.AddMinutes(30);// 过期时间
  199. // 生成 Policy,并进行 Base64 编码
  200. var policy = ossClient.GeneratePostPolicy(expire.LocalDateTime, config);
  201. var policyBase64 = Convert.ToBase64String(Encoding.UTF8.GetBytes(policy));
  202. // 计算签名
  203. var hmac = new HMACSHA1(Encoding.UTF8.GetBytes(AccessKeySecret));
  204. var bytes = hmac.ComputeHash(Encoding.UTF8.GetBytes(policyBase64));
  205. var Signature = Convert.ToBase64String(bytes);
  206. Obj.Add("OssUrl", OssUrl);
  207. Obj.Add("AccessKeyId", AccessKeyId);
  208. // Obj.Add("AccessKeySecret", AccessKeySecret);
  209. Obj.Add("Policy", policyBase64);
  210. Obj.Add("Expiration", expire);
  211. Obj.Add("Signature", Signature);
  212. Obj.Add("dir", dir);
  213. return Json(new AppResultJson() { Status = "1", Info = "", Data = Obj });
  214. }
  215. #endregion
  216. // [Route("/api/v1/{c1}/{c2}")]
  217. // public JsonResult ToApServer(string c1, string c2, string value)
  218. // {
  219. // string apis = function.CheckNull(RedisDbconn.Instance.Get<string>("ToApServer"));
  220. // Utils.WriteLog(DateTime.Now.ToString() + "\n" + value, "接口转发日志");
  221. // string hasDo = "";
  222. // if (apis.Contains(c1 + "/" + c2))
  223. // {
  224. // value = dbconn.DesEncrypt(value, "*ga34|^7");
  225. // }
  226. // else
  227. // {
  228. // hasDo = "do";
  229. // }
  230. // Utils.WriteLog(value, "接口转发日志");
  231. // string url = AppConfig.Base.ApHost + "api/v1/" + c1 + "/" + c2 + hasDo;
  232. // Utils.WriteLog(url, "接口转发日志");
  233. // string result = function.PostWebRequest(url, "value=" + value);
  234. // Utils.WriteLog(str: result, "接口转发日志");
  235. // JsonData data = JsonMapper.ToObject(result);
  236. // if(result.Contains("\"status\""))
  237. // {
  238. // return Json(new AppResultJson() { Status = data["status"].ToString(), Data = data["data"].ToJson(), Info = data["info"].ToString(), Other = data["other"] == null ? "" : data["other"].ToJson(), Timestamp = int.Parse(function.CheckInt(data["timestamp"].ToString())) });
  239. // }
  240. // return Json(new AppResultJson() { Status = "1", Data = result, Info = "" });
  241. // }
  242. }
  243. }