123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129 |
- using System;
- using System.Collections.Generic;
- using System.Linq;
- using System.Data;
- using Microsoft.AspNetCore.Mvc;
- using Microsoft.AspNetCore.Http;
- using Microsoft.Extensions.Logging;
- using Microsoft.Extensions.Options;
- using Microsoft.AspNetCore.Authorization;
- using System.Web;
- using MySystem.Models.KxsMainModels;
- using LitJson;
- using Library;
- namespace MySystem.Areas.Api.Controllers.v1.pos
- {
- [Area("Api")]
- [Route("Api/v1/[controller]/[action]")]
- public class PayController : BaseController
- {
- public PayController(IHttpContextAccessor accessor) : base(accessor)
- {
- }
- #region 商户激活-确认支付
- // [Authorize]
- public JsonResult Pay(string value)
- {
- value = DesDecrypt(value);
- JsonData data = JsonMapper.ToObject(value);
- AppResultJson result = PayDo(value);
- return Json(new AppResultJson() { Status = result.Status, Info = result.Info, Data = result.Data });
- }
- public AppResultJson PayDo(string value)
- {
- JsonData data = JsonMapper.ToObject(value);
- int PayMode = int.Parse(function.CheckInt(data["PayMode"].ToString())); //支付方式(1 支付宝)
- Dictionary<string, object> Obj = new Dictionary<string, object>();
- int MerchantId = int.Parse(function.CheckInt(data["MerchantId"].ToString()));
- int Id = int.Parse(function.CheckInt(data["Id"].ToString()));
- Orders query = kxsdb.Orders.FirstOrDefault(m => m.Id == Id);
- if (query != null)
- {
- query.PayMode = PayMode; //支付方式
- kxsdb.SaveChanges();
- string PayData = "";
- PublicAccountSet set = new AlipayFunctionForKxs(_accessor.HttpContext).SetData(MerchantId);
- if (PayMode == 1)
- {
- string TotalPrice = query.TotalPrice.ToString();
- function.WriteLog(query.OrderNo, "支付宝支付日志");
- function.WriteLog(TotalPrice.ToString(), "支付宝支付日志");
- function.WriteLog("商户激活—确认订单", "支付宝支付日志");
- string ProductName = "商户激活—确认订单";
- PayData = new Alipay.AlipayPublicClass(_accessor.HttpContext).GetAlipayInfo(query.OrderNo, TotalPrice, ProductName, set.AlipayAppId, set.AlipayPrivateKey, SourceHost + "/Api/Alipay/NoticePay");
- function.WriteLog(PayData, "支付宝支付日志");
- }
- Obj.Add("PayData", PayData); //支付宝微信SDK所需数据
- }
- return new AppResultJson() { Status = "1", Info = "", Data = Obj };
- }
- #endregion
- #region 商户激活—确认订单
- // [Authorize]
- public JsonResult ConfirmOrder(string value)
- {
- value = DesDecrypt(value);
- JsonData data = JsonMapper.ToObject(value);
- AppResultJson result = ConfirmOrderDo(value);
- return Json(new AppResultJson() { Status = result.Status, Info = result.Info, Data = result.Data });
- }
- public AppResultJson ConfirmOrderDo(string value)
- {
- function.WriteLog(value, "商户激活—确认订单");
- JsonData data = JsonMapper.ToObject(value);
- int MerchantId = int.Parse(function.CheckInt(data["MerchantId"].ToString())); //商户Id
- Dictionary<string, object> Obj = new Dictionary<string, object>();
- string OrderNo = "SHJH" + DateTime.Now.ToString("yyyyMMddHHmmssfff") + function.get_Random(8);
- string check = RedisDbconn.Instance.Get<string>("ConfirmOrder:" + MerchantId + "_" + OrderNo);
- if (!string.IsNullOrEmpty(check))
- {
- return new AppResultJson() { Status = "-1", Info = "请勿重复下单!" };
- }
- RedisDbconn.Instance.Set("ConfirmOrder:" + MerchantId + "_" + OrderNo, "1");
- RedisDbconn.Instance.SetExpire("ConfirmOrder:" + MerchantId + "_" + OrderNo, 60);
- decimal ActPayPrice = 365; //服务费总额
- // MerchantActOrders query = maindb.MerchantActOrders.Add(new MerchantActOrders()
- // {
- // OrderNo = OrderNo,
- // UserId = UserId, //创客
- // MerchantId = MerchantId, //商户Id
- // ActPayPrice = ActPayPrice, //服务费总额
- // }).Entity;
- // maindb.SaveChanges();
- // Obj.Add("Id", query.Id); //Id
- // Obj.Add("CreateDate", query.CreateDate); //创建时间
- return new AppResultJson() { Status = "1", Info = "", Data = Obj };
- }
- #endregion
- #region 检查签名是否合法,合法返回1,不合法返回提示信息
- /// <summary>
- /// 检查签名是否合法,合法返回1,不合法返回提示信息
- /// </summary>
- /// <param name="value">请求的参数(json字符串)</param>
- /// <param name="signField">要签名的字段</param>
- /// <returns></returns>
- private string CheckSign(string value, string[] signField)
- {
- JsonData json = JsonMapper.ToObject(value);
- Dictionary<string, string> dic = new Dictionary<string, string>();
- for (int i = 0; i < signField.Length; i++)
- {
- dic.Add(signField[i], json[signField[i]].ToString());
- }
- string sign = json["sign"].ToString(); //客户端签名字符串
- return new Sign().sign(dic, sign);
- }
- #endregion
- }
- }
|