Пример #1
0
        /// <summary>
        /// 多利储值卡充值方法
        /// </summary>
        /// <param name="customerId"></param>
        /// <param name="orderId"></param>
        /// <returns></returns>
        public string RechargeTonysCardAct2(AppOrderEntity appOrder)
        {
            try
            {
                string msg  = string.Empty;
                var    rest = GetTonyCardInfo(appOrder.AppOrderID, appOrder.AppClientID, out msg);
                if (!rest.Item1)
                {
                    Loggers.Debug(new DebugLogInfo()
                    {
                        Message = string.Format("多利【{0}】充值异常:{1}", appOrder.AppOrderID, msg),
                    });
                }

                if (rest.Item4 == 0)
                {
                    // 调用储值卡充值接口
                    var rspData = RechargeCard(rest.Item2, rest.Item3, appOrder);
                    CreateTonyCardChargeOrder(appOrder, rspData);
                }
            }
            catch (Exception ex)
            {
                Loggers.Debug(new DebugLogInfo()
                {
                    Message = string.Format("多利【{0}】充值异常:" + ex.Message),
                });
            }
            return("SUCCESS");
        }
Пример #2
0
        private string CreateTonyCardChargeOrder(AppOrderEntity appOrder, string rspData)
        {
            string returnStr = "FAIL";

            try
            {
                var    notifyUrl = ConfigurationManager.AppSettings["ApiHost"] + "OnlineShopping/data/Data.aspx";
                string param     = "{\"common\": { \"isALD\": \"0\", \"customerId\": \"" + appOrder.AppClientID + "\", \"locale\": \"zh\"}, \"special\": { \"orderId\": \"" + appOrder.AppOrderID + "\",\"status\":\"" + (rspData == "SUCCESS" ? "2" : "1") + "\"} }";
                string fulParam  = string.Format("action=createTonyCardChargeOrder&ReqContent={0}", param);
                Loggers.Debug(new DebugLogInfo()
                {
                    Message = "GetTonyCardInfo 开始调用通知接口:" + notifyUrl + "?" + fulParam
                });
                returnStr = HttpService.Get(notifyUrl + "?" + fulParam);
                string message = returnStr == "SUCCESS" ? " CreateTonyCardChargeOrder调用通知接口成功" : " CreateTonyCardChargeOrder调用通知接口失败";
                message += (":" + returnStr);
                Loggers.Debug(new DebugLogInfo()
                {
                    Message = message
                });
                return(returnStr);
            }
            catch (Exception ex)
            {
            }
            return(returnStr);
        }
Пример #3
0
        /// <summary>
        /// 通知cpos
        /// </summary>
        /// <param name="pEntity"></param>
        /// <param name="msg"></param>
        /// <param name="ht">附加参数</param>
        /// <param name="isTonyCard"></param>
        /// <returns></returns>
        public static bool Notify(AppOrderEntity pEntity, out string msg, Hashtable ht, bool isTonyCard = false)
        {
            string content = string.Format("OrderID={0}&OrderStatus={1}&CustomerID={2}&UserID={3}&ChannelID={4}&SerialPay={5}&isTonyCard={6}", pEntity.AppOrderID, pEntity.Status, pEntity.AppClientID, pEntity.AppUserID, pEntity.PayChannelID, pEntity.OrderID, isTonyCard ? 1 : 0);

            // 附加参数
            if (ht.Count > 0)
            {
                foreach (DictionaryEntry item in ht)
                {
                    content += "&" + item.Key + "=" + item.Value;
                }
            }
            var    channelbll = new PayChannelBLL(new JIT.Utility.BasicUserInfo());
            var    channel    = channelbll.GetByID(pEntity.PayChannelID);
            string notifyUrl  = channel.NotifyUrl;

            Loggers.Debug(new DebugLogInfo()
            {
                Message = "wx pay Notify 开始调用通知接口:" + pEntity.ToJSON()
            });
            var    i       = NotifyHandler.Notify(channel.NotifyUrl, content, out msg);
            string message = i ? " wx pay Notify 调用通知接口成功" : " wx pay Notify 调用通知接口失败";

            message += (":" + msg + "::" + notifyUrl + "?" + content);
            Loggers.Debug(new DebugLogInfo()
            {
                Message = message
            });
            return(i);
        }
Пример #4
0
        /// <summary>
        /// 调用汇付支付接口
        /// </summary>
        /// <param name="rp"></param>
        /// <param name="appOrder"></param>
        /// <returns></returns>
        private static BaseRsponse Consumption(PrePaidCardPayRP rp, AppOrderEntity appOrder, out string errMsg)
        {
            errMsg = string.Empty;
            string url          = PrePaidCardUtil.GetTonyRechargeUrl();
            string desKey       = PrePaidCardUtil.GetEncodingKey();
            string merchantCode = PrePaidCardUtil.GetMerchantCode();
            BaseRequest <RechargeReqBody> req = new BaseRequest <RechargeReqBody>();
            var recordBll    = new PayRequestRecordBLL(new Utility.BasicUserInfo());
            int amount       = appOrder.AppOrderAmount.Value;
            var recordEntity = new PayRequestRecordEntity()
            {
                ChannelID = appOrder.PayChannelID,
                ClientID  = appOrder.AppClientID,
                UserID    = appOrder.AppUserID,
                Platform  = 8
            };

            req.bizCd             = HuiFuInterfaceEnum.consumption.ToString();
            req.reqSeq            = DateTime.Now.ToString("yyMMddHHmmss");
            req.reqBody           = new RechargeReqBody();
            req.reqBody.orderId   = DateTime.Now.ToString("yyyyMMddHHmmssffff");
            req.reqBody.transDate = DateTime.Now.ToString("yyyyMMddHHmmss");
            req.reqBody.transAmt  = (amount * 100).ToString();
            // req.reqBody.cardNo = "9300100203000020002";
            // req.reqBody.transAmt = "10";    // 交易金额以分为单位
            req.reqBody.cardNo   = rp.CardNo;
            req.reqBody.passWord = rp.Password;

            string reqJson = JsonMapper.ToJson(req).Replace("\\\"", "'");
            string strReq  = CommonUtil.EncryptDES(reqJson, desKey);

            url = string.Format("{0}{1}&merchantCode={2}", url, HttpContext.Current.Server.UrlEncode(strReq), merchantCode);
            string result = HttpService.Get(url);

            string strRsp = CommonUtil.DecryptDES(result);

            Loggers.Debug(new DebugLogInfo()
            {
                Message = string.Format("多利【{0}】充值结果:", appOrder.AppOrderID) + strRsp,
            });
            recordEntity.RequestJson  = reqJson;
            recordEntity.ResponseJson = strRsp;
            recordBll.Create(recordEntity);

            var rspEntity = JsonMapper.ToObject <BaseRsponse>(strRsp);

            // var rsp = rspEntity.rspCd == "0000" ? "SUCCESS" : "FAIL";
            return(rspEntity);
        }
Пример #5
0
        public static bool Notify(AppOrderEntity pEntity, out string msg)
        {
            string content    = string.Format("OrderID={0}&OrderStatus={1}&CustomerID={2}&UserID={3}&ChannelID={4}&SerialPay={5}", pEntity.AppOrderID, pEntity.Status, pEntity.AppClientID, pEntity.AppUserID, pEntity.PayChannelID, pEntity.OrderID);
            var    channelbll = new PayChannelBLL(new JIT.Utility.BasicUserInfo());
            var    channel    = channelbll.GetByID(pEntity.PayChannelID);

            Loggers.Debug(new DebugLogInfo()
            {
                Message = "开始调用通知接口:" + pEntity.ToJSON()
            });
            var i = Notify(channel.NotifyUrl, content, out msg);

            Loggers.Debug(new DebugLogInfo()
            {
                Message = i ? "调用通知接口成功" : "调用通知接口失败"
            });
            return(i);
        }
Пример #6
0
        /// <summary>
        /// 服务商支付
        /// </summary>
        /// <param name="entity"></param>
        /// <returns></returns>
        public PrePayResult serPrePay(AppOrderEntity entity)
        {
            string appid   = ConfigurationManager.AppSettings["appid"];
            string mch_id  = ConfigurationManager.AppSettings["mch_id"];
            string signKey = ConfigurationManager.AppSettings["signKey"];

            Loggers.Debug(new DebugLogInfo()
            {
                Message = "entity:" + entity.ToJSON()
            });
            Loggers.Debug(new DebugLogInfo()
            {
                Message = "appid:" + appid + "mch_id:"
                          + mch_id + "sub_appid:" + this.channel.appid + "sub_mch_id:" + this.channel.mch_id
            });
            this.prePayParameters = new Dictionary <string, string>();
            this.prePayParameters.Add("appid", appid);
            this.prePayParameters.Add("mch_id", mch_id);
            this.prePayParameters.Add("sub_appid", this.channel.appid);   //子商户公众账号ID
            this.prePayParameters.Add("sub_mch_id", this.channel.mch_id); //子商户号
            this.prePayParameters.Add("nonce_str", Guid.NewGuid().ToString("N"));
            this.prePayParameters.Add("body", entity.AppOrderDesc);
            this.prePayParameters.Add("out_trade_no", entity.OrderID.ToString());//在支付中心生成的订单号****
            this.prePayParameters.Add("total_fee", entity.AppOrderAmount.Value.ToString());
            this.prePayParameters.Add("spbill_create_ip", entity.ClientIP);
            this.prePayParameters.Add("notify_url", entity.NotifyUrl);
            this.prePayParameters.Add("trade_type", this.channel.trade_type);
            this.prePayParameters.Add("sub_openid", entity.OpenId);

            KeyValuePair <string, string>[] sortParameters = this.prePayParameters.OrderBy(item => item.Key).ToArray();
            List <string> paramater = new List <string>();

            foreach (KeyValuePair <string, string> item in sortParameters)
            {
                paramater.Add(string.Format("<{0}>{1}</{0}>", item.Key, item.Value));
            }
            paramater.Add(string.Format("<sign>{0}</sign>", this.getSign(this.prePayParameters, signKey)));

            //下面向微信支付发起了支付
            this.prePayResponse = WeiXinPayHelper.getResponse(entity.PayUrl, this.prePayRequest = string.Format("<xml>{0}</xml>", string.Join("", paramater.ToArray())));
            return(new XmlSerializer(typeof(PrePayResult)).Deserialize(new MemoryStream(Encoding.UTF8.GetBytes(this.prePayResponse.Replace("xml>", "PrePayResult>")))) as PrePayResult);
        }
Пример #7
0
        private bool Notify(AppOrderEntity pEntity, out string msg, bool isTonyCard = false)
        {
            string content    = string.Format("OrderID={0}&OrderStatus={1}&CustomerID={2}&UserID={3}&ChannelID={4}&SerialPay={5}&isTonyCard={6}", pEntity.AppOrderID, pEntity.Status, pEntity.AppClientID, pEntity.AppUserID, pEntity.PayChannelID, pEntity.OrderID, isTonyCard ? 1 : 0);
            var    channelbll = new PayChannelBLL(new JIT.Utility.BasicUserInfo());
            var    channel    = channelbll.GetByID(pEntity.PayChannelID);
            string notifyUrl  = channel.NotifyUrl;

            Loggers.Debug(new DebugLogInfo()
            {
                Message = "wx pay Notify 开始调用通知接口:" + pEntity.ToJSON()
            });
            var    i       = Notify(channel.NotifyUrl, content, out msg);
            string message = i ? " wx pay Notify 调用通知接口成功" : " wx pay Notify 调用通知接口失败";

            message += (":" + msg + "::" + notifyUrl + "?" + content);
            Loggers.Debug(new DebugLogInfo()
            {
                Message = message
            });
            return(i);
        }
Пример #8
0
        /// <summary>
        /// 普通商户支付
        /// </summary>
        /// <param name="entity"></param>
        /// <returns></returns>
        public PrePayResult prePay(AppOrderEntity entity)
        {
            this.prePayParameters = new Dictionary <string, string>();
            this.prePayParameters.Add("appid", this.channel.appid);
            this.prePayParameters.Add("mch_id", this.channel.mch_id);
            //this.prePayParameters.Add("device_info", "");
            this.prePayParameters.Add("nonce_str", Guid.NewGuid().ToString("N"));
            this.prePayParameters.Add("body", entity.AppOrderDesc);
            //this.prePayParameters.Add("attach", "");
            this.prePayParameters.Add("out_trade_no", entity.OrderID.ToString());//在支付中心生成的订单号****
            this.prePayParameters.Add("total_fee", entity.AppOrderAmount.Value.ToString());
            this.prePayParameters.Add("spbill_create_ip", entity.ClientIP);
            //this.prePayParameters.Add("spbill_create_ip","192.168.1.120");  //操作者ip测试 add by Henry
            //this.prePayParameters.Add("time_start", "");
            //this.prePayParameters.Add("time_expire", "");
            //this.prePayParameters.Add("goods_tag", "");
            this.prePayParameters.Add("notify_url", entity.NotifyUrl);
            this.prePayParameters.Add("trade_type", this.channel.trade_type);
            if (!string.IsNullOrEmpty(entity.OpenId))//trade_type=JSAPI,此参数必传,app是不需要填写,而如果值为空时,就不要做为键值对放到sign里***
            {
                this.prePayParameters.Add("openid", entity.OpenId);
            }
            //this.prePayParameters.Add("openid", "on9oCuAzFW9nbK8yC62LwaHnYWf0"); //openId测试 add by Henry
            //this.prePayParameters.Add("product_id", "");

            KeyValuePair <string, string>[] sortParameters = this.prePayParameters.OrderBy(item => item.Key).ToArray();
            List <string> paramater = new List <string>();

            foreach (KeyValuePair <string, string> item in sortParameters)
            {
                paramater.Add(string.Format("<{0}>{1}</{0}>", item.Key, item.Value));
            }
            paramater.Add(string.Format("<sign>{0}</sign>", this.getSign(this.prePayParameters, this.channel.signKey)));

            //下面向微信支付发起了支付
            this.prePayResponse = WeiXinPayHelper.getResponse(entity.PayUrl, this.prePayRequest = string.Format("<xml>{0}</xml>", string.Join("", paramater.ToArray())));
            return(new XmlSerializer(typeof(PrePayResult)).Deserialize(new MemoryStream(Encoding.UTF8.GetBytes(this.prePayResponse.Replace("xml>", "PrePayResult>")))) as PrePayResult);
        }
Пример #9
0
        public void ProcessRequest(HttpContext context)
        {
            string res = "{\"CODE\": \"00\", \"MSG\": \"OK\"}";// Y/N 接收成功或失败

            try
            {
                context.Response.ContentType = "application/json";
                #region 获取流数据
                System.IO.Stream s    = context.Request.InputStream;
                int           count   = 0;
                byte[]        buffer  = new byte[1024];
                StringBuilder builder = new StringBuilder();
                while ((count = s.Read(buffer, 0, 1024)) > 0)
                {
                    builder.Append(Encoding.UTF8.GetString(buffer, 0, count));
                }
                s.Flush();
                s.Close();
                s.Dispose();
                #endregion

                string rspStr = builder.ToString();
                //Task.Factory.StartNew(() =>
                //{
                //    HttpHelper.SendSoapRequest(DateTime.Now + "  收到旺财支付回调:" + rspStr, "http://182.254.242.12:56789/log/push/");
                //});
                Loggers.Debug(new DebugLogInfo()
                {
                    Message = string.Format("Receive data from PALifePay : {0}", rspStr)
                });


                LifePayRP req = rspStr.DeserializeJSONTo <LifePayRP>();

                string orderId    = req.merOrderNo;
                string resultcode = req.notifyType;
                string openId     = req.openId;

                AppOrderBLL    bll      = new AppOrderBLL(new Utility.BasicUserInfo());
                AppOrderEntity appOrder = bll.QueryByEntity(new AppOrderEntity()
                {
                    AppOrderID = orderId,
                }, null).FirstOrDefault();

                // 00 成功 01 失败 02 其他
                if (appOrder != null && resultcode == "00" && appOrder.Status != 2)
                {
                    appOrder.Status = 2;
                }

                if (appOrder != null && !(appOrder.IsNotified ?? false))
                {
                    try
                    {
                        string    msg;
                        Hashtable ht = new Hashtable();
                        ht.Add("serialNo", req.serialNo);
                        // 异步通知cpos
                        if (NotifyHandler.Notify(appOrder, out msg, ht))
                        {
                            appOrder.IsNotified = true;
                        }
                        else
                        {
                            appOrder.NextNotifyTime = DateTime.Now.AddMinutes(1);
                        }
                        //通知完成,通知次数+1
                        appOrder.NotifyCount = (appOrder.NotifyCount ?? 0) + 1;
                        bll.Update(appOrder);
                    }
                    catch (Exception ex)
                    {
                        Loggers.Exception(new ExceptionLogInfo(ex));
                    }
                }
                if ((appOrder.IsNotified ?? false) && appOrder.Status == 2)
                {
                    res = "{\"CODE\": \"00\", \"MSG\": \"OK\"}";//
                }
            }
            catch (Exception ex)
            {
                res = "{\"CODE\": \"01\", \"MSG\": \"" + ex + "\"}";//
            }
            Loggers.Debug(new DebugLogInfo()
            {
                Message = string.Format("Response data from PALifePay : {0}", res)
            });
            context.Response.Write(res);
            context.Response.End();
        }
Пример #10
0
 /// <summary>
 /// 更新
 /// </summary>
 /// <param name="pEntity">实体实例</param>
 public void Update(AppOrderEntity pEntity)
 {
     _currentDAO.Update(pEntity);
 }
Пример #11
0
 /// <summary>
 /// 根据实体条件查询实体
 /// </summary>
 /// <param name="pQueryEntity">以实体形式传入的参数</param>
 /// <param name="pOrderBys">排序组合</param>
 /// <returns>符合条件的实体集</returns>
 public AppOrderEntity[] QueryByEntity(AppOrderEntity pQueryEntity, OrderBy[] pOrderBys)
 {
     return(_currentDAO.QueryByEntity(pQueryEntity, pOrderBys));
 }
Пример #12
0
 /// <summary>
 /// 删除
 /// </summary>
 /// <param name="pEntity"></param>
 public void Delete(AppOrderEntity pEntity)
 {
     _currentDAO.Delete(pEntity);
 }
Пример #13
0
        /// <summary>
        /// 记录请求支付日志信息
        /// </summary>
        /// <param name="response"></param>
        /// <param name="para"></param>
        /// <param name="bll"></param>
        /// <param name="entity"></param>
        /// <param name="channel"></param>
        /// <returns></returns>
        private static string CreatePayRecord(CreateOrderResponse response, CreateOrderParameters para, AppOrderBLL bll, AppOrderEntity entity, PayChannelEntity channel)
        {
            string url = string.Empty;


            //用于记录支付平台的请求和响应
            string requestJson  = string.Empty;
            string responseJson = string.Empty;

            var recordBll    = new PayRequestRecordBLL(new Utility.BasicUserInfo());
            var recordEntity = new PayRequestRecordEntity()
            {
                ChannelID = channel.ChannelID,
                ClientID  = entity.AppClientID,
                UserID    = entity.AppUserID
            };

            #region 根据Channel类型创建支付订单
            try
            {
                switch (channel.PayType)
                {
                case 1:
                    recordEntity.Platform = 1;
                    #region 银联Wap支付
                    UnionPayChannel unionWapPaychannel = channel.ChannelParameters.DeserializeJSONTo <UnionPayChannel>();
                    PreOrderRequest Wapreq             = new PreOrderRequest()
                    {
                        BackUrl               = ConfigurationManager.AppSettings["UnionPayWapNotifyUrl"].Trim('?') + string.Format("?ChannelID={0}", channel.ChannelID),
                        FrontUrl              = string.IsNullOrEmpty(para.ReturnUrl) ? ConfigurationManager.AppSettings["UnionPayCallBackUrl"] : para.ReturnUrl,
                        MerchantID            = unionWapPaychannel.MerchantID,
                        SendTime              = DateTime.Now,
                        MerchantOrderCurrency = Currencys.RMB,
                        MerchantOrderDesc     = entity.AppOrderDesc,
                        MerchantOrderAmt      = entity.AppOrderAmount,
                        MerchantOrderID       = entity.OrderID.ToString(),
                        SendSeqID             = Guid.NewGuid().ToString("N"),
                        MerchantOrderTime     = entity.AppOrderTime
                    };
                    requestJson = Wapreq.ToJSON();
                    var unionWapResponse = JIT.Utility.Pay.UnionPay.Interface.Wap.WapGateway.PreOrder(unionWapPaychannel, Wapreq);
                    responseJson = unionWapResponse.ToJSON();
                    if (unionWapResponse.IsSuccess)
                    {
                        entity.PayUrl = unionWapResponse.RedirectURL;
                        entity.Status = 1;
                        bll.Update(entity);
                        url = unionWapResponse.RedirectURL;
                        Loggers.Debug(new DebugLogInfo()
                        {
                            Message = string.Format("银联Wap创建订单成功{0}【请求】:{1}{0}【响应】:{2}", Environment.NewLine, Wapreq.ToJSON(), unionWapResponse.ToJSON())
                        });
                    }
                    else
                    {
                        Loggers.Debug(new DebugLogInfo()
                        {
                            Message = string.Format("银联Wap创建订单失败{0}【请求】:{1}{0}【响应】:{2}", Environment.NewLine, Wapreq.ToJSON(), unionWapResponse.ToJSON())
                        });
                        response.ResultCode = 100;
                        response.Message    = unionWapResponse.Description;
                    }
                    #endregion
                    break;

                case 2:
                    recordEntity.Platform = 1;
                    #region 银联语音支付
                    UnionPayChannel unionIVRPaychannel = channel.ChannelParameters.DeserializeJSONTo <UnionPayChannel>();
                    JIT.Utility.Pay.UnionPay.Interface.IVR.Request.PreOrderRequest IVRreq = new Utility.Pay.UnionPay.Interface.IVR.Request.PreOrderRequest()
                    {
                        SendTime          = DateTime.Now,
                        SendSeqID         = Guid.NewGuid().ToString("N"),
                        FrontUrl          = string.IsNullOrEmpty(para.ReturnUrl) ? ConfigurationManager.AppSettings["UnionPayCallBackUrl"] : para.ReturnUrl,
                        BackUrl           = ConfigurationManager.AppSettings["UnionPayIVRNotifyUrl"].Trim('?') + string.Format("?ChannelID={0}", channel.ChannelID),
                        MerchantOrderDesc = entity.AppOrderDesc,
                        Mode                  = IVRModes.Callback,
                        TransTimeout          = entity.AppOrderTime,
                        MerchantOrderCurrency = Currencys.RMB,
                        MerchantOrderAmt      = entity.AppOrderAmount,
                        MerchantID            = unionIVRPaychannel.MerchantID,
                        MerchantOrderTime     = entity.AppOrderTime,
                        MerchantOrderID       = entity.OrderID.ToString(),
                        MobileNum             = entity.MobileNO
                    };
                    requestJson = IVRreq.ToJSON();
                    var IvrResponse = IVRGateway.PreOrder(unionIVRPaychannel, IVRreq);
                    responseJson = IvrResponse.ToJSON();
                    if (IvrResponse.IsSuccess)
                    {
                        entity.Status = 1;
                        bll.Update(entity);
                        Loggers.Debug(new DebugLogInfo()
                        {
                            Message = string.Format("银联IVR创建订单成功{0}【请求】:{1}{0}【响应】:{2}", Environment.NewLine, IVRreq.ToJSON(), IvrResponse.ToJSON())
                        });
                    }
                    else
                    {
                        Loggers.Debug(new DebugLogInfo()
                        {
                            Message = string.Format("银联IVR创建订单失败{0}【请求】:{1}{0}【响应】:{2}", Environment.NewLine, IVRreq.ToJSON(), IvrResponse.ToJSON())
                        });
                        response.ResultCode = 200;
                        response.Message    = IvrResponse.Description;
                    }
                    #endregion
                    break;

                case 3:
                    recordEntity.Platform = 2;
                    #region 阿里Wap支付
                    AliPayChannel         aliPayWapChannel = channel.ChannelParameters.DeserializeJSONTo <AliPayChannel>();
                    AliPayWapTokenRequest tokenRequest     = new AliPayWapTokenRequest(aliPayWapChannel)
                    {
                        CallBackUrl       = string.IsNullOrEmpty(para.ReturnUrl) ? ConfigurationManager.AppSettings["AliPayCallBackUrl"] : para.ReturnUrl,
                        NotifyUrl         = ConfigurationManager.AppSettings["AlipayWapNotify"].Trim('?') + string.Format("?ChannelID={0}", channel.ChannelID),
                        OutTradeNo        = entity.OrderID.ToString(),
                        Partner           = aliPayWapChannel.Partner,
                        SellerAccountName = aliPayWapChannel.SellerAccountName,
                        Subject           = entity.AppOrderDesc,
                        TotalFee          = Math.Round((Convert.ToDecimal(entity.AppOrderAmount) / 100), 2).ToString(),
                        ReqID             = Guid.NewGuid().ToString().Replace("-", "")
                    };
                    requestJson = tokenRequest.ToJSON();
                    var aliPayWapResponse = AliPayWapGeteway.GetQueryTradeResponse(tokenRequest, aliPayWapChannel);
                    responseJson = aliPayWapResponse.ToJSON();
                    if (aliPayWapResponse.IsSucess)
                    {
                        entity.PayUrl = aliPayWapResponse.RedirectURL;
                        entity.Status = 1;
                        bll.Update(entity);
                        url = aliPayWapResponse.RedirectURL;
                        Loggers.Debug(new DebugLogInfo()
                        {
                            Message = string.Format("AliPayWap创建订单成功{0}【请求】:{1}{0}【响应】:{2}", Environment.NewLine, tokenRequest.ToJSON(), aliPayWapResponse.ToJSON())
                        });
                    }
                    else
                    {
                        Loggers.Debug(new DebugLogInfo()
                        {
                            Message = string.Format("AliPayWap创建订单失败{0}【请求】:{1}{0}【响应】:{2}", Environment.NewLine, tokenRequest.ToJSON(), aliPayWapResponse.ToJSON())
                        });
                        response.ResultCode = 300;
                        response.Message    = aliPayWapResponse.Message;
                    }
                    #endregion
                    break;

                case 4:
                    recordEntity.Platform = 2;
                    #region 阿里OffLine支付
                    AliPayChannel aliPayChannel = channel.ChannelParameters.DeserializeJSONTo <AliPayChannel>();
                    //根据DynamicID判断是否预定单支付,DynamicID为空或者Null时调用OffLine预订单接口
                    if (string.IsNullOrWhiteSpace(para.DynamicID))
                    {
                        OfflineQRCodePreRequest qrRequest = new OfflineQRCodePreRequest(aliPayChannel)
                        {
                            OutTradeNo = entity.OrderID.ToString(),
                            NotifyUrl  = ConfigurationManager.AppSettings["AlipayOfflineNotify"].Trim('?') + string.Format("?ChannelID={0}", channel.ChannelID),
                            Subject    = entity.AppOrderDesc,
                            TotalFee   = Math.Round((Convert.ToDecimal(entity.AppOrderAmount) / 100), 2).ToString(),
                            //下面是测试数据,正式须更改
                            ExtendParams = new
                            {
                                MACHINE_ID  = "BJ_001", //?
                                AGENT_ID    = aliPayChannel.AgentID,
                                STORE_TYPE  = "0",      //?
                                STORE_ID    = "12314",  //?
                                TERMINAL_ID = "111",    //?
                                SHOP_ID     = "only"    //?
                            }.ToJSON()
                        };
                        requestJson = qrRequest.ToJSON();
                        var offlineQrResponse = AliPayOffLineGeteway.OfflineQRPay(qrRequest);
                        responseJson = offlineQrResponse.ToJSON();
                        if (offlineQrResponse.IsSucess)
                        {
                            entity.Status = 1;
                            entity.PayUrl = offlineQrResponse.PicUrl;
                            bll.Update(entity);
                            response.QrCodeUrl = offlineQrResponse.PicUrl;
                            Loggers.Debug(new DebugLogInfo()
                            {
                                Message = string.Format("AliPayOffline二维码支付创建订单成功{0}【请求】:{1}{0}【响应】:{2}", Environment.NewLine, qrRequest.ToJSON(), offlineQrResponse.ToJSON())
                            });
                        }
                        else
                        {
                            Loggers.Debug(new DebugLogInfo()
                            {
                                Message = string.Format("AliPayOffline二维码支付创建订单失败{0}【请求】:{1}{0}【响应】:{2}", Environment.NewLine, qrRequest.ToJSON(), offlineQrResponse.ToJSON())
                            });
                            response.ResultCode = 400;
                            response.Message    = offlineQrResponse.DetailErrorCode + ":" + offlineQrResponse.DetailErrorDes;
                        }
                    }
                    else
                    {
                        CreateAndPayRequest createAndPayrequest = new CreateAndPayRequest(aliPayChannel)
                        {
                            Subject       = entity.AppOrderDesc,
                            TotalFee      = Math.Round((Convert.ToDecimal(entity.AppOrderAmount) / 100), 2).ToString(),
                            NotifyUrl     = ConfigurationManager.AppSettings["AlipayOfflineNotify"].Trim('?') + string.Format("?ChannelID={0}", channel.ChannelID),
                            OutTradeNo    = entity.OrderID.ToString(),
                            DynamicIDType = para.DynamicIDType,
                            DynamicID     = para.DynamicID,
                        };
                        if (!string.IsNullOrEmpty(aliPayChannel.AgentID))
                        {
                            createAndPayrequest.ExtendParams = (new
                            {
                                AGENT_ID = aliPayChannel.AgentID,
                                MACHINE_ID = "BJ_001",
                                STORE_TYPE = "0",
                                STORE_ID = "BJ_ZZ_001",
                                TERMINAL_ID = "A80001",
                                SHOP_ID = "only"
                            }).ToJSON();
                        }
                        requestJson = createAndPayrequest.ToJSON();
                        var offlineCreateAndPayResponse = AliPayOffLineGeteway.OfflineCreateAndPay(createAndPayrequest);
                        responseJson = offlineCreateAndPayResponse.ToJSON();
                        if (offlineCreateAndPayResponse.IsSuccess)
                        {
                            entity.Status = 2;
                            bll.Update(entity);
                            Loggers.Debug(new DebugLogInfo()
                            {
                                Message = string.Format("AliPayOffline即支付创建订单成功{0}【请求】:{1}{0}【响应】:{2}", Environment.NewLine, createAndPayrequest.ToJSON(), offlineCreateAndPayResponse.ToJSON())
                            });
                        }
                        else if (offlineCreateAndPayResponse.ResultCode == ResultCodes.ORDER_SUCCESS_PAY_FAIL.ToString())
                        {
                            entity.Status = 1;
                            bll.Update(entity);
                            Loggers.Debug(new DebugLogInfo()
                            {
                                Message = string.Format("AliPayOffline即支付创建订单成功{0},支付失败【请求】:{1}{0}【响应】:{2}", Environment.NewLine, createAndPayrequest.ToJSON(), offlineCreateAndPayResponse.ToJSON())
                            });
                        }
                        else if (offlineCreateAndPayResponse.ResultCode == ResultCodes.ORDER_SUCCESS_PAY_INPROCESS.ToString())
                        {
                            entity.Status = 1;
                            bll.Update(entity);
                            Loggers.Debug(new DebugLogInfo()
                            {
                                Message = string.Format("AliPayOffline即支付创建订单成功{0},支付处理中【请求】:{1}{0}【响应】:{2}", Environment.NewLine, createAndPayrequest.ToJSON(), offlineCreateAndPayResponse.ToJSON())
                            });
                        }
                        else
                        {
                            Loggers.Debug(new DebugLogInfo()
                            {
                                Message = string.Format("AliPayOffline即支付创建订单失败{0}【请求】:{1}{0}【响应】:{2}", Environment.NewLine, createAndPayrequest.ToJSON(), offlineCreateAndPayResponse.ToJSON())
                            });
                            response.ResultCode = 400;
                            response.Message    = offlineCreateAndPayResponse.DetailErrorCode + ":" + offlineCreateAndPayResponse.DetailErrorDes;
                        }
                    }
                    #endregion
                    break;

                case 5:    //Native
                case 6:    //微信JS
                case 7:    //微信App
                    recordEntity.Platform = 3;
                    #region 微信Native支付,JS支付
                    //把channel里的参数传了过去
                    WeiXinPayHelper helper = new WeiXinPayHelper(channel.ChannelParameters.DeserializeJSONTo <WeiXinPayHelper.Channel>());
                    entity.PayUrl    = ConfigurationManager.AppSettings["WeiXinPrePay"];
                    entity.NotifyUrl = ConfigurationManager.AppSettings["WeiXinPayNotify"];
                    WeiXinPayHelper.PrePayResult result = null;

                    if (para.PaymentMode == 1)    //PaymentMode=1标示微信扫码支付进入
                    {
                        helper.channel.trade_type = "NATIVE";
                        channel.PayType           = 5; //走扫码回调返回参数
                    }

                    Loggers.Debug(new DebugLogInfo()
                    {
                        Message = "isSpPay:" + helper.channel.isSpPay
                    });

                    if (helper.channel.isSpPay == "1")     //isSpPay=1 服务商支付
                    {
                        result = helper.serPrePay(entity); //统一下单,服务商支付
                    }
                    else
                    {
                        result = helper.prePay(entity);    //统一下单,获取微信网页支付的预支付信息,app支付和js支付是一样的
                    }

                    Loggers.Debug(new DebugLogInfo()
                    {
                        Message = "微信支付_预支付返回结果:" + result.ToJSON()
                    });
                    requestJson  = helper.prePayRequest;
                    responseJson = helper.prePayResponse;
                    if (result.return_code == "SUCCESS" && result.result_code == "SUCCESS")
                    {
                        if (channel.PayType == 6)
                        {
                            response.WXPackage = helper.getJsParamater(result);
                        }
                        else if (channel.PayType == 7)    //后面传的参数和js支付的就不一样了
                        {
                            response.WXPackage = helper.getAppParamater(result);
                            response.OrderID   = entity.OrderID;
                        }
                        else    //Native
                        {
                            response.WXPackage = result.ToJSON();
                            response.QrCodeUrl = result.code_url;
                        }
                        Loggers.Debug(new DebugLogInfo()
                        {
                            Message = "WXPackage:" + response.WXPackage
                        });
                    }
                    else
                    {
                        response.ResultCode = 101;                    //支付失败
                        if (!string.IsNullOrEmpty(result.return_msg)) //不同错误,错误信息位置不同
                        {
                            response.Message = result.return_msg;
                        }
                        else
                        {
                            response.Message = result.err_code_des;
                        }
                    }

                    #endregion
                    break;

                case 8:    //旺财支付
                    return(string.Empty);

                case 9:    //新版支付宝扫码支付
                    #region
                    AliPayChannel     aliPayScanChannel = channel.ChannelParameters.DeserializeJSONTo <AliPayChannel>();
                    RequestScanEntity scRequest         = new RequestScanEntity(aliPayScanChannel);
                    scRequest.notify_url = "" + ConfigurationManager.AppSettings["AlipayOfflineNotify"];

                    RequstScanDetail scanDetail = new RequstScanDetail();
                    scanDetail.out_trade_no = "" + entity.OrderID;
                    scanDetail.total_amount = "" + Math.Round((Convert.ToDecimal(entity.AppOrderAmount) / 100), 2);
                    scanDetail.seller_id    = aliPayScanChannel.Partner;
                    scanDetail.subject      = entity.AppOrderDesc;

                    var scResponseJson = AliPayScanGeteway.GetResponseStr(scRequest, scanDetail.ToJSON(), aliPayScanChannel.RSA_PrivateKey);
                    var scResponse     = scResponseJson.DeserializeJSONTo <ResponsetScanEntity>();

                    if (scResponse.alipay_trade_precreate_response.code == "10000")
                    {
                        response.QrCodeUrl = scResponse.alipay_trade_precreate_response.qr_code;
                        Loggers.Debug(new DebugLogInfo()
                        {
                            Message = string.Format("aliPayScanChannel二维码支付创建订单成功{0}【请求】:{1}{0}【响应】:{2}", Environment.NewLine, requestJson, scResponseJson)
                        });
                    }
                    else
                    {
                        Loggers.Debug(new DebugLogInfo()
                        {
                            Message = string.Format("AliPayOffline二维码支付创建订单失败{0}【请求】:{1}{0}【响应】:{2}", Environment.NewLine, requestJson, scResponseJson)
                        });
                        response.ResultCode = 400;
                        response.Message    = scResponse.alipay_trade_precreate_response.code + ":" + scResponse.alipay_trade_precreate_response.msg;
                    }
                    #endregion
                    break;

                default:
                    break;
                }
                recordEntity.RequestJson  = requestJson;
                recordEntity.ResponseJson = responseJson;
                recordBll.Create(recordEntity);
            }
            catch (Exception ex)
            {
                recordEntity.RequestJson  = requestJson;
                recordEntity.ResponseJson = responseJson;
                recordBll.Create(recordEntity);
                throw ex;
            }
            #endregion
            return(url);
        }
Пример #14
0
        /// <summary>
        /// 创建交易中心支付订单AppOrder
        /// </summary>
        /// <param name="pRequest"></param>
        /// <returns></returns>
        public static CreateOrderResponse CreateOrder(TradeRequest pRequest)
        {
            var userInfo = pRequest.GetUserInfo();
            CreateOrderResponse response = new CreateOrderResponse();

            response.ResultCode = 0;
            CreateOrderParameters para = pRequest.GetParameter <CreateOrderParameters>();

            Loggers.Debug(new DebugLogInfo()
            {
                Message = "业务参数:" + para.ToJSON()
            });
            if (para == null)
            {
                throw new Exception("Parameters参数不正确");
            }
            AppOrderBLL    bll = new AppOrderBLL(userInfo);
            AppOrderEntity entity;

            #region 支付等待5秒后可再次支付
            var appOrderEntity = bll.QueryByEntity(new AppOrderEntity()
            {
                ClientIP = pRequest.ClientID, AppOrderID = para.AppOrderID
            }, null).FirstOrDefault();
            if (appOrderEntity != null)
            {
                DateTime dtNow = DateTime.Now;
                TimeSpan ts    = dtNow - appOrderEntity.CreateTime.Value;
                if (ts.TotalSeconds < 5)
                {
                    throw new Exception("支付已启动,请稍后再试");
                }
            }
            #endregion

            #region  在支付中心创建订单
            var tran = bll.CreateTran();
            using (tran.Connection)
            {
                try
                {
                    #region  除已存在的订单
                    bll.DeleteByAppInfo(pRequest.ClientID, para.AppOrderID, pRequest.AppID.Value, tran);
                    #endregion

                    #region 创建订单
                    entity = new AppOrderEntity()
                    {
                        Status         = 0,
                        MobileNO       = para.MobileNO,
                        AppClientID    = pRequest.ClientID,
                        AppUserID      = pRequest.UserID,
                        AppID          = pRequest.AppID,
                        AppOrderAmount = Convert.ToInt32(para.AppOrderAmount),
                        AppOrderDesc   = para.AppOrderDesc,
                        AppOrderID     = para.AppOrderID,
                        AppOrderTime   = para.GetDateTime(),
                        Currency       = 1,
                        CreateBy       = pRequest.UserID,
                        PayChannelID   = para.PayChannelID,
                        LastUpdateBy   = pRequest.UserID,
                        OpenId         = para.OpenId,
                        ClientIP       = para.ClientIP
                    };
                    bll.Create(entity, tran);//并且生成了一个自动增长的订单标识orderid
                    Loggers.Debug(new DebugLogInfo()
                    {
                        Message = "创建支付中心订单并保存数据库:" + entity.ToJSON()
                    });
                    #endregion

                    tran.Commit();
                }
                catch
                {
                    tran.Rollback();
                    throw;
                }
            }
            #endregion

            #region 获取Channel
            PayChannelBLL channelBll = new PayChannelBLL(userInfo);
            var           channel    = channelBll.GetByID(para.PayChannelID);//PayChannelID是不同商户的支付方式的标识
            if (channel == null)
            {
                throw new Exception("无此ChannelID的Channel信息");
            }
            #endregion

            #region 测试Channel订单价格设置为1分钱***
            entity.AppOrderAmount = channel.IsTest.Value ? 1 : entity.AppOrderAmount;
            #endregion

            string url = string.Empty;
            if (para.AppOrderDesc != "ScanWxPayOrder")
            {
                if (para.PaymentMode == 0)
                {
                    channel.PayType = 9; //新版支付宝扫码支付
                }
                url = CreatePayRecord(response, para, bll, entity, channel);
            }

            response.PayUrl  = url;
            response.OrderID = entity.OrderID;
            return(response);
        }
Пример #15
0
 /// <summary>
 /// 分页根据实体条件查询实体
 /// </summary>
 /// <param name="pQueryEntity">以实体形式传入的参数</param>
 /// <param name="pOrderBys">排序组合</param>
 /// <returns>符合条件的实体集</returns>
 public PagedQueryResult <AppOrderEntity> PagedQueryByEntity(AppOrderEntity pQueryEntity, OrderBy[] pOrderBys, int pPageSize, int pCurrentPageIndex)
 {
     return(_currentDAO.PagedQueryByEntity(pQueryEntity, pOrderBys, pPageSize, pCurrentPageIndex));
 }
Пример #16
0
 public abstract bool Process(PayChannelEntity pChannel, HttpContext pContext, out AppOrderEntity pEntity);
Пример #17
0
        /*
         * <xml><appid><![CDATA[wxb4f8f3d799d22f03]]></appid>
         * <attach><![CDATA[测试数据]]></attach>
         * <bank_type><![CDATA[CFT]]></bank_type>
         * <cash_fee><![CDATA[1]]></cash_fee>
         * <fee_type><![CDATA[CNY]]></fee_type>
         * <is_subscribe><![CDATA[Y]]></is_subscribe>
         * <mch_id><![CDATA[1264926201]]></mch_id>
         * <nonce_str><![CDATA[rdwbEb2FXXmV7LBF]]></nonce_str>
         * <openid><![CDATA[oY-Cqs7wZ6p_Cq_0AAP2QHLhANRc]]></openid>
         * <out_trade_no><![CDATA[126492620120160426005955291]]></out_trade_no>
         * <result_code><![CDATA[SUCCESS]]></result_code>
         * <return_code><![CDATA[SUCCESS]]></return_code>
         * <sign><![CDATA[C251718418AFA3FDEB764E258F220340]]></sign>
         * <time_end><![CDATA[20160426010056]]></time_end>
         * <total_fee>1</total_fee>
         * <trade_type><![CDATA[NATIVE]]></trade_type>
         * <transaction_id><![CDATA[4008492001201604265225452570]]></transaction_id>
         * </xml>
         */
        #endregion
        public void ProcessRequest(HttpContext context)
        {
            WxPayData res = new WxPayData();

            try
            {
                context.Response.ContentType = "text/plain";

                System.IO.Stream s    = context.Request.InputStream;
                int           count   = 0;
                byte[]        buffer  = new byte[1024];
                StringBuilder builder = new StringBuilder();
                while ((count = s.Read(buffer, 0, 1024)) > 0)
                {
                    builder.Append(Encoding.UTF8.GetString(buffer, 0, count));
                }
                s.Flush();
                s.Close();
                s.Dispose();

                Loggers.Debug(new DebugLogInfo()
                {
                    Message = string.Format("Receive data from WeChat : {0}", builder.ToString())
                });

                string rspStr = builder.ToString().
                                Replace("<![CDATA[", "").Replace("]]>", "");
                XmlDocument doc = new XmlDocument();
                doc.LoadXml(rspStr);

                string orderId    = doc.GetElementsByTagName("out_trade_no")[0].InnerText;
                string resultcode = doc.GetElementsByTagName("result_code")[0].InnerText;
                string openId     = doc.GetElementsByTagName("openid")[0].InnerText;

                AppOrderBLL    bll      = new AppOrderBLL(new Utility.BasicUserInfo());
                AppOrderEntity appOrder = bll.QueryByEntity(new AppOrderEntity()
                {
                    AppOrderID = orderId,
                }, null).FirstOrDefault();


                if (appOrder != null && resultcode == "SUCCESS" && appOrder.Status != 2)
                {
                    appOrder.Status = 2;
                    new RechargeBLL().RechargeTonysCardAct2(appOrder);
                }

                if (appOrder != null && !(appOrder.IsNotified ?? false))
                {
                    try
                    {
                        string msg;
                        if (NotifyHandler.Notify(appOrder, out msg, true))
                        {
                            appOrder.IsNotified = true;
                        }
                        else
                        {
                            appOrder.NextNotifyTime = DateTime.Now.AddMinutes(1);
                        }
                        //通知完成,通知次数+1
                        appOrder.NotifyCount = (appOrder.NotifyCount ?? 0) + 1;
                        bll.Update(appOrder);
                    }
                    catch (Exception ex)
                    {
                        Loggers.Exception(new ExceptionLogInfo(ex));
                        res.SetValue("return_code", "FAIL");
                        res.SetValue("return_msg", "FAIL");
                    }
                }

                NotifyHandler.NotifyTFSaveWxVipInfo(appOrder.AppOrderID, appOrder.AppClientID, openId);
                if ((appOrder.IsNotified ?? false) && appOrder.Status == 2)
                {
                    res.SetValue("return_code", "SUCCESS");
                    res.SetValue("return_msg", "OK");
                }
            }
            catch (Exception ex)
            {
                res.SetValue("return_code", "FAIL");
                res.SetValue("return_msg", ex.Message);
            }
            context.Response.Write(res.ToXml());
            context.Response.End();
        }
Пример #18
0
 /// <summary>
 /// 更新
 /// </summary>
 /// <param name="pEntity">实体实例</param>
 /// <param name="pTran">事务实例,可为null,如果为null,则不使用事务来更新</param>
 public void Update(AppOrderEntity pEntity, IDbTransaction pTran)
 {
     _currentDAO.Update(pEntity, pTran);
 }
Пример #19
0
 /// <summary>
 /// 创建一个新实例
 /// </summary>
 /// <param name="pEntity">实体实例</param>
 public void Create(AppOrderEntity pEntity)
 {
     _currentDAO.Create(pEntity);
 }