v3版本验签

官方v3文档

wechatPay-API-v3

//调用微信支付客户端
tenpay.UseMchId(mchId);
//请求支付信息
 tenpay.SendAsync<TransactionsResponse>(transactionRequest);
//获取支付明文信息 有信息表示支付成功
var data= await tenpay.GetNotifyDataAsync<TransactionsSuccessNotifyData>(Request);

以jsapi为例

调用微信统一下单接口 获取jsapi支付所需要的参数

async Task<object> GetTenpayJsapiInfo(OrderInfo order,string openId)
{
    var payOptions = tenpay.UseMchId(mchId);
    var transactionRequest = new TransactionsJsapiRequest ()
    {
        AppId = appId,
        MchId = mchId,
        Description = order.OrderName,
        OutTradeNo = order.OrderNo,
        NotifyUrl = $"https://pan.rs888.net/tenpay/notify/{mchId}",
        PrepaidAmountInfo = new  PrepaidAmountInfo
        {
            Total = TenpayTool.Price(order.PayAmount),
            Currency = "CNY"
        },
         PayerInfo=new PayerInfo() { 
           SpOpenId= openId
         },
         OrderDiscountInfo= new OrderDiscountInfo()
        {
            CostPrice = TenpayTool.Price(order.TotalAmount),
            GoodsDetail = new GoodsDetailInfo[] {
            new GoodsDetailInfo{

             GoodsName=order.OrderName,
             Quantity=order.OrderItems.Count,
             UnitPrice=TenpayTool.Price( order.PayAmount)
            }
         }
        },
        SceneInfo = new  JsapiSceneInfo
        {
            PayerClientIp = tenpay.GetIp(),
            DeviceId="", 
            StoreInfo =new StoreInfo
            {
                Id="01"
            }
        }
    };
    var ret= await tenpay.SendAsync<TransactionsResponse>(transactionRequest);
    if (ret.StatusCode == 200)
    {
        string timeStamp = TenpayTool.GetTimeStamp();
        string nonceStr = TenpayTool.GetNonceStr();
        string package = $"prepay_id={ret.PrepayId}";

        string message = $"{appId}\n{timeStamp}\n{nonceStr}\n{package}\n";
        string sign = TenpayTool.Sign(message, payOptions);

        return new
        {
            appId = appId,
            timeStamp = timeStamp,
            nonceStr = nonceStr,
            package = package,
            signType = "RSA",
            paySign = sign
        };
    }
    throw new AppException("系统忙,请稍后再试");
}

jsAPI发起支付,成功后,得到回调的数据

[Route("tenpay")]
public class TenpayController : Controller
{
    ITenpayClient tenpay;
    public TenpayController(ITenpayClient _tenpayClient)
    {
        tenpay = _tenpayClient;
    }

    [HttpPost("notify/{mchid}")]
    public async Task PayNotify(string mchid)
    {
        var payOption = tenpay.UseMchId(mchid);
        var data= await tenpay.GetNotifyDataAsync<TransactionsSuccessNotifyData>(Request); 

        if(data!=null)
        {
           //TODO处理支付成功的逻辑
            //jsapi 支付成功后返回的数据
            //{"appid":"wx7c829604a62b02e8","mchid":"1604955852","out_trade_no":"103111921664","transaction_id":"4200000998202103112715168358","trade_type":"JSAPI","trade_state":"SUCCESS","trade_state_desc":"\u652F\u4ED8\u6210\u529F","bank_type":"OTHERS","attach":"","success_time":"2021-03-11T18:54:19\u002B08:00","payer":{"openid":"o-v-jwuELrppUucqSug9f6kuEzZc"},"amount":{"total":1,"currency":"CNY","payer_total":1,"payer_currency":"CNY"},"scene_info":null,"promotion_detail":null} 

        }
    }
}

results matching ""

    No results matching ""