コード例 #1
0
        protected void Page_Load(object sender, EventArgs e)
        {
            if (!IsPostBack)
            {
                IsLoad = false;
                JsApiPay jsApiPay = new JsApiPay(this);
                try
                {
                    //定义一个回调地址
                    //ViewState["callbackurl"] = "http://keaideyibaobao.com/charactertest.aspx";

                    //调用【网页授权获取用户信息】接口获取用户的openid和access_token
                    jsApiPay.GetOpenidAndAccessToken();

                    //获取收货地址js函数入口参数
                    //wxEditAddrParam = jsApiPay.GetEditAddressParameters();
                    ViewState["openid"] = jsApiPay.openid;
                    //ViewState["access_token"] = jsApiPay.access_token;
                    string resToken = HttpService.Get("https://api.weixin.qq.com/cgi-bin/token?grant_type=client_credential&appid=wxcaf17959e7a40461&secret=d6e05480d9cebeecd672e08d84dd3737");

                    LitJson.JsonData jdata = LitJson.JsonMapper.ToObject(resToken);

                    WxPayData data = new WxPayData();
                    data.SetValue("access_token", jdata["access_token"]);
                    data.SetValue("openid", jsApiPay.openid);

                    string url    = "https://api.weixin.qq.com/cgi-bin/user/info?" + data.ToUrl();
                    string result = HttpService.Get(url);
                    jdata = LitJson.JsonMapper.ToObject(result);
                    if (!string.IsNullOrEmpty(jdata["subscribe"].ToString()))
                    {
                        if (jdata["subscribe"].ToString() == "1")
                        {
                            Session["openid"] = jsApiPay.openid;
                            //关注该公众账号,进行推荐处理
                            if (Request["reference"] != null)
                            {
                                string reference = Request["reference"].ToString();
                            }
                            //Response.Write("<span style='color:#FF0000;font-size:20px'>" + "您已关注本公众号" + "</span>");
                        }
                        else
                        {
                            Response.Write("<script>alert('您尚未关注该公众号')</script>");
                            // Response.Write("<script>window.location.href='weixin://weixin.qq.com/r/dz8fB6zE8fGOrehk92pl';</script>");
                            Server.Transfer("./pic.aspx");
                            return;
                        }
                    }

                    //Response.Write("<span style='color:#FF0000;font-size:20px'>" + result + jsApiPay.openid + "</span>");
                }
                catch (Exception ex)
                {
                    Response.Write("<script>alert('系统出了点小问题,请您稍后再试')");
                }
            }
        }
コード例 #2
0
ファイル: ProOrders.aspx.cs プロジェクト: ZhiWenGu/MeiJiaMall
        protected void Page_Load(object sender, EventArgs e)
        {
            GoodsServer     server    = new GoodsServer();
            SinglePayServer sinserver = new SinglePayServer();

            //string goodid = "";
            Log.Info(this.GetType().ToString(), "page load");
            if (!IsPostBack)
            {
                //if (Request["GoodId"] != null){
                //    goodid=Request["GoodId"];
                //    goods = server.GetGoods(goodid);
                //    string price = goods.GPrice.ToString();
                //    string name = goods.GName;
                //    ViewState["goodsprice"] = price;
                //    ViewState["name"] = name;
                //}
                //string GoodId = Request["GoodId"];
                JsApiPay jsApiPay = new JsApiPay(this);
                //jsApiPay.QueryId = GoodId;

                try
                {
                    //调用【网页授权获取用户信息】接口获取用户的openid和access_token
                    jsApiPay.GetOpenidAndAccessToken();

                    //获取收货地址js函数入口参数
                    wxEditAddrParam     = jsApiPay.GetEditAddressParameters();
                    ViewState["openid"] = jsApiPay.openid;
                    //dic.Add(jsApiPay.openid,goodid);
                }
                catch (Exception ex)
                {
                    Response.Write("<span style='color:#FF0000;font-size:20px'>" + "页面加载出错,请重试" + ex.Message + "</span>");
                    Button1.Visible = false;
                    //  Button2.Visible = false;
                    Label1.Visible = false;
                    // Label2.Visible = false;
                }
                if (Request["count"] != null && ViewState["openid"] != null && Request["GoodId"] != null)
                {
                    SinglePay sin = new SinglePay();
                    sin.OpenID         = ViewState["openid"].ToString();
                    sin.GID            = Request["GoodId"].ToString();
                    sin.GCount         = Convert.ToInt32(Request["count"].ToString());
                    Session["sid"]     = sinserver.AddSinglePay(sin);
                    goodid             = Request["GoodId"];
                    ViewState["count"] = Request["count"];
                    goods = server.GetGoods(goodid);
                    string price = goods.GPrice.ToString();
                    string name  = goods.GName;
                    ViewState["goodsprice"] = price;
                    ViewState["name"]       = name;
                }
            }
        }
コード例 #3
0
 protected void Page_Load(object sender, EventArgs e)
 {
     if (!IsPostBack)
     {
         GoodsServer server = new GoodsServer();
         goodslist_JYJ = server.GetGoodsList("JYJ");
         JsApiPay jsApiPay = new JsApiPay(this);
         jsApiPay.GetOpenidAndAccessToken();
         Session["openid"] = jsApiPay.openid;
     }
 }
コード例 #4
0
        }                                        //H5调起JS API参数
        protected void Page_Load(object sender, EventArgs e)
        {
            Log.Info(this.GetType().ToString(), "page load");
            if (!IsPostBack)
            {
                string openid    = Request.QueryString["openid"];
                string total_fee = Request.QueryString["total_fee"];
                //检测是否给当前页面传递了相关参数
                if (string.IsNullOrEmpty(openid) || string.IsNullOrEmpty(total_fee))
                {
                    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;
                }

                //若传递了相关参数,则调统一下单接口,获得后续相关接口的入口参数
                JsApiPay jsApiPay = new JsApiPay(this);
                jsApiPay.openid    = openid;
                jsApiPay.total_fee = int.Parse(total_fee);

                //JSAPI支付预处理
                try
                {
                    WxPayData unifiedOrderResult = jsApiPay.GetUnifiedOrderResult();
                    wxJsApiParam = jsApiPay.GetJsApiParameters();//获取H5调起JS API参数
                    Log.Debug(this.GetType().ToString(), "wxJsApiParam : " + wxJsApiParam);
                    //在页面上显示订单信息
                    //将订单信息详情更新至数据库
                    //Response.Write("<span style='color:#00CD00;font-size:20px'>订单详情:</span><br/>");
                    //Response.Write("<span style='color:#00CD00;font-size:20px'>" + unifiedOrderResult.ToPrintStr() + "</span>");
                }
                catch (Exception ex)
                {
                    Response.Write("<span style='color:#FF0000;font-size:20px'>" + "下单失败,请返回重试" + "</span>");
                    //submit.Visible = false;
                }
            }
        }
コード例 #5
0
        protected void Page_Load(object sender, EventArgs e)
        {
            Log.Info(this.GetType().ToString(), "page load");
            if (!IsPostBack)
            {
                //string GoodId = Request["GoodId"];
                JsApiPay jsApiPay = new JsApiPay(this);
                //jsApiPay.QueryId = GoodId;


                try
                {
                    //调用【网页授权获取用户信息】接口获取用户的openid和access_token
                    jsApiPay.GetOpenidAndAccessToken();

                    //获取收货地址js函数入口参数
                    wxEditAddrParam     = jsApiPay.GetEditAddressParameters();
                    ViewState["openid"] = jsApiPay.openid;
                    string            openid = jsApiPay.openid;
                    ShoppingCarServer server = new ShoppingCarServer();
                    Carlist   = server.QueryShoppingCar(openid);
                    Goodslist = server.QueryGoods(openid);
                    //dic.Add(jsApiPay.openid,goodid);
                    CartOrder car = new CartOrder();
                    car.Openid = ViewState["openid"].ToString();
                    CartOrderServer server1 = new CartOrderServer();
                    Session["glid"] = server1.GetGLid(car);
                }
                catch (Exception ex)
                {
                    Response.Write("<span style='color:#FF0000;font-size:20px'>" + "页面加载出错,请重试" + ex.Message + "</span>");
                    Button1.Visible = false;
                    //  Button2.Visible = false;
                    //Label1.Visible = false;
                    // Label2.Visible = false;
                }
            }
        }
コード例 #6
0
        //public static string wxEditAddrParam { get; set; }
        protected void Page_Load(object sender, EventArgs e)
        {
            Log.Info(this.GetType().ToString(), "page load");
            #region 预加载处理
            if (!IsPostBack)
            {
                IsLoad = false;
                JsApiPay jsApiPay = new JsApiPay(this);
                try
                {
                    //定义一个回调地址
                    //ViewState["callbackurl"] = "http://keaideyibaobao.com/charactertest.aspx";

                    //调用【网页授权获取用户信息】接口获取用户的openid和access_token
                    jsApiPay.GetOpenidAndAccessToken();

                    //获取收货地址js函数入口参数
                    //wxEditAddrParam = jsApiPay.GetEditAddressParameters();
                    ViewState["openid"] = jsApiPay.openid;
                    //ViewState["access_token"] = jsApiPay.access_token;
                    string resToken = HttpService.Get("https://api.weixin.qq.com/cgi-bin/token?grant_type=client_credential&appid=wxcaf17959e7a40461&secret=d6e05480d9cebeecd672e08d84dd3737");

                    LitJson.JsonData jdata = LitJson.JsonMapper.ToObject(resToken);

                    WxPayData data = new WxPayData();
                    data.SetValue("access_token", jdata["access_token"]);
                    data.SetValue("openid", jsApiPay.openid);

                    string url    = "https://api.weixin.qq.com/cgi-bin/user/info?" + data.ToUrl();
                    string result = HttpService.Get(url);
                    jdata = LitJson.JsonMapper.ToObject(result);
                    if (!string.IsNullOrEmpty(jdata["subscribe"].ToString()))
                    {
                        if (jdata["subscribe"].ToString() == "1")
                        {
                            //Response.Write("<span style='color:#FF0000;font-size:20px'>" + "您已关注本公众号" + "</span>");
                        }
                        else
                        {
                            Response.Write("<script>alert('您尚未关注该公众号')</script>");
                            // Response.Write("<script>window.location.href='weixin://weixin.qq.com/r/dz8fB6zE8fGOrehk92pl';</script>");
                            Server.Transfer("./pic.aspx");
                            return;
                        }
                    }

                    //Response.Write("<span style='color:#FF0000;font-size:20px'>" + result + jsApiPay.openid + "</span>");
                }
                catch (Exception ex)
                {
                    //Response.Write("<span style='color:#FF0000;font-size:20px'>" + "页面加载出错,请重试" + ex.Message + "</span>");
                }
            }
            #endregion
            else
            {
                Random r = new Random();
                if (Request["user-sex"] == null || Request["user-name"] == null)
                {
                    // Response.Write("<span style='color:#FF0000;font-size:20px'>" + "页面加载出错~~~" + "</span>");
                    return;
                }
                string test = "";
                if (!string.IsNullOrEmpty(Request["user-sex"]) || !string.IsNullOrEmpty(Request["user-name"]))
                {
                    string sex  = Request["user-sex"];
                    string name = Request["user-name"];
                    for (int i = 0; i < name.Length; i++)
                    {
                        if (business.SqlServer.IsContain(name[i] + sex))
                        {
                            business.SqlServer.Search(name[i] + sex);
                            int[] temp = business.SqlServer.Search(name[i] + sex);
                            for (int j = 0; j < list1.Length; j++)
                            {
                                list1[j] += temp[j];
                            }
                        }
                        else
                        {
                            int[] temp = new int[9];
                            for (int j = 0; j < list1.Length; j++)
                            {
                                temp[j] = r.Next(40, 120);
                                if (temp[j] >= 100)
                                {
                                    temp[j] = 100;
                                }
                                list1[j] += temp[j];
                            }
                            business.SqlServer.Add(name[i] + sex, temp);
                        }
                    }

                    sum  = 0;
                    list = list1;
                    for (int j = 0; j < list1.Length; j++)
                    {
                        list[j] = list1[j] / name.Length;
                        sum    += list[j];
                    }
                    sum    = sum / 9;
                    IsLoad = true;
                    if (name == "纪春光")
                    {
                        for (int j = 0; j < list.Length; j++)
                        {
                            list[j] = r.Next(98, 101);
                            sum     = 99;
                        }
                    }
                }
            }
        }