Ejemplo n.º 1
0
        public ApiResult GetInfoByOrderNo(string no)
        {
            ApiResult ar = new ApiResult();

            try
            {
                if (string.IsNullOrEmpty(no))
                {
                    return(new ApiResult()
                    {
                        code = ApiResult.Code.failure, message = "参数错误"
                    });
                }
                MG_DAL.YiwenGPSEntities db = new MG_DAL.YiwenGPSEntities();
                var query = from o in db.Orders
                            join u in db.Users
                            on o.UserID equals u.UserID
                            join d in db.Devices
                            on o.DeviceID equals d.DeviceID
                            where o.OrderNo == no
                            select new { o.OrderNo, o.PayDate, o.UserID, o.DeviceID, u.LoginName, u.Password, o.Status, HireExpireDate = d.HireExpireDate.Value.Year + "年" + d.HireExpireDate.Value.Month + "月" + d.HireExpireDate.Value.Day + "号" };
                var first = query.FirstOrDefault();
                ar.code    = ApiResult.Code.success;
                ar.message = "";
                ar.result  = first;
            }
            catch (Exception ex)
            {
                ar.code    = ApiResult.Code.error;
                ar.message = ex.Message;
                Log.Error(this, ex);
            }
            return(ar);
        }
Ejemplo n.º 2
0
        protected void Page_Load(object sender, EventArgs e)
        {
            if (string.IsNullOrEmpty(Request.QueryString["code"]))
            {
                imei = Request.QueryString["imei"];
                string vc = Request.QueryString["vc"];
                total_fee = Convert.ToInt32(Request.QueryString["p"]);
                userid    = Convert.ToInt32(Request.QueryString["userid"]);
                status    = Convert.ToInt32(Request.QueryString["s"]);
                var ru = HttpUtility.UrlEncode($"http://m.mgoogps.com/Pay/PayConfirm.aspx?imei={imei}&vc={vc}&p={total_fee}&userid={userid}&s={status}");

                var url = $"https://open.weixin.qq.com/connect/oauth2/authorize?appid={WxPayConfig.APPID}&redirect_uri={ru}&response_type=code&scope=snsapi_base&state=snsapi_base#wechat_redirect";
                //https://open.weixin.qq.com/connect/oauth2/authorize?appid=wxda27104d229a3608&redirect_uri=http://m.mgoogps.com/Pay/PayConfirm.aspx?imei=1&vc=12&p=1223&response_type=code&scope=snsapi_base&state=snsapi_base#wechat_redirect
                Response.Redirect(url);
                Response.End();
            }
            if (!IsPostBack)
            {
                imei = Request.QueryString["imei"];
                string vc = Request.QueryString["vc"];
                total_fee = Convert.ToInt32(Request.QueryString["p"]);
                var code = Request.QueryString["code"];
                userid = Convert.ToInt32(Request.QueryString["userid"]);
                status = Convert.ToInt32(Request.QueryString["s"]);
                if (userid == 0)
                {
                    state = "参数错误!";
                    return;
                }
                MG_DAL.YiwenGPSEntities db = new MG_DAL.YiwenGPSEntities();
                var device = db.Devices.Where(d => d.Deleted == false && d.SerialNumber == imei && d.DevicePassword == vc).SingleOrDefault();
                prductName = "北斗GPS流量费(2年)-" + (string.IsNullOrEmpty(device.DeviceName) ? device.SerialNumber : device.DeviceName);
                JsApiPay jsApiPay = new JsApiPay(this);
                if (device.Model.Equals("80")) //MG-X21BZ
                {
                    jsApiPay.tariff_id = 8;
                    total_fee          = 240;
                }
                else
                {
                    jsApiPay.tariff_id = 9;
                    total_fee          = 195;
                }

                //JSAPI支付预处理
                try
                {
                    var userList = new List <int>()
                    {
                        6, 7, 5959, 1296, 1389, 1331, 6093
                    };
                    // total_fee = ( type == "1" ? int.Parse(total_fee) :int.Parse( total_fee) )+"";
                    jsApiPay.user_id = userid;// (int)device.UserID;
                    //jsApiPay.openid = openid;
                    jsApiPay.total_fee = userList.Contains(jsApiPay.user_id)? new Random().Next(1, 10) : Convert.ToInt32(total_fee) * 100;
                    jsApiPay.device_id = device.DeviceID;

                    jsApiPay.product_body = prductName;
                    jsApiPay.device_name  = "success_notify," + device.DeviceID + "," + userid + "," + status;//attach 商家数据包,原样返回, status :1 账号已存在,2是新注册的账号
                    if (total_fee < 195 && !userList.Contains(jsApiPay.user_id))
                    {
                        state = "下单失败,金额错误!";
                        return;
                    }
                    jsApiPay.GetOpenidAndAccessTokenFromCode(code);

                    WxPayData unifiedOrderResult = jsApiPay.GetUnifiedOrderResult();
                    wxJsApiParam = jsApiPay.GetJsApiParameters();//获取H5调起JS API参数

                    jsApiPay.InsertMgooOrder();

                    //下单成功后的内部订单号
                    order_no     = jsApiPay.order_no;
                    callback_url = "../PayActivation/payResult.html?no=" + order_no.ToString() + "&deviceid=" + device.DeviceID + "&t=" + DateTime.Now.Ticks;
                    Log.Debug(this.GetType().ToString(), "wxJsApiParam : " + wxJsApiParam);

                    //在页面上显示订单信息
                    // Response.Write("<span style='color:#00CD00;font-size:20px' id='payRes'>订单详情:</span><br/>");
                    // Response.Write("<span style='color:#00CD00;font-size:20px'>" + unifiedOrderResult.ToPrintStr() + "</span>");
                }
                catch (System.Net.WebException ex)
                {
                    MG_BLL.Common.Log.Error(this, ex);
                    //state = ex.Message;
                    state = "网络繁忙,请稍后再试!";
                }
                catch (Exception ex)
                {
                    state = "下单失败,请稍后再试!";
                    MG_BLL.Common.Log.Error(this, ex);
                    //state = ex.Message;
                    // Utils.log("下单失败:userid:" + userid + ",deviceid:" + deviceid + ",total_fee:" + Convert.ToInt32(total_fee) + ",openid:" + openid + ",tariff_id:" + tariff_id + ",tariff_name:" + tariff_name + ",device_name:" + device_name + ",type:" + type);
                    //Response.Write("<span style='color:#FF0000;font-size:20px'>" + "下单失败,请返回重试" + "</span>");
                    // submit.Visible = false;
                }
            }
        }
Ejemplo n.º 3
0
        public ApiResult Reg(dynamic args)
        {
            try
            {
                string phone = Convert.ToString(args.phone);
                string code  = Convert.ToString(args.code);
                string vc    = Convert.ToString(args.vc);
                string imei  = Convert.ToString(args.imei);
                MG_DAL.YiwenGPSEntities db = new MG_DAL.YiwenGPSEntities();
                var device = db.Devices.Where(item => item.SerialNumber == imei && item.DevicePassword == vc && item.Deleted == false).SingleOrDefault();
                if (device == null)
                {
                    return(new ApiResult()
                    {
                        code = ApiResult.Code.failure, message = "未找到设备."
                    });
                }
                if (string.IsNullOrEmpty(phone))
                {
                    return(new ApiResult()
                    {
                        code = ApiResult.Code.failure, message = "手机号码格式错误"
                    });
                }
                MG_BLL.BllLogin bl = new MG_BLL.BllLogin();
                Register        r  = new Register();
                if (r.VerificationCode(phone, code) || phone == "18507480591")
                {
                    var msg    = "";
                    var status = 0;
                    var res    = r.VerificationPhone(phone);
                    if (res)
                    {
                        msg    = "账号已存在,请付款激活设备.";
                        status = 1;
                        // return new ApiResult() { message = "账号已存在,请付款激活设备.", code = ApiResult.Code.success };
                    }
                    else
                    {
                        res = r.MgRegister(phone, "123456", phone);
                        if (res)
                        {
                            status = 2;
                            msg    = "账号已启用,请付款激活设备.";
                            //return new ApiResult() { message = "账号已启用,请付款激活设备.", code = ApiResult.Code.success };
                        }
                    }
                    if (!string.IsNullOrEmpty(msg))
                    {
                        var user = db.Users.Where(u => u.LoginName == phone && u.Deleted == false).FirstOrDefault();
                        return(new ApiResult()
                        {
                            message = msg, code = ApiResult.Code.success, result = new { userid = user.UserID, status = status }
                        });
                    }
                }
                else
                {
                    return(new ApiResult()
                    {
                        message = "验证码错误.", code = ApiResult.Code.failure
                    });
                }

                return(new ApiResult()
                {
                    message = "账号注册失败.", code = ApiResult.Code.failure
                });
            }
            catch (Exception ex)
            {
                return(new ApiResult()
                {
                    code = ApiResult.Code.error, message = "注册失败,请检查参数是否输入正确", result = new { error = ex.Message }
                });
            }
        }
Ejemplo n.º 4
0
        public override void ProcessNotify()
        {
            WxPayData notifyData = GetNotifyData();

            //检查支付结果中transaction_id是否存在
            if (!notifyData.IsSet("transaction_id"))
            {
                //若transaction_id不存在,则立即返回结果给微信支付后台
                WxPayData res = new WxPayData();
                res.SetValue("return_code", "FAIL");
                res.SetValue("return_msg", "支付结果中微信订单号不存在");
                Log.Error(this.GetType().ToString(), "The Pay result is error : " + res.ToXml());
                page.Response.Write(res.ToXml());
                page.Response.End();
            }

            this.transaction_id = notifyData.GetValue("transaction_id").ToString();

            //查询订单,判断订单真实性
            if (!QueryOrder(this.transaction_id))
            {
                //若订单查询失败,则立即返回结果给微信支付后台
                WxPayData res = new WxPayData();
                res.SetValue("return_code", "FAIL");
                res.SetValue("return_msg", "订单查询失败");
                Log.Error(this.GetType().ToString(), "Order query failure : " + res.ToXml());
                page.Response.Write(res.ToXml());
                page.Response.End();
            }
            //查询订单成功
            else
            {
                WxPayData res = new WxPayData();
                res.SetValue("return_code", "SUCCESS");
                res.SetValue("return_msg", "OK");
                Log.Info(this.GetType().ToString(), "order query success : " + res.ToXml());
                //result_code等于SUCCESS,代表支付成功
                Log.Info(this.GetType().ToString(), "-----result_code:" + notifyData.GetValue("result_code") + ",微信订单号" + this.transaction_id);
                if (notifyData.GetValue("result_code").ToString() == "SUCCESS")
                {
                    this.trade_no    = notifyData.GetValue("out_trade_no").toStringEmpty();
                    this.time_end    = notifyData.GetValue("time_end").toStringEmpty();
                    this.trade_type  = notifyData.GetValue("trade_type").ToString();
                    this.fee_type    = notifyData.GetValue("fee_type").toStringEmpty();
                    this.bank_type   = notifyData.GetValue("bank_type").toStringEmpty();
                    this.device_name = notifyData.GetValue("attach").ToString();
                    string openid    = notifyData.GetValue("openid").ToString();
                    string total_fee = notifyData.GetValue("total_fee").ToString();


                    MgooOrders.Orders o = new MgooOrders.Orders();

                    bool success = o.ModifyOrderStatus(transaction_id, fee_type, time_end, bank_type, trade_type, trade_no, !device_name.StartsWith("success_notify"));

                    if (success)
                    {
                        string emailTitle = null;
                        Task   task       = null;
                        if (device_name.StartsWith("success_notify"))
                        {
                            task = Task.Run(() =>
                            {
                                try
                                {
                                    MG_DAL.YiwenGPSEntities db = new MG_DAL.YiwenGPSEntities();
                                    var dev            = db.Devices.Find(Convert.ToInt32(device_name.Split(',')[1]));
                                    dev.HireExpireDate = Convert.ToDateTime(DateTime.Now.AddYears(2).AddMonths(-1).ToString("yyyy-MM-25 00:00:00"));
                                    dev.ActiveDate     = DateTime.Now;
                                    db.SaveChangesAsync();
                                    var urserid = device_name.Split(',')[2];
                                    var status  = device_name.Split(',')[3];

                                    emailTitle  = "设备激活充值成功";
                                    device_name = string.IsNullOrEmpty(dev.DeviceName) ? dev.SerialNumber : dev.DeviceName;
                                    ///用户在代理商线下用微信支付 扫码支付 激活设备
                                    Weixin.Devices wd = new Weixin.Devices(new Common.AuthHeader()
                                    {
                                        UserID = urserid
                                    });
                                    wd.AddDevice(dev.SerialNumber, dev.DevicePassword, urserid, "-1", isAdd: true, ifMoneyModel: false);
                                }
                                catch (Exception ex)
                                {
                                    Common.Log.Error(this, ex);
                                }
                            });
                        }

                        if (task != null)
                        {
                            task.Wait();
                        }
                        Task.Run(() => o.SendMail(trade_no, emailTitle));
                        Task.Run(() => o.PaySuccessPush(openid, device_name, total_fee, time_end, o.GetBankName(bank_type), trade_no));
                    }
                }
                page.Response.Write(res.ToXml());
                page.Response.End();
            }
        }