ConsumerOrdersController.cs 27 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4. using Microsoft.AspNetCore.Mvc;
  5. using Microsoft.AspNetCore.Http;
  6. using Microsoft.Extensions.Logging;
  7. using Microsoft.Extensions.Options;
  8. using Microsoft.AspNetCore.Authorization;
  9. using System.Web;
  10. using MySystem.MainModels;
  11. using LitJson;
  12. using Library;
  13. using System.Data;
  14. namespace MySystem.Areas.Api.Controllers.v1
  15. {
  16. [Area("Api")]
  17. [Route("Api/v1/[controller]/[action]")]
  18. public class ConsumerOrdersController : BaseController
  19. {
  20. public ConsumerOrdersController(IHttpContextAccessor accessor, ILogger<BaseController> logger, IOptions<Setting> setting) : base(accessor, logger, setting)
  21. {
  22. }
  23. #region 商户-经营数据(日)
  24. [Authorize]
  25. public JsonResult ByDate(string value)
  26. {
  27. value = DesDecrypt(value);
  28. JsonData data = JsonMapper.ToObject(value);
  29. List<Dictionary<string, object>> dataList = ByDateDo(value);
  30. return Json(new AppResultJson() { Status = "1", Info = "", Data = dataList });
  31. }
  32. public List<Dictionary<string, object>> ByDateDo(string value)
  33. {
  34. JsonData data = JsonMapper.ToObject(value);
  35. int MerchantId = int.Parse(function.CheckInt(data["MerchantId"].ToString())); //商户
  36. string Month = data["Month"].ToString(); //月份
  37. int PageSize = int.Parse(function.CheckInt(data["PageSize"].ToString()));
  38. int PageNum = int.Parse(function.CheckInt(data["PageNum"].ToString()));
  39. List<Dictionary<string, object>> dataList = new List<Dictionary<string, object>>();
  40. DataTable dt = MerchantAmountSummary.Instance.GetTradeListByDate(MerchantId, Month, PageNum, PageSize);
  41. foreach (DataRow dr in dt.Rows)
  42. {
  43. string TradeDate = dr["TradeDate"].ToString();
  44. Dictionary<string, object> curData = new Dictionary<string, object>();
  45. curData.Add("Date", TradeDate.Substring(0, 4) + "-" + TradeDate.Substring(4, 2) + "-" + TradeDate.Substring(6, 2)); //日期
  46. curData.Add("TotalAmount", dr[5].ToString()); //营收金额
  47. curData.Add("TotalActual", dr[3].ToString()); //实收金额
  48. curData.Add("WeChatAmount", dr[2].ToString()); //微信实收
  49. curData.Add("AlipayAmount", dr[1].ToString()); //支付宝实收
  50. curData.Add("OrderCount", dr[4].ToString()); //订单数
  51. curData.Add("AddCount", 0); //新增会员
  52. dataList.Add(curData);
  53. }
  54. return dataList;
  55. }
  56. #endregion
  57. #region 商户-经营数据(月)
  58. [Authorize]
  59. public JsonResult ByMonth(string value)
  60. {
  61. value = DesDecrypt(value);
  62. JsonData data = JsonMapper.ToObject(value);
  63. List<Dictionary<string, object>> dataList = ByMonthDo(value);
  64. return Json(new AppResultJson() { Status = "1", Info = "", Data = dataList });
  65. }
  66. public List<Dictionary<string, object>> ByMonthDo(string value)
  67. {
  68. JsonData data = JsonMapper.ToObject(value);
  69. int MerchantId = int.Parse(function.CheckInt(data["MerchantId"].ToString())); //商户
  70. int PageSize = int.Parse(function.CheckInt(data["PageSize"].ToString()));
  71. int PageNum = int.Parse(function.CheckInt(data["PageNum"].ToString()));
  72. List<Dictionary<string, object>> dataList = new List<Dictionary<string, object>>();
  73. DataTable dt = MerchantAmountSummary.Instance.GetTradeListByMonth(MerchantId, PageNum, PageSize);
  74. foreach (DataRow dr in dt.Rows)
  75. {
  76. string TradeDate = dr["TradeMonth"].ToString();
  77. Dictionary<string, object> curData = new Dictionary<string, object>();
  78. curData.Add("Date", TradeDate.Substring(0, 4) + "-" + TradeDate.Substring(4, 2)); //日期
  79. curData.Add("TotalAmount", dr[5].ToString()); //营收金额
  80. curData.Add("TotalActual", dr[3].ToString()); //实收金额
  81. curData.Add("WeChatAmount", dr[2].ToString()); //微信实收
  82. curData.Add("AlipayAmount", dr[1].ToString()); //支付宝实收
  83. curData.Add("OrderCount", dr[4].ToString()); //订单数
  84. curData.Add("AddCount", 0); //新增会员
  85. dataList.Add(curData);
  86. }
  87. return dataList;
  88. }
  89. #endregion
  90. #region 商户-经营数据-按月
  91. [Authorize]
  92. public JsonResult BussinessRecordForMonth(string value)
  93. {
  94. value = DesDecrypt(value);
  95. JsonData data = JsonMapper.ToObject(value);
  96. List<Dictionary<string, object>> dataList = BussinessRecordForMonthDo(value);
  97. return Json(new AppResultJson() { Status = "1", Info = "", Data = dataList });
  98. }
  99. public List<Dictionary<string, object>> BussinessRecordForMonthDo(string value)
  100. {
  101. JsonData data = JsonMapper.ToObject(value);
  102. int MerchantId = int.Parse(function.CheckInt(data["MerchantId"].ToString())); //商户
  103. string Month = data["Month"].ToString(); //月份
  104. int PageSize = int.Parse(function.CheckInt(data["PageSize"].ToString()));
  105. int PageNum = int.Parse(function.CheckInt(data["PageNum"].ToString()));
  106. List<Dictionary<string, object>> dataList = new List<Dictionary<string, object>>();
  107. DataTable dt = MerchantAmountSummary.Instance.GetTradeListByDate(MerchantId, Month, PageNum, PageSize);
  108. foreach (DataRow dr in dt.Rows)
  109. {
  110. string TradeDate = dr["TradeDate"].ToString();
  111. Dictionary<string, object> curData = new Dictionary<string, object>();
  112. curData.Add("Date", TradeDate.Substring(0, 4) + "-" + TradeDate.Substring(4, 2) + "-" + TradeDate.Substring(6, 2)); //日期
  113. curData.Add("TotalAmount", dr[5].ToString()); //营收金额
  114. curData.Add("TotalActual", dr[3].ToString()); //实收金额
  115. curData.Add("WeChatAmount", dr[2].ToString()); //微信实收
  116. curData.Add("AlipayAmount", dr[1].ToString()); //支付宝实收
  117. curData.Add("OrderCount", dr[4].ToString()); //订单数
  118. curData.Add("AddCount", 0); //新增会员
  119. dataList.Add(curData);
  120. }
  121. return dataList;
  122. }
  123. #endregion
  124. #region 商户-订单列表
  125. [Authorize]
  126. public JsonResult ForMer(string value)
  127. {
  128. value = DesDecrypt(value);
  129. JsonData data = JsonMapper.ToObject(value);
  130. List<Dictionary<string, object>> dataList = ForMerDo(value);
  131. return Json(new AppResultJson() { Status = "1", Info = "", Data = dataList });
  132. }
  133. public List<Dictionary<string, object>> ForMerDo(string value)
  134. {
  135. JsonData data = JsonMapper.ToObject(value);
  136. int MerchantId = int.Parse(function.CheckInt(data["MerchantId"].ToString())); //商户
  137. string OrderNo = data["OrderNo"].ToString(); //订单号
  138. string Date = data["Date"].ToString(); //日期
  139. int PageSize = int.Parse(function.CheckInt(data["PageSize"].ToString()));
  140. int PageNum = int.Parse(function.CheckInt(data["PageNum"].ToString()));
  141. List<Dictionary<string, object>> dataList = new List<Dictionary<string, object>>();
  142. string condition = "";
  143. if (!string.IsNullOrEmpty(data["MerchantId"].ToString()))
  144. {
  145. condition += " and MerchantId=" + MerchantId;
  146. }
  147. if (!string.IsNullOrEmpty(data["OrderNo"].ToString()))
  148. {
  149. condition += " and OrderNo='" + OrderNo + "'";
  150. }
  151. List<Dictionary<string, object>> query = new ConsumerOrdersService().List(new List<FieldItem>(), condition, PageNum, PageSize);
  152. foreach (var subdata in query)
  153. {
  154. Dictionary<string, object> curData = new Dictionary<string, object>();
  155. curData.Add("OrderNo", subdata["OrderNo"].ToString()); //订单号
  156. curData.Add("PayMode", subdata["PayMode"].ToString()); //支付方式
  157. curData.Add("PayMoney", subdata["PayMoney"].ToString()); //支付金额
  158. curData.Add("ReturnMoney", subdata["ReturnMoney"].ToString()); //已返金额
  159. curData.Add("SnNo", subdata["SnNo"].ToString()); //SN号
  160. curData.Add("Id", subdata["Id"].ToString()); //Id
  161. curData.Add("Status", subdata["Status"].ToString()); //Status
  162. curData.Add("CreateDate", subdata["CreateDate"].ToString()); //CreateDate
  163. curData.Add("MerchantName", ""); //门店信息
  164. dataList.Add(curData);
  165. }
  166. return dataList;
  167. }
  168. #endregion
  169. #region 消费者-我的订单
  170. [Authorize]
  171. public JsonResult List(string value)
  172. {
  173. value = DesDecrypt(value);
  174. JsonData data = JsonMapper.ToObject(value);
  175. List<Dictionary<string, object>> dataList = ListDo(value);
  176. return Json(new AppResultJson() { Status = "1", Info = "", Data = dataList });
  177. }
  178. public List<Dictionary<string, object>> ListDo(string value)
  179. {
  180. JsonData data = JsonMapper.ToObject(value);
  181. int ConsumerId = int.Parse(function.CheckInt(data["ConsumerId"].ToString())); //消费者
  182. int PageSize = int.Parse(function.CheckInt(data["PageSize"].ToString()));
  183. int PageNum = int.Parse(function.CheckInt(data["PageNum"].ToString()));
  184. List<Dictionary<string, object>> dataList = new List<Dictionary<string, object>>();
  185. List<Dictionary<string, object>> query = new ConsumerOrdersService().List(new List<FieldItem>(), " and ConsumerId=" + ConsumerId + " and Status>0", PageNum, PageSize);
  186. foreach (Dictionary<string, object> subdata in query)
  187. {
  188. MerchantInfo merchant = MerchantInfoDbconn.Instance.Get(int.Parse(subdata["MerchantId"].ToString())) ?? new MerchantInfo();
  189. Dictionary<string, object> curData = new Dictionary<string, object>();
  190. curData.Add("OrderNo", subdata["OrderNo"].ToString()); //订单号
  191. curData.Add("PayMoney", subdata["PayMoney"].ToString()); //支付金额
  192. curData.Add("ReturnMoney", subdata["ReturnMoney"].ToString()); //已返金额
  193. curData.Add("Id", subdata["Id"].ToString()); //Id
  194. curData.Add("Status", subdata["Status"].ToString()); //Status
  195. curData.Add("CreateDate", subdata["CreateDate"].ToString()); //CreateDate
  196. curData.Add("MerchantName", merchant.Name); //商户名称
  197. dataList.Add(curData);
  198. }
  199. return dataList;
  200. }
  201. #endregion
  202. #region 消费者-支付接口
  203. [Authorize]
  204. public JsonResult Pay(string value)
  205. {
  206. if (string.IsNullOrEmpty(value))
  207. {
  208. System.IO.StreamReader sr = new System.IO.StreamReader(Request.Body);
  209. value = sr.ReadToEnd();
  210. value = value.Split('=')[1];
  211. }
  212. value = DesDecrypt(value);
  213. JsonData data = JsonMapper.ToObject(value);
  214. AppResultJson result = PayDo(value);
  215. return Json(new AppResultJson() { Status = result.Status, Info = result.Info, Data = result.Data });
  216. }
  217. public AppResultJson PayDo(string value)
  218. {
  219. JsonData data = JsonMapper.ToObject(value);
  220. string SnNo = data["Sn"].ToString(); //商户
  221. string Machine = data["Machine"].ToString();
  222. int PayMode = int.Parse(function.CheckInt(data["PayMode"].ToString())); //支付方式
  223. decimal PayMoney = decimal.Parse(function.CheckNum(data["PayMoney"].ToString())); //支付金额
  224. string Code = data["Code"].ToString();
  225. if (string.IsNullOrEmpty(data["PayMode"].ToString()))
  226. {
  227. return new AppResultJson() { Status = "-1", Info = "请填写支付方式" };
  228. }
  229. if (string.IsNullOrEmpty(data["PayMoney"].ToString()))
  230. {
  231. return new AppResultJson() { Status = "-1", Info = "请填写支付金额" };
  232. }
  233. if (!function.IsNum(data["PayMoney"].ToString()))
  234. {
  235. return new AppResultJson() { Status = "-1", Info = "请填写正确的支付金额" };
  236. }
  237. Dictionary<string, object> Obj = new Dictionary<string, object>();
  238. MerchantQrCode qrcode = MerchantQrCodeDbconn.Instance.Get(SnNo) ?? new MerchantQrCode();
  239. PosMachinesTwo pos = PosMachinesTwoDbconn.Instance.Get(SnNo) ?? new PosMachinesTwo();
  240. // PosMachines machine = PosMachinesDbconn.Instance.Get(qrcode.SnId) ?? new PosMachines();
  241. // if (machine.BindMerchantId == 0) machine.BindMerchantId = 1; // TODO: 需要绑定二维码
  242. if(pos.OpId == 1)
  243. {
  244. MerchantInfo merchant = MerchantInfoDbconn.Instance.Get(qrcode.MerchantId) ?? new MerchantInfo();
  245. MerchantAddInfo merchantAdd = MerchantAddInfoDbconn.Instance.Get(qrcode.MerchantId) ?? new MerchantAddInfo();
  246. MerchantParamSet merchantset = MerchantParamSetDbconn.Instance.Get(qrcode.MerchantId) ?? new MerchantParamSet();
  247. string openid = "";
  248. if (PayMode == 1)
  249. {
  250. openid = new AlipayFunction(_accessor.HttpContext).GetAlipayUserId(Code);
  251. if (openid.Contains("|"))
  252. {
  253. openid = openid.Split('|')[0];
  254. }
  255. }
  256. else
  257. {
  258. string result = function.GetWebRequest("https://api.weixin.qq.com/sns/jscode2session?appid=" + new WeChatFunction().AppId + "&secret=" + new WeChatFunction().AppSecret + "&js_code=" + Code + "&grant_type=authorization_code");
  259. function.WriteLog(DateTime.Now.ToString() + "\n" + result, "微信小程序获取openid");
  260. JsonData jsonObj = JsonMapper.ToObject(result);
  261. openid = jsonObj["openid"].ToString();
  262. }
  263. int ConsumerId = 0;
  264. ConsumerOpenIds check = maindb.ConsumerOpenIds.FirstOrDefault(m => m.OpenId == openid);
  265. if (check == null)
  266. {
  267. // ConsumerId = PublicFunction.MakeConsumerId();
  268. Consumers consumer = maindb.Consumers.Add(new Consumers()
  269. {
  270. Id = ConsumerId,
  271. CreateDate = DateTime.Now,
  272. WechatOpenId = openid,
  273. }).Entity;
  274. maindb.SaveChanges();
  275. ConsumerId = consumer.Id;
  276. check = maindb.ConsumerOpenIds.Add(new ConsumerOpenIds()
  277. {
  278. OpenId = openid,
  279. ConsumerId = ConsumerId,
  280. }).Entity;
  281. }
  282. else
  283. {
  284. ConsumerId = check.ConsumerId;
  285. }
  286. maindb.SaveChanges();
  287. string OrderNo = DateTime.Now.ToString("yyyyMMddHHmmssfff") + function.get_Random(8);
  288. bool ActFlag = merchantset.IsAll == 1 ? false : true;
  289. if(PayMoney < merchantset.MinPayMoney) //支付金额小于活动最小金额,则不分账
  290. {
  291. ActFlag = false;
  292. }
  293. ConsumerOrders order = maindb.ConsumerOrders.Add(new ConsumerOrders()
  294. {
  295. // Id = PublicFunction.MakeConsumerOrderId(),
  296. CreateDate = DateTime.Now, //创建时间
  297. MerchantId = qrcode.MerchantId, //商户
  298. ConsumerId = ConsumerId, //消费者
  299. UserId = merchant.UserId, //创客
  300. PayMode = PayMode, //支付方式
  301. PayMoney = PayMoney, //支付金额
  302. SnNo = SnNo, //SN号
  303. OrderNo = OrderNo,
  304. MaxDivi = ActFlag ? PayMoney * merchantset.DiviPercent / 100 : 0,
  305. IsAct = ActFlag ? 1u : 0u,
  306. MerchantActualAmount = ActFlag ? PayMoney * merchantset.GetPercent / 100 : PayMoney,
  307. SeoDescription = Newtonsoft.Json.JsonConvert.SerializeObject(merchantset),
  308. }).Entity;
  309. maindb.SaveChanges();
  310. maindb.ConsumerOrderForNo.Add(new ConsumerOrderForNo()
  311. {
  312. OrderNo = OrderNo,
  313. OrderIds = order.Id,
  314. });
  315. maindb.SaveChanges();
  316. if (PayMode == 1)
  317. {
  318. string backString = new AlipayFunction(_accessor.HttpContext).CreateTrade(OrderNo, merchant.Name, PayMoney, openid, merchantAdd.AlipayAuthToken, SpHost + "/api/alipay/notice");
  319. JsonData obj = JsonMapper.ToObject(backString);
  320. if (obj["alipay_trade_create_response"]["code"].ToString() == "10000")
  321. {
  322. string tradeNo = obj["alipay_trade_create_response"]["trade_no"].ToString();
  323. Obj.Add("respCode", obj["alipay_trade_create_response"]["code"].ToString());
  324. Obj.Add("tradeNo", tradeNo);
  325. }
  326. else
  327. {
  328. Obj.Add("respCode", obj["alipay_trade_create_response"]["code"].ToString());
  329. Obj.Add("tradeNo", "");
  330. return new AppResultJson() { Status = "-1", Info = obj["alipay_trade_create_response"]["sub_msg"].ToString(), Data = Obj };
  331. }
  332. }
  333. else if (PayMode == 2)
  334. {
  335. string SubMchId = merchantAdd.SubMchid;
  336. string Description = merchant.Name;
  337. string OpenId = openid;
  338. string Key = AppConfig.WeChatParam.AesGemKey;
  339. string NotifyUrl = SpHost + "/api/wechat/notice";
  340. Dictionary<string, string> dic = new WeChatFunction(_accessor.HttpContext).Pay(SubMchId, PayMoney, OrderNo, Description, OpenId, Key, NotifyUrl, ActFlag);
  341. Obj.Add("appId", dic["appId"]); //微信小程序appid
  342. Obj.Add("timeStamp", dic["timeStamp"]); //时间戳
  343. Obj.Add("nonceStr", dic["nonceStr"]); //随机字符串
  344. Obj.Add("package", dic["package"]); //统一支付接口返回的prepayid参数值
  345. Obj.Add("paySign", dic["paySign"]); //支付签名
  346. Obj.Add("ConsumerId", ConsumerId);
  347. }
  348. }
  349. else
  350. {
  351. MainModels2.MerchantInfo merchant = maindb2.MerchantInfo.FirstOrDefault(m => m.Id == qrcode.MerchantId) ?? new MainModels2.MerchantInfo();
  352. MainModels2.MerchantAddInfo merchantAdd = maindb2.MerchantAddInfo.FirstOrDefault(m => m.Id == qrcode.MerchantId) ?? new MainModels2.MerchantAddInfo();
  353. MainModels2.MerchantParamSet merchantset = maindb2.MerchantParamSet.FirstOrDefault(m => m.Id == qrcode.MerchantId) ?? new MainModels2.MerchantParamSet();
  354. string openid = "";
  355. if (PayMode == 1)
  356. {
  357. openid = new AlipayFunction(_accessor.HttpContext).GetAlipayUserId(Code);
  358. if (openid.Contains("|"))
  359. {
  360. openid = openid.Split('|')[0];
  361. }
  362. }
  363. else
  364. {
  365. string result = function.GetWebRequest("https://api.weixin.qq.com/sns/jscode2session?appid=" + new WeChatFunction().AppId + "&secret=" + new WeChatFunction().AppSecret + "&js_code=" + Code + "&grant_type=authorization_code");
  366. function.WriteLog(DateTime.Now.ToString() + "\n" + result, "微信小程序获取openid");
  367. JsonData jsonObj = JsonMapper.ToObject(result);
  368. openid = jsonObj["openid"].ToString();
  369. }
  370. int ConsumerId = 0;
  371. MainModels2.ConsumerOpenIds check = maindb2.ConsumerOpenIds.FirstOrDefault(m => m.OpenId == openid);
  372. if (check == null)
  373. {
  374. MainModels2.Consumers consumer = maindb2.Consumers.Add(new MainModels2.Consumers()
  375. {
  376. Id = ConsumerId,
  377. CreateDate = DateTime.Now,
  378. WechatOpenId = openid,
  379. }).Entity;
  380. maindb2.SaveChanges();
  381. ConsumerId = consumer.Id;
  382. check = maindb2.ConsumerOpenIds.Add(new MainModels2.ConsumerOpenIds()
  383. {
  384. OpenId = openid,
  385. ConsumerId = ConsumerId,
  386. }).Entity;
  387. }
  388. else
  389. {
  390. ConsumerId = check.ConsumerId;
  391. }
  392. maindb2.SaveChanges();
  393. string OrderNo = DateTime.Now.ToString("yyyyMMddHHmmssfff") + function.get_Random(8);
  394. bool ActFlag = merchantset.IsAll == 1 ? false : true;
  395. if(PayMoney < merchantset.MinPayMoney) //支付金额小于活动最小金额,则不分账
  396. {
  397. ActFlag = false;
  398. }
  399. MainModels2.ConsumerOrders order = maindb2.ConsumerOrders.Add(new MainModels2.ConsumerOrders()
  400. {
  401. // Id = PublicFunction.MakeConsumerOrderId(),
  402. CreateDate = DateTime.Now, //创建时间
  403. MerchantId = qrcode.MerchantId, //商户
  404. ConsumerId = ConsumerId, //消费者
  405. UserId = merchant.UserId, //创客
  406. PayMode = PayMode, //支付方式
  407. PayMoney = PayMoney, //支付金额
  408. SnNo = SnNo, //SN号
  409. OrderNo = OrderNo,
  410. MaxDivi = ActFlag ? PayMoney * merchantset.DiviPercent / 100 : 0,
  411. IsAct = ActFlag ? 1u : 0u,
  412. MerchantActualAmount = ActFlag ? PayMoney * merchantset.GetPercent / 100 : PayMoney,
  413. SeoDescription = Newtonsoft.Json.JsonConvert.SerializeObject(merchantset),
  414. }).Entity;
  415. maindb2.SaveChanges();
  416. maindb2.ConsumerOrderForNo.Add(new MainModels2.ConsumerOrderForNo()
  417. {
  418. OrderNo = OrderNo,
  419. OrderIds = order.Id,
  420. });
  421. maindb2.SaveChanges();
  422. if (PayMode == 1)
  423. {
  424. string backString = new AlipayFunction(_accessor.HttpContext).CreateTrade(OrderNo, merchant.Name, PayMoney, openid, merchantAdd.AlipayAuthToken, SpHost + "/api/alipay/notice");
  425. JsonData obj = JsonMapper.ToObject(backString);
  426. if (obj["alipay_trade_create_response"]["code"].ToString() == "10000")
  427. {
  428. string tradeNo = obj["alipay_trade_create_response"]["trade_no"].ToString();
  429. Obj.Add("respCode", obj["alipay_trade_create_response"]["code"].ToString());
  430. Obj.Add("tradeNo", tradeNo);
  431. }
  432. else
  433. {
  434. Obj.Add("respCode", obj["alipay_trade_create_response"]["code"].ToString());
  435. Obj.Add("tradeNo", "");
  436. return new AppResultJson() { Status = "-1", Info = obj["alipay_trade_create_response"]["sub_msg"].ToString(), Data = Obj };
  437. }
  438. }
  439. else if (PayMode == 2)
  440. {
  441. string SubMchId = merchantAdd.SubMchid;
  442. string Description = merchant.Name;
  443. string OpenId = openid;
  444. string Key = AppConfig.WeChatParam.AesGemKey;
  445. string NotifyUrl = SpHost + "/api/wechat/notice";
  446. Dictionary<string, string> dic = new WeChatFunction(_accessor.HttpContext).Pay(SubMchId, PayMoney, OrderNo, Description, OpenId, Key, NotifyUrl, ActFlag);
  447. Obj.Add("appId", dic["appId"]); //微信小程序appid
  448. Obj.Add("timeStamp", dic["timeStamp"]); //时间戳
  449. Obj.Add("nonceStr", dic["nonceStr"]); //随机字符串
  450. Obj.Add("package", dic["package"]); //统一支付接口返回的prepayid参数值
  451. Obj.Add("paySign", dic["paySign"]); //支付签名
  452. Obj.Add("ConsumerId", ConsumerId);
  453. }
  454. }
  455. return new AppResultJson() { Status = "1", Info = "", Data = Obj };
  456. }
  457. #endregion
  458. public string test()
  459. {
  460. return new WeChatFunction(_accessor.HttpContext).GetPlatCert();
  461. }
  462. public string test2()
  463. {
  464. return new WeChatFunction(_accessor.HttpContext).GetPublicKey();
  465. }
  466. #region 检查签名是否合法,合法返回1,不合法返回提示信息
  467. /// <summary>
  468. /// 检查签名是否合法,合法返回1,不合法返回提示信息
  469. /// </summary>
  470. /// <param name="value">请求的参数(json字符串)</param>
  471. /// <param name="signField">要签名的字段</param>
  472. /// <returns></returns>
  473. private string CheckSign(string value, string[] signField)
  474. {
  475. JsonData json = JsonMapper.ToObject(value);
  476. Dictionary<string, string> dic = new Dictionary<string, string>();
  477. for (int i = 0; i < signField.Length; i++)
  478. {
  479. dic.Add(signField[i], json[signField[i]].ToString());
  480. }
  481. string sign = json["sign"].ToString(); //客户端签名字符串
  482. return new Sign().sign(dic, sign);
  483. }
  484. #endregion
  485. }
  486. }