コード例 #1
0
        /// <summary>
        /// 查询订单的支付结果
        /// </summary>
        /// <param name="orderId">订单编号</param>
        /// <param name="tradeNo">交易流水号</param>
        /// <returns></returns>
        public ActionResult Query(string orderId = "", string tradeNo = "")
        {
            HttpResponseBase response = HttpContext.Response;

            try
            {
                var resData = SwiftPassPayApi.OrderQuery(orderId, tradeNo);
                var xmlStr  = resData.ToXml(false);
                response.ContentType = "text/xml";
                response.Write(xmlStr);
            }
            catch (Exception ex)
            {
                response.Write("系统执行时发生异常:" + ex.Message);
            }
            return(new EmptyResult());
        }
コード例 #2
0
ファイル: PayResult.cs プロジェクト: iampkm/ebs.pay
        /// <summary>
        /// 校验支付结果请求
        /// </summary>
        /// <param name="data">业务数据报文</param>
        /// <param name="resultInfo">支付结果记录</param>
        /// <returns></returns>
        public override ExecuteResult CheckRequest(string data, PayResultInfo resultInfo)
        {
            var result = new ExecuteResult();

            try
            {
                //校验请求报文
                var notifyData = new ParameterData();
                notifyData.FromXml(data);
                resultInfo.OrderId = notifyData.GetValue("out_trade_no");
                if (notifyData.GetValue("status") != "0") //校验返回状态
                {
                    throw new BizException("返回状态错误代码:" + notifyData.GetValue("status") + ",错误信息:" + notifyData.GetValue("message"));
                }

                if (!SwiftPassCore.CheckSign(notifyData)) //校验数据签名
                {
                    throw new BizException("签名校验未通过");
                }

                if (notifyData.GetValue("result_code") != "0") //校验业务结果
                {
                    throw new BizException("业务结果错误代码:" + notifyData.GetValue("err_code") + ",错误信息:" + notifyData.GetValue("err_msg"));
                }

                if (notifyData.GetValue("pay_result") != "0") //校验支付结果
                {
                    resultInfo.ExecuteResult = (int)ResultStatus.Failure;
                    resultInfo.ResultDesc    = "用户支付失败:" + notifyData.GetValue("pay_info");
                    PayResultDAL.Update(resultInfo);

                    result.Message = resultInfo.ResultDesc;
                    result.Status  = ResultStatus.Failure;
                    return(result);
                }

                //检查支付结果中transaction_id是否存在
                resultInfo.TradeNo = notifyData.GetValue("transaction_id");
                if (string.IsNullOrEmpty(resultInfo.TradeNo))
                {
                    resultInfo.ExecuteResult = (int)ResultStatus.Failure;
                    resultInfo.ResultDesc    = "支付结果中平台交易单号不存在";
                    PayResultDAL.Update(resultInfo);

                    result.Message = resultInfo.ResultDesc;
                    result.Status  = ResultStatus.Failure;
                    return(result);
                }

                //查询支付单,判断支付单真实性
                var queryData = SwiftPassPayApi.OrderQuery(resultInfo.OrderId, resultInfo.TradeNo);
                if (queryData.GetValue("status") != "0" || //校验返回状态
                    queryData.GetValue("result_code") != "0" || //校验业务结果
                    !SwiftPassCore.CheckSign(queryData) || //校验数据签名
                    queryData.GetValue("trade_state") != "SUCCESS")    //校验交易状态
                {
                    resultInfo.ExecuteResult = (int)ResultStatus.Failure;
                    resultInfo.ResultDesc    = "平台交易单号查询失败";
                    PayResultDAL.Update(resultInfo);

                    result.Message = resultInfo.ResultDesc;
                    result.Status  = ResultStatus.Failure;
                    return(result);
                }
            }
            catch (BizException wex)
            {
                resultInfo.ExecuteResult = (int)ResultStatus.Error;
                resultInfo.ResultDesc    = wex.Message;
                PayResultDAL.Update(resultInfo);

                result.Message = resultInfo.ResultDesc;
                result.Status  = ResultStatus.Error;
                return(result);
            }
            result.Status = ResultStatus.Success;
            return(result);
        }