Yi.Framework.Net6/Yi.Framework.WeChatPay/Core/Helper/PayHelper.cs

(开头部分) 6KB

这里只显示每个文件的开头 60 行。登录后可以解锁完整代码。

using Microsoft.AspNetCore.Http;
using Newtonsoft.Json;
using Newtonsoft.Json.Linq;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Net;
using System.Text;
using System.Threading.Tasks;
using Yi.Framework.WeChatPay.Options;

namespace Yi.Framework.WeChatPay.Core
{
    public class PayHelper
    {
        public static readonly string KEY_PAY_PREFIX = "order:pay:url:";
        private readonly IPayConfig _IPayConfig = null;
        private readonly PayApi _PayApi = null;

        private HttpContext _httpContext;
        public PayHelper(IPayConfig PayConfig, PayApi PayApi, IHttpContextAccessor httpContextAccessor)
        {
            this._IPayConfig = PayConfig;
            this._PayApi = PayApi;
            this._httpContext = httpContextAccessor.HttpContext;
        }

        /// <summary>
        /// 创建支付连接
        /// </summary>
        /// <param name="orderId"></param>
        /// <param name="description"></param>
        /// <param name="totalPay"></param>
        /// <param name="httpContext"></param>
        /// <returns></returns>
        public string CreatePayUrl(long orderId, string description, long totalPay)
        {
            // 定义返回的支付连接
            string url;
            try
            {
                // 构建支付需要的参数对象
                PayData data = new PayData();
                //描述
                data.SetValue("body", description);
                //订单号
                data.SetValue("out_trade_no", orderId.ToString());
                data.SetValue("product_id", orderId.ToString());
                //货币(默认就是人民币)
                data.SetValue("fee_type", "CNY");
                //TODO 总金额 (模拟1分钱, 线上环境换成真实价格)
                data.SetValue("total_fee", /*totalPay.ToString()*/ 1); // 单位是分
                //调用微信支付的终端ip
                data.SetValue("spbill_create_ip", "0.0.0.0");
                //回调地址
                data.SetValue("notify_url", this._IPayConfig.GetNotifyUrl());
                //交易类型为扫码支付
                data.SetValue("trade_type", "NATIVE");

                PayData result = this._PayApi.UnifiedOrder(data);//调用统一下单接口
后面还有 118 行代码,解锁后查看完整代码

24 小时内免费解锁 3 个项目,之后 1 算力/个。 规则说明

AI 解读 AI

登录后可用,每次 10 算力,解读结果公开显示在下面。

还没有人解读过这个文件。