示例#1
0
        public override string BeginPay(PayParameter parameter)
        {
            var config = PayFactory.GetConfig <Config>(this.GetType(), parameter.TradeID);

            var head = new Dictionary <string, object>();

            head["service"] = ServiceType;

            var body = new Dictionary <string, object>();

            body["merchant_no"]      = config.merchant_id;
            body["channel_type"]     = ChannelType;
            body["out_trade_no"]     = parameter.TradeID;
            body["total_amount"]     = parameter.Amount.ToString();
            body["subject"]          = parameter.TradeName;
            body["spbill_create_ip"] = "8.8.8.8";
            body["auth_code"]        = parameter.AuthCode;

            var strResult = LianTuo_Helper.PostJsonReturnString(config, URL, head, body, parameter.RequestTimeout);

            PayFactory.OnLog(parameter.TradeID, LogEventType.ReceivePayResult, strResult);

            var responseObj = Newtonsoft.Json.JsonConvert.DeserializeObject <ResponseObject>(strResult);

            string serverSign = responseObj.head["sign"].ToString();

            if (LianTuo_Helper.Sign(config.key, responseObj.head, responseObj.body) != serverSign)
            {
                throw new Exception("服务器返回信息签名检验失败");
            }

            if ((string)responseObj.body["is_success"] == "S")
            {
                double?receipt_amount = null;
                try
                {
                    if (responseObj.body["receipt_amount"] != null)
                    {
                        receipt_amount = Convert.ToDouble(responseObj.body["receipt_amount"]);
                    }
                }
                catch
                {
                }
                PayFactory.OnPaySuccessed(parameter.TradeID, receipt_amount, null, strResult);
            }
            else if ((string)responseObj.body["is_success"] == "F")
            {
                throw new Exception((string)responseObj.body["message"]);
            }
            else if ((string)responseObj.body["is_success"] == "P")
            {
                new Thread(() =>
                {
                    CheckPayStateInLoop(parameter);
                }).Start();
            }
            return(null);
        }
示例#2
0
        public override bool CheckPayState(PayParameter parameter)
        {
            var config = PayFactory.GetConfig <Config>(this.GetType(), parameter.TradeID);

            var head = new Dictionary <string, object>();

            head["service"] = "front.query";

            var body = new Dictionary <string, object>();

            body["out_trade_no"] = parameter.TradeID;

            var strResult = LianTuo_Helper.PostJsonReturnString(config, URL, head, body, parameter.RequestTimeout);

            var responseObj = Newtonsoft.Json.JsonConvert.DeserializeObject <ResponseObject>(strResult);

            string serverSign = responseObj.head["sign"].ToString();

            if (LianTuo_Helper.Sign(config.key, responseObj.head, responseObj.body) != serverSign)
            {
                throw new Exception("服务器返回信息签名检验失败");
            }

            if ((string)responseObj.body["is_success"] == "S")
            {
                if ((string)responseObj.body["trade_status"] == "success")
                {
                    double?receipt_amount = null;
                    try
                    {
                        if (responseObj.body["receipt_amount"] != null)
                        {
                            receipt_amount = Convert.ToDouble(responseObj.body["receipt_amount"]);
                        }
                    }
                    catch
                    {
                    }
                    PayFactory.OnPaySuccessed(parameter.TradeID, receipt_amount, null, strResult);
                    return(true);
                }
                else if ((string)responseObj.body["trade_status"] == "fail")
                {
                    PayFactory.OnPayFailed(parameter.TradeID, (string)responseObj.body["trade_error_msg"], strResult);
                    return(true);
                }
                else if ((string)responseObj.body["trade_status"] == "closed")
                {
                    throw new Exception("订单已关闭");
                }
                else if ((string)responseObj.body["trade_status"] == "cancel")
                {
                    throw new Exception("订单已取消");
                }
            }
            return(false);
        }
        public TaskStatus Handle(IHttpProxy httpProxy)
        {
            try
            {
                var requestJson = httpProxy.Form["requestJson"];
                if (!string.IsNullOrEmpty(requestJson))
                {
                    var responseObj = Newtonsoft.Json.JsonConvert.DeserializeObject <ResponseObject>(requestJson);
                    var tradeId     = responseObj.body["out_trade_no"].ToString();
                    var config      = PayFactory.GetConfig <Config>(typeof(LianTuo_WeixinJsApi), tradeId);

                    string serverSign = responseObj.head["sign"].ToString();
                    if (LianTuo_Helper.Sign(config.key, responseObj.head, responseObj.body) != serverSign)
                    {
                        throw new Exception("服务器返回信息签名检验失败");
                    }

                    if ((string)responseObj.body["is_success"] == "S")
                    {
                        double?receipt_amount = null;
                        try
                        {
                            if (responseObj.body["receipt_amount"] != null)
                            {
                                receipt_amount = Convert.ToDouble(responseObj.body["receipt_amount"]);
                            }
                        }
                        catch
                        {
                        }
                        PayFactory.OnPaySuccessed(tradeId, receipt_amount, null, requestJson);
                    }
                    else if ((string)responseObj.body["is_success"] == "F")
                    {
                        PayFactory.OnPayFailed(tradeId, (string)responseObj.body["message"], requestJson);
                    }
                }
                httpProxy.ResponseWrite("success");
            }
            catch (Exception ex)
            {
                using (Log log = new Log("Jack.Pay.LianTuo.WXJSApi.Result Error", false))
                {
                    log.Log(ex.ToString());
                    log.LogJson(httpProxy.Form);
                }
            }
            return(TaskStatus.Completed);
        }
示例#4
0
        public override RefundResult Refund(RefundParameter parameter)
        {
            var config = PayFactory.GetConfig <Config>(this.GetType(), parameter.TradeID);

            var head = new Dictionary <string, object>();

            head["service"] = "front.refund";

            var body = new Dictionary <string, object>();

            body["merchant_no"]      = config.merchant_id;
            body["out_trade_no"]     = parameter.TradeID;
            body["out_refund_no"]    = Guid.NewGuid().ToString("N");
            body["refund_fee"]       = parameter.Amount;
            body["refund_reason"]    = parameter.Reason;
            body["spbill_create_ip"] = "8.8.8.8";

            var strResult = LianTuo_Helper.PostJsonReturnString(config, URL, head, body, 8);

            var responseObj = Newtonsoft.Json.JsonConvert.DeserializeObject <ResponseObject>(strResult);

            string serverSign = responseObj.head["sign"].ToString();

            if (LianTuo_Helper.Sign(config.key, responseObj.head, responseObj.body) != serverSign)
            {
                throw new Exception("服务器返回信息签名检验失败");
            }

            if ((string)responseObj.body["is_success"] == "S")
            {
                return(new RefundResult {
                    Result = RefundResult.ResultEnum.SUCCESS,
                    ServerMessage = strResult
                });
            }
            else if ((string)responseObj.body["is_success"] == "F")
            {
                return(new RefundResult
                {
                    Error = (string)responseObj.body["message"],
                    Result = RefundResult.ResultEnum.FAIL,
                    ServerMessage = strResult
                });
            }
            return(CheckRefundStateInLoop(parameter.TradeID, (string)body["out_refund_no"]));
        }
示例#5
0
        /// <summary>
        /// 查询退款状态
        /// </summary>
        /// <param name="tradeId"></param>
        /// <param name="refundNo">退款交易号</param>
        /// <returns></returns>
        public RefundResult CheckRefundState(string tradeId, string refundNo)
        {
            var config = PayFactory.GetConfig <Config>(this.GetType(), tradeId);

            var head = new Dictionary <string, object>();

            head["service"] = "front.refundquery";

            var body = new Dictionary <string, object>();

            body["out_refund_no"] = refundNo;

            var strResult = LianTuo_Helper.PostJsonReturnString(config, URL, head, body, 8);

            var responseObj = Newtonsoft.Json.JsonConvert.DeserializeObject <ResponseObject>(strResult);

            string serverSign = responseObj.head["sign"].ToString();

            if (LianTuo_Helper.Sign(config.key, responseObj.head, responseObj.body) != serverSign)
            {
                throw new Exception("服务器返回信息签名检验失败");
            }

            if ((string)responseObj.body["is_success"] == "S")
            {
                if ((string)responseObj.body["refund_status"] == "success")
                {
                    return(new RefundResult
                    {
                        Result = RefundResult.ResultEnum.SUCCESS,
                        ServerMessage = strResult
                    });
                }
                else if ((string)responseObj.body["refund_status"] == "fail")
                {
                    return(new RefundResult
                    {
                        Error = (string)responseObj.body["refund_error_msg"],
                        Result = RefundResult.ResultEnum.FAIL,
                        ServerMessage = strResult
                    });
                }
            }
            return(null);
        }
示例#6
0
        public override string BeginPay(PayParameter parameter)
        {
            bool enableNotify = false;
            var  config       = PayFactory.GetConfig <Config>(this.GetType(), parameter.TradeID);

            var head = new Dictionary <string, object>();

            head["service"] = "front.jsapi";

            var body = new Dictionary <string, object>();

            body["merchant_no"]      = config.merchant_id;
            body["channel_type"]     = "WX";
            body["out_trade_no"]     = parameter.TradeID;
            body["total_amount"]     = parameter.Amount.ToString();
            body["subject"]          = parameter.TradeName;
            body["spbill_create_ip"] = "8.8.8.8";
            body["open_id"]          = parameter.AuthCode;
            body["sub_appid"]        = config.weixin_appid;
            if (!string.IsNullOrEmpty(parameter.NotifyDomain))
            {
                enableNotify       = true;
                body["notify_url"] = $"{parameter.NotifyDomain}/{PayResult_RequestHandler.NotifyPageName}";
            }


            var strResult = LianTuo_Helper.PostJsonReturnString(config, URL, head, body, parameter.RequestTimeout);

            PayFactory.OnLog(parameter.TradeID, LogEventType.ReceivePayResult, strResult);

            var responseObj = Newtonsoft.Json.JsonConvert.DeserializeObject <ResponseObject>(strResult);

            string serverSign = responseObj.head["sign"].ToString();

            if (LianTuo_Helper.Sign(config.key, responseObj.head, responseObj.body) != serverSign)
            {
                throw new Exception("服务器返回信息签名检验失败");
            }

            if ((string)responseObj.body["is_success"] == "S")
            {
                if (enableNotify == false)
                {
                    new Thread(() =>
                    {
                        CheckPayStateInLoop(parameter);
                    }).Start();
                }
                //pay_info参数是微信jsapi发起的参数
                var jsonWeiXinBody = Newtonsoft.Json.JsonConvert.DeserializeObject <string>(responseObj.body["pay_info"].ToString());
                Dictionary <string, string> returnDict = Newtonsoft.Json.JsonConvert.DeserializeObject <Dictionary <string, string> >(jsonWeiXinBody);

                returnDict["ReturnUrl"] = parameter.ReturnUrl;
                returnDict["TradeID"]   = parameter.TradeID;
                var jsonStr = Newtonsoft.Json.JsonConvert.SerializeObject(returnDict);


                //先把jsonStr保存成一个临时文件
                string tranid   = Guid.NewGuid().ToString("N");
                string tempFile = $"{Helper.GetSaveFilePath()}\\{tranid}.txt";
                System.IO.File.WriteAllText(tempFile, jsonStr, Encoding.UTF8);

                return($"{parameter.NotifyDomain}/{Weixin.WeiXinPayRedirect_RequestHandler.NotifyPageName}?tranId={tranid}");
            }
            else if ((string)responseObj.body["is_success"] == "F")
            {
                throw new Exception((string)responseObj.body["message"]);
            }
            return(null);
        }