一、申请APPID和APPKEY

登录QQ互联,登录地址:https://connect.qq/ ,登录===》创建应用

注意:1、手机网站和PC网站要分开创建两个应用,都是“网站应用”,只有APP才是手机应用

          2、网站回调域 写你回调的地址,写错了没有关系,后面可以修改

          3、这个申请得到唯一标识【OpenID】只对一个应用唯一,如果开发者有多个应用,需要申请Unionid,

     

Unionid申请方法:发送邮件到connect@qq,

邮件格式如下:


申请通过以后,得到APPID、APPKey。

二、开发:

1、HTML页面

<html xmlns="http://www.w3/1999/xhtml" lang="zh-cn" xml:lang="zh-cn">

<head>

    <title>会员登录</title>

    <script type="text/javascript" src="http://qzonestyle.gtimg/qzone/openapi/qc_loader.js" data-appid="你的APPID" charset="utf-8"></script>

</head>

<body>

    <span>其它账号登录:</span>

    <!--登录按钮-->

    <span  style=" margin-right:10px"  id="qqLoginBtn"></span>

    <script src="../JS/JQuery.js" type="text/javascript"></script>

    <!--QQ登录-->

    <script type="text/javascript">

        $(function () {

            QC.Login.signOut();

        });

        QC.Login({

            btnId: "qqLoginBtn"    //插入按钮的节点id

        });

        var paras = {};

        //if (QC.Login.check()) {

        QC.api("get_user_info", paras).success(function (s) {//成功回调

            console.log("success",arguments);

            //成功回调

            QC.Login.getMe(function (openId, accessToken) {

                console.log("getMe",arguments)

                showBgProc(true, "正在登录,请稍候...");

                $.post("../ajax.ashx?action=QQlogin&t=" + Math.random(), {

                    name: s.data.nickname, //昵称

                    gender: s.data.gender, //性别

                    province: s.data.province, //省

                    city: s.data.city, //市

                    year: s.data.year, //出生年

                    figureurl: s.data.figureurl_2, //头像

                    openid: openId,

                    otype: 1,

                    token: accessToken

                }, function (msg) {

                    showBgProc(false);

                    if (gav(msg, "state") == "1") {

                        $a(s.data.nickname + "恭喜你,登录成功!");

                        location.href = "/user/";   //跳转到会员中心页

                    } else {

                        $a(gav(msg, "msg"));

                    }

                });

            });

        })

        .error(function (f) {//失败回调

            alert("获取用户信息失败!");

        })

        plete(function (c) {

            //完成请求回调

        });

      //}

    </script>


</body>
</html>


2、AJAX.ashx页面

                      /// <summary>
        /// QQ快速登录
        /// </summary>
        private static void QQLogin()
        {

            //获取unionid
            string token = HttpContext.Current.Request["token"];
            string unid = "";
            if (!string.IsNullOrEmpty(token))
            {
                string str = Get("https://graph.qq/oauth2.0/me?access_token=" + token + "&unionid=1");
               
                if (!string.IsNullOrEmpty(str))
                {
                    str = str.Replace("callback(", "").Replace(")", "").Replace(";","").Trim();
                    System.Collections.Hashtable ht = Newtonsoft.Json.JsonConvert.DeserializeObject<System.Collections.Hashtable>(str);
                    unid = ht["unionid"] as string;
                    //WriteString(str);
                }
            }

            string ChnName = HttpContext.Current.Request.Form["name"];//昵称
            string openid = HttpContext.Current.Request.Form["openid"];//其它用户信息略。。
            if (!string.IsNullOrEmpty(unid)) openid = unid; //如果有unionid 就把unionid 作为唯一标识保存到数据库中

            //先判断 openid 是否存在   
            //读取用户表,看数据库中是否有相应的信息

            
            if (user_OBJ == null)
            {
                //如果不存在,先保存用户信息,再登录
                //1.1 保存到自己的数据库表中
                //1.2 登录代码,保存自己的cookie


            }else{
                //如果存在,直接登录
                //1.1登录代码,保存自己的cookie

                
            }
            //返回结果内容
            WriteXml(node, node2);
        }



未完。。。。。。。