예제 #1
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();
            var notifyData = new AllinpayData(AllinpayDataType.PayResult);

            notifyData.FromUrl(data);

            //校验参数个数
            if (notifyData.GetValues().Count == 0)
            {
                result.Status            = ResultStatus.Failure;
                result.Message           = resultInfo.ResultDesc = "支付结果无通知参数";
                resultInfo.ExecuteResult = (int)ResultStatus.Failure;
                PayResultDAL.Update(resultInfo);
                return(result);
            }

            //校验参数合法性
            resultInfo.OrderId = notifyData.GetValue("orderNo");
            bool verifyResult = AllinpayCore.VerifyResultSign(notifyData);

            if (!verifyResult)
            {
                result.Status            = ResultStatus.Failure;
                result.Message           = resultInfo.ResultDesc = "verify failed";
                resultInfo.ExecuteResult = (int)ResultStatus.Failure;
                PayResultDAL.Update(resultInfo);
                return(result);
            }

            result.Status = ResultStatus.Success;
            return(result);
        }
예제 #2
0
        /// <summary>
        /// 发起退款请求
        /// </summary>
        /// <param name="data"></param>
        /// <returns></returns>
        public static ExecuteResult <AllinpayData> RefundRequest(AllinpayData data)
        {
            var    result   = new ExecuteResult <AllinpayData>();
            string param    = data.ToUrl();
            string response = HttpHelper.HttpRequest("post", AppConfig.Global.AllinpayRefundServerUrl, param);

            if (response == null)
            {
                result.Status  = ResultStatus.Failure;
                result.Message = "请求发送异常";
                return(result);
            }
            var responseData = new AllinpayData(AllinpayDataType.RefundResponse);

            responseData.FromUrl(response);
            result.Data = responseData;
            if (responseData.HasValue("ERRORCODE") || responseData.HasValue("ERRORMSG"))
            {
                LogWriter.WriteLog(data.GetValue("orderNo") + "退款响应数据:" + response, AppConfig.Global.AllinpayLogFolder);
                result.Status  = ResultStatus.Failure;
                result.Message = string.Format("{0}(错误码:{1})", responseData.GetValue("ERRORMSG"), responseData.GetValue("ERRORCODE"));
                return(result);
            }
            if (!AllinpayCore.VerifyRefundSign(responseData))
            {
                LogWriter.WriteLog(data.GetValue("orderNo") + "退款响应数据:" + response, AppConfig.Global.AllinpayLogFolder);
                result.Status  = ResultStatus.Failure;
                result.Message = "退款响应数据签名校验未通过";
                return(result);
            }
            //退款结果(成功:20  其他为失败)
            if (responseData.GetValue("refundResult") != "20")
            {
                LogWriter.WriteLog(data.GetValue("orderNo") + "退款响应数据:" + response, AppConfig.Global.AllinpayLogFolder);
                result.Status  = ResultStatus.Failure;
                result.Message = string.Format("退款失败(错误码:{0})", responseData.GetValue("errorCode"));
                return(result);
            }
            result.Status = ResultStatus.Success;
            return(result);
        }