Ejemplo n.º 1
0
        /**
         * 调用统一下单,获得下单结果
         * @return 统一下单结果
         * @失败时抛异常WxPayException
         */
        public static string PayOrder(TCom.EF.MyOrder order, TCom.EF.User user)
        {
            try
            {
                //统一下单
                WxPayData data = new WxPayData();
                data.SetValue("body", order.merc + "-" + (order.otype == 1 ? "宽带" : "报装"));
                data.SetValue("attach", order.spec);
                data.SetValue("out_trade_no", order.orderno + "");
                double total_fee = order.totalfee != null ? order.totalfee.Value : 0;

                data.SetValue("total_fee", (int)(total_fee * 100));
                data.SetValue("time_start", DateTime.Now.ToString("yyyyMMddHHmmss"));
                data.SetValue("time_expire", DateTime.Now.AddDays(1).ToString("yyyyMMddHHmmss"));
                data.SetValue("goods_tag", "test");
                data.SetValue("trade_type", "JSAPI");
                data.SetValue("openid", user.idweixin);
                WxPayData result = WxPayApi.UnifiedOrder(data);
                if (!result.IsSet("appid") || !result.IsSet("prepay_id") || result.GetValue("prepay_id").ToString() == "")
                {
                    return(null);
                }
                return(GetJsOrder(result));
            }
            catch (Exception)
            {
            }
            return(null);
        }
Ejemplo n.º 2
0
        public Result <PayResult> Create(PayData data)
        {
            Result <PayResult> result = new Result <PayResult>();

            result.Msg = "生成支付订单失败";
            if (data != null && !string.IsNullOrWhiteSpace(data.iduser) && !string.IsNullOrWhiteSpace(data.orderno))
            {
                try
                {
                    long _iduser  = long.Parse(data.iduser);
                    long _orderno = long.Parse(data.orderno);
                    using (TCom.EF.TN db = new TCom.EF.TN())
                    {
                        TCom.EF.User u = db.Users.Where(m => m.iduser == _iduser && m.inuse == true).FirstOrDefault();
                        if (u != null)
                        {
                            TCom.EF.MyOrder o = db.MyOrders.Where(m => m.orderno == _orderno && m.inuse == true).FirstOrDefault();
                            if (o != null)
                            {
                                if (o.paystatus == PayStatus.WeiXin_CLOSED)
                                {
                                    o.status = OrderStatus.Close;
                                    db.SaveChanges();
                                    result.Msg = "订单已关闭";
                                }
                                else
                                {
                                    o.paystatus = PayStatus.WaitPay;
                                    if (o.payway != "weixin")
                                    {
                                        o.payway = "weixin";
                                        if (db.SaveChanges() <= 0)
                                        {
                                            result.Msg = "更新支付方式失败";
                                            return(result);
                                        }
                                    }
                                    result.Data = new PayResult
                                    {
                                        order = JsApiPay.PayOrder(o, u)
                                    };
                                    result.Code = R.Ok;
                                }
                            }
                        }
                    }
                }
                catch (Exception)
                {
                    result.Code = R.Error;
                    result.Msg  = "拉取订单出错";
                }
            }
            else
            {
                result.Msg = "不存在该订单";
            }
            return(result);
        }
Ejemplo n.º 3
0
        public UserInfo(TCom.EF.User u, MUser mu)
        {
            this.idweixin = u.idweixin;
            this.iduser   = u.iduser + "";
            this.name     = u.name;
            this.phone    = u.phone;
            this.sex      = u.sex;
            this.comp     = u.comp;
            this.avatar   = u.avatar;
            this.cretime  = u.cretime != null?u.cretime.Value.ToString("yyyy-MM-dd HH:mm") : "";

            this.notes = u.notes;
            this.mu    = mu;
        }