12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576 |
- using System.Collections.Generic;
- using Alipay.AopSdk.Core.Util;
- using GxPress.Common.AliPay;
- using Microsoft.AspNetCore.Authorization;
- using Microsoft.AspNetCore.Mvc;
- namespace GxPress.Api.WebControllers
- {
- [Route("api/web/alipay")]
- [ApiController]
- [Authorize]
- public class AlipayController : Controller
- {
- [HttpGet()]
- [AllowAnonymous]
- public string GetNativePayUrl()
- {
- var alipay = new PcPay();
- return alipay.PayRequest("637263608658642540", "汪峰讲故事", "0.01", "汪峰讲故事");
- }
- /// <summary>
- /// 回调地址
- /// </summary>
- [HttpGet("notify")]
- [AllowAnonymous]
- public void Callback()
- {
- /* 实际验证过程建议商户添加以下校验。
- 1、商户需要验证该通知数据中的out_trade_no是否为商户系统中创建的订单号,
- 2、判断total_amount是否确实为该订单的实际金额(即商户订单创建时的金额),
- 3、校验通知中的seller_id(或者seller_email) 是否为out_trade_no这笔单据的对应的操作方(有的时候,一个商户可能有多个seller_id/seller_email)
- 4、验证app_id是否为该商户本身。
- */
- Dictionary<string, string> sArray = GetRequestGet();
- if (sArray.Count != 0)
- {
- bool flag = AlipaySignature.RSACheckV1(sArray, Config.AlipayPublicKey, Config.CharSet, Config.SignType, false);
- if (flag)
- {
- //Console.WriteLine($"同步验证通过,订单号:{sArray["out_trade_no"]}");
- ViewData["PayResult"] = "同步验证通过";
- }
- else
- {
- // Console.WriteLine($"同步验证失败,订单号:{sArray["out_trade_no"]}");
- ViewData["PayResult"] = "同步验证失败";
- }
- }
- }
- private Dictionary<string, string> GetRequestPost()
- {
- Dictionary<string, string> sArray = new Dictionary<string, string>();
- ICollection<string> requestItem = Request.Form.Keys;
- foreach (var item in requestItem)
- {
- sArray.Add(item, Request.Form[item]);
- }
- return sArray;
- }
- private Dictionary<string, string> GetRequestGet()
- {
- Dictionary<string, string> sArray = new Dictionary<string, string>();
- ICollection<string> requestItem = Request.Query.Keys;
- foreach (var item in requestItem)
- {
- sArray.Add(item, Request.Query[item]);
- }
- return sArray;
- }
- }
- }
|