Exemplo n.º 1
0
        protected void Page_Load(object sender, EventArgs e)
        {
            WxPayData notifyData = JsApiPay.GetNotifyData();

            LogHelper.WriteDebugLog("[wxapppay]" + notifyData.ToJson());

            //检查支付结果中transaction_id是否存在
            if (!notifyData.IsSet("transaction_id"))
            {
                //若transaction_id不存在,则立即返回结果给微信支付后台
                WxPayData res = new WxPayData();
                res.SetValue("return_code", "FAIL");
                res.SetValue("return_msg", "支付结果中微信订单号不存在");
                Response.Write(res.ToXml());
                return;
            }

            string transaction_id = notifyData.GetValue("transaction_id").ToString(); //微信支付订单号

            //查询订单,判断订单真实性
            if (!QueryOrder(transaction_id))
            {
                //若订单查询失败,则立即返回结果给微信支付后台
                WxPayData res = new WxPayData();
                res.SetValue("return_code", "FAIL");
                res.SetValue("return_msg", "订单查询失败");
                Response.Write(res.ToXml());
                return;
            }

            //获取订单信息
            string order_no  = notifyData.GetValue("out_trade_no").ToString(); //商户订单号
            string total_fee = notifyData.GetValue("total_fee").ToString();    //获取总金额

            BLL.users          bll  = new BLL.users();
            List <Model.users> list = bll.GetModelByWx(order_no);

            foreach (Model.users u in list)
            {
                bll.UpdateField(u.id, "[is_pay]='1'");
            }

            //返回成功通知
            WxPayData res1 = new WxPayData();

            res1.SetValue("return_code", "SUCCESS");
            res1.SetValue("return_msg", "OK");
            Response.Write(res1.ToXml());
            return;
        }
Exemplo n.º 2
0
        protected void Page_Load(object sender, EventArgs e)
        {
            if (!IsPostBack)
            {
                string code = Common.DTRequest.GetString("code");
                if (!string.IsNullOrEmpty(code))
                {
                    string openid  = Utils.GetCookie("wx_openid");
                    string unionid = Utils.GetCookie("wx_unionid");
                    if (string.IsNullOrEmpty(openid) || string.IsNullOrEmpty(unionid))
                    {
                        OAuthAccessTokenResult oauthResult = OAuthApi.GetAccessToken(appId, appSecret, code);
                        Utils.WriteCookie("wx_openid", oauthResult.openid);
                        Utils.WriteCookie("wx_unionid", oauthResult.unionid);
                        openid  = oauthResult.openid;
                        unionid = oauthResult.unionid;
                    }

                    //if (string.IsNullOrEmpty(accessToken) || tokenTime > DateTime.Now.AddMinutes(-30))
                    //{
                    //    accessToken = AccessTokenContainer.GetAccessToken(appId);
                    //    tokenTime = DateTime.Now;
                    //}
                    //UserInfoJson userInfo = UserApi.Info(accessToken, oauthResult.openid);

                    BLL.users bll = new BLL.users();
                    if (bll.ExistsWxOpenID(openid))
                    {
                        LogHelper.WriteDebugLog("[wx_init] login,wx_open_id:" + openid);
                        LogHelper.WriteDebugLog("[wx_init] login,UnionID:" + unionid);
                        List <Model.users> list = bll.GetModelByWx(openid);

                        Session[DTKeys.SESSION_USER_INFO] = list;
                        Session.Timeout = 45;

                        foreach (Model.users model in list)
                        {
                            //检查用户二维码
                            if (!Common.Utils.FileExists("/upload/InviterQRCode/" + model.id + ".png"))
                            {
                                string url = (siteConfig.weburl.StartsWith("http://") ? siteConfig.weburl : "http://" + siteConfig.weburl) + "/inviter.aspx?from=" + model.id;
                                Bitmap img = Common.QRCode.Create_ImgCode(url, 4);
                                Common.QRCode.SaveImg(Server.MapPath("~/upload/InviterQRCode/"), model.id + ".png", img);
                            }
                        }

                        Response.Write("inviter:" + Common.Utils.GetCookie("inviter"));
                        Response.Write("<br />turl:" + Common.Utils.GetCookie(Common.DTKeys.COOKIE_URL_REFERRER));

                        //Utils.WriteCookie(DTKeys.COOKIE_WEIXIN_FOCUS_ON, userInfo.subscribe.ToString());
                        Response.Redirect("login.aspx?wxopenid=" + openid + "&turl=" + Server.UrlEncode(Utils.GetCookie(DTKeys.COOKIE_URL_REFERRER)));
                    }
                    else
                    {
                        Response.Write("inviter:" + Common.Utils.GetCookie("inviter"));
                        Response.Write("<br />turl:" + Common.Utils.GetCookie(Common.DTKeys.COOKIE_URL_REFERRER));
                        LogHelper.WriteDebugLog("[wx_init] register,wx_open_id:" + openid);
                        try
                        {
                            #region 用户注册

                            Model.user_groups modelGroup = new BLL.user_groups().GetDefault();

                            #region 保存用户注册信息
                            Model.users model = new Model.users();
                            model.group_id  = modelGroup.id;
                            model.user_name = openid;
                            model.salt      = Utils.GetCheckCode(6); //获得6位的salt加密字符串
                            model.password  = "******";
                            model.email     = openid + "@yuedujing.com";
                            model.mobile    = string.Empty;
                            model.reg_ip    = DTRequest.GetIP();
                            model.reg_time  = DateTime.Now;
                            model.nick_name = "新用户";


                            //设置用户状态
                            if (userConfig.regstatus == 3)
                            {
                                model.status = 1; //待验证
                            }
                            else if (userConfig.regverify == 1)
                            {
                                model.status = 2; //待审核
                            }
                            else
                            {
                                model.status = 0; //正常
                            }
                            //开始写入数据库
                            model.id = bll.Add(model);
                            if (model.id < 1)
                            {
                                return;
                            }

                            //检查用户二维码
                            if (!Common.Utils.FileExists("/upload/InviterQRCode/" + model.id + ".png"))
                            {
                                string url = (siteConfig.weburl.StartsWith("http://") ? siteConfig.weburl : "http://" + siteConfig.weburl) + "/inviter.aspx?from=" + model.id;
                                Bitmap img = Common.QRCode.Create_ImgCode(url, 4);
                                Common.QRCode.SaveImg(Server.MapPath("~/upload/InviterQRCode/"), model.id + ".png", img);
                            }
                            //检查用户组是否需要赠送积分
                            if (modelGroup.point > 0)
                            {
                                new BLL.user_point_log().Add(model.id, model.user_name, modelGroup.point, "注册赠送积分", false);
                            }
                            //检查用户组是否需要赠送金额
                            if (modelGroup.amount > 0)
                            {
                                new BLL.user_amount_log().Add(model.id, model.user_name, modelGroup.amount, "注册赠送金额");
                            }
                            #endregion

                            #region 登录
                            if (bll.ExistsWxOpenID(openid))
                            {
                                LogHelper.WriteDebugLog("[wx_init] login,wx_open_id:" + openid);
                                LogHelper.WriteDebugLog("[wx_init] login,UnionID:" + unionid);
                                model = new Model.users();
                                model = bll.GetModelByWx(openid).First();
                                Session[DTKeys.SESSION_USER_INFO] = model;
                                Session.Timeout = 45;

                                //检查用户二维码
                                if (!Common.Utils.FileExists("/upload/InviterQRCode/" + model.id + ".png"))
                                {
                                    string url = (siteConfig.weburl.StartsWith("http://") ? siteConfig.weburl : "http://" + siteConfig.weburl) + "/inviter.aspx?from=" + model.id;
                                    Bitmap img = Common.QRCode.Create_ImgCode(url, 4);
                                    Common.QRCode.SaveImg(Server.MapPath("~/upload/InviterQRCode/"), model.id + ".png", img);
                                }

                                Response.Write("inviter:" + Common.Utils.GetCookie("inviter"));
                                Response.Write("<br />turl:" + Common.Utils.GetCookie(Common.DTKeys.COOKIE_URL_REFERRER));
                                //Utils.WriteCookie(DTKeys.COOKIE_WEIXIN_FOCUS_ON, userInfo.subscribe.ToString());
                                Response.Redirect("login.aspx?wxopenid=" + openid + "&turl=" + Utils.GetCookie(DTKeys.COOKIE_URL_REFERRER));
                            }
                            #endregion

                            #endregion
                        }
                        catch
                        {
                            //Utils.WriteCookie(DTKeys.COOKIE_WEIXIN_FOCUS_ON, userInfo.subscribe.ToString());
                            Response.Redirect("register.aspx?wxopenid=" + openid + "&turl=" + Utils.GetCookie(DTKeys.COOKIE_URL_REFERRER));
                        }
                    }
                }
                else
                {
                    Response.Redirect("login.aspx");
                }
            }
        }
Exemplo n.º 3
0
        protected void Page_Load(object sender, EventArgs e)
        {
            if (!IsPostBack)
            {
                string code = Common.DTRequest.GetQueryString("code");
                if (!string.IsNullOrEmpty(code))
                {
                    string openid = "";// Utils.GetCookie("wx_openid");
                    //if (string.IsNullOrEmpty(openid) || string.IsNullOrEmpty(unionid))
                    //{OAuthAccessTokenResult result = OAuthApi.GetAccessToken(appId, secret, code);
                    OAuthAccessTokenResult oauthResult = OAuthApi.GetAccessToken(appId, appSecret, code);
                    //Utils.WriteCookie("wx_openid", oauthResult.openid);
                    //Utils.WriteCookie("wx_unionid", oauthResult.unionid);
                    openid = oauthResult.openid;
                    //}


                    //if (string.IsNullOrEmpty(accessToken) || tokenTime > DateTime.Now.AddMinutes(-30))
                    //{
                    //    accessToken = AccessTokenContainer.GetAccessToken(appId);
                    //    tokenTime = DateTime.Now;
                    //}
                    //UserInfoJson userInfo = UserApi.Info(accessToken, oauthResult.openid);

                    BLL.users bll = new BLL.users();
                    if (bll.ExistsWxOpenID(openid))
                    {
                        LogHelper.WriteDebugLog("[wx_init] login,wx_open_id:" + openid);
                        Model.users model = bll.GetModelByWx(openid).First();
                        //if (string.IsNullOrEmpty(model.wx_unionid))
                        //{
                        //    bll.UpdateWxUnionID(model.id, unionid);
                        //}
                        Session[DTKeys.SESSION_USER_INFO] = model;
                        Session.Timeout = 45;

                        //检查用户二维码
                        if (!Common.Utils.FileExists("/upload/InviterQRCode/" + model.id + ".png"))
                        {
                            string url = (siteConfig.weburl.StartsWith("http://") ? siteConfig.weburl : "http://" + siteConfig.weburl) + "/inviter.aspx?from=" + model.id;
                            Bitmap img = Common.QRCode.Create_ImgCode(url, 4);
                            Common.QRCode.SaveImg(Server.MapPath("~/upload/InviterQRCode/"), model.id + ".png", img);
                        }

                        //#region 云端记录 邀请记录
                        //Model.inviter_history inviter = new Model.inviter_history();
                        //inviter.add_time = DateTime.Now;
                        //inviter.channel = "qrcode";
                        //inviter.inviter_id = TypeConverter.ObjectToInt(Common.Utils.GetCookie("inviter"), 0);
                        //inviter.remark = "通过扫码邀请";
                        //inviter.url = "";
                        //inviter.user_id = model.id;
                        //new BLL.inviter_history().Add(inviter);
                        //#endregion

                        //Response.Redirect("login.aspx?wxopenid=" + oauthResult.openid + "&subscribe=" + userInfo.subscribe);
                        Common.Utils.WriteCookie("openid", openid);
                        Response.Redirect("index.aspx?openid=" + openid);
                    }
                    else
                    {
                        //    Model.user_groups modelGroup = new BLL.user_groups().GetDefault();
                        //    Model.users u1 = new Model.users();
                        //    u1.group_id = modelGroup.id;
                        //    u1.user_name = openid + "-1";
                        //    u1.salt = Utils.GetCheckCode(6); //获得6位的salt加密字符串
                        //    u1.password = DESEncrypt.Encrypt("123456", u1.salt);
                        //    u1.email = u1.user_name + "@a.com";
                        //    u1.mobile = "";
                        //    u1.reg_ip = "";
                        //    u1.reg_time = DateTime.Now;
                        //    u1.status = 0; //正常
                        //    u1.id = bll.Add(u1);

                        //    Model.users u2 = new Model.users();
                        //    u2.group_id = modelGroup.id;
                        //    u2.user_name = openid + "-2";
                        //    u2.salt = Utils.GetCheckCode(6); //获得6位的salt加密字符串
                        //    u2.password = DESEncrypt.Encrypt("123456", u2.salt);
                        //    u2.email = u2.user_name + "@a.com";
                        //    u2.mobile = "";
                        //    u2.reg_ip = "";
                        //    u2.reg_time = DateTime.Now;
                        //    u2.status = 0; //正常

                        //    //开始写入数据库
                        //    u2.id = bll.Add(u2);

                        //    Model.users u3 = new Model.users();
                        //    u3.group_id = modelGroup.id;
                        //    u3.user_name = openid + "-3";
                        //    u3.salt = Utils.GetCheckCode(6); //获得6位的salt加密字符串
                        //    u3.password = DESEncrypt.Encrypt("123456", u3.salt);
                        //    u3.email = u3.user_name + "@a.com";
                        //    u3.mobile = "";
                        //    u3.reg_ip = "";
                        //    u3.reg_time = DateTime.Now;
                        //    u3.status = 0; //正常

                        //    //开始写入数据库
                        //    u3.id = bll.Add(u3);


                        Common.Utils.WriteCookie("openid", openid);
                        Response.Redirect("index.aspx?openid=" + openid);
                    }
                }
            }
        }