• asp:第三平台登陆


     第三平台登陆接口申请网址: http://open.51094.com/

    文档:

    第三方合作登录平台使用说明

    为方便更多的开发朋友,本人特将当前市面上所有支持第三方联合登录的接口集为一体,以前需要多次开发才能完成的登录现在只需要一次即可搞定。再也不需要因为等待审核而耽误进度项目进度了。使用方便,操作简单,以下为本插件的具体使用方法:

     

    申请使用

    1、首先登录网站 http://open.51094.com/

    2、点击右上角《登录》按钮进行登录,登录成功后会自动跳转至管理中心。

    3、进入管理中心后点击创建应用按钮,如下图:

     

    4、选择应用类型为《网站应用》,完成后跳转至应用信息填写页面。

    5、信息填写页面如下图所示,按要求正确填写应用信息,完成后点击创建应用即可使用。

     参数说明:

    名称: 申请应用的简称

    详情: 应用的说明信息,字数不得少于10个汉字

    登录成功回调地址:

    申请方接收用户信息的url , 我们以url+?+参数的格式通知申请方。切记填写的url中不可以带有?

    支持的登录方式:

    提供自己选择,默认为全选。

     

    创建应用图

    客户端引用(网站应用)

    1、在用户中心的管理中心处可以查看到应用需要引用的js地址,如下图红框所示:

    2、在需要登录的页面中加入如下js代码

    <script type="text/javascript" src="http://open.51094.com/user/myscript/153dee5be21e2.html"></script>

    3、在页面标签中加入(<span id="hzy_fast_login"></span>)如下图所示

     

    4、成功加入后在登录页面即可看到相应的登录。如下图所示。

     

    登录成功回调通知

    2014-11-1日之后注册用户请使用方式二

    方案一(已弃用)

    回调方式

    GET 

    回调url

    申请应用时填写的登录成功回调地址

    回调格式

    http://url/user/hezuo.html?param=%7B%22name%22%3A%22oh%21no%22%2C%22img%22%3A%22http%3A%5C%2F%5C%2Fq.qlogo.cn%5C%2Fqqapp%5C%2F100478927%5C%2F863A85B9B176E2408E05DF05D46FDB3F%5C%2F100%22%2C%22sex%22%3A0%2C%22uniq%22%3A%22qqO8HdWKMKpVI%22%2C%22from%22%3A%22qq%22%7D

    参数

    取得param参数内容后先做url解码,再进行json解码即可得到如下内容:

     

    name

    登录获取的用户名称

    img

    头像地址

    sex

    性别

    uniq

    第三方获得的唯一码

    from

    登录来源  如 qq、weibo、renren等

     

    方案二

    可参考:http://test.open.51094.com/index.php

    回调方式

    GET

    回调url

    申请应用时填写的登录成功回调地址

    回调格式

    http://url/user/hezuo.html?code=code

    参数

    取得code参数内容后先再使用post方式请求:

    url: http://open.51094.com/user/auth.html

    POST参数:

    type:get_user_info

    code:传回的code值

    appid:申请到的appid值 ( 网页上点击应用名称获取 )

        token:申请到的token值 ( 网页上点击应用名称获取 )

    信息会以json串的形式返回,得到信息后json_decode( $str,true )后得到以下内容:(获取方式可参考附录

    name

    登录获取的用户名称

    img

    头像地址

    sex

    性别

    uniq

    第三方获得的唯一码

    from

    登录来源  如 qq、weibo、renren等

     

     

    此插件为免费插件,可用于商业用途,请在使用时标注开发人。

     

     

    使用注意点:

    1、引用js页面域名与申请时的回调地址域名一定要相同。

    2、引用的js后页面上一定要加 id='hzy_fast_login' 的标签。

    3、申请的回调url中不允许出现?

     

     

    错误代码集:

    错误码

    问题

    10001

    用户appid错误

    10002

    所传token与appid不匹配

    10003

    请求域名与注册域名不匹配(有回调地址决定注册域名)

    time out

    登录超时,需要重新登录

     

    附录:

    Php获取信息代码:    源码http://test.open.51094.com/index.php

    1、配置文件  open.config.php

    内容:

    <?php

    /**

     *@ 注册地址 http://open.51094.com

     *@ QQ交流群:373703921

     *@ 博客地址:http://www.51094.com

     *@ 测试地址:http://open.51094.com/user/login.html

     *

     *@ author: hzy@51094.com

     *

     **/

           define( 'APPID', '申请时得到的appid');

           define( 'TOKEN', '申请时得到的token值');

    ?>

    2、open类文件 open51094.class.php

    <?php

    include 'open.config.php';

    class open51094{

           private $appid;

           private $token;      

           private $return_uri;

           private $access_token;

           private $url = 'http://open.51094.com/user/auth.html';

     

           function __construct(){

                  $this->appid = APPID;

                  $this->token = TOKEN;

           }

     

           function me( $code ){

                  #$this->getAccessToken();

                  $params=array(

                                'type'=>'get_user_info',

                                'code'=>$code,

                                'appid'=>$this->appid,

                                'token'=>$this->token

                         );

                  return $this->http( $params );

           }

           private function http( $postfields='', $method='POST', $headers=array()){

                  $ci=curl_init();

                  curl_setopt($ci, CURLOPT_SSL_VERIFYPEER, FALSE);

                  curl_setopt($ci, CURLOPT_RETURNTRANSFER, 1);

                  curl_setopt($ci, CURLOPT_CONNECTTIMEOUT, 30);

                  curl_setopt($ci, CURLOPT_TIMEOUT, 30);

                  if($method=='POST'){

                         curl_setopt($ci, CURLOPT_POST, TRUE);

                         if($postfields!='')curl_setopt($ci, CURLOPT_POSTFIELDS, $postfields);

                  }

                  $headers[]="User-Agent: 51094PHP(open.51094.com)";

                  curl_setopt($ci, CURLOPT_HTTPHEADER, $headers);

                  curl_setopt($ci, CURLOPT_URL, $this->url);

                  $response=curl_exec($ci);

                  curl_close($ci);

                  $json_r=array();

                  if(!empty( $response ))$json_r=json_decode($response, true);

                  return $json_r;

           }

    }

    ?>

    3、返回页面 back.php

    <?php

           include 'open51094.class.php';

     

           $open = new open51094();

           $code = $_GET['code'];

           var_dump( $open->me($code) );

    ?>

     

    JAVA获取信息代码:

    import java.util.Date;

    import java.util.UUID;

     

    import javax.servlet.http.HttpServletRequest;

    import javax.servlet.http.HttpServletResponse;

     

    import org.apache.struts2.ServletActionContext;

    import org.json.JSONObject;

    import org.springframework.beans.factory.annotation.Autowired;

    import org.springframework.context.annotation.Scope;

    import org.springframework.stereotype.Controller;

     

    @SuppressWarnings("serial")

    @Controller

    @Scope("prototype")

    public class UserthirdpartyAction{

           //第三方平台提供的参数

           private static String appid="15********";

           private static String token="14**********";

     

           public String thirdlogin(){

                  HttpServletRequest  request = ServletActionContext.getRequest();

                  String code  = CheckNull.check(request.getParameter("code"));

                  System.out.println("第三方登录返回结果:"+code );

                  if("".equals(code )||null==code ){

                         System.out.println("回调函数没有执行");

                         return "fail";

                  }else{           

                          String url=HttpRequest.sendPost("http://open.51094.com/user/auth.html", "type=get_user_info&code="+code+"&appid="+appid+"&token="+token+"");

                    System.out.println(url);

                          //解析结果         

                          JSONObject jsonObj = new JSONObject(url);

                // 得到指定json key对象的value对象

                        //解析封装对象

                        

                         return "Redirect";

                  }

                 

           }

          

    }

     

     

    HttpRequet 类:

    package wzh.Http;
    
    
    import java.io.BufferedReader;
    import java.io.IOException;
    import java.io.InputStreamReader;
    import java.io.PrintWriter;
    import java.net.URL;
    import java.net.URLConnection;
    import java.util.List;
    import java.util.Map;
    public class HttpRequest {
        /**
         * 向指定URL发送GET方法的请求
         * 
         * @param url
         *            发送请求的URL
         * @param param
         *            请求参数,请求参数应该是 name1=value1&name2=value2 的形式。
         * @return URL 所代表远程资源的响应结果
         */
        public static String sendGet(String url, String param) {
            String result = "";
            BufferedReader in = null;
            try {
                String urlNameString = url + "?" + param;
                URL realUrl = new URL(urlNameString);
                // 打开和URL之间的连接
                URLConnection connection = realUrl.openConnection();
                // 设置通用的请求属性
                connection.setRequestProperty("accept", "*/*");
                connection.setRequestProperty("connection", "Keep-Alive");
                connection.setRequestProperty("user-agent",
                        "Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.1;SV1)");
                // 建立实际的连接            connection.connect();
                // 获取所有响应头字段
                Map<String, List<String>> map = connection.getHeaderFields();
                // 遍历所有的响应头字段
                for (String key : map.keySet()) {
                    System.out.println(key + "--->" + map.get(key));
                }
                // 定义 BufferedReader输入流来读取URL的响应
                in = new BufferedReader(new InputStreamReader(
                        connection.getInputStream()));
                String line;
                while ((line = in.readLine()) != null) {
                    result += line;
                }
            } catch (Exception e) {
                System.out.println("发送GET请求出现异常!" + e);
                e.printStackTrace();
            }
            // 使用finally块来关闭输入流
            finally {
                try {
                    if (in != null) {
                        in.close();
                    }
                } catch (Exception e2) {
                    e2.printStackTrace();
                }
            }
            return result;
        }
    
    
        /**
         * 向指定 URL 发送POST方法的请求
         * 
         * @param url
         *            发送请求的 URL
         * @param param
         *            请求参数,请求参数应该是 name1=value1&name2=value2 的形式。
         * @return 所代表远程资源的响应结果
         */
        public static String sendPost(String url, String param) {
            PrintWriter out = null;
            BufferedReader in = null;
            String result = "";
            try {
                URL realUrl = new URL(url);
                // 打开和URL之间的连接
                URLConnection conn = realUrl.openConnection();
                // 设置通用的请求属性
                conn.setRequestProperty("accept", "*/*");
                conn.setRequestProperty("connection", "Keep-Alive");
                conn.setRequestProperty("user-agent",
                        "Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.1;SV1)");
                // 发送POST请求必须设置如下两行
                conn.setDoOutput(true);
                conn.setDoInput(true);
                // 获取URLConnection对象对应的输出流
                out = new PrintWriter(conn.getOutputStream());
                // 发送请求参数
                out.print(param);
                // flush输出流的缓冲
                out.flush();
                // 定义BufferedReader输入流来读取URL的响应
                in = new BufferedReader(
                        new InputStreamReader(conn.getInputStream()));
                String line;
                while ((line = in.readLine()) != null) {
                    result += line;
                }
            } catch (Exception e) {
                System.out.println("发送 POST 请求出现异常!"+e);
                e.printStackTrace();
            }
            //使用finally块来关闭输出流、输入流
            finally{
                try{
                    if(out!=null){
                        out.close();
                    }
                    if(in!=null){
                        in.close();
                    }
                }
                catch(IOException ex){
                    ex.printStackTrace();
                }
            }
            return result;
        }    
    }

     

     

    附上post写法和读取方法:

    //交换获得值得方法,post方法;

    public static string Login( string code)
    {
    string info = string.Empty;
    if (code != "" && code != null)
    {
    HttpHelper m_Http = new HttpHelper();
    HttpItem item = new HttpItem();
    // item.Method = "Post";
    item.URL = "http://open.51094.com/user/auth.html";
    item.Method = "POST";
    item.Encoding = Encoding.GetEncoding("gbk");
    item.ContentType = "application/x-www-form-urlencoded; charset=gbk";
    item.Postdata = string.Format("type=get_user_info&code={0}&appid=1558be447a9ec7&token=e383684d8f0acb39d622457f361dc1dc", code);
    // item.Postdata = sbTemp.ToString();

    HttpResult result = m_Http.GetHtml(item);
    string resultHTML = result.Html;
    JObject obj = JObject.Parse(resultHTML);
    string name = obj["name"].ToString();
    string img = obj["img"].ToString();
    string sex = obj["sex"].ToString();
    string uniq = obj["uniq"].ToString();
    string from = obj["from"].ToString();
    info = name + "@" + img + "@" + sex + "@" + uniq + "@" + from;
    }
    return info;
    }

    //接受返回code页面代码

    //接口登陆
    string code = Request["code"];
    string[] arr = PublicLogin.Login(code).Split('@');
    if (arr.Length == 5)
    {
    string unip = arr[3];
    string sql = string.Format("select * from bs_user where unip = '{0}'", unip);
    if (CSA.DAL.DBAccess.getRS(sql).Rows.Count > 0)
    {
    if (CSA.DAL.DBAccess.getRS(sql).Rows[0]["Password"].ToString() == "" || CSA.DAL.DBAccess.getRS(sql).Rows[0]["Password"] == null)
    {
    string str = string.Format("location.href ='MyInformation.aspx?unip={0}'", arr[3]);
    CSA.HC.Common.EchoJS(str);
    }
    else
    {
    Bs_User user = new Bs_User();
    user.Unip = unip;
    Factory.getUserBllInstance().loginUnip(user);
    if (CurInfo.CurUser != null)
    {
    levelname = CurInfo.CurUser.levelName;
    name = CurInfo.CurUser.Name;
    sex = CurInfo.CurUser.Sex;
    pwd = CurInfo.CurUser.Password;
    img = CurInfo.CurUser.Pic;
    }
    CSA.HC.Common.EchoJS("location.href ='MyInformation.aspx'");
    }
    }
    else
    {
    //生成会员code
    string date = DateTime.Now.ToString("ymdHmssffff");
    string usercode = getTreeNumRandomTop() + date + getTreeNumRandomEnd();
    string ip = HttpContext.Current.Request.UserHostAddress;
    string inssql = string.Format(@"INSERT INTO [Bs_User]([Code],[UserName],[levelName],[RealName],[Sex],[Pic],[unip],[Password],[Phone],[fxip])
    VALUES('{0}','{1}','{2}','{3}','{4}','{5}','{6}','{7}','{8}','{9}')", usercode, arr[0].Trim('"'), "fkt_" + usercode.Substring(3, 8), arr[0].Trim('"'), arr[2], arr[1].Trim('"'), arr[3], CSA.Security.Encrypt.getMD5("123456"), "fkt_" + usercode.Substring(3, 8), ip);
    int row = CSA.DAL.DBAccess.ExecuteNonQuery(inssql);
    if (row > 0)
    {
    Bs_User user = new Bs_User();
    user.Unip = arr[3];
    Factory.getUserBllInstance().loginUnip(user);

    string str = string.Format("location.href ='MyInformation.aspx?unip={0}'", arr[3]);
    CSA.HC.Common.EchoJS(str);
    }
    }
    }

     

  • 相关阅读:
    一些python练习题
    爬取某房源网数据
    练习1:定义 is_Even 函数,传一 int 参数,判断是否是偶数,return True;不是,return False
    pycharm中tkinter 不显示窗口
    保护眼睛颜色的RGB数值
    Python study----------class的实例化
    HTML----------STUDY
    Python study----------字典 popitem()
    Python study----------Python搜索路径
    Python study----------第三方module-----chardet(识别编码)
  • 原文地址:https://www.cnblogs.com/Leon-Jenny/p/5149409.html
Copyright © 2020-2023  润新知