public bool notifyCheck(NotifyResponseMessage notifyResponseMessage) { Dictionary <string, string> param = new Dictionary <string, string>(); param["return_code"] = notifyResponseMessage.return_code.ToString(); param["total_fee"] = notifyResponseMessage.total_fee.ToString(); param["out_trade_no"] = notifyResponseMessage.out_trade_no.ToString(); param["payjs_order_id"] = notifyResponseMessage.payjs_order_id; param["transaction_id"] = notifyResponseMessage.transaction_id; param["time_end"] = notifyResponseMessage.time_end; param["openid"] = notifyResponseMessage.openid; if (!string.IsNullOrEmpty(notifyResponseMessage.attach)) { param["attach"] = notifyResponseMessage.attach; } if (!string.IsNullOrEmpty(notifyResponseMessage.type)) { param["type"] = notifyResponseMessage.type; } param["sign"] = notifyResponseMessage.sign; string originSign = param["sign"]; param.Remove("sign"); return(sign(param)["sign"] == originSign); }
public IActionResult AsyncNotification(NotifyResponseMessage notifyResponseMessage) { if (notifyResponseMessage == null) { Response.StatusCode = (int)HttpStatusCode.BadRequest; return(Content("BadRequest")); } else { Console.WriteLine(notifyResponseMessage.openid); bool identify = pay.notifyCheck(notifyResponseMessage); if (!identify) { Response.StatusCode = (int)HttpStatusCode.BadRequest; return(Content("BadRequest")); } try { var orderObj = dataContext.GoodOrder.Where(b => b.payjs_order_id.Equals(notifyResponseMessage.payjs_order_id)).FirstOrDefault(); if (orderObj.total_fee != notifyResponseMessage.total_fee) { throw new Exception("金额不正确"); } orderObj.PayStatus = true; orderObj.transaction_id = notifyResponseMessage.transaction_id; orderObj.openid = notifyResponseMessage.openid; orderObj.Notify = true; orderObj.NotifyResponseMessage = notifyResponseMessage.ToJsonString(); dataContext.SaveChanges(); Response.StatusCode = (int)HttpStatusCode.OK; return(Content("OK")); } catch (Exception) { Response.StatusCode = (int)HttpStatusCode.BadRequest; return(Content("BadRequest")); } } }