Esempio n. 1
0
        /// <summary>
        /// Adds new order to database.
        /// </summary>
        /// <param name="conn"></param>
        /// <param name="order"></param>
        /// <returns></returns>
        public bool AddNewOrder(SqlConnection conn, TradeOrder order)
        {
            SqlParameter[] sqlParameters = new SqlParameter[]
            {
                new SqlParameter("@OrderId", order.OrderId),
                new SqlParameter("@Amount", order.Amount),
                new SqlParameter("@Subject", order.Subject),
                new SqlParameter("@Body", order.Body),
                new SqlParameter("@UserName", order.UserName),
                new SqlParameter("@CreatedTime", order.CreatedTime),
                new SqlParameter("@LastUpdatedTime", order.LastUpdatedTime),
                new SqlParameter("@State", order.State),
                new SqlParameter("@ResourceUrl", order.ResourceUrl),
                new SqlParameter("@OrderType", order.OrderType),
                new SqlParameter("@ResourceId", order.ResourceId)
            };

            return DBHelper.RunNonQueryProcedure(conn, "sp_AddNewOrder", sqlParameters) > 0;
        }
Esempio n. 2
0
        /// <summary>
        /// Adds new order to database.
        /// </summary>
        /// <returns></returns>
        public TradeOrder AddNewOrder(string orderId, string subject, string body, decimal amount,
            int state, string username, string resourceUrl, int orderType, int resourceId)
        {
            bool result = false;
            TradeOrder order = null;

            var conn = DBHelper.GetSqlConnection();
            try
            {
                orderId.CheckEmptyString("Order ID");
                subject.CheckEmptyString("Order Subject");
                body.CheckEmptyString("Order Body");

                if (state != (int)OrderState.New)
                {
                    throw new ArgumentException("Parameter Error");
                }

                order = new TradeOrder();
                order.OrderId = orderId;
                order.Amount = amount;
                order.Subject = subject;
                order.Body = body;
                order.UserName = username;
                order.CreatedTime = DateTime.Now;
                order.LastUpdatedTime = DateTime.Now;
                order.State = state;
                order.ResourceUrl = resourceUrl;
                order.OrderType = orderType;
                order.ResourceId = resourceId;

                conn.Open();
                result = orderDao.AddNewOrder(conn, order);
            }
            catch (Exception e)
            {
                LogService.Log("添加订单信息失败--" + e.Message, e.ToString().ToString());
            }
            finally
            {
                conn.Close();
            }

            return order;
        }
Esempio n. 3
0
        /// <summary>
        /// Gets order details by order id.
        /// </summary>
        /// <param name="conn"></param>
        /// <param name="orderId"></param>
        /// <returns></returns>
        public TradeOrder GetOrderByOrderId(SqlConnection conn, string orderId)
        {
            TradeOrder order = null;
            SqlParameter[] sqlParameters = new SqlParameter[]
            {
                new SqlParameter("@OrderId", orderId)
            };

            SqlDataReader reader = DBHelper.RunProcedure(conn, "sp_SelectOrderByOrderId", sqlParameters);

            while (reader.Read())
            {
                order = new TradeOrder()
                {
                    OrderId = orderId,
                    Amount = reader["Amount"].DBToDecimal(),
                    Body = reader["Body"].DBToString(),
                    CreatedTime = reader["CreatedTime"].DBToDateTime().Value,
                    LastUpdatedTime = reader["LastUpdatedTime"].DBToDateTime().Value,
                    State = reader["State"].DBToInt32(),
                    Subject = reader["Subject"].DBToString(),
                    UserName = reader["UserName"].DBToString(),
                    ResourceUrl = reader["ResourceUrl"].DBToString(),
                    OrderType = reader["OrderType"].DBToInt32(),
                    ResourceId = reader["ResourceId"].DBToInt32()
                };
            }

            if (reader != null)
            {
                reader.Close();
            }

            return order;
        }
Esempio n. 4
0
        private bool PreparePaySign(TradeOrder order, out string appId, out string timeStamp,
            out string nonceStr, out string package, out string paySign, out string message)
        {
            bool isSuccessFul = false;

            appId = string.Empty;
            timeStamp = string.Empty;
            nonceStr = string.Empty;
            package = string.Empty;
            paySign = string.Empty;

            message = string.Empty;

            try
            {

                //创建支付应答对象
                RequestHandler packageReqHandler = new RequestHandler(null);
                //初始化
                packageReqHandler.Init();

                appId = TenPayV3Info.AppId;
                timeStamp = TenPayV3Util.GetTimestamp();
                nonceStr = TenPayV3Util.GetNoncestr();

                string body = "活动在线网-购买需求联系方式";

                //设置package订单参数
                packageReqHandler.SetParameter("appid", TenPayV3Info.AppId);		  //公众账号ID
                packageReqHandler.SetParameter("mch_id", TenPayV3Info.MchId);		  //商户号
                packageReqHandler.SetParameter("nonce_str", nonceStr);                    //随机字符串
                packageReqHandler.SetParameter("body", body);    //商品信息
                packageReqHandler.SetParameter("out_trade_no", order.OrderId);		//商家订单号
                packageReqHandler.SetParameter("total_fee", (Convert.ToInt32(order.Amount * 100).ToString()));			        //商品金额,以分为单位(money * 100).ToString()
                packageReqHandler.SetParameter("spbill_create_ip", Request.UserHostAddress);   //用户的公网ip,不是商户服务器IP
                packageReqHandler.SetParameter("notify_url", TenPayV3Info.TenPayV3Notify);		    //接收财付通通知的URL
                packageReqHandler.SetParameter("trade_type", TenPayV3Type.JSAPI.ToString());	                    //交易类型
                packageReqHandler.SetParameter("openid", CurrentWeChatUser.OpenId);	                    //用户的openId

                string sign = packageReqHandler.CreateMd5Sign("key", TenPayV3Info.Key);
                packageReqHandler.SetParameter("sign", sign);	                    //签名

                string data = packageReqHandler.ParseXML();

                var result = TenPayV3.Unifiedorder(data);
                var res = XDocument.Parse(result);

                LogService.LogWexin("微信支付参数", res.ToString());
                string prepayId = res.Element("xml").Element("prepay_id").Value;

                //设置支付参数
                RequestHandler paySignReqHandler = new RequestHandler(null);
                paySignReqHandler.SetParameter("appId", TenPayV3Info.AppId);
                paySignReqHandler.SetParameter("timeStamp", timeStamp);
                paySignReqHandler.SetParameter("nonceStr", nonceStr);
                paySignReqHandler.SetParameter("package", string.Format("prepay_id={0}", prepayId));
                paySignReqHandler.SetParameter("signType", "MD5");

                paySign = paySignReqHandler.CreateMd5Sign("key", TenPayV3Info.Key);
                package = string.Format("prepay_id={0}", prepayId);
            }
            catch (Exception ex)
            {
                message = "支付过程发生错误";
                LogService.LogWexin("构建支付参数出错", ex.ToString());
            }

            if (!string.IsNullOrEmpty(appId) &&
                !string.IsNullOrEmpty(timeStamp) &&
                !string.IsNullOrEmpty(nonceStr) &&
                !string.IsNullOrEmpty(package) &&
                !string.IsNullOrEmpty(paySign))
            {
                isSuccessFul = true;
            }

            return isSuccessFul;
        }