Beispiel #1
0
        public void UnifiedOrder(string deviceid, string tariffid, string tradetype)
        {
            int tariff_id         = int.Parse(tariffid);
            SQLServerOperating s  = new SQLServerOperating();
            DataTable          dt = s.Selects(" select ID, TariffName, Price, OldPrice, BuyCount, Type  from TariffPackages where ID=@tariff_id", new SqlParameter[] { new SqlParameter("tariff_id", tariff_id) });

            if (dt.Rows.Count <= 0)
            {
                return;
            }
            s.ExecuteSql("update TariffPackages set BuyCount=BuyCount+cast( ceiling(rand()*100) as int) where ID=@ID", new SqlParameter[] { new SqlParameter("ID", tariff_id) });
            s.Selects(" select ID, TariffName, Price, OldPrice, BuyCount, Type  from TariffPackages where ID=@tariff_id", new SqlParameter[] { new SqlParameter("tariff_id", tariff_id) });
            string total_fee   = dt.Rows[0]["Price"].toStringEmpty();
            string tariff_name = dt.Rows[0]["TariffName"].toStringEmpty();
            string device_name = s.Select("select case when DeviceName='' then SerialNumber else DeviceName end from Devices where deviceid=@deviceid", new SqlParameter[] { new SqlParameter("deviceid", deviceid) });

            if (string.IsNullOrEmpty(device_name))
            {
                return;
            }
            tariff_name = "GPS移动流量-" + device_name + " 充值" + tariff_name;
            JsApiPay jsApiPay = new JsApiPay();

            jsApiPay.user_id   = int.Parse(myHeader.UserID);
            jsApiPay.openid    = "";
            jsApiPay.total_fee = jsApiPay.user_id == 6 || jsApiPay.user_id == 7 ? new Random().Next(1, 10) : int.Parse(total_fee);
            jsApiPay.device_id = int.Parse(deviceid);
            jsApiPay.tariff_id = tariff_id;

            jsApiPay.product_body = tariff_name;
            WxPayData unifiedOrderResult = jsApiPay.GetUnifiedOrderResult();

            jsApiPay.InsertMgooOrder();
            // AddOrder(myHeader.UserID,deviceid,"",);
        }
Beispiel #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;
                }
            }
        }
Beispiel #3
0
        protected void Page_Load(object sender, EventArgs e)
        {
            if (!IsPostBack)
            {
                userid    = Request.QueryString["userid"];
                total_fee = Request.QueryString["total_fee"];
                deviceid  = Request.QueryString["deviceid"];
                string openid = Request.QueryString["openid"];
                type = Request.QueryString["type"];
                imei = Request.QueryString["imei"];
                string tid = Request.QueryString["tariff_id"];
                if (type == "1")
                {
                    tid       = "7";
                    userid    = "7";
                    total_fee = "1";
                }
                else
                {
                    type = "2";
                }
                //检测是否给当前页面传递了相关参数string.IsNullOrEmpty(openid) ||
                if (string.IsNullOrEmpty(total_fee) || string.IsNullOrEmpty(deviceid) || string.IsNullOrEmpty(tid) || string.IsNullOrEmpty(openid) || string.IsNullOrEmpty(userid))
                {
                    state = "页面传参出错,请返回重试";
                    //Response.Write("<span style='color:#FF0000;font-size:20px'>" + "页面传参出错,请返回重试" + "</span>");
                    Log.Error(this.GetType().ToString(), "This page have not get params, cannot be inited, exit...");
                    //submit.Visible = false;
                    return;
                }
                int tariff_id        = int.Parse(tid);
                SQLServerOperating s = new SQLServerOperating();
                // DataTable dt= s.Selects(" select ID, TariffName, Price, OldPrice, BuyCount, Type  from TariffPackages where ID=@tariff_id", new SqlParameter[] { new SqlParameter("tariff_id", tariff_id) });
                string    strSql = @"update TariffPackages set BuyCount=BuyCount+cast( ceiling(rand()*100) as int) where ID=@tariff_id;
                                  select ID, TariffName, Price, OldPrice, BuyCount, Type,
                                  (select case when DeviceName='' then SerialNumber else DeviceName end from Devices where deviceid=@deviceid) DeviceName
                                  from TariffPackages where ID=@tariff_id  ";
                DataTable dt     = s.Selects(strSql, new SqlParameter[] { new SqlParameter("tariff_id", tariff_id), new SqlParameter("deviceid", deviceid) });
                if (dt.Rows.Count <= 0)
                {
                    state = "页面传参出错,请返回重试";
                    return;
                }
                //s.ExecuteSql("update TariffPackages set BuyCount=BuyCount+cast( ceiling(rand()*100) as int) where ID=@ID", new SqlParameter[] { new SqlParameter("ID", tariff_id) });

                total_fee   = dt.Rows[0]["Price"].toStringEmpty();
                tariff_name = dt.Rows[0]["TariffName"].toStringEmpty();
                device_name = dt.Rows[0]["DeviceName"].toStringEmpty(); // s.Select("", new SqlParameter[] { new SqlParameter("deviceid", deviceid) });
                if (string.IsNullOrEmpty(device_name))
                {
                    return;
                }
                tariff_name = "GPS移动流量-" + device_name + " 充值" + tariff_name;
                //若传递了相关参数,则调统一下单接口,获得后续相关接口的入口参数
                JsApiPay jsApiPay = new JsApiPay(this);
                //JSAPI支付预处理
                try
                {
                    // total_fee = ( type == "1" ? int.Parse(total_fee) :int.Parse( total_fee) )+"";
                    jsApiPay.user_id      = int.Parse(userid);
                    jsApiPay.openid       = openid;
                    jsApiPay.total_fee    = jsApiPay.user_id == 6 || jsApiPay.user_id == 7 ? new Random().Next(1, 10) : Convert.ToInt32(total_fee);
                    jsApiPay.device_id    = int.Parse(deviceid);
                    jsApiPay.tariff_id    = tariff_id;
                    jsApiPay.product_body = tariff_name;
                    jsApiPay.device_name  = device_name;
                    WxPayData unifiedOrderResult = jsApiPay.GetUnifiedOrderResult();
                    wxJsApiParam = jsApiPay.GetJsApiParameters();//获取H5调起JS API参数

                    jsApiPay.InsertMgooOrder();

                    //下单成功后的内部订单号
                    order_no     = jsApiPay.order_no;
                    callback_url = "http://m.mgoogps.com:8070/pay/pay_success.aspx?no=" + order_no.ToString() + "&deviceid=" + 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)
                {
                    //state = ex.Message;
                    state = "网络繁忙,请稍后再试!";
                }
                catch (Exception ex)
                {
                    state = "下单失败,请稍后再试!";
                    //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;
                }
            }
        }