Example #1
0
        public static bool OperateKnownClass(ref Transfer trans)
        {
            var pubInfo = default(PubInfo);

            switch (trans.Class)
            {
            case "QualityManage":
                pubInfo = new QualityManage();
                break;

            case "EquipmentManage":
                pubInfo = new EquipmentManage();
                break;

            default:
                return(false);
            }

            if (pubInfo == null)
            {
                return(false);
            }

            var HashString = trans.Attribute.ToString() + DateTime.Now.ToString("yyyyMMdd") + pubInfo.Token;
            var Mac        = AppPKI.getMd5Hash(HashString);

            //if (trans.Mac == Mac)
            {
                pubInfo.Operate(ref trans);

                return(true);
            }

            return(false);
        }
Example #2
0
 public static void Operate(ref Common.Transfer Trans)
 {
     try
     {
         PubInfo Rp         = (PubInfo)Assembly.Load("Business").CreateInstance("Business." + Trans.Class);
         var     HashString = Trans.Attribute.ToString() + DateTime.Now.ToString("yyyyMMdd") + Rp.Token;
         var     Mac        = AppPKI.getMd5Hash(HashString);
         #region 针对参数值带特殊字符的进行修改转义
         if (Trans.Attribute.Contains("&"))
         {
             Trans.Attribute = Trans.Attribute.Replace("&", "&");
         }
         #endregion
         //鸿坤第三方 不要安全验证 单独去掉
         if (Trans.Class == "HKCallCenter")
         {
             Rp.Operate(ref Trans);
         }
         else if (Trans.Class == "DataVHJ")
         {
             //合景datav 大屏 去掉验证
             Rp.Operate(ref Trans);
         }
         else if (Trans.Class == "ContractAuditInfo_FanWei")
         {
             //合景经营合同审核 去掉验证
             Rp.Operate(ref Trans);
         }
         else if (Trans.Class == "PolyDataV")
         {
             //合景datav 大屏 去掉验证
             Rp.Operate(ref Trans);
         }
         else if (Trans.Class == "CostInfoSunshineNewest")
         {
             Rp.Operate(ref Trans);
         }
         else if (Trans.Class == "HKParkCostInfo")
         {
             Rp.Operate(ref Trans);
         }
         else if (Trans.Class == "CostInfo_RS" || Trans.Class == "Meter_RS" || Trans.Class == "Material_RS")
         {
             if (Trans.Mac == Mac)
             {
                 Rp.Operate(ref Trans);
             }
             else
             {
                 Trans.Error = "验证令牌错误";
             }
         }
         else
         {
             if (HttpContext.Current.Request.Url.Host.ToLower() == "localhost")
             {
                 Rp.Operate(ref Trans);
             }
             else
             {
                 if (!OperateKnownClass(ref Trans))
                 {
                     if (Trans.Mac == Mac)
                     {
                         Rp.Operate(ref Trans);
                     }
                     else
                     {
                         Trans.Error = "验证令牌错误";
                     }
                 }
             }
         }
     }
     catch (Exception ex)
     {
         PubInfo.GetLog().Error(ex);
         Trans.Error = new ApiResult(false, ex.Message + Environment.NewLine + ex.StackTrace).toJson();
     }
 }
Example #3
0
        private string OnPay(DataRow row)
        {
            #region 获取参数
            if (!row.Table.Columns.Contains("CommunityId") || string.IsNullOrEmpty(row["CommunityId"].ToString()))
            {
                return(new ApiResult(false, "缺少参数CommunityId").toJson());
            }
            string CommunityId = row["CommunityId"].ToString();

            if (!row.Table.Columns.Contains("CustID") || string.IsNullOrEmpty(row["CustID"].ToString()))
            {
                return(new ApiResult(false, "缺少参数CustID").toJson());
            }
            long CustID = Convert.ToInt64(row["CustID"].ToString());
            if (!row.Table.Columns.Contains("RoomID") || string.IsNullOrEmpty(row["RoomID"].ToString()))
            {
                return(new ApiResult(false, "缺少参数RoomID").toJson());
            }
            long RoomID = Convert.ToInt64(row["RoomID"].ToString());

            if (!row.Table.Columns.Contains("PayData") || string.IsNullOrEmpty(row["PayData"].ToString()))
            {
                return(new ApiResult(false, "缺少参数PayData").toJson());
            }
            string PayData = row["PayData"].ToString();
            if (!row.Table.Columns.Contains("PayType") || string.IsNullOrEmpty(row["PayType"].ToString()))
            {
                return(new ApiResult(false, "缺少参数PayType").toJson());
            }
            // 默认为微信支付
            if (!int.TryParse(row["PayType"].ToString(), out int PayType) || (PayType != 0 && PayType != 1))
            {
                PayType = 0;
            }
            #endregion

            #region 验证小区是否存在
            Tb_Community tb_Community = GetCommunity(CommunityId);
            if (null == tb_Community)
            {
                return(new ApiResult(false, "该项目未在运营系统中配置").toJson());
            }

            string erpConnStr = GetConnectionStr(tb_Community);
            #endregion

            #region 获取小区支付配置
            dynamic payConfig;
            using (IDbConnection conn = new SqlConnection(PubConstant.UnifiedContionString))
            {
                payConfig = conn.QueryFirstOrDefault("SELECT * FROM Tb_CCBPay_Config WHERE CommunityId = @CommunityId", new { CommunityId = tb_Community.Id });
                if (null == payConfig)
                {
                    return(new ApiResult(false, "该小区未配置支付信息").toJson());
                }
            }
            #endregion

            #region 检测支付数据格式
            if (!CheckPayData(erpConnStr, CustID, RoomID, PayData, out decimal Amt, out string errMsg, true))
            {
                return(new ApiResult(false, errMsg).toJson());
            }
            if (Amt <= 0.00M)
            {
                return(new ApiResult(false, "订单已被支付或者支付金额小于0").toJson());
            }
            #endregion

            DateTime DateNow = DateTime.Now;

            string OrderSN = DateNow.ToString("yyyyMMddHHmmssfff") + GetRandomCode(3);

            Dictionary <string, string> resultDic = new Dictionary <string, string>();
            resultDic.Add("MERCHANTID", Convert.ToString(payConfig.MerchantId));
            resultDic.Add("POSID", Convert.ToString(payConfig.PosId));
            resultDic.Add("BRANCHID", Convert.ToString(payConfig.BranchId));
            resultDic.Add("ORDERID", OrderSN);
            resultDic.Add("PAYMENT", Convert.ToString(Amt));
            resultDic.Add("CURCODE", "01");
            resultDic.Add("TXCODE", Convert.ToString(payConfig.TxCode));
            resultDic.Add("REMARK1", "");
            resultDic.Add("REMARK2", "");
            resultDic.Add("TYPE", Convert.ToString(payConfig.Type));

            string pub = Convert.ToString(payConfig.Pub);
            if (string.IsNullOrEmpty(pub) || pub.Length < 30)
            {
                log.Error("支付配置PUB有误:" + pub);
                return(new ApiResult(false, "支付配置PUB有误").toJson());
            }
            else
            {
                pub = pub.Substring(pub.Length - 30, 30);
            }
            resultDic.Add("PUB", pub);
            resultDic.Add("GATEWAY", 0 == PayType ? "" : "UnionPay");
            resultDic.Add("CLIENTIP", "");
            resultDic.Add("REGINFO", "");
            resultDic.Add("PROINFO", "");
            resultDic.Add("REFERER", "");
            resultDic.Add("THIRDAPPINFO", string.Format("comccbpay{0}{1}", Convert.ToString(payConfig.MerchantId), "hkccbpay"));

            string signStr = "";
            foreach (var item in resultDic)
            {
                signStr += string.Format("{0}={1}&", item.Key, item.Value);
            }
            signStr  = signStr.Remove(signStr.Length - 1, 1);
            signStr += "&MAC=" + AppPKI.getMd5Hash(signStr);

            #region 插入订单表
            using (IDbConnection conn = new SqlConnection(PubConstant.UnifiedContionString))
            {
                DynamicParameters parameters = new DynamicParameters();
                parameters.Add("PayConfigId", payConfig.Id);
                parameters.Add("OrderSN", OrderSN);
                parameters.Add("CustID", CustID);
                parameters.Add("RoomID", RoomID);
                parameters.Add("PayData", PayData);
                parameters.Add("Amt", Amt);
                parameters.Add("CreateTime", DateNow.ToString());
                if (conn.Execute(@"INSERT INTO Tb_CCBPay_Order(PayConfigId, OrderSN, CustID, RoomID, PayData, Amt, CreateTime) 
                                    VALUES(@PayConfigId, @OrderSN, @CustID, @RoomID, @PayData, @Amt, @CreateTime)", parameters) <= 0)
                {
                    return(new ApiResult(false, "保存订单信息失败,请重试").toJson());
                }
            }
            #endregion
            return(new ApiResult(true, signStr).toJson());
        }