Ejemplo n.º 1
0
        /// <summary>
        ///
        /// </summary>
        /// <param name="out_trade_no"></param>
        /// <param name="openid"></param>
        /// <param name="spbill_create_ip"></param>
        /// <param name="total_fee">单位分</param>
        /// <returns></returns>
        public JSSDKPrepay Prepay(string out_trade_no, string openid, string spbill_create_ip, string total_fee)
        {
            var prepay = new JSSDKPrepay();
            var o      = new JSSDKPayOrder();

            o.body             = WxConfig.wxpay_body;
            o.attach           = WxConfig.wxpay_attach;
            o.out_trade_no     = out_trade_no;     //.Substring(0, 32);
            o.spbill_create_ip = spbill_create_ip; //APP和网页支付提交用户端ip,Native支付填调用微信支付API的机器IP。
            o.openid           = openid;
            o.total_fee        = total_fee;
            //prepay.prepay_id = "test";//todo test
            prepay.prepay_id = GetPaymentId(o);
            prepay.appId     = WxConfig.Appid;
            prepay.timeStamp = Utility.GetTimeSpan();
            prepay.nonceStr  = Utility.GenerateNonceStr();
            prepay.signType  = "MD5";
            string payRaw = "appId=" + prepay.appId
                            + "&nonceStr=" + prepay.nonceStr
                            + "&package=" + prepay.package
                            + "&signType=" + prepay.signType
                            + "&timeStamp=" + prepay.timeStamp
                            + "&key=" + WxConfig.wxpay_key;

            prepay.paySign = Utility.WXPaySignature(payRaw, prepay.signType);
            return(prepay);
        }
Ejemplo n.º 2
0
        private string GetPaymentId(JSSDKPayOrder order)
        {
            const string url = "https://api.mch.weixin.qq.com/pay/unifiedorder";

            order.appid            = WxConfig.Appid;
            order.mch_id           = WxConfig.mch_id;
            order.spbill_create_ip = order.spbill_create_ip;
            order.notify_url       = WxConfig.NOTIFY_URL;
            order.nonce_str        = Utility.GenerateNonceStr();
            order.trade_type       = "JSAPI";
            var raw = "appid=" + order.appid
                      + "&attach=" + order.attach
                      + "&body=" + order.body
                      //+ "&detail=" + order.detail
                      //+ "&goods_tag=" + order.goods_tag
                      + "&mch_id=" + order.mch_id
                      + "&nonce_str=" + order.nonce_str
                      + "&notify_url=" + order.notify_url
                      + "&openid=" + order.openid
                      + "&out_trade_no=" + order.out_trade_no
                      + "&spbill_create_ip=" + order.spbill_create_ip
                      + "&total_fee=" + order.total_fee
                      + "&trade_type=" + order.trade_type
                      + "&key=" + WxConfig.wxpay_key;

            order.sign = Utility.Signature(raw, "MD5").ToUpper();
            var unifiedorder = PostXmlData <UnifiedOrder>(Utility.Serialize <JSSDKPayOrder>(order), url);

            if (unifiedorder.return_code != "SUCCESS")
            {
                throw new Exception(unifiedorder.return_msg);
            }
            return(unifiedorder.prepay_id);
        }
Ejemplo n.º 3
0
        public PlaceResult PlaceOrder(OrderInfo orderInfo)
        {
            var result = new PlaceResult()
            {
                Success = true, OrderId = Guid.NewGuid()
            };

            if (orderInfo.Positions == null || orderInfo.Positions.Count == 0)
            {
                result.Success = false;
                result.Message = "请选择位置";
                return(result);
            }
            var o = new JSSDKPayOrder();

            o.out_trade_no     = result.OrderId.ToString();
            o.body             = "";           //腾讯充值中心-QQ会员充值
            o.attach           = "";           //深圳分店
            o.spbill_create_ip = orderInfo.IP; //APP和网页支付提交用户端ip,Native支付填调用微信支付API的机器IP。
            result.prepay_id   = "test";
            //result.prepay_id = WxApiHelper.Instance.GetPaymentId(o);//todo test
            result.appId     = WxConfig.Appid;
            result.timeStamp = Utility.GetTimeSpan();
            result.nonceStr  = Utility.GenerateNonceStr();
            result.signType  = "MD5";
            string payRaw = "appId=" + result.appId
                            + "&nonceStr=" + result.nonceStr
                            + "&package=" + result.package
                            + "&signType=" + result.signType
                            + "&timeStamp=" + result.timeStamp;

            result.paySign = Utility.Signature(payRaw, result.signType);
            try
            {
                using (var uow = GetUnitOfWork())
                {
                    var desk =
                        uow.Repository <ZY_Shop_Desk>()
                        .Query()
                        .Filter(x => x.DeskId == orderInfo.DeskId)
                        .Get()
                        .FirstOrDefault();
                    if (desk == null)
                    {
                        result.Success = false;
                        result.Message = "没有找到桌子";
                        return(result);
                    }
                    var order = new ZY_Order()
                    {
                        OrderId        = result.OrderId,
                        Amount         = orderInfo.Positions.Count * desk.UnitPrice,
                        CustomerOpenId = orderInfo.CustomerOpenId,
                        OrderDate      = orderInfo.pickDate.Date,
                        Prepay_id      = result.prepay_id,
                        PickTime       = orderInfo.pickTime,
                        Status         = 0
                    };
                    var positions = new List <ZY_Booked_Position>();
                    orderInfo.Positions.ForEach(x =>
                    {
                        var p = new ZY_Booked_Position()
                        {
                            Id             = Guid.NewGuid(),
                            CustomerOpenId = orderInfo.CustomerOpenId,
                            OrderDate      = orderInfo.pickDate.Date,
                            DeskId         = orderInfo.DeskId,
                            Position       = x,
                            Status         = "1",
                            OrderId        = order.OrderId
                        };
                        positions.Add(p);
                    });
                    uow.Repository <ZY_Order>().Insert(order);
                    uow.Repository <ZY_Booked_Position>().InsertRange(positions);
                    uow.Save();
                    result.Success = true;
                    result.Message = string.Format("下单成功"); //todo message 优化
                }
            }
            catch (Exception ex)
            {
                result.Success = false;
                result.Message = "失败啦";
            }
            return(result);
        }