/// <summary> /// Webs the notify ali. /// </summary> /// <returns></returns> public ActionResult AliNotify(AliNotifyResponse aliNotifyResponse) { if (!AliPayment.CheckSign(aliNotifyResponse)) return Content("error"); var order = _orderService.GetOrderByTradeNo(aliNotifyResponse.out_trade_no); _orderProcessingService.MarkOrderAsPaid(order); return Content("success"); }
public ActionResult AliMobileNotify(AliNotifyResponse aliNotifyResponse) { //验证签名 if (AliPayMobile.CheckAliCharSign(aliNotifyResponse)) { var order = _orderService.GetOrderByTradeNo(aliNotifyResponse.out_trade_no); _orderProcessingService.MarkOrderAsPaid(order); return Content("success"); } else { return Content("error"); } }
/// <summary> /// Checks the ali character sign. /// </summary> /// <param name="aliNotifyResponse">The ali notify response.</param> /// <returns></returns> public static bool CheckAliCharSign(AliNotifyResponse aliNotifyResponse) { var flag = false; var paras = new SortedDictionary<string, string>() { {"body", aliNotifyResponse.body}, {"buyer_email", aliNotifyResponse.buyer_email}, {"buyer_id", aliNotifyResponse.buyer_id}, {"discount", aliNotifyResponse.discount}, {"gmt_create", aliNotifyResponse.gmt_create}, { "gmt_payment",aliNotifyResponse.gmt_payment}, {"is_total_fee_adjust", aliNotifyResponse.is_total_fee_adjust}, {"notify_id", aliNotifyResponse.notify_id}, {"notify_time", aliNotifyResponse.notify_time}, {"notify_type", aliNotifyResponse.notify_type}, {"out_trade_no", aliNotifyResponse.out_trade_no}, {"payment_type", aliNotifyResponse.payment_type}, {"price", aliNotifyResponse.price}, {"quantity", aliNotifyResponse.quantity}, {"seller_email", aliNotifyResponse.seller_email}, {"seller_id", aliNotifyResponse.seller_id}, {"subject", aliNotifyResponse.subject}, {"total_fee", aliNotifyResponse.total_fee}, {"trade_no", aliNotifyResponse.trade_no}, {"trade_status", aliNotifyResponse.trade_status}, {"use_coupon", aliNotifyResponse.use_coupon}, {"refund_status", aliNotifyResponse.refund_status}, {"gmt_refund", aliNotifyResponse.gmt_refund} }; //clear empty value var removeKey = paras.Where(d => string.IsNullOrEmpty(d.Value)).Select(d => d.Key).ToList(); removeKey.ForEach(d=> paras.Remove(d)); var sb = new StringBuilder(); foreach (var temp in paras) { sb.Append($"{temp.Key}={temp.Value}&"); } var paymentString = sb.ToString().TrimEnd('&'); //验证 flag = SignSecurity.Verify(PublicCertificate, InputCharset, paymentString, aliNotifyResponse.sign); return flag; }
/// <summary> /// 验证支付宝签名 /// </summary> /// <param name="aliNotifyResponse">The ali notify response.</param> /// <returns></returns> public static bool CheckSign(AliNotifyResponse aliNotifyResponse) { var paras = new SortedDictionary<string, string>() { {"body", aliNotifyResponse.body}, {"buyer_email", aliNotifyResponse.buyer_email}, {"buyer_id", aliNotifyResponse.buyer_id}, {"discount", aliNotifyResponse.discount}, {"gmt_create", aliNotifyResponse.gmt_create}, { "gmt_payment",aliNotifyResponse.gmt_payment}, {"is_total_fee_adjust", aliNotifyResponse.is_total_fee_adjust}, {"notify_id", aliNotifyResponse.notify_id}, {"notify_time", aliNotifyResponse.notify_time}, {"notify_type", aliNotifyResponse.notify_type}, {"out_trade_no", aliNotifyResponse.out_trade_no}, {"payment_type", aliNotifyResponse.payment_type}, {"price", aliNotifyResponse.price}, {"quantity", aliNotifyResponse.quantity}, {"seller_email", aliNotifyResponse.seller_email}, {"seller_id", aliNotifyResponse.seller_id}, {"subject", aliNotifyResponse.subject}, {"total_fee", aliNotifyResponse.total_fee}, {"trade_no", aliNotifyResponse.trade_no}, {"trade_status", aliNotifyResponse.trade_status}, {"use_coupon", aliNotifyResponse.use_coupon}, {"refund_status", aliNotifyResponse.refund_status}, {"gmt_refund", aliNotifyResponse.gmt_refund} }; //clear empty value var removeKey = paras.Where(d => string.IsNullOrEmpty(d.Value)).Select(d => d.Key).ToList(); removeKey.ForEach(d => paras.Remove(d)); //验证 return aliNotifyResponse.sign == CreatUrlSing(paras,InputCharset); }