public ActionResult SpgatewayCustomer() { Request.LogFormData("SpgatewayCustomer(資料回傳)"); // Status 回傳狀態 // MerchantID 回傳訊息 // TradeInfo 交易資料AES 加密 // TradeSha 交易資料SHA256 加密 // Version 串接程式版本 NameValueCollection collection = Request.Form; if (collection["MerchantID"] != null && string.Equals(collection["MerchantID"], _bankInfoModel.MerchantID)) { var decryptTradeInfo = CryptoUtil.DecryptAESHex(collection["TradeInfo"], _bankInfoModel.HashKey, _bankInfoModel.HashIV); // 取得回傳參數(ex:key1=value1&key2=value2),儲存為NameValueCollection NameValueCollection decryptTradeCollection = HttpUtility.ParseQueryString(decryptTradeInfo); SpgatewayTakeNumberDataModel convertModel = LambdaUtil.DictionaryToObject <SpgatewayTakeNumberDataModel>(decryptTradeCollection.AllKeys.ToDictionary(k => k, k => decryptTradeCollection[k])); LogUtil.WriteLog(JsonConvert.SerializeObject(convertModel)); // TODO 將回傳訊息寫入資料庫 return(Content(JsonConvert.SerializeObject(convertModel))); } else { LogUtil.WriteLog("MerchantID錯誤"); } return(Content(string.Empty)); }
public IHttpActionResult SpgatewayNotify() { // 取法同SpgatewayResult var httpRequestBase = new HttpRequestWrapper(HttpContext.Current.Request); RazorExtensions.LogFormData(httpRequestBase, "SpgatewayNotify(支付完成)"); // Status 回傳狀態 // MerchantID 回傳訊息 // TradeInfo 交易資料AES 加密 // TradeSha 交易資料SHA256 加密 // Version 串接程式版本 NameValueCollection collection = HttpContext.Current.Request.Form; if (collection["MerchantID"] != null && string.Equals(collection["MerchantID"], _bankInfoModel.MerchantID) && collection["TradeInfo"] != null && string.Equals(collection["TradeSha"], CryptoUtil.EncryptSHA256($"HashKey={_bankInfoModel.HashKey}&{collection["TradeInfo"]}&HashIV={_bankInfoModel.HashIV}"))) { var decryptTradeInfo = CryptoUtil.DecryptAESHex(collection["TradeInfo"], _bankInfoModel.HashKey, _bankInfoModel.HashIV); // 取得回傳參數(ex:key1=value1&key2=value2),儲存為NameValueCollection NameValueCollection decryptTradeCollection = HttpUtility.ParseQueryString(decryptTradeInfo); SpgatewayOutputDataModel convertModel = LambdaUtil.DictionaryToObject <SpgatewayOutputDataModel>(decryptTradeCollection.AllKeys.ToDictionary(k => k, k => decryptTradeCollection[k])); //LogUtil.WriteLog(JsonConvert.SerializeObject(convertModel)); // TODO 將回傳訊息寫入資料庫 VipOrder pay = db.VipOrders.Find(Convert.ToInt32(convertModel.MerchantOrderNo)); pay.Message = convertModel.Message; pay.Status = convertModel.Status; db.VipOrders.Add(pay); // return Content(JsonConvert.SerializeObject(convertModel)); if (pay.Status == "SUCCESS") { //MerchantOrderNo = "O202009100034" //convertModel.MerchantOrderNo VipOrder vip = db.VipOrders.Find(pay.BrandId); vip.Status = "已付款成功"; db.Entry(vip).State = EntityState.Modified; db.SaveChanges(); } else//付款失敗 { } return(Ok()); } else { //LogUtil.WriteLog("MerchantID/TradeSha驗證錯誤"); } return(Ok()); }
public HttpResponseMessage SpgatewayNotify() { // Status 回傳狀態 // MerchantID 回傳訊息 // TradeInfo 交易資料AES 加密 // TradeSha 交易資料SHA256 加密 // Version 串接程式版本 var collection = HttpContext.Current.Request; if (collection["MerchantID"] != null && string.Equals(collection["MerchantID"], _bankInfoModel.MerchantID) && collection["TradeInfo"] != null && string.Equals(collection["TradeSha"], CryptoUtil.EncryptSHA256($"HashKey={_bankInfoModel.HashKey}&{collection["TradeInfo"]}&HashIV={_bankInfoModel.HashIV}"))) { var decryptTradeInfo = CryptoUtil.DecryptAESHex(collection["TradeInfo"], _bankInfoModel.HashKey, _bankInfoModel.HashIV); // 取得回傳參數(ex:key1=value1&key2=value2),儲存為NameValueCollection NameValueCollection decryptTradeCollection = HttpUtility.ParseQueryString(decryptTradeInfo); SpgatewayOutputDataModel convertModel = LambdaUtil.DictionaryToObject <SpgatewayOutputDataModel>( decryptTradeCollection.AllKeys.ToDictionary(k => k, k => decryptTradeCollection[k])); Pay pay = db.Pays.Find(Convert.ToInt32(convertModel.MerchantOrderNo)); pay.Message = convertModel.Message; pay.Status = convertModel.Status; db.Pays.Add(pay); if (pay.Status == "SUCCESS") { Orders orders = db.Orders.Find(pay.OrderId); orders.Status = OrderType.已付款; db.Entry(orders).State = EntityState.Modified; db.SaveChanges(); } // TODO 將回傳訊息寫入資料庫 } return(Request.CreateResponse(HttpStatusCode.OK)); }
public ActionResult SpgatewayReturn() { Request.LogFormData("SpgatewayReturn(支付完成)"); // Status 回傳狀態 // MerchantID 回傳訊息 // TradeInfo 交易資料AES 加密 // TradeSha 交易資料SHA256 加密 // Version 串接程式版本 NameValueCollection collection = Request.Form; if (collection["MerchantID"] != null && string.Equals(collection["MerchantID"], _bankInfoModel.MerchantID) && collection["TradeInfo"] != null && string.Equals(collection["TradeSha"], CryptoUtil.EncryptSHA256($"HashKey={_bankInfoModel.HashKey}&{collection["TradeInfo"]}&HashIV={_bankInfoModel.HashIV}"))) { var decryptTradeInfo = CryptoUtil.DecryptAESHex(collection["TradeInfo"], _bankInfoModel.HashKey, _bankInfoModel.HashIV); // 取得回傳參數(ex:key1=value1&key2=value2),儲存為NameValueCollection NameValueCollection decryptTradeCollection = HttpUtility.ParseQueryString(decryptTradeInfo); SpgatewayOutputDataModel convertModel = LambdaUtil.DictionaryToObject <SpgatewayOutputDataModel>(decryptTradeCollection.AllKeys.ToDictionary(k => k, k => decryptTradeCollection[k])); LogUtil.WriteLog(JsonConvert.SerializeObject(convertModel)); // TODO 將回傳訊息寫入資料庫 intoDB DB = new intoDB(); var Status = convertModel.Status; var OrderNo = convertModel.MerchantOrderNo; var PayWay = convertModel.PaymentType; var PayWay_id = 0; switch (PayWay) { case "CREDIT": PayWay_id = 1; break; case "SAMSUNGPAY": PayWay_id = 2; break; case "ANDROIDPAY": PayWay_id = 3; break; case "WEBATM": PayWay_id = 4; break; case "VACC": PayWay_id = 5; break; default: PayWay_id = 6; break; } if (Status == "SUCCESS") { var data = Data; AccountDetailService Account = new AccountDetailService(); var user_name = HttpContext.User.Identity.Name; var viewmodel = Account.get_account_detail(user_name); DB._intoDB(data, Status, OrderNo, PayWay_id, viewmodel.Cust_id); } } else { LogUtil.WriteLog("MerchantID/TradeSha驗證錯誤"); } return(View()); }
public IHttpActionResult SpgatewayNotify() { // 取法同SpgatewayResult var httpRequestBase = new HttpRequestWrapper(HttpContext.Current.Request); RazorExtensions.LogFormData(httpRequestBase, "SpgatewayNotify(支付完成)"); // Status 回傳狀態 // MerchantID 回傳訊息 // TradeInfo 交易資料AES 加密 // TradeSha 交易資料SHA256 加密 // Version 串接程式版本 NameValueCollection collection = HttpContext.Current.Request.Form; if (collection["MerchantID"] != null && string.Equals(collection["MerchantID"], _bankInfoModel.MerchantID) && collection["TradeInfo"] != null && string.Equals(collection["TradeSha"], CryptoUtil.EncryptSHA256($"HashKey={_bankInfoModel.HashKey}&{collection["TradeInfo"]}&HashIV={_bankInfoModel.HashIV}"))) { var decryptTradeInfo = CryptoUtil.DecryptAESHex(collection["TradeInfo"], _bankInfoModel.HashKey, _bankInfoModel.HashIV); // 取得回傳參數(ex:key1=value1&key2=value2),儲存為NameValueCollection NameValueCollection decryptTradeCollection = HttpUtility.ParseQueryString(decryptTradeInfo); SpgatewayOutputDataModel convertModel = LambdaUtil.DictionaryToObject <SpgatewayOutputDataModel>(decryptTradeCollection.AllKeys.ToDictionary(k => k, k => decryptTradeCollection[k])); //LogUtil.WriteLog(JsonConvert.SerializeObject(convertModel)); // TODO 將回傳訊息寫入資料庫 // return Content(JsonConvert.SerializeObject(convertModel)); if (convertModel.Status == "SUCCESS") { //MerchantOrderNo = "O202009100034" //convertModel.MerchantOrderNo Order order = db.Order.Find(convertModel.MerchantOrderNo); order.state = 1; db.Entry(order).State = EntityState.Modified; db.SaveChanges(); //signalr即時通知 改寫法 Utility.signalR_notice(order.memberseq, order.companyseq, order.orderseq, "", Noticetype.單通知); var context = GlobalHost.ConnectionManager.GetHubContext <DefaultHub>(); var connectid = db.Signalr.Where(x => x.whoseq == order.companyseq).Select(x => x.connectid).ToList();//需要通知的廠商signalr connectid var notices = db.Notice.Where(x => x.toseq == order.companyseq).ToList(); var unread = notices.Where(x => x.state == Convert.ToBoolean(Noticestate.未讀)).Count(); List <Notice> notices_ = notices.OrderBy(x => x.state).ThenByDescending(x => x.postday).Take(10).ToList(); var result = new { unread = unread, notices = notices_.Select( x => new { x.noticeseq, x.fromseq, x.toseq, state = Enum.Parse(typeof(Noticestate), x.state.GetHashCode().ToString()).ToString(), x.text, type = Enum.Parse(typeof(Noticetype), x.type.ToString()).ToString(), time = Convert.ToDateTime(x.postday).ToString("yyyy-MM-dd HH:mm") }) }; foreach (var c in connectid) { context.Clients.Client(c).Get(result); } ////signalr即時通知 //Utility.signalR_notice(order.memberseq, order.companyseq, order.orderseq, "", Noticetype.下單通知); //var context = GlobalHost.ConnectionManager.GetHubContext<DefaultHub>(); //var connectid = db.Signalr.Where(x => x.whoseq == order.companyseq).Select(x => x.connectid).ToList();//需要通知的廠商signalr connectid //foreach (var c in connectid) //{ // context.Clients.Client(c).Get(); //} } else//付款失敗 { } return(Ok()); } else { //LogUtil.WriteLog("MerchantID/TradeSha驗證錯誤"); } return(Ok()); }