コード例 #1
0
        private void Wchat_Register(HttpContext context)
        {
            string result = "no";

            #region  获取微信登录的信息

            string wcode = String_Manage.Return_Request_Str("wcode");

            if (wcode != "")
            {
                // 获取用户的access_token和openid
                wcode = Get_Http_Url_Content.GetPostContent("https://api.weixin.qq.com/sns/oauth2/access_token?appid=wx2fbe800be068f5ec&secret=592edb2d54ec68eb935b3b731441cbf8&code=" + wcode + "&grant_type=authorization_code");
                Wchat wchat_access_token = JsonHelper.JsonDeserialize <Wchat>(wcode);

                if (!string.IsNullOrEmpty(wchat_access_token.access_token))
                {
                    // 获取用户信息
                    wcode = Get_Http_Url_Content.GetPostContent("https://api.weixin.qq.com/sns/userinfo?access_token=" + wchat_access_token.access_token + "&openid=" + wchat_access_token.openid + "");

                    GetUser_Wchat wchat_userinfo = JsonHelper.JsonDeserialize <GetUser_Wchat>(wcode);

                    if (!string.IsNullOrEmpty(wchat_userinfo.openid))
                    {
                        result = Is_Register_Wchat(wchat_userinfo.nickname, wchat_userinfo.sex, wchat_userinfo.headimgurl, 3, wchat_userinfo.openid);
                    }
                }
            }

            context.Response.Write(result);

            #endregion
        }
コード例 #2
0
        private void Wchat_Register(NVelocity.VelocityContext context)
        {
            string result = "no";

            #region  获取微信登录的信息

            string wcode = String_Manage.Return_Request_Str("code");

            if (wcode != "")
            {
                // 获取用户的access_token和openid
                wcode = Get_Http_Url_Content.GetPostContent("https://api.weixin.qq.com/sns/oauth2/access_token?appid=wx2fbe800be068f5ec&secret=592edb2d54ec68eb935b3b731441cbf8&code=" + wcode + "&grant_type=authorization_code");
                NewXzc.Web.templatecs.Handle.ThirdRegisterHandle.Wchat wchat_access_token = JsonHelper.JsonDeserialize <NewXzc.Web.templatecs.Handle.ThirdRegisterHandle.Wchat>(wcode);

                if (!string.IsNullOrEmpty(wchat_access_token.access_token))
                {
                    // 获取用户信息
                    wcode = Get_Http_Url_Content.GetPostContent("https://api.weixin.qq.com/sns/userinfo?access_token=" + wchat_access_token.access_token + "&openid=" + wchat_access_token.openid + "");

                    NewXzc.Web.templatecs.Handle.ThirdRegisterHandle.GetUser_Wchat wchat_userinfo = JsonHelper.JsonDeserialize <NewXzc.Web.templatecs.Handle.ThirdRegisterHandle.GetUser_Wchat>(wcode);

                    if (!string.IsNullOrEmpty(wchat_userinfo.openid))
                    {
                        result = Is_Register_Wchat(wchat_userinfo.nickname, wchat_userinfo.sex, wchat_userinfo.headimgurl, 3, wchat_userinfo.openid);
                    }
                }
            }

            context.Put("resultss", result);

            if (result.Contains("people"))
            {
                context.Put("redirecturl", "http://www.ypindapei.com");
            }

            #endregion
        }