Exemple #1
0
        /// <summary>
        /// 订单是否支付成功
        /// </summary>
        public bool IsPaySuccess(string orderNo, decimal amount)
        {
            bool success = false;

            //组装业务参数
            var model = new AlipayTradeQueryModel()
            {
                OutTradeNo = orderNo
            };

            var request = new AlipayTradeQueryRequest();

            request.SetBizModel(model);

            AlipayTradeQueryResponse response = aopClient.Execute(request);

            if (response != null && response.Code == "10000")
            {
                if (response.TradeStatus == AliPayTradeStatus.TRADE_SUCCESS.ToString() || response.TradeStatus == AliPayTradeStatus.TRADE_FINISHED.ToString())
                {
                    if (response.TotalAmount.ToDecimal() == amount)
                    {
                        success = true;
                    }
                }
            }

            //记日志response.ToJson();

            return(success);
        }
Exemple #2
0
    protected void BtnAlipay_Click(object sender, EventArgs e)
    {
        DefaultAopClient client = new DefaultAopClient(Config.gatewayUrl, Config.app_id, Config.merchant_private_key, "json", "1.0", Config.sign_type, Config.alipay_public_key, Config.charset, true);

        // 商户订单号,和交易号不能同时为空
        string out_trade_no = WIDout_trade_no.Text.Trim();

        // 支付宝交易号,和商户订单号不能同时为空
        string trade_no = WIDtrade_no.Text.Trim();

        AlipayTradeQueryModel model = new AlipayTradeQueryModel();

        model.OutTradeNo = out_trade_no;
        model.TradeNo    = trade_no;

        AlipayTradeQueryRequest request = new AlipayTradeQueryRequest();

        request.SetBizModel(model);

        AlipayTradeQueryResponse response = null;

        try
        {
            response       = client.Execute(request);
            WIDresule.Text = response.Body;
        }
        catch (Exception exp)
        {
            throw exp;
        }
    }
Exemple #3
0
        public PaymentInfo GetPaymentInfo(Order order)
        {
            AlipayTradeQueryModel model = new AlipayTradeQueryModel
            {
                OutTradeNo = order.ID,
                TradeNo    = order.PaymentID
            };

            AlipayTradeQueryRequest request = new AlipayTradeQueryRequest();

            request.SetBizModel(model);

            var response = _alipayService.Execute(request);
            var info     = JObject.Parse(response.Body).GetValue("alipay_trade_query_response").ToObject <AliPaymentResponse>();

            //response.Body;
            return(new PaymentInfo
            {
                Account = info.buyer_logon_id,
                PayDate = info.send_pay_date,
                TotalAmount = info.total_amount,
                TradeStatus = info.msg,
                Body = response.Body
            });
        }
Exemple #4
0
        public JsonResult QueryInfo(string tradeno, string alipayTradeNo)
        {
            DefaultAopClient client = new DefaultAopClient(Config.gatewayUrl, Config.app_id, Config.private_key, "json", "1.0", Config.sign_type, Config.alipay_public_key, Config.charset, false);

            AlipayTradeQueryModel model = new AlipayTradeQueryModel();

            // 商户订单号,和交易号不能同时为空
            model.OutTradeNo = tradeno;
            // 支付宝交易号,和商户订单号不能同时为空
            model.TradeNo = alipayTradeNo;

            AlipayTradeQueryRequest request = new AlipayTradeQueryRequest();

            request.SetBizModel(model);

            AlipayTradeQueryResponse response = null;

            try
            {
                response = client.Execute(request);
                return(Json(response.Body));
            }
            catch (Exception exp)
            {
                throw exp;
            }
        }
Exemple #5
0
        /// <summary>
        /// 查询订单
        /// </summary>
        public ActionResult Query()
        {
            DefaultAopClient client = new DefaultAopClient(Help.gatewayUrl, Help.app_id, Help.private_key, "json", "1.0", Help.sign_type, Help.alipay_public_key, Help.charset, false);

            // 商户订单号,和交易号不能同时为空
            string out_trade_no = "22222";

            // 支付宝交易号,和商户订单号不能同时为空
            string trade_no = "222222";

            AlipayTradeQueryModel model = new AlipayTradeQueryModel();

            model.OutTradeNo = out_trade_no;
            model.TradeNo    = trade_no;

            AlipayTradeQueryRequest request = new AlipayTradeQueryRequest();

            request.SetBizModel(model);

            AlipayTradeQueryResponse response = null;

            try
            {
                response = client.Execute(request);
                return(Content(response.Body));
            }
            catch (Exception exp)
            {
                throw exp;
            }
        }
        public static int AlipayAPPOrderQuery(string out_trade_no)
        {
            DefaultAopClient      client = new DefaultAopClient(AlipayConfig.mobile_gatewayUrl, AlipayConfig.mobile_app_id, AlipayConfig.mobile_private_key_value, "json", "1.0", AlipayConfig.sign_type, AlipayConfig.mobile_public_key_value, AlipayConfig.charset, false);
            AlipayTradeQueryModel model  = new AlipayTradeQueryModel();

            model.OutTradeNo = out_trade_no;

            AlipayTradeQueryRequest request = new AlipayTradeQueryRequest();

            request.BizContent = "{\"out_trade_no\":\"" + out_trade_no + "\"}";
            request.SetBizModel(model);
            AlipayTradeQueryResponse response = new AlipayTradeQueryResponse();

            try
            {
                response = client.Execute(request);
                if (response.TradeStatus.Equals(AliPayTradeStatus.WAIT_BUYER_PAY.ToString()))
                {
                    return(1);
                }
                if (response.TradeStatus.Equals(AliPayTradeStatus.TRADE_SUCCESS.ToString()))
                {
                    Web.APPCode.PaymentHelper.SaveRoomFee(out_trade_no, "APP支付宝支付", "支付宝");
                    return(2);
                }
                return(3);
            }
            catch (Exception exp)
            {
                LogHelper.WriteError("PaymentHelper", "AlipayAPPOrderQuery", exp);
                return(3);
            }
        }
Exemple #7
0
        public async Task <IActionResult> Query(string out_trade_no, string trade_no)
        {
            var model = new AlipayTradeQueryModel
            {
                OutTradeNo = out_trade_no,
                TradeNo    = trade_no
            };

            var req = new AlipayTradeQueryRequest();

            req.SetBizModel(model);

            var response = await _client.ExecuteAsync(req);

            ResponseModel responseModel = new ResponseModel()
            {
                code    = HTTPResponseCode.PartialContent,
                message = string.Empty,
                data    = response.Body
            };

            if (response.IsError)
            {
                responseModel.code    = HTTPResponseCode.BadRequest;
                responseModel.message = response.Msg;
            }
            else
            {
                responseModel.code = HTTPResponseCode.Successful;
            }
            return(Json(responseModel));
        }
        public IActionResult Query(string WIDout_trade_no, string WIDtrade_no)
        {
            DefaultAopClient client = new DefaultAopClient(_settings.Value.gateway_url, _settings.Value.app_id, _settings.Value.private_key, _settings.Value.format, _settings.Value.version, _settings.Value.sign_type, _settings.Value.alipay_public_key, _settings.Value.charset, false);

            // 商户订单号,和交易号不能同时为空
            string out_trade_no = WIDout_trade_no;

            // 支付宝交易号,和商户订单号不能同时为空
            string trade_no = WIDtrade_no;

            AlipayTradeQueryModel model = new AlipayTradeQueryModel
            {
                OutTradeNo = out_trade_no,
                TradeNo    = trade_no
            };

            AlipayTradeQueryRequest request = new AlipayTradeQueryRequest();

            request.SetBizModel(model);

            AlipayTradeQueryResponse response = null;

            try
            {
                response = client.Execute(request);
                // response.Body;
            }
            catch (Exception exp)
            {
                throw exp;
            }

            return(Content(response.Body));
        }
Exemple #9
0
		public Result<AlipayOrderQueryResult> QueryOrder(string orderNo) {
			var model = new AlipayTradeQueryModel {
				OutTradeNo = orderNo
			};
			var request = new AlipayTradeQueryRequest();
			request.SetBizModel(model);

			try {
				var response = _alipay.Execute(request);
				var ok = response is { IsError: false, Msg: "Success", TradeStatus: "TRADE_SUCCESS" };

				if ( !ok ) {
					return new Failure<AlipayOrderQueryResult>(response.SubMsg ?? response.Msg);
				}
				return new Success<AlipayOrderQueryResult> {
					Data = new AlipayOrderQueryResult {
						AlipayTradeNo = response.TradeNo,
						AlipayBuyerUserId = response.BuyerUserId,
						AlipayBuyerLogonId = response.BuyerLogonId,
						Amount = response.TotalAmount.AsDecimal(),
						OriginalResult = response
					}
				};
			}
			catch ( Exception e ) {
				return new Failure<AlipayOrderQueryResult>(e.Message);
			}
		}
Exemple #10
0
        // 查询
        public async Task <Pay_Order> Query(Pay_Order order)
        {
            var model = new AlipayTradeQueryModel
            {
                OutTradeNo = order.Order_SN
            };
            var req = new AlipayTradeQueryRequest();

            req.SetBizModel(model);

            var res = await client.ExecuteAsync(req, options.Value);

            if (res.TradeStatus == "TRADE_SUCCESS")
            {
                if (order.State == OrderState.Pending)
                {
                    return(OrderService.Paidup(
                               order,
                               res.TradeNo,
                               res.TotalAmount.ToObject <decimal>(),
                               res.SendPayDate,
                               PayType.Alipay
                               ));
                }
            }
            return(order);
        }
Exemple #11
0
        /// <summary>
        /// 查询订单
        /// </summary>
        /// <param name="request">提交给查询订单API的参数</param>
        /// <param name="config"></param>
        /// <param name="accessToken">用户授权token</param>
        /// <param name="timeOut">超时时间</param>
        /// <returns>成功时返回订单查询结果,其他抛异常</returns>
        public static async Task <AlipayTradeQueryResponse> OrderQueryAsync(AlipayTradeQueryModel request, AlipayConfig config, string accessToken = null, int timeOut = 6)
        {
            IAopClient client      = new AopClient(AlipayConstants.GATEWAYURL, config.AppId, config.PrivateKey, config.Format, config.Version, config.SignType, config.AliPublicKey, config.Charset, config.KeyFromFile);
            var        requestData = new AlipayTradeQueryRequest();

            requestData.SetBizModel(request);

            return(await client.ExecuteAsync(requestData, accessToken));
        }
Exemple #12
0
        /// <summary>
        /// 订单查询
        /// </summary>
        /// <param name="input">查询数据</param>
        /// <returns></returns>
        public async Task <AlipayTradeQueryResponse> Query(AlipayTradeQueryModel input)
        {
            var request = new AlipayTradeQueryRequest();

            request.SetBizModel(input);

            var response = await _alipayService.ExecuteAsync(request);

            return(response);
        }
        public string query(AlipayTradeQueryModel para)
        {
            AlipayTradeQueryRequest request = new AlipayTradeQueryRequest();

            // 将业务model载入到request
            request.SetBizModel(para);

            AlipayTradeQueryResponse response = client.Execute(request);

            return(response.Body);
        }
Exemple #14
0
        // 查询
        public async Task <AlipayTradeQueryResponse> Query(string order_sn)
        {
            var model = new AlipayTradeQueryModel
            {
                OutTradeNo = order_sn
            };

            var req = new AlipayTradeQueryRequest();

            req.SetBizModel(model);

            return(await client.ExecuteAsync(req, options.Value));
        }
Exemple #15
0
        public async Task <IActionResult> Query(AlipayTradeQueryViewModel viewMode)
        {
            var model = new AlipayTradeQueryModel
            {
                OutTradeNo = viewMode.OutTradeNo,
                TradeNo    = viewMode.TradeNo
            };

            var req = new AlipayTradeQueryRequest();

            req.SetBizModel(model);

            var response = await _client.CertificateExecuteAsync(req, _optionsAccessor.Value);

            return(Ok(response.Body));
        }
        public async Task <IActionResult> Query(string out_trade_no, string trade_no)
        {
            var model = new AlipayTradeQueryModel()
            {
                OutTradeNo = out_trade_no,
                TradeNo    = trade_no
            };

            var req = new AlipayTradeQueryRequest();

            req.SetBizModel(model);

            var response = await _client.ExecuteAsync(req);

            return(Ok(response.Body));
        }
        public async Task <IActionResult> Query(AlipayTradeQueryViewModel viewMode)
        {
            var model = new AlipayTradeQueryModel()
            {
                OutTradeNo = viewMode.OutTradeNo,
                TradeNo    = viewMode.TradeNo
            };

            var req = new AlipayTradeQueryRequest();

            req.SetBizModel(model);

            var response = await _client.ExecuteAsync(req);

            ViewData["response"] = response.Body;
            return(View());
        }
Exemple #18
0
        public JsonResult Query(string tradeno, string alipayTradeNo)
        {
            DefaultAopClient client = new DefaultAopClient(Config.Gatewayurl, Config.AppId, Config.PrivateKey, "json", "2.0",
                                                           Config.SignType, Config.AlipayPublicKey, Config.CharSet, false);
            AlipayTradeQueryModel model = new AlipayTradeQueryModel();

            model.OutTradeNo = tradeno;
            model.TradeNo    = alipayTradeNo;

            AlipayTradeQueryRequest request = new AlipayTradeQueryRequest();

            request.SetBizModel(model);

            var response = client.Execute(request);

            return(Json(response.Body));
        }
Exemple #19
0
        private void btnOrderStatus_Press(object sender, EventArgs e)
        {
            IAopClient client = GetAPOClient();
            //实例化具体API对应的request类,类名称和接口名称对应,当前调用接口名称如:alipay.trade.app.pay
            AlipayTradeQueryRequest request = new AlipayTradeQueryRequest();
            //SDK已经封装掉了公共参数,这里只需要传入业务参数。以下方法为sdk的model入参方式(model和biz_content同时存在的情况下取biz_content)。
            AlipayTradeQueryModel model = new AlipayTradeQueryModel();

            model.OutTradeNo = tradeNo;
            request.SetBizModel(model);
            //这是普通的接口使用Execute
            AlipayTradeQueryResponse response = client.Execute(request);

            //页面输出的response.Body就是orderString 可以直接给客户端请求,无需再做处理。
            System.Diagnostics.Debug.WriteLine(response.Body);
            MessageBox.Show(response.Body);
        }
Exemple #20
0
        public JsonResult Query(string tradeno, string alipayTradeNo)
        {
            IAopClient client = new DefaultAopClient(URL, APPID, APP_PRIVATE_KEY, FORMAT, "1.0", "RSA2", ALIPAY_PUBLIC_KEY, CHARSET, false);

            AlipayTradeQueryModel model = new AlipayTradeQueryModel
            {
                OutTradeNo = tradeno,
                TradeNo    = alipayTradeNo
            };

            AlipayTradeQueryRequest request = new AlipayTradeQueryRequest();

            request.SetBizModel(model);

            var response = client.Execute(request);

            return(Json(response.Body));
        }
        public async Task <JsonResult> Query(string tradeno, string alipayTradeNo)
        {
            /*DefaultAopClient client = new DefaultAopClient(Config.Gatewayurl, Config.AppId, Config.PrivateKey, "json", "2.0",
             *      Config.SignType, Config.AlipayPublicKey, Config.CharSet, false);*/
            AlipayTradeQueryModel model = new AlipayTradeQueryModel
            {
                OutTradeNo = tradeno,
                TradeNo    = alipayTradeNo
            };

            AlipayTradeQueryRequest request = new AlipayTradeQueryRequest();

            request.SetBizModel(model);

            var response = await _alipayService.ExecuteAsync(request);

            return(Json(response.Body));
        }
Exemple #22
0
        public bool QueryNow()
        {
            IAopClient alipayClient = GetAopClient();
            AlipayTradeQueryRequest alipayRequest = new AlipayTradeQueryRequest();
            AlipayTradeQueryModel   model         = new AlipayTradeQueryModel();

            model.OutTradeNo = Order.OrderNo;
            alipayRequest.SetBizModel(model);
            AlipayTradeQueryResponse response = alipayClient.Execute(alipayRequest);

            if (((string.Compare(response.TradeStatus, "TRADE_FINISHED") == 0 || string.Compare(response.TradeStatus, "TRADE_SUCCESS") == 0)))
            {
                var orderAmount = double.Parse(response.TotalAmount);
                if (Order.OrderAmount == orderAmount && string.Compare(Order.OrderNo, response.OutTradeNo) == 0)
                {
                    return(true);
                }
            }
            return(false);
        }
Exemple #23
0
        //订单查询接口
        public bool OrderQuery(Order order)
        {
            // 根据商户订单号查支付宝服务器上的订单信息
            string out_trade_no = order.Id.ToString();

            if (!string.IsNullOrEmpty(out_trade_no))
            {
                DefaultAopClient        client  = new DefaultAopClient(_aliPayPaymentSettings.GatewayUrl, _aliPayPaymentSettings.AppID, _aliPayPaymentSettings.PrivateKey, "json", "1.0", _aliPayPaymentSettings.SignType, _aliPayPaymentSettings.AlipayPublicKey, "UTF-8", false);
                AlipayTradeQueryRequest request = new AlipayTradeQueryRequest();
                request.SetBizModel(new AlipayTradeQueryModel()
                {
                    OutTradeNo = out_trade_no
                });
                AlipayTradeQueryResponse response = null;
                try
                {
                    response = client.Execute(request);
                    var    result       = JObject.Parse(response.Body);
                    string trade_status = Convert.ToString(result["alipay_trade_query_response"]["trade_status"]);
                    if (trade_status == "TRADE_SUCCESS" || trade_status == "TRADE_FINISHED")
                    {
                        return(true);
                    }
                }
                catch (Exception exp)
                {
                    //log
                    _logger.Information($"{DateTime.Now.ToLocalTime().ToString()}商城订单{order.Id}接口查询失败:{exp.Message}");
                    return(false);
                }
            }
            else
            {
                _logger.Information($"{DateTime.Now.ToLocalTime().ToString()}商城订单查询失败:无订单号");
            }
            return(false);
        }
Exemple #24
0
        /// <summary>
        /// 支付宝支付查询(蚂蚁金服)
        /// </summary>
        /// <param name="alipayTradeQueryInfo">查询信息</param>
        /// <param name="config">config</param>
        /// <returns>结果</returns>
        public static string QueryPayTrade(AlipayTradeQueryInfo alipayTradeQueryInfo, SdkPay.Config config)
        {
            const string                url          = SdkPay.Config.ServerUrl;
            string                      appId        = config.GetAppId();
            string                      rivateKeyPem = config.GetPrivateKeyPem();
            const string                format       = SdkPay.Config.Format;
            const string                version      = SdkPay.Config.Version;
            const string                signType     = SdkPay.Config.SignType;
            string                      publicKeyPem = config.GetPublicKeyPemAliPay();
            const string                charset      = SdkPay.Config.Charset;
            IAopClient                  client       = new DefaultAopClient(url, appId, rivateKeyPem, format, version, signType, publicKeyPem, charset, false);
            AlipayTradeQueryRequest     request      = new AlipayTradeQueryRequest();
            AlipayTradeAppPayQueryModel model        = new AlipayTradeAppPayQueryModel
            {
                out_trade_no = alipayTradeQueryInfo.OutTradeNo,
                trade_no     = alipayTradeQueryInfo.TradeNo
            };

            request.SetBizModel(model);
            AlipayTradeQueryResponse response = client.Execute(request);
            var body = response.Body;

            return(body);
        }
Exemple #25
0
        /// <summary>
        /// 主动查询支付结果
        /// </summary>
        /// <param name="orderCode">平台交易单号</param>
        /// <returns></returns>
        public override ApiResultModel <string> QueryPayResult(string orderCode)
        {
            IAopClient client = new DefaultAopClient(AliPayConfig.gatewayUrl, AliPayConfig.AppId, AliPayConfig.privatekey, "json", "1.0", AliPayConfig.sign_type, AliPayConfig.alipublickey, AliPayConfig.charset, false);
            //实例化具体API对应的request类,类名称和接口名称对应,当前调用接口名称如:alipay.trade.app.pay
            AlipayTradeQueryRequest request = new AlipayTradeQueryRequest();
            //SDK已经封装掉了公共参数,这里只需要传入业务参数。以下方法为sdk的model入参方式(model和biz_content同时存在的情况下取biz_content)。
            AlipayTradeQueryModel pmodel = new AlipayTradeQueryModel
            {
                TradeNo    = "",
                OutTradeNo = orderCode
            };

            request.SetBizModel(pmodel);
            //这里和普通的接口调用不同,使用的是sdkExecute
            AlipayTradeQueryResponse response = null;
            var reqTime = DateTime.Now;

            //HttpUtility.HtmlEncode是为了输出到页面时防止被浏览器将关键参数html转义,实际打印到日志以及http传输不会有这个问题
            try
            {
                response = client.Execute(request);

                //记录支付宝调用的日志
                //WritePostThirdApi(ThirdPlatformBusinessType.Payment, orderCode, ThirdPlatformType.Alipay, AliPayConfig.gatewayUrl, request.ToJsonString(), reqTime, response.Body, DateTime.Now, true);
            }
            catch (Exception ex)
            {
                //LogHelper.LogError(" 主动查询支付结果 - 支付宝预付款订单 QueryPayResult", ex.ToString());
                ////记录支付宝调用的日志
                //WritePostThirdApi(ThirdPlatformBusinessType.Payment, orderCode, ThirdPlatformType.Alipay, AliPayConfig.gatewayUrl, request.ToJsonString(), reqTime,
                //    response.IsNull() ? ex.ToString() : response.Body, DateTime.Now, true);
            }
            if (response != null && !response.IsError)
            {
                PayStatusType payStatusType = PayStatusType.UnPay;
                if (response.TradeStatus == "WAIT_BUYER_PAY")
                {
                    payStatusType = PayStatusType.UnPay;
                }
                else if (response.TradeStatus == "TRADE_CLOSED")
                {
                    payStatusType = PayStatusType.TimeOut;
                }
                else if (response.TradeStatus == "TRADE_SUCCESS")
                {
                    payStatusType = PayStatusType.Paid;
                }
                else if (response.TradeStatus == "TRADE_FINISHED")
                {
                    payStatusType = PayStatusType.Paid;
                }
                string tradeNo = response.TradeNo;
                //ConfrimPayResult(orderCode, tradeNo, payStatusType);
            }
            var res = new ApiResultModel <string>()
            {
                Code    = ApiResultCode.Success,
                Message = response.Body
            };

            return(res);
        }
Exemple #26
0
        public void ProcessRequest(HttpContext context)
        {
            try
            {
                string orderno      = context.Request.Form["orderno"];//查询的订单号
                string appid        = context.Request.Form["appid"];
                string account_type = context.Request.Form["account_type"];
                if (!string.IsNullOrEmpty(orderno))
                {
                    //查询订单支付状态
                    //获取账户信息
                    var type = Convert.ToInt32(account_type);
                    QueryAccountResult accountResult = ApiHelper.QueryPayAccount(appid, type, logger);
                    if (type == 2)
                    {//查询微信支付状态
                        string wxPayType = System.Configuration.ConfigurationManager.AppSettings["wxPayMtd"];
                        wxPayType = string.IsNullOrEmpty(wxPayType) ? "weixin" : wxPayType;
                        Message result = null;
                        var     config = new TenPayConfig()
                        {
                            appid  = accountResult.Appid,
                            key    = accountResult.Pubkey,
                            mch_id = accountResult.Mchid
                        };
                        if (wxPayType.Equals("weixin"))
                        {
                            result = TenPayMode.OrderQuery(config, orderno);
                        }
                        else if (wxPayType.Equals("pingan"))
                        {
                            result = PingAnPay.OrderQuery(config, orderno);
                        }
                        else
                        {
                            logger.Info("微信查询支付订单的wxPayType参数错误");//日志输出
                            context.Response.ContentType = "text/plain";
                            context.Response.Write(JsonConvert.SerializeObject(new { success = false, info = "查询出错" }));
                            return;
                        }

                        if (result.state)
                        {                                                                       //支付成功
                            logger.Info("微信查询支付订单的返回参数" + JsonConvert.SerializeObject(result)); //日志输出
                            context.Response.ContentType = "text/plain";
                            context.Response.Write(JsonConvert.SerializeObject(new { success = true, info = "支付成功" }));
                        }
                        else
                        {
                            logger.Info("微信查询支付订单的返回参数" + JsonConvert.SerializeObject(result));//日志输出
                            context.Response.ContentType = "text/plain";
                            context.Response.Write(JsonConvert.SerializeObject(new { success = false, info = "支付失败" }));
                        }
                    }
                    else
                    {
                        //查询支付宝支付状态
                        IAopClient client = new DefaultAopClient("https://openapi.alipay.com/gateway.do",
                                                                 accountResult.Appid, //"2017081108144704",//支付宝分配给开发者的应用ID
                                                                 accountResult.Prikey,
                                                                 "json",              //仅支持JSON
                                                                 "1.0",               //调用的接口版本,固定为:1.0
                                                                 "RSA2",              //商户生成签名字符串所使用的签名算法类型,目前支持RSA2和RSA,推荐使用RSA2
                                                                 accountResult.Pubkey,
                                                                 "utf-8",
                                                                 false);
                        AlipayTradeQueryRequest request = new AlipayTradeQueryRequest();
                        AlipayTradeQueryModel   model   = new AlipayTradeQueryModel();
                        model.OutTradeNo = orderno;
                        request.SetBizModel(model);
                        AlipayTradeQueryResponse response = client.Execute(request);
                        //获取响应返回的数据
                        if (!response.IsError)
                        {
                            if (response.TradeStatus == "TRADE_SUCCESS")
                            {
                                context.Response.ContentType = "text/plain";
                                context.Response.Write(JsonConvert.SerializeObject(new { success = true, info = "支付成功" }));
                            }
                            else
                            {
                                logger.Info("支付宝查询支付订单的返回参数" + response.Body);//日志输出
                                context.Response.ContentType = "text/plain";
                                context.Response.Write(JsonConvert.SerializeObject(new { success = false, info = "支付失败" }));
                            }
                        }
                        else
                        {                                                                     //错误信息
                            logger.Info("支付宝查询支付订单的返回参数:" + response.Code + response.SubMsg); //日志输出
                            context.Response.ContentType = "text/plain";
                            context.Response.Write(JsonConvert.SerializeObject(new { success = false, info = "支付失败" }));
                        }
                    }
                }
                else
                {
                    context.Response.ContentType = "text/plain";
                    context.Response.Write(JsonConvert.SerializeObject(new { success = false, info = "缺少参数" }));
                }
            }
            catch (Exception e)
            {
                logger.Info(e.Message);
                logger.Fatal(e.Message, e);
                var res = new { success = false, info = "服务错误" };
                context.Response.ContentType = "text/plain";
                context.Response.Write(JsonConvert.SerializeObject(res));
            }
        }
Exemple #27
0
    protected void Page_Load(object sender, EventArgs e)
    {
        // 商户订单号,和交易号不能同时为空
        string out_trade_no = Request.Form["out_trade_no"];
        // 支付宝交易号,和商户订单号不能同时为空
        string trade_no = Request.Form["trade_no"];
        string key      = Request.Form["key"];
        object result   = null;

        try
        {
            if (DataAccess.ExecuteScalar <int>(string.Format("select count(*) from Merchant where MerchantKey='{0}'", key)) == 0)
            {
                result = new ResponseResult()
                {
                    code             = "40001",
                    msg              = "Invalid merchant key",
                    sub_code         = "ACQ.INVALID_KEY",
                    sub_msg          = "无效的商户秘钥",
                    buyer_pay_amount = "0.00",
                    invoice_amount   = "0.00",
                    out_trade_no     = out_trade_no,
                    point_amount     = "0.00",
                    receipt_amount   = "0.00"
                };
            }
            else
            {
                var sql = string.Format("select count(*) from Orders where CaseNumber='{0}'", out_trade_no);

                if (DataAccess.ExecuteScalar <int>(sql) == 1)
                {
                    sql = string.Format("select seller_email from Orders where CaseNumber='{0}'", out_trade_no);
                    var seller_email     = DataAccess.ExecuteScalar <string>(sql);
                    var aliAccount       = Config.getAliAccount(seller_email);
                    var alipayPublicKey  = string.Format(Config.alipay_public_key, aliAccount.AppName);
                    var alipayPrivateKey = string.Format(Config.merchant_private_key, aliAccount.AppName);

                    DefaultAopClient client = new DefaultAopClient(Config.gatewayUrl, aliAccount.AppId, alipayPrivateKey, "json", "1.0", Config.sign_type, alipayPublicKey, Config.charset, true);

                    AlipayTradeQueryModel model = new AlipayTradeQueryModel();
                    model.OutTradeNo = out_trade_no;
                    model.TradeNo    = trade_no;

                    AlipayTradeQueryRequest request = new AlipayTradeQueryRequest();
                    request.SetBizModel(model);

                    AlipayTradeQueryResponse response = client.Execute(request);

                    JObject jo = (JObject)JsonConvert.DeserializeObject(response.Body);
                    result = jo["alipay_trade_query_response"];
                }
                else
                {
                    result = new ResponseResult()
                    {
                        code             = "40004",
                        msg              = "Business Failed",
                        sub_code         = "ACQ.TRADE_NOT_EXIST",
                        sub_msg          = "交易不存在",
                        buyer_pay_amount = "0.00",
                        invoice_amount   = "0.00",
                        out_trade_no     = out_trade_no,
                        point_amount     = "0.00",
                        receipt_amount   = "0.00"
                    };
                }
            }
        }
        catch (Exception exp)
        {
            Logger.Log("query::" + exp.ToString());
            result = new ResponseResult()
            {
                code             = "50000",
                msg              = "Internal server error",
                sub_code         = "ACQ.INTERNAL_SERVER_ERROR",
                sub_msg          = "服务器异常",
                buyer_pay_amount = "0.00",
                invoice_amount   = "0.00",
                out_trade_no     = out_trade_no,
                point_amount     = "0.00",
                receipt_amount   = "0.00"
            };
        }

        Response.ContentType = "application/json; charset=utf-8";
        Response.Write(JsonConvert.SerializeObject(result));
    }