Пример #1
0
        /// <summary>
        /// 订单支付通知
        /// </summary>
        public void POSOrderPaidNotify()
        {
            try
            {
                Dictionary <string, string> param = HttpUtility.UrlDecode(content).ToDictionary(true);

                if (!param.ContainsKey("bizseq"))
                {
                    throw new Exception("bizseq不能为空");
                }

                string bizseq = param["bizseq"];

                var orderPaid = iOrderPaidService.Get(t => t.OrderNumber == bizseq);

                if (orderPaid == null)
                {
                    throw new Exception("订单不存在:" + bizseq);
                }

                //获取支付参数
                var preferences = iPreferencesService.Get(t => t.MerchantID == orderPaid.MerchantID);
                this.vspExec = new VSPExec(preferences.POSBaoMerchant, preferences.POSBaoKey, preferences.APPID);

                if (vspExec.IsVerify(param))//验签成功
                {
                    POSOrderQueryResponse posOrderQueryResponse = JsonHelper.Deserialize <POSOrderQueryResponse>(JsonHelper.Serialize(param));
                    byte[] bytes = Encoding.GetEncoding("gbk").GetBytes(posOrderQueryResponse.trxreserve ?? ""); //将字符串转成gbk编码的字节数组
                    posOrderQueryResponse.trxreserve = Encoding.GetEncoding("utf-8").GetString(bytes);           //将字节数组转回为字符串

                    if (posOrderQueryResponse.trxcode == "VSP001" && posOrderQueryResponse.trxstatus == "0000")
                    {
                        //订单支付成功后的平安和光大订单的后续处理
                        iOrderPaidService.VspOrderHandle(posOrderQueryResponse, orderPaid);

                        Response.Write("success");
                    }
                }
                else
                {
                    throw new Exception("通知验签失败");
                }
            }
            catch (Exception ex)
            {
                logger.Error(ex.Message);
                Response.Write("error");
            }
        }
        public void GetOrderMsg()
        {
            string bizseq = "";
            string cusid  = "";
            RspObj rsp    = new RspObj();

            for (int i = 0; i < Request.Form.Count; i++)
            {
                if (Request.Form.Keys[i] == "bizseq")
                {
                    bizseq = Request.Form[i].ToString();
                }
                if (Request.Form.Keys[i] == "cusid")
                {
                    cusid = Request.Form[i].ToString();
                }
            }

            var orderpaid = iOrderPaidService.Get(t => t.OrderNumber == bizseq);

            Preferences preferences = iPreferencesService.Get(t => t.POSBaoMerchant == cusid);

            if (orderpaid == null)
            {
                rsp.init("9999", "订单不存在", preferences.APPID, preferences.POSBaoMerchant);
                rsp.amount     = "";
                rsp.trxreserve = "";
                rsp.bizseq     = "";
                rsp            = BuildSignRspObj(rsp, preferences.POSBaoKey);//签名
                Response.Write(JsonHelper.Serialize(rsp));
                return;
            }

            //Preferences preferences = iPreferencesService.Get(t => t.MerchantID == orderpaid.MerchantID);
            this.vspExec = new VSPExec(preferences.POSBaoMerchant, preferences.POSBaoKey, preferences.APPID);

            //获取支付参数
            string formString = HttpUtility.UrlDecode(Request.Form.ToString());
            Dictionary <String, String> dicReqeust = formString.ToDictionary(true);

            if (vspExec.IsVerify(dicReqeust))//验签成功
            {
                if (DateTime.Now > orderpaid.Project.Deadline)
                {
                    rsp.init("9999", "订单已过期", preferences.APPID, preferences.POSBaoMerchant);
                    rsp.amount     = "";//由于nettonsoft.json会自动将空字段转化为null,因此手动赋值空字符串
                    rsp.trxreserve = "";
                    rsp.bizseq     = "";
                }
                else
                {
                    rsp.init("0000", "查询成功", preferences.APPID, preferences.POSBaoMerchant);
                    rsp.amount = ((int)(orderpaid.TransactionAmount * 100)).ToString();
                    // rsp.trxreserve = "05(业务类型)##订购人姓名#广州体育西(订购人地址)#15820335584(联系电话)#TN000001#01#440992198709257433(跟踪订单号)####";
                    rsp.trxreserve = "05##" + orderpaid.Member.Name + "#" + orderpaid.MemberMobile + "#" + orderpaid.OrderNumber + "#######";
                    //rsp.trxreserve = "05##" + "AAA" + "#" + orderpaid.MemberMobile + "#" + orderpaid.OrderNumber + "#######";
                    rsp.bizseq = orderpaid.OrderNumber;//业务流水号
                }
            }
            else //验签失败
            {
                rsp.init("9999", "验签失败", preferences.APPID, preferences.POSBaoMerchant);
                rsp.amount     = "";//由于nettonsoft.json会自动将空字段转化为null,因此手动赋值空字符串
                rsp.trxreserve = "";
                rsp.bizseq     = "";
            }

            rsp = BuildSignRspObj(rsp, preferences.POSBaoKey);//签名

            Response.Write(JsonHelper.Serialize(rsp));
        }