微信开放平台—网站应用开发—微信登录功能 简介 – 冰点の爱

1 微信开放平台:https://open.weixin.qq.com/

2 开放换异:

3 微信权力跑过:https://open.weixin.qq.com/cgi-bin/showdocument?action=dir_list&t=resource/res_list&verify=1&id=open1419316505&token=&lang=zh_CN

4 影响启示:

点击微信图标废料桶到…页。

应用个别的微信扫描后,单击证实登录

这时候,将在PC年史上停止更改。:

话说回来,年史将径直跳到1个好铺子的主页。,并经过了微信用户的知。。

5 经过权力寄给报社,我们家可以瞥见有4个诉讼程序。

第一步:需求CODE
次要的步:经过密码获取Access作为对某事的保证的
第三步:经过叫作为对某事的保证的呼唤啮合扣
第4步:获取用户个别的知(一致机制)

我们家构成一任一某一API密码。:  

publicclass weixin_helper
    {
        public weixin_helper()
        {
        }
        ////// 由于AppID和AppHead获取叫运转 作为对某事的保证的(默许逝世工夫为2小时)
        //////Dictionarypublicstatic Dictionary<string, object> get_access_token()
        {
            //获取设定知
            oauth_config config = (2);
            string send_url = "" +
                              config.oauth_app_id + "&secret=" + config.oauth_app_key + "";
            //发送和接纳赢利值string result = (send_url);
            if (("errmsg"))
            {
                returnnull;
            }
            try
            {
                Dictionary<string, object> dic = JsonConvert.DeserializeObjectstring, object>>(卒)
                return dic;
            }
            catch
            {
                returnnull;
            }
        } ////// 购置物暂时叫权 作为对某事的保证的(默许逝世工夫为2小时)
        //////暂时Authorization Code///避免CSRF袭击,成归因于后回调时会买方收到的卖方寄来的样本带回///Dictionarypublicstatic Dictionary<string, object> get_access_token(string code, string 规定)
        {
            //获取设定知
            oauth_config config = (2);
            string send_url = "" +
                              config.oauth_app_id + "&secret=" + config.oauth_app_key + "&code="+code+"&grant_type=authorization_code";
            //发送和接纳赢利值string result = (send_url);
            if (("errmsg"))
            {
                returnnull;
            }
            try
            {
                Dictionary<string, object> dic = JsonConvert.DeserializeObjectstring, object>>(卒)
                return dic;
            }
            catch
            {
                returnnull;
            }
        }
        ////// 由于Access作为对某事的保证的决议Access作为对某事的保证的其中的哪一个成熟。
        /////////TRUE讲授遗失。publicstaticbool check_access_token(string access_token)
        {
            //获取设定知
            oauth_config config = (2);
            string send_url = "" + access_token + "&openid=" + config.oauth_app_id;
            //发送和接纳赢利值string result = (send_url);
            try
            {
                Dictionary<string, object> dic = JsonConvert.DeserializeObjectstring, object>>(卒)
                if (("errmsg"))
                {
                    if (DIC)"errmsg"].ToString()=="ok")
                    {
                        returntrue;
                    }
                    else
                    {
                        returnfalse;
                    }
                    
                }
                returnfalse;

            }
            catch
            {
                returnfalse;
            }
        }


      ////// 若fresh_token已逝世则由于refresh_token流行新的refresh_token
      //////refresh_token///Dictionarypublicstatic Dictionary<string, object> get_refresh_token(string refresh_token)
        {
            //获取设定知
            oauth_config config = (2);
            string send_url =
                "" +
                              config.oauth_app_id + "&grant_type=refresh_token&refresh_token=" + refresh_token;
            //发送和接纳赢利值string result = (send_url);
            if (("errmsg"))
            {
                returnnull;
            }
            try
            {
                Dictionary<string, object> dic = JsonConvert.DeserializeObjectstring, object>>(卒)
                return dic;
            }
            catch
            {
                returnnull;
            }
        }
        ////// 获取登录用户的根本知。
        //////暂时叫 Token///用户openid///Dictionarypublicstatic Dictionary<string, object> get_user_info(string access_token, string open_id)
        {
            //获取设定知
            oauth_config config = (2);
            //发送和接纳赢利值   string send_url = ""+access_token+"&openid="+open_id;
            //发送和接纳赢利值string result = (send_url);
            if (("errmsg"))
            {
                returnnull;
            }
            //反序列化JSON
            Dictionary<string, object> dic = (卒)
            return dic;
        }
    }

向导心密码:

#region 微视频博客登录

        ////// 微视频博客登录
        ///public ActionResult WeChat()
        {
            //获取设定知
            oauth_config config = (2); //大调IDif (设定) == null)
            {
                return Content("出错了,您还没有设定与WebTead相干的API知。!");
            }
            string state = ().ToString().Replace("-", "");
            Session["oauth_state"] = state;
            string send_url =
                "qrconnect?appid=" + config.oauth_app_id +
                              "&redirect_uri=" + (()) +
                              "&response_type=code&scope=snsapi_login&state=" + state +
                              "#wechat_redirect";
            //开端发送return Redirect(send_url); //跳到本身的交谈室 详细说明的关系登陆年史        }

        ////// 微视频博客登录赢利action
        ///public ActionResult WeChatReturnUrl(string state, string 密码)
        {
            //获取赢利参量string access_token = string.Empty;
            string expires_in = string.Empty;
            string client_id = string.Empty;
            string openid = string.Empty;
            string refresh_token = string.Empty;

            if (意见分歧者之间的意见交换)"oauth_state"] == null || Session["oauth_state"].ToString() == "" ||
                state != Session["oauth_state"].ToString() || string.IsNullOrEmpty(密码))//假如赢利参量不克制密码或规定,则不经过使生效            {
                return Content("出错啦,未设定初值规定。!");
            }

            //第一步:经过密码叫 作为对某事的保证的和OpenID
            Dictionary<string, object> dic1 = (密码), 规定);
            if (DIC)1 == null || !("access_token"))
            {
                return Content("错误密码:,无法叫 Token,请反省敷用药 钥匙弥撒书的章节吗?!");
            }
            if (DIC)1 == null || !("openid"))
            {
                if (("errmsg"))
                {
                    return Content("errcode:" + dic1["errcode"] + ",errmsg:" + dic1["errmsg"]);
                }
                else
                {
                    return Content("出错啦,无法购置物用户归因于OpenID!");
                }
            }

            access_token = dic1["access_token"].ToString();//获取access_token
            expires_in = dic1["expires_in"].ToString();//购置物成熟日
            refresh_token = dic1["refresh_token"].ToString();//获取恢复Access作为对某事的保证的的凭据
            openid = dic1["openid"].ToString();//用户最适当的跺脚OpenID

            //回忆用于获取知的知。
            Session["oauth_name"] = "webchat";
            Session["oauth_access_token"] = access_token;
            Session["oauth_openid"] = openid;
            Session["oauth_refresh_token"] = refresh_token;
            #region todo 将获取的用户知保持健康到知库中。

            #endregion//次要的步:经过叫 作为对某事的保证的和OpenID来获取用户的根本知
            //Dictionary dic2 = (access_token,openid);


            //第三步:废料桶到详细说明年史return Content(WeChatResultJson());

        }

        ////// 微视频博客登录赢利action, 处置用户知
        ///publicstring WeChatResultJson()
        {
            string oauth_access_token = string.Empty;
            string oauth_openid = string.Empty;
            string oauth_name = string.Empty;
            string oauth_refresh_token = string.Empty;

            if (意见分歧者之间的意见交换)"oauth_name"] == null || Session["oauth_access_token"] == null ||
                Session["oauth_openid"] == null)
            {
                return"{\"ret\":\"1\", \"msg\":\"出错啦,Access 作为对某事的保证的已逝世或不存在。!\"}";
            }
            oauth_name = Session["oauth_name"].ToString();
            oauth_access_token = Session["oauth_access_token"].ToString();
            oauth_openid = Session["oauth_openid"].ToString();
            oauth_refresh_token = Session["oauth_refresh_token"].ToString();

            if (!(oauth_access_token)) //在呼唤Access作为对某事的保证的先于,我们家需求决议其中的哪一个逝世。            {
                Dictionary<string, object> dic1 = (oauth_refresh_token);//假如已逝世,将更新新的Access作为对某事的保证的。if (DIC)1 == null || !("access_token"))
                {
                    return"{\"openid\":\"0\", \"msg\":\"出错啦,无法叫Access作为对某事的保证的!\"}";
                }
                oauth_access_token = dic1["access_token"].ToString();
            }

            Dictionary<string, object> dic = (oauth_access_token, oauth_openid);
            if (DIC) == null)
            {
                return"{\"openid\":\"0\", \"msg\":\"出错啦,无法购置物归因于用户知!\"}";
            }
            try
            {
                StringBuilder str = new StringBuilder();
                ("{");
                ("\"openid\": \"" + dic["openid"].ToString() + "\", ");
                ("\"nickname\": \"" + dic["nickname"].ToString() + "\", ");
                ("\"sex\": \"" + dic["sex"].ToString() + "\", ");
                ("\"province\": \"" + dic["province"].ToString() + "\", ");
                ("\"city\": \"" + dic["city"].ToString() + "\", ");
                ("\"country\": \"" + dic["country"].ToString() + "\", ");
                ("\"headimgurl\": \"" + dic["headimgurl"].ToString() + "\", ");
                ("\"privilege\": \"" + dic["privilege"].ToString() + "\", ");
                ("\"unionid\": \"" + dic["unionid"].ToString() + "\"");
                ("\"oauth_name\": \"" + oauth_name + "\"");
                ("\"oauth_access_token\": \"" + oauth_access_token + "\"");
                ("\"oauth_openid\": \"" + oauth_openid + "\"");
                ("}");
                return str.ToString();
            }
            catch
            {
                return"{\"ret\":\"0\", \"msg\":\"出错啦,无法购置物归因于用户知!\"}";
            }

        }
        #endregion

心密码已被写作。。

在在这一点上,我要感激萧雅的硬密码。。我径直拿来了。。

面临新的知和工力,率先,我们家需求温存看一眼权力的讲授。,重行熟虑,按部就班,按部就班。。

萧雅去岁大学毕业。,你也可以纤细的地构成这些密码。,不足为奇。

发表评论

电子邮件地址不会被公开。 必填项已用*标注