Пример #1
0
        /// <summary>
        /// 发送支付请求
        /// </summary>
        /// <param name="out_trade_no">订单号</param>
        /// <param name="subject">名称</param>
        /// <param name="total_fee">付款金额</param>
        /// <param name="body">描述</param>
        /// <param name="paytype">支付类型(3供应商认证支付,2产品认证支付,1排名付费支付,0订单支付)</param>
        /// <param name="type">类型 webcz:充值 webzf:支付</param>
        /// <param name="iplm">类型 1.是账户余额支付 2.第三方其它支付方式</param>
        /// <returns></returns>
        public JsonResult SetAliPay(string out_trade_no, string subject, string total_fee, string body, string paytype, string type, string iplm, string targetid, string paymodel)
        {
            string hots = Request.Url.Scheme + "://" + Request.Url.Host + ":" + Request.Url.Port + "/";
            //把请求参数打包成数组
            SortedDictionary <string, string> sParaTemp = new SortedDictionary <string, string>();

            sParaTemp.Add("service", AlipayConfig.service);
            sParaTemp.Add("partner", AlipayConfig.partner);
            sParaTemp.Add("seller_id", AlipayConfig.seller_id);
            sParaTemp.Add("_input_charset", AlipayConfig.input_charset.ToLower());
            sParaTemp.Add("payment_type", AlipayConfig.payment_type);
            sParaTemp.Add("notify_url", AlipayConfig.notify_url);
            sParaTemp.Add("return_url", hots + "/Pay/Return?orderid=" + out_trade_no + "&price=" + total_fee + "&paytype=" + paytype + "&type=" + type + "&iplm=" + iplm + "&targetid=" + targetid + "&paymodel=zfb");
            sParaTemp.Add("anti_phishing_key", AlipayConfig.anti_phishing_key);
            sParaTemp.Add("exter_invoke_ip", AlipayConfig.exter_invoke_ip);
            sParaTemp.Add("out_trade_no", out_trade_no);
            sParaTemp.Add("subject", subject);
            sParaTemp.Add("total_fee", total_fee);
            sParaTemp.Add("body", body);
            //其他业务参数根据在线开发文档,添加参数.文档地址:https://doc.open.alipay.com/doc2/detail.htm?spm=a219a.7629140.0.0.O9yorI&treeId=62&articleId=103740&docType=1
            //如sParaTemp.Add("参数名","参数值");

            //建立请求
            string sHtmlText = AlipaySubmit.BuildRequest(sParaTemp, "get", "确认");

            return(Json(sHtmlText));
        }
Пример #2
0
        /// <summary>
        /// 调用授权接口获取授权令牌
        /// </summary>
        /// <param name="response">订单处理网页Response对象</param>
        /// <param name="subject">用户购买的商品名称,不可空</param>
        /// <param name="out_trade_no">支付宝合作商户网站唯一订单号。不可空</param>
        /// <param name="total_fee">该笔订单的资金总额,单位为RMB-Yuan。取值范围为[0.01,100000000.00],精确到小数点后两位。不可空</param>
        /// <param name="call_back_url">支付成功跳转页面路径,不可空</param>
        /// <param name="out_user">买家在商户系统的唯一标识。当该买家支付成功一次后,再次支付金额在30元内时,不需要再次输入密码,可为空</param>
        /// <param name="notify_url">服务器异步通知页面路径。可为空</param>
        /// <param name="merchant_url">用户付款中途退出返回商户的地址。可为空</param>
        /// <param name="pay_expire">交易自动关闭时间。可为空</param>
        public string GetAliPayToken(string subject, string out_trade_no, string total_fee,
                                     string out_user, string call_back_url, string notify_url = "", string merchant_url = "", string pay_expire = "")
        {
            string res = string.Empty;
            Dictionary <string, string> sParaTempToken = new Dictionary <string, string>();

            sParaTempToken.Add("service", "alipay.wap.trade.create.direct");
            sParaTempToken.Add("format", "xml");
            sParaTempToken.Add("v", "2.0");
            sParaTempToken.Add("partner", partner);
            sParaTempToken.Add("sec_id", sign_type.ToUpper());
            sParaTempToken.Add("_input_charset", input_charset.ToLower());

            sParaTempToken.Add("req_data", BuildReqData(subject, out_trade_no, total_fee,
                                                        seller_account_name, call_back_url, notify_url, out_user,
                                                        merchant_url, pay_expire));
            string sHtmlTextToken = AlipaySubmit.BuildRequest(gateway_new, sParaTempToken);
            //URLDECODE返回的信息
            Encoding code = Encoding.GetEncoding(input_charset);

            sHtmlTextToken = HttpUtility.UrlDecode(sHtmlTextToken, code);
            //解析远程模拟提交后返回的信息
            Dictionary <string, string> dicHtmlTextToken = AlipaySubmit.ParseResponse(sHtmlTextToken);

            //获取token
            res = dicHtmlTextToken["request_token"];
            return(res);
        }
Пример #3
0
        protected void dlstOrders_ItemCommand(object sender, DataListCommandEventArgs e)
        {
            bool      flag      = false;
            OrderInfo orderInfo = OrderHelper.GetOrderInfo(e.CommandArgument.ToString());

            if (orderInfo != null)
            {
                if (e.CommandName == "PAY" && orderInfo.OrderStatus == OrderStatus.WaitBuyerPay)//开始后台支付流程
                {
                    if (orderInfo.Gateway != "hishop.plugins.payment.advancerequest")
                    {
                        //HttpContext.Current.Response.Redirect("AliPay/default.aspx?orderId=" + orderInfo.OrderId);//(Globals.GetSiteUrls().UrlData.FormatUrl("sendPayment", new object[] { orderInfo.OrderId }));
                        ////////////////////////////////////////////请求参数////////////////////////////////////////////

                        //商户订单号,商户网站订单系统中唯一订单号,必填
                        string out_trade_no = orderInfo.OrderId;

                        //订单名称,必填
                        string subject = "代理商" + orderInfo.RealName + "的采购订单";

                        //付款金额,必填
                        string total_fee = orderInfo.GetCostPrice().ToString("F2"); //去成本价

                        //商品描述,可空
                        string body = orderInfo.ProductDescription;

                        ////////////////////////////////////////////////////////////////////////////////////////////////

                        //把请求参数打包成数组
                        SortedDictionary <string, string> sParaTemp = new SortedDictionary <string, string>();
                        AlipayConfig ac = new AlipayConfig();
                        sParaTemp.Add("service", AlipayConfig.service);
                        sParaTemp.Add("partner", AlipayConfig.partner);
                        sParaTemp.Add("seller_id", AlipayConfig.seller_id);
                        sParaTemp.Add("_input_charset", AlipayConfig.input_charset.ToLower());
                        sParaTemp.Add("payment_type", AlipayConfig.payment_type);
                        sParaTemp.Add("notify_url", AlipayConfig.notify_url);
                        sParaTemp.Add("return_url", AlipayConfig.return_url);
                        sParaTemp.Add("anti_phishing_key", AlipayConfig.anti_phishing_key);
                        sParaTemp.Add("exter_invoke_ip", AlipayConfig.exter_invoke_ip);
                        sParaTemp.Add("out_trade_no", out_trade_no);
                        sParaTemp.Add("subject", subject);
                        sParaTemp.Add("total_fee", total_fee);
                        sParaTemp.Add("body", body);
                        //其他业务参数根据在线开发文档,添加参数.文档地址:https://doc.open.alipay.com/doc2/detail.htm?spm=a219a.7629140.0.0.O9yorI&treeId=62&articleId=103740&docType=1
                        //如sParaTemp.Add("参数名","参数值");

                        //建立请求
                        string sHtmlText = AlipaySubmit.BuildRequest(sParaTemp, "get", "确认");
                        Response.Write(sHtmlText);
                    }
                    else
                    {
                        HttpContext.Current.Response.Redirect(string.Format("/user/pay.aspx?OrderId={0}", orderInfo.OrderId));
                    }
                }
            }
        }
Пример #4
0
        private void get_Alipay(System.Web.HttpContext context)
        {
            //商户订单号,商户网站订单系统中唯一订单号,必填
            string out_trade_no = context.Request["orderid"];

            //订单名称,必填
            string subject = context.Request["productDescribe"];

            //付款金额,必填
            string total_fee = context.Request["total_fee"];

            //商品描述,可空
            string body = context.Request["productDescribe"];

            Uri    prevUri       = HttpContext.Current.Request.UrlReferrer;
            string strDomainName = (prevUri != null) ? prevUri.Host : Globals.DomainName;

            ////////////////////////////////////////////////////////////////////////////////////////////////

            //把请求参数打包成数组
            SortedDictionary <string, string> sParaTemp = new SortedDictionary <string, string>();
            AlipayConfig ac = new AlipayConfig();

            sParaTemp.Add("service", AlipayConfig.service);
            sParaTemp.Add("partner", AlipayConfig.partner);
            sParaTemp.Add("seller_id", AlipayConfig.seller_id);
            sParaTemp.Add("_input_charset", AlipayConfig.input_charset.ToLower());
            sParaTemp.Add("payment_type", AlipayConfig.payment_type);
            sParaTemp.Add("notify_url", AlipayConfig.notify_url);
            sParaTemp.Add("return_url", string.Format(AlipayConfig.return_url_Custom, strDomainName));//返回
            sParaTemp.Add("anti_phishing_key", AlipayConfig.anti_phishing_key);
            sParaTemp.Add("exter_invoke_ip", AlipayConfig.exter_invoke_ip);
            sParaTemp.Add("out_trade_no", out_trade_no);
            sParaTemp.Add("subject", subject);
            sParaTemp.Add("total_fee", total_fee);
            sParaTemp.Add("body", body);
            //其他业务参数根据在线开发文档,添加参数.文档地址:https://doc.open.alipay.com/doc2/detail.htm?spm=a219a.7629140.0.0.O9yorI&treeId=62&articleId=103740&docType=1
            //如sParaTemp.Add("参数名","参数值");

            //建立请求
            string sHtmlText = AlipaySubmit.BuildRequest(sParaTemp, "get", "确认");

            context.Response.Write(sHtmlText);
            context.Response.End();
        }
Пример #5
0
        /// <summary>
        /// 退款
        /// </summary>
        /// <param name="money"></param>
        /// <param name="trade_No"></param>
        /// <param name="batch_no"></param>
        /// <param name="batch_num"></param>
        /// <param name="reason"></param>
        public static string ReimburseOrder(string money, string trade_No, string batch_no, string batch_num = "1", string reason = "协商退款")
        {
            string detail_data = trade_No + "^" + money + "^" + reason;
            //
            SortedDictionary <string, string> sParaTemp = new SortedDictionary <string, string>();

            sParaTemp.Add("service", AlipayConfig.service);
            sParaTemp.Add("partner", AlipayConfig.partner);
            sParaTemp.Add("_input_charset", AlipayConfig.input_charset.ToLower());
            sParaTemp.Add("notify_url", AlipayConfig.notify_url);
            sParaTemp.Add("seller_user_id", AlipayConfig.seller_user_id);
            sParaTemp.Add("refund_date", AlipayConfig.refund_date);
            sParaTemp.Add("batch_no", batch_no);
            sParaTemp.Add("batch_num", batch_num);
            sParaTemp.Add("detail_data", detail_data);
            string sHtmlText = AlipaySubmit.BuildRequest(sParaTemp, "post", "确认");

            return(sHtmlText);
        }
Пример #6
0
        /// <summary>
        /// 调用支付接入进行支付
        /// </summary>
        /// <param name="response">订单处理网页Response对象</param>
        /// <param name="request_token">授权令牌,不可空</param>
        public void RequestWapPayment(HttpResponse response, string request_token)
        {
            string req_data = "<auth_and_execute_req><request_token>" + request_token + "</request_token></auth_and_execute_req>";
            //必填
            Dictionary <string, string> sParaTempToken = new Dictionary <string, string>();

            sParaTempToken.Add("service", "alipay.wap.auth.authAndExecute");
            sParaTempToken.Add("format", "xml");
            sParaTempToken.Add("v", "2.0");
            sParaTempToken.Add("partner", partner);
            sParaTempToken.Add("sec_id", sign_type.ToUpper());
            sParaTempToken.Add("_input_charset", input_charset.ToLower());

            sParaTempToken.Add("req_data", req_data);

            //建立请求
            string sHtmlText = AlipaySubmit.BuildRequest(gateway_new, sParaTempToken, "get", "确认");

            response.Write(sHtmlText);
        }
Пример #7
0
        /// <summary>
        /// 建立请求
        /// </summary>
        /// <param name="userId">用户名</param>
        /// <param name="money">支付金额</param>
        /// <param name="subject">订单名称</param>
        /// <param name="exId">兑换id</param>
        /// <param name="address">收货地址id</param>
        /// <param name="deposit">押金</param>
        /// <param name="method">兑换方式</param>
        /// <returns></returns>
        public static string BuildRequest(string userId, string money, string subject, string exId = "", string address = "", string deposit = "", string method = "")
        {
            //DONE: 支付宝充值
            //↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓以下支付宝↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓
            ////////////////////////////////////////////请求参数////////////////////////////////////////////
            //商户订单号,商户网站订单系统中唯一订单号,必填
            string out_trade_no = Guid.NewGuid().ToString();

            //付款金额,必填
            string total_fee = string.Format("{0:0.00}", money?.Split(',')[0]);
            //商品描述,可空
            string body = subject;

            ////////////////////////////////////////////////////////////////////////////////////////////////
            //把请求参数打包成数组
            SortedDictionary <string, string> sParaTemp = new SortedDictionary <string, string>();

            sParaTemp.Add("service", AlipayConfig.service);
            sParaTemp.Add("partner", AlipayConfig.partner);
            sParaTemp.Add("seller_id", AlipayConfig.seller_id);
            sParaTemp.Add("_input_charset", AlipayConfig.input_charset.ToLower());
            sParaTemp.Add("payment_type", AlipayConfig.payment_type);
            sParaTemp.Add("notify_url", AlipayConfig.notify_url);
            sParaTemp.Add("return_url", AlipayConfig.return_url);
            sParaTemp.Add("anti_phishing_key", AlipayConfig.anti_phishing_key);
            //sParaTemp.Add("exter_invoke_ip", AlipayConfig.exter_invoke_ip);
            sParaTemp.Add("out_trade_no", out_trade_no);
            sParaTemp.Add("subject", subject);
            sParaTemp.Add("total_fee", total_fee);
            sParaTemp.Add("body", body);
            string extra_common_param = "{" + $"\"UserId\":\"{userId}\",\"ExId\":\"{exId}\",\"Address\":\"{address}\",\"Deposit\":\"{deposit}\",\"Method\":\"{method}\"" + "}";

            sParaTemp.Add("extra_common_param", extra_common_param);
            //其他业务参数根据在线开发文档,添加参数.文档地址:https://doc.open.alipay.com/doc2/detail.htm?spm=a219a.7629140.0.0.O9yorI&treeId=62&articleId=103740&docType=1
            //如sParaTemp.Add("参数名","参数值");

            //建立请求
            return(AlipaySubmit.BuildRequest(sParaTemp, "post", "确认"));
        }
Пример #8
0
        /// <summary>
        /// 支付
        /// </summary>
        public ActionResult Pay()
        {
            //订单id列表
            string oidList = WebHelper.GetQueryString("oidList");

            decimal          allSurplusMoney = 0M;
            List <OrderInfo> orderList       = new List <OrderInfo>();

            foreach (string oid in StringHelper.SplitString(oidList))
            {
                //订单信息
                OrderInfo orderInfo = Orders.GetOrderByOid(TypeHelper.StringToInt(oid));
                if (orderInfo != null && orderInfo.Uid == WorkContext.Uid && orderInfo.OrderState == (int)OrderState.WaitPaying && orderInfo.PayMode == 1)
                {
                    orderList.Add(orderInfo);
                }
                else
                {
                    return(Redirect("/"));
                }
                allSurplusMoney += orderInfo.SurplusMoney;
            }

            if (orderList.Count < 1 || allSurplusMoney == 0M)
            {
                return(Redirect("/"));
            }

            //支付类型,必填,不能修改
            string paymentType = "1";

            //服务器异步通知页面路径,需http://格式的完整路径,不能加?id=123这类自定义参数
            string notifyUrl = string.Format("http://{0}/Alipay/Notify", BMAConfig.MallConfig.SiteUrl);
            //页面跳转同步通知页面路径,需http://格式的完整路径,不能加?id=123这类自定义参数,不能写成http://localhost/
            string returnUrl = string.Format("http://{0}/Alipay/Return", BMAConfig.MallConfig.SiteUrl);

            //收款支付宝帐户
            string sellerEmail = AlipayConfig.Seller;
            //合作者身份ID
            string partner = AlipayConfig.Partner;
            //交易安全检验码
            string key = AlipayConfig.Key;

            //商户订单号
            string outTradeNo = oidList + Randoms.CreateRandomValue(10, false);
            //订单名称
            string subject = BMAConfig.MallConfig.SiteTitle + "购物";
            //付款金额
            string totalFee = allSurplusMoney.ToString();
            //订单描述
            string body = "";

            //防钓鱼时间戳,若要使用请调用类文件submit中的query_timestamp函数
            string antiPhishingKey = "";
            //客户端的IP地址,非局域网的外网IP地址,如:221.0.0.1
            string exterInvokeIP = "";

            //把请求参数打包成数组
            SortedDictionary <string, string> parms = new SortedDictionary <string, string>();

            parms.Add("partner", partner);
            parms.Add("_input_charset", AlipayConfig.InputCharset);
            parms.Add("service", "create_direct_pay_by_user");
            parms.Add("payment_type", paymentType);
            parms.Add("notify_url", notifyUrl);
            parms.Add("return_url", returnUrl);
            parms.Add("seller_email", sellerEmail);
            parms.Add("out_trade_no", outTradeNo);
            parms.Add("subject", subject);
            parms.Add("total_fee", totalFee);
            parms.Add("body", body);
            parms.Add("show_url", "");
            parms.Add("anti_phishing_key", antiPhishingKey);
            parms.Add("exter_invoke_ip", exterInvokeIP);

            //建立请求
            string sHtmlText = AlipaySubmit.BuildRequest(parms, AlipayConfig.SignType, AlipayConfig.Key, AlipayConfig.Code, AlipayConfig.Gateway, AlipayConfig.InputCharset, "get", "确认");

            return(Content(sHtmlText));
        }
        /// <summary>
        /// 退款
        /// </summary>
        /// <param name="refundPaymentRequest">Request</param>
        /// <returns>Result</returns>
        public RefundPaymentResult Refund(RefundPaymentRequest refundPaymentRequest)
        {
            var   result = new RefundPaymentResult();
            Order order  = refundPaymentRequest.Order;

            if (order == null)
            {
                result.AddError("订单为空");
                return(result);
            }
            PaymentInfo paymentInfo = _paymentInfoService.GetByOrderId(order.Id);

            if (!(paymentInfo != null && !string.IsNullOrEmpty(paymentInfo.Out_Trade_No)))
            {
                result.AddError("交易号为空");
                return(result);
            }
            if (_aliPayPaymentSettings.Partner != paymentInfo.Seller_id)
            {
                result.AddError("退款合作身份者ID错误");
                return(result);
            }
            if (refundPaymentRequest.AmountToRefund <= 0)
            {
                result.AddError("退款金额大于0");
                return(result);
            }
            if (refundPaymentRequest.AmountToRefund + refundPaymentRequest.Order.RefundedAmount > paymentInfo.Total)
            {
                result.AddError("退款金额错误");
                return(result);
            }

            //卖家账号,退款账号
            string seller_emailToRefund = paymentInfo.Seller_email; // 卖家退款账号邮箱
            string seller_user_id       = paymentInfo.Seller_id;    //卖家退款账号ID

            //批次号,必填,格式:当天日期[8位]+序列号[3至24位],如:201603081000001

            string batch_no = DateTime.Now.ToString("yyyyMMdd") + GuidToLongID();//退款编号

            //退款笔数,必填,参数detail_data的值中,“#”字符出现的数量加1,最大支持1000笔(即“#”字符出现的数量999个)

            string batch_num = "1";

            //退款详细数据,必填,格式(支付宝交易号^退款金额^备注),多笔请用#隔开
            string out_trade_no   = paymentInfo.Out_Trade_No;                                    //支付宝交易号交易号
            string amountToRefund = refundPaymentRequest.AmountToRefund.ToString().TrimEnd('0'); //退款金额
            string refundResult   = "协商退款";                                                      //备注
            string detail_data    = string.Format("{0}^{1}^{2}",
                                                  out_trade_no,
                                                  amountToRefund,
                                                  refundResult
                                                  );
            //退款通知
            string notify_url = _webHelper.GetStoreLocation(false) + "Plugins/AliPay/RefundNotify";

            //新增退款记录
            var refundInfo = new RefundInfo()
            {
                OrderId        = refundPaymentRequest.Order.Id,
                Batch_no       = batch_no,
                AmountToRefund = refundPaymentRequest.AmountToRefund,
                RefundStatusId = (int)RefundStatus.refunding,
                CreateOnUtc    = DateTime.Now,
                Seller_Email   = seller_emailToRefund,
                Seller_Id      = seller_user_id,
                Out_Trade_No   = out_trade_no,
            };

            _refundInfoService.Insert(refundInfo);

            ////////////////////////////////////////////////////////////////////////////////////////////////
            var alipayReturnConfig = new AlipayReturnConfig()
            {
                partner       = _aliPayPaymentSettings.Partner,
                key           = _aliPayPaymentSettings.Key,
                sign_type     = "MD5",
                input_charset = "utf-8"
            };
            //把请求参数打包成数组
            SortedDictionary <string, string> sParaTemp = new SortedDictionary <string, string>();

            sParaTemp.Add("service", alipayReturnConfig.service);
            sParaTemp.Add("partner", alipayReturnConfig.partner);
            sParaTemp.Add("_input_charset", alipayReturnConfig.input_charset.ToLower());
            sParaTemp.Add("refund_date", alipayReturnConfig.refund_date);
            sParaTemp.Add("seller_user_id", seller_user_id);
            sParaTemp.Add("batch_no", batch_no);
            sParaTemp.Add("batch_num", batch_num);
            sParaTemp.Add("detail_data", detail_data);
            sParaTemp.Add("notify_url", notify_url);

            var post = AlipaySubmit.BuildRequest(sParaTemp, alipayReturnConfig, "POST");

            post.Post();

            result.AddError("退款请求已提交,请到支付宝网站中进行退款确认");//必须有,否则影响退款金额
            return(result);
        }
        /// <summary>
        /// Post process payment (used by payment gateways that require redirecting to a third-party URL)
        /// </summary>
        /// <param name="postProcessPaymentRequest">Payment info required for an order processing</param>
        public void PostProcessPayment(PostProcessPaymentRequest postProcessPaymentRequest)
        {
            var partner = _aliPayPaymentSettings.Partner;

            if (string.IsNullOrEmpty(partner))
            {
                throw new Exception("合作身份者ID 不能为空");
            }

            var key = _aliPayPaymentSettings.Key;

            if (string.IsNullOrEmpty(key))
            {
                throw new Exception("MD5密钥不能为空");
            }

            var sellerEmail = _aliPayPaymentSettings.SellerEmail;

            if (string.IsNullOrEmpty(sellerEmail))
            {
                throw new Exception("卖家Email 不能为空");
            }

            var    customer = _workContext.CurrentCustomer;//当前用户
            string username = customer.Username;


            //商户订单号,商户网站订单系统中唯一订单号,必填
            string out_trade_no = postProcessPaymentRequest.Order.Id.ToString().Trim();//订单编号

            //订单名称,必填
            string subject = _storeContext.CurrentStore.Name + ":订单" + out_trade_no;

            //付款金额,必填
            string total_fee = postProcessPaymentRequest.Order.OrderTotal.ToString("0.00", CultureInfo.InvariantCulture);

            //商品描述,可空
            string body = _storeContext.CurrentStore.Name + ":用户_" + username;

            //支付配置信息
            var aliPayDirectConfig = new AlipayDirectConfig()
            {
                key           = _aliPayPaymentSettings.Key,
                partner       = _aliPayPaymentSettings.Partner,
                seller_email  = _aliPayPaymentSettings.SellerEmail,
                notify_url    = _webHelper.GetStoreLocation(false) + "Plugins/AliPay/Notify",
                return_url    = _webHelper.GetStoreLocation(false) + "Plugins/AliPay/Return",
                sign_type     = "MD5",
                input_charset = "utf-8",
            };
            //把请求参数打包成数组
            SortedDictionary <string, string> sParaTemp = new SortedDictionary <string, string>();

            sParaTemp.Add("service", aliPayDirectConfig.service);
            sParaTemp.Add("partner", aliPayDirectConfig.partner);
            sParaTemp.Add("seller_email", aliPayDirectConfig.seller_email);
            sParaTemp.Add("payment_type", aliPayDirectConfig.payment_type);
            sParaTemp.Add("notify_url", aliPayDirectConfig.notify_url);
            sParaTemp.Add("return_url", aliPayDirectConfig.return_url);
            sParaTemp.Add("_input_charset", aliPayDirectConfig.input_charset);
            sParaTemp.Add("out_trade_no", out_trade_no);
            sParaTemp.Add("subject", subject);
            sParaTemp.Add("body", body);
            sParaTemp.Add("total_fee", total_fee);
            //创建支付宝请求
            var post = AlipaySubmit.BuildRequest(sParaTemp, aliPayDirectConfig, "POST");

            post.Post();
        }
Пример #11
0
        public async Task <IActionResult> AliPay()
        {
            string payment_type = "1";
            //服务器异步通知页面路径
            string notify_url = ConfigurationManager.GetValue("CarBusinessUrl") + "/CallBack/AsynUrl";
            //页面跳转同步通知页面路径
            string return_url   = ConfigurationManager.GetValue("CarBusinessUrl") + "/Alipay/MessagePayReturnUrl";
            string seller_email = "*****@*****.**";
            //商户订单号
            string out_trade_no = "2019091002111158";
            //订单名称
            string subject = "短信充值";
            //支付宝回传参数
            //公用回传参数,如果请求时传递了该参数,则返回给商户时会回传该参数。支付宝只会在同步返回(包括跳转回商户网站)和异步通知时将该参数原样返回。本参数必须进行UrlEncode之后才可以发送给支付宝。
            //不过好像不好用,最后我还是用body了。。。。
            string passback_params = "用户id1231";
            //必填
            string total_fee = "0.01";
            //订单描述
            string body = "短信充值";
            //商品展示地址
            string show_url = "";
            //防钓鱼时间戳
            string anti_phishing_key = "";
            //客户端的IP地址
            string exter_invoke_ip = "";
            string it_b_pay        = "20m";

            //把请求参数打包成数组
            SortedDictionary <string, string> sParaTemp = new SortedDictionary <string, string>();

            sParaTemp.Add("partner", AlipayConfig.Partner);
            sParaTemp.Add("_input_charset", AlipayConfig.Input_charset.ToLower());
            sParaTemp.Add("service", "create_direct_pay_by_user");
            sParaTemp.Add("payment_type", payment_type);
            sParaTemp.Add("notify_url", notify_url);
            sParaTemp.Add("return_url", return_url);
            sParaTemp.Add("it_b_pay", it_b_pay);//订单未支付超时时间
            sParaTemp.Add("seller_email", seller_email);
            sParaTemp.Add("out_trade_no", out_trade_no);
            sParaTemp.Add("subject", subject);
            sParaTemp.Add("passback_params", passback_params);
            sParaTemp.Add("total_fee", total_fee);
            sParaTemp.Add("body", body);
            sParaTemp.Add("show_url", show_url);
            sParaTemp.Add("anti_phishing_key", anti_phishing_key);
            sParaTemp.Add("exter_invoke_ip", exter_invoke_ip);

            //建立请求
            string sHtmlText = AlipaySubmit.BuildRequest(sParaTemp, "get", "确认");

            Response.ContentType = "text/html";

            //不加utf-8,输出会乱码
            StreamWriter sw = new StreamWriter(Response.Body, Encoding.UTF8);
            await sw.WriteAsync(sHtmlText);

            await sw.FlushAsync();

            return(new EmptyResult());//也可以直接用task
        }
Пример #12
0
        private void Submit()
        {
            BaseService.WriteLog("支付宝交易开始-----------------------AlipayWapTrade2/Trade.aspx");
            BaseService.WriteLog("调用授权接口alipay.wap.trade.create.direct获取授权码token");
            ////////////////////////////////////////////调用授权接口alipay.wap.trade.create.direct获取授权码token////////////////////////////////////////////

            string order_id      = string.Empty;
            string call_back_url = AlipayConfig.Merchant_url;

            //订单号
            if (!string.IsNullOrEmpty(Request["order_id"]))
            {
                order_id = Request["order_id"].Trim();
                BaseService.WriteLog("order_id:  " + Request["order_id"]);
            }
            else
            {
                BaseService.WriteLog("请求参数order_id is null!!!!!");
            }
            //产品名称
            if (!string.IsNullOrEmpty(Request["prod_name"]))
            {
                AlipayConfig.Subject = Request["prod_name"].Trim();
                BaseService.WriteLog("prod_name:  " + Request["prod_name"]);
            }
            else
            {
                BaseService.WriteLog("请求参数prod_name is null!!!!!");
            }
            //产品价格
            if (!string.IsNullOrEmpty(Request["prod_price"]))
            {
                AlipayConfig.Total_fee = Request["prod_price"].Trim();
                BaseService.WriteLog("prod_price:  " + Request["prod_price"]);
            }
            else
            {
                BaseService.WriteLog("请求参数prod_price is null!!!!!");
            }
            //用户付款中途退出返回URL
            if (!string.IsNullOrEmpty(Request["merchant_url"]))
            {
                AlipayConfig.Merchant_url = Request["merchant_url"].Trim();
                BaseService.WriteLog("merchant_url:  " + Request["merchant_url"]);
            }
            else
            {
                BaseService.WriteLog("请求参数merchant_url is null!!!!!");
            }
            //用户付款成功同步返回URL
            if (!string.IsNullOrEmpty(Request["call_back_url"]))
            {
                call_back_url = Request["call_back_url"].Trim();
                BaseService.WriteLog("call_back_url:  " + Request["call_back_url"]);
            }
            else
            {
                BaseService.WriteLog("请求参数call_back_url is null!!!!!");
            }

            AlipayConfig.Req_id       = System.Guid.NewGuid().ToString().Replace("-", "");
            AlipayConfig.Out_trade_no = System.Guid.NewGuid().ToString().Replace("-", "");

            //分润参数
            if (!string.IsNullOrEmpty(Request["params"]))
            {
                BaseService.WriteLog("params:  " + Request["params"]);

                var entity = new AlipayRoyaltyEntity()
                {
                    RoyaltyID         = System.Guid.NewGuid().ToString().Replace("-", ""),
                    OutTradeNo        = AlipayConfig.Out_trade_no,
                    RoyaltyParameters = Request["params"]
                };

                //保存分润参数到数据库
                var royaltyServer = new AlipayRoyaltyBLL(Default.GetLoggingSession());
                royaltyServer.Create(entity);
            }
            else
            {
                BaseService.WriteLog("请求参数params is null!!!!!");
            }

            //请求业务参数详细
            string req_dataToken = ""
                                   + "<direct_trade_create_req>"
                                   + "<notify_url>" + AlipayConfig.Notify_url + "</notify_url>"
                                   + "<call_back_url>" + AlipayConfig.Call_back_url + "</call_back_url>"
                                   + "<seller_account_name>" + AlipayConfig.Seller_account_name + "</seller_account_name>"
                                   + "<out_trade_no>" + AlipayConfig.Out_trade_no + "</out_trade_no>"
                                   + "<subject>" + AlipayConfig.Subject + "</subject>"
                                   + "<total_fee>" + AlipayConfig.Total_fee + "</total_fee>"
                                   + "</direct_trade_create_req>";

            BaseService.WriteLog("请求业务参数详细: " + req_dataToken);

            //把请求参数打包成数组
            Dictionary <string, string> sParaTempToken = new Dictionary <string, string>();

            sParaTempToken.Add("partner", AlipayConfig.Partner);
            sParaTempToken.Add("_input_charset", AlipayConfig.Input_charset.ToLower());
            sParaTempToken.Add("sec_id", AlipayConfig.Sign_type.ToUpper());
            sParaTempToken.Add("service", AlipayConfig.Service_Create);
            sParaTempToken.Add("format", AlipayConfig.Format);
            sParaTempToken.Add("v", AlipayConfig.V);
            sParaTempToken.Add("req_id", AlipayConfig.Req_id);
            sParaTempToken.Add("req_data", req_dataToken);

            //建立请求
            string sHtmlTextToken = AlipaySubmit.BuildRequest(AlipayConfig.Req_url, sParaTempToken);
            //URLDECODE返回的信息
            Encoding code = Encoding.GetEncoding(AlipayConfig.Input_charset);

            sHtmlTextToken = HttpUtility.UrlDecode(sHtmlTextToken, code);

            //解析远程模拟提交后返回的信息
            Dictionary <string, string> dicHtmlTextToken = AlipaySubmit.ParseResponse(sHtmlTextToken);

            //获取token
            string request_token = dicHtmlTextToken["request_token"];

            BaseService.WriteLog("根据授权码token调用交易接口alipay.wap.auth.authAndExecute");
            ////////////////////////////////////////////根据授权码token调用交易接口alipay.wap.auth.authAndExecute////////////////////////////////////////////

            //业务详细
            string req_data = ""
                              + "<auth_and_execute_req>"
                              + "<request_token>" + request_token + "</request_token>"
                              + "</auth_and_execute_req>";

            BaseService.WriteLog("业务详细: " + req_data);

            //把请求参数打包成数组
            Dictionary <string, string> sParaTemp = new Dictionary <string, string>();

            sParaTemp.Add("partner", AlipayConfig.Partner);
            sParaTemp.Add("_input_charset", AlipayConfig.Input_charset.ToLower());
            sParaTemp.Add("sec_id", AlipayConfig.Sign_type.ToUpper());
            sParaTemp.Add("service", AlipayConfig.Service_Execute);
            sParaTemp.Add("format", AlipayConfig.Format);
            sParaTemp.Add("v", AlipayConfig.V);
            sParaTemp.Add("req_data", req_data);

            BaseService.WriteLog("保存交易记录到数据库");

            var alipayEntity = new AlipayWapTradeResponseEntity()
            {
                ResponseID  = System.Guid.NewGuid().ToString().Replace("-", ""),
                OrderID     = order_id,
                OutTradeNo  = AlipayConfig.Out_trade_no,
                Subject     = AlipayConfig.Subject,
                TotalFee    = AlipayConfig.Total_fee,
                MerchantUrl = AlipayConfig.Merchant_url,
                CallBackUrl = call_back_url,
                Status      = "1"
            };

            //保存交易记录到数据库
            AlipayWapTradeResponseBLL alipayServer = new AlipayWapTradeResponseBLL(new Utility.BasicUserInfo());

            alipayServer.Create(alipayEntity);

            //建立请求
            string sHtmlText = AlipaySubmit.BuildRequest(AlipayConfig.Req_url, sParaTemp, "get", "确认");

            Response.Write(sHtmlText);
        }
Пример #13
0
        protected void Page_Load(object sender, EventArgs e)
        {
            //充值配置验证
            int payId = GameRequest.GetInt("id", 0);

            if (payId <= 0)
            {
                Response.Redirect("/Menu/Buy.aspx");
            }
            RoomCardConfig config = FacadeManage.aideTreasureFacade.GetRoomCardConfig(payId);

            if (config == null)
            {
                Response.Redirect("/Menu/Buy.aspx");
            }

            //充值下单
            string      orderID     = PayHelper.GetOrderIDByPrefix("WapZFB");
            OnLineOrder onlineOrder = new OnLineOrder();

            onlineOrder.ShareID = 81;
            onlineOrder.OrderID = orderID;

            UserTicketInfo info = userTicket;

            onlineOrder.OperUserID  = info.UserID;
            onlineOrder.GameID      = info.GameID;
            onlineOrder.OrderAmount = config.Amount;
            onlineOrder.IPAddress   = GameRequest.GetUserIP();

            //生成订单
            Message umsg = FacadeManage.aideTreasureFacade.RequestOrderFK(onlineOrder, payId);

            if (!umsg.Success)
            {
                ShowInfo(umsg.Content);
                return;
            }

            #region 支付宝提交

            //接口名称
            string service = AlipayConfig.service;
            //合作者身份ID
            string partner = AlipayConfig.partner;
            //参数编码字符集
            string _input_charset = AlipayConfig.input_charset;
            //签名方式
            string sign_type = AlipayConfig.sign_type;
            //签名
            string sign = "";
            //服务器异步通知页面路径
            string notify_url = AlipayConfig.notify_url;
            //页面跳转同步通知页面路径
            string return_url = AlipayConfig.return_url;
            //商户网站唯一订单号
            string out_trade_no = orderID;
            //商品名称
            string subject = "充值房卡";
            //交易金额
            string total_fee = config.Amount.ToString();
            //卖家支付宝用户号
            string seller_id = AlipayConfig.seller_id;
            //支付类型
            string payment_type = AlipayConfig.payment_type;
            //商品展示网址
            string show_url = AlipayConfig.show_url;

            //把请求参数打包成数组
            SortedDictionary <string, string> sParaTemp = new SortedDictionary <string, string>();
            sParaTemp.Add("partner", partner);
            sParaTemp.Add("seller_id", seller_id);
            sParaTemp.Add("_input_charset", _input_charset);
            sParaTemp.Add("service", service);
            sParaTemp.Add("payment_type", payment_type);
            sParaTemp.Add("notify_url", notify_url);
            sParaTemp.Add("return_url", return_url);
            sParaTemp.Add("out_trade_no", out_trade_no);
            sParaTemp.Add("subject", subject);
            sParaTemp.Add("total_fee", total_fee);
            sParaTemp.Add("show_url", show_url);

            //建立请求
            string sHtmlText = AlipaySubmit.BuildRequest(sParaTemp, "get", "确认");
            Response.Write(sHtmlText);

            #endregion
        }
Пример #14
0
 private string PayAndRedirect(SortedDictionary <string, string> sParaTemp)
 {
     return(AlipaySubmit.BuildRequest(sParaTemp, "get", "确认"));
     //PaymentHubAlipay.HttpContext.Response.WriteAsync(s);
 }