zoukankan      html  css  js  c++  java
  • 微信支付,支付宝支付.退款 转账

    转。https://www.cnblogs.com/liuxiaoji/p/9234161.html

    微信支付 

    https://github.com/842549829/Fund/blob/master/Weixin/CreateRequest.cs


    /// <summary>
        /// 创建请求信息
        /// </summary>
        public class CreateRequest
        {
            #region web微信公众号
            /// <summary>
            /// 创建支付信息(安卓 IOS)
            /// </summary>
            /// <param name="request">request</param>
            /// <param name="config">配置</param>
            /// <returns>结果</returns>
            public static UnifiedOrderResult CreateDirectPayByUser(UnifiedOrderRequest request, Config config)
            {
                // 统一下单
                var requestStr = TenpayUtil.GetUnifiedOrderXml(request, config);
                var response = HttpHelp.PostXmlToUrl(Config.UnifiedPayUrl, requestStr);
                var unifiedOrderResult = TenpayUtil.ConvertToUnifiedOrderResult(response);
                // 调起支付
                var parameters = TenpayUtil.GetPaySign(unifiedOrderResult, config);
                var result = TenpayUtil.CreatePayParameters(parameters, unifiedOrderResult);
                return result;
            }
    
            /// <summary>
            /// 创建支付信息(网页公众号)
            /// </summary>
            /// <param name="request">request</param>
            /// <param name="config">配置</param>
            /// <returns>结果</returns>
            public static WapUnifiedOrderResult CreateDirectWapPayByUser(WapUnifiedOrderRequest request, Config config)
            {
                // 统一下单
                var requestStr = TenpayUtil.GetUnifiedWapOrderXml(request, config);
                var response = HttpHelp.PostXmlToUrl(Config.UnifiedPayUrl, requestStr);
                var unifiedOrderResult = TenpayUtil.ConvertToWapUnifiedOrderResult(response);
                // 调起支付
                var parameters = TenpayUtil.GetWapPaySign(unifiedOrderResult, config);
                var result = TenpayUtil.CreatePayParameters(parameters, unifiedOrderResult);
                return result;
            }
    ......

    支付通知:https://github.com/842549829/Fund/blob/master/Notify/Controllers/TenpayNoticeController.cs

    /// <summary>
        /// 腾讯通知
        /// </summary>
        public class TenpayNoticeController : BaseController
        {
            /// <summary>
            /// 微信Sdk支付通知
            /// </summary>
            /// <returns>ContentResult</returns>
            public ContentResult PaySdkNotice()
            {
                try
                {
                    var requestStr = GetRequestStr();
                    var flg = Weixin.Notify.PayNotify(requestStr, new Weixin.Model.Config { /*微信配置信息*/ });
                    if (flg.IsSuccess)
                    {
                        // 处理业务
                        return new ContentResult { Content = GetResult(true, "OK") };
                    }
                    else
                    {
                        return new ContentResult { Content = GetResult(false, flg.Message) };
                    }
                }
                catch (Exception ex)
                {
                    return new ContentResult { Content = GetResult(false, "微信支付通知异常") };
                }
            }

    支付宝支付

    老版本 :https://github.com/842549829/Fund/blob/master/AliPay/CreateRequest.cs


    /// <summary>
        /// CreateRequest
        /// 航旅版 :加密参数需要Pid Key 
        /// 蚂蚁金服 :全部
        /// </summary>    
        public class CreateRequest
        {
            /// <summary>
            /// 创建PC支付链接串(航旅版)
            /// </summary>
            /// <param name="directInfo">支付信息</param>
            /// <param name="config">config</param>
            /// <returns>请求连接</returns>
            public static string CreateDirectGetPcPayByUser(DirectInfo directInfo, Config config)
            {
                var partner = config.GetPid();
                Submit submit = new Submit(config);
                var sParaTemp = new SortedDictionary<string, string>
                {
                    {"service", "create_direct_pay_by_user"},
                    {"partner", partner},
                    {"_input_charset", Config.InputCharset.ToLower()},
                    {"payment_type", "1"},
                    {"notify_url", directInfo.Notify},
                    {"return_url", directInfo.Return},
                    {"out_trade_no", directInfo.OutTradeNo},
                    {"subject", directInfo.Subject},
                    {"total_fee", directInfo.TotalFee.ToString("0.00")},
                    {"show_url", directInfo.ShowUrl},
                    {"seller_email", Config.SellerEmail},
                };
                string responseResult = submit.BuildRequest(sParaTemp);
                return responseResult;
            }
    .................
    支付通知:https://github.com/842549829/Fund/blob/master/Notify/Controllers/AliPayNoticeController.cs
    /// <summary>
            /// 支付通知
            /// </summary>
            /// <returns>返回结果</returns>
            public ContentResult PayNotice()
            {
                
                var sPara = GetRequestPost();
                if (sPara.Count > 0)
                {
                    // 签名验证
                    var flg = AliPay.Notify.Verify(sPara, Request.Form["notify_id"], Request.Form["sign"], new AliPay.Model.Config{ });
                    if (flg)
                    {
                        //交易状态
                        string trade_status = Request.Form["trade_status"];
    
                        //商户订单号
                        string out_trade_no = Request.Form["out_trade_no"];
    
                        //支付宝交易号
                        string trade_no = Request.Form["trade_no"];
    
                        //获取总金额
                        decimal total_fee = Convert.ToDecimal(Request.Form["total_fee"]);
    
                        //买家支付宝账号
                        //string accocunt = Request.Form["buyer_email"];
    
                        //买家支付宝账号ID
                        string accountID = Request.Form["buyer_id"];
    
                        if (trade_status == "TRADE_SUCCESS")
                        {
                            // 处理业务
                            return new ContentResult { Content = "success" };
                        }
                        else
                        {
                            // 支付失败的通知直接返回结果不再来通知
                            return new ContentResult { Content = "success" };
                        }
                    }
                    else//验证失败
                    {
                        return new ContentResult { Content = "fail" };
                    }
                }
                else
                {
                    return new ContentResult { Content = "无通知参数" };
                }
            }

    新版本:https://github.com/842549829/Fund/blob/master/AliPay/CreateRequest.cs

    /// <summary>
            /// 创建Sdk支付链接串(蚂蚁金服)
            /// </summary>
            /// <param name="directInfo">支付信息</param>
            /// <param name="config">config</param>
            /// <returns>请求连接</returns>
            public static string CreateDirectSdkPayByUser(DirectInfo directInfo, SdkPay.Config config)
            {
                const string url = SdkPay.Config.ServerUrl;
                string appId = config.GetAppId();
                string privateKeyPem = config.GetPrivateKeyPem();
                const string format = SdkPay.Config.Format;
                const string version = SdkPay.Config.Version;
                const string signType = SdkPay.Config.SignType;
                string publicKeyPem = config.GetPublicKeyPem();
                const string charset = SdkPay.Config.Charset;
                const string productCode = SdkPay.Config.ProductCode;
                string pid = config.GetPid();
                IAopClient client = new DefaultAopClient(url, appId, privateKeyPem, format, version, signType, publicKeyPem, charset, false);
                AlipayTradeAppPayRequest request = new AlipayTradeAppPayRequest();
                if (!string.IsNullOrWhiteSpace(directInfo.Notify))
                {
                    request.SetNotifyUrl(directInfo.Notify);
                }
                if (!string.IsNullOrWhiteSpace(directInfo.Return))
                {
                    request.SetReturnUrl(directInfo.Return);
                }
                AlipayTradeAppPayModel model = new AlipayTradeAppPayModel
                {
                    Body = directInfo.ExtraCommonParam,
                    Subject = directInfo.Subject,
                    TotalAmount = directInfo.TotalFee.ToString("0.00"),
                    ProductCode = productCode,
                    OutTradeNo = directInfo.OutTradeNo,
                    TimeoutExpress = "30m",
                    SellerId = pid
                };
                request.SetBizModel(model);
                AlipayTradeAppPayResponse response = client.SdkExecute(request);
                var body = response.Body;
                return body;
            }
    
    ....................

    支付通知: https://github.com/842549829/Fund/blob/master/Notify/Controllers/AliPayNoticeController.cs

    /// <summary>
            /// 支付宝Sdk支付通知
            /// </summary>
            /// <returns>返回结果</returns>
            public ContentResult PaySdkNotice()
            {
                var sPara = GetRequestPost();
                if (sPara.Count > 0)
                {
                    // 签名验证
                    var flg = AliPay.Notify.VerifySdk(sPara, new AliPay.SdkPay.Config { });
                    if (flg)
                    {
                        //交易状态
                        string trade_status = Request.Form["trade_status"];
    
                        //商户订单号
                        string out_trade_no = Request.Form["out_trade_no"];
    
                        //支付宝交易号
                        string trade_no = Request.Form["trade_no"];
    
                        //获取总金额
                        decimal total_fee = Convert.ToDecimal(Request.Form["buyer_pay_amount"]);
    
                        // 订单金额(用于获取不到总金额的时候第二次验证)
                        decimal orderAmount = Convert.ToDecimal(Request.Form["total_amount"]);
    
                        //买家支付宝账号
                        string accocunt = Request.Form["buyer_logon_id"];
    
                        if (trade_status == "TRADE_SUCCESS")
                        {
                            try
                            {
                                if (total_fee <= 0)
                                {
                                    total_fee = orderAmount;
                                }
                                // 处理业务
                                return new ContentResult { Content = "success" };
                            }
                            catch (Exception ex)
                            {
                                return new ContentResult { Content = "fail" };
                            }
                        }
                        else
                        {
                            // 支付失败的通知直接返回结果不再来通知
                            return new ContentResult { Content = "success" };
                        }
                    }
                    else//验证失败
                    {
                        return new ContentResult { Content = "fail" };
                    }
                }
                else
                {
                    return new ContentResult { Content = "无通知参数" };
                }
            }

    退款请去github下载源代码自己撸

    github地址 :https://github.com/842549829/Fund



  • 相关阅读:
    mvn tomcat7:help的14个命令
    leetcode Next Permutation
    leetcode Permutation
    java HashMap
    单链表反转(递归和非递归) (Java)
    java数据类型
    Multiply Strings 大数相乘 java
    SQL中如何使用UPDATE语句进行联表更新(转)
    循环建立索引
    js 跨域访问
  • 原文地址:https://www.cnblogs.com/wybshyy/p/13783717.html
Copyright © 2011-2022 走看看