第三平臺(tái)登陸接口申請(qǐng)網(wǎng)址: http://open.51094.com/
文檔:
為方便更多的開(kāi)發(fā)朋友,本人特將當(dāng)前市面上所有支持第三方聯(lián)合登錄的接口集為一體,以前需要多次開(kāi)發(fā)才能完成的登錄現(xiàn)在只需要一次即可搞定。再也不需要因?yàn)榈却龑徍硕⒄`進(jìn)度項(xiàng)目進(jìn)度了。使用方便,操作簡(jiǎn)單,以下為本插件的具體使用方法:
1、首先登錄網(wǎng)站 http://open.51094.com/ 。
2、點(diǎn)擊右上角《登錄》按鈕進(jìn)行登錄,登錄成功后會(huì)自動(dòng)跳轉(zhuǎn)至管理中心。
3、進(jìn)入管理中心后點(diǎn)擊創(chuàng)建應(yīng)用按鈕,如下圖:
4、選擇應(yīng)用類型為《網(wǎng)站應(yīng)用》,完成后跳轉(zhuǎn)至應(yīng)用信息填寫(xiě)頁(yè)面。
5、信息填寫(xiě)頁(yè)面如下圖所示,按要求正確填寫(xiě)應(yīng)用信息,完成后點(diǎn)擊創(chuàng)建應(yīng)用即可使用。
參數(shù)說(shuō)明:
名稱: 申請(qǐng)應(yīng)用的簡(jiǎn)稱
詳情: 應(yīng)用的說(shuō)明信息,字?jǐn)?shù)不得少于10個(gè)漢字
登錄成功回調(diào)地址:
申請(qǐng)方接收用戶信息的url , 我們以u(píng)rl+?+參數(shù)的格式通知申請(qǐng)方。切記填寫(xiě)的url中不可以帶有?
支持的登錄方式:
提供自己選擇,默認(rèn)為全選。
創(chuàng)建應(yīng)用圖
1、在用戶中心的管理中心處可以查看到應(yīng)用需要引用的js地址,如下圖紅框所示:
2、在需要登錄的頁(yè)面中加入如下js代碼
<script type="text/javascript" src="http://open.51094.com/user/myscript/153dee5be21e2.html"></script>
3、在頁(yè)面標(biāo)簽中加入(<span id="hzy_fast_login"></span>)如下圖所示
4、成功加入后在登錄頁(yè)面即可看到相應(yīng)的登錄。如下圖所示。
2014-11-1日之后注冊(cè)用戶請(qǐng)使用方式二
方案一(已棄用)
回調(diào)方式 | GET | |
回調(diào)url | 申請(qǐng)應(yīng)用時(shí)填寫(xiě)的登錄成功回調(diào)地址 | |
回調(diào)格式 | 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 | |
參數(shù) | 取得param參數(shù)內(nèi)容后先做url解碼,再進(jìn)行json解碼即可得到如下內(nèi)容:
| |
name | 登錄獲取的用戶名稱 | |
img | 頭像地址 | |
sex | 性別 | |
uniq | 第三方獲得的唯一碼 | |
from | 登錄來(lái)源 如 qq、weibo、renren等 | |
方案二
可參考:http://test.open.51094.com/index.php
回調(diào)方式 | GET | |
回調(diào)url | 申請(qǐng)應(yīng)用時(shí)填寫(xiě)的登錄成功回調(diào)地址 | |
回調(diào)格式 | http://url/user/hezuo.html?code=code | |
參數(shù) | 取得code參數(shù)內(nèi)容后先再使用post方式請(qǐng)求: url: http://open.51094.com/user/auth.html POST參數(shù): type:get_user_info code:傳回的code值 appid:申請(qǐng)到的appid值 ( 網(wǎng)頁(yè)上點(diǎn)擊應(yīng)用名稱獲取 ) token:申請(qǐng)到的token值 ( 網(wǎng)頁(yè)上點(diǎn)擊應(yīng)用名稱獲取 ) 信息會(huì)以json串的形式返回,得到信息后json_decode( $str,true )后得到以下內(nèi)容:(獲取方式可參考附錄) | |
name | 登錄獲取的用戶名稱 | |
img | 頭像地址 | |
sex | 性別 | |
uniq | 第三方獲得的唯一碼 | |
from | 登錄來(lái)源 如 qq、weibo、renren等 | |
此插件為免費(fèi)插件,可用于商業(yè)用途,請(qǐng)?jiān)谑褂脮r(shí)標(biāo)注開(kāi)發(fā)人。
使用注意點(diǎn):
1、引用js頁(yè)面域名與申請(qǐng)時(shí)的回調(diào)地址域名一定要相同。
2、引用的js后頁(yè)面上一定要加 id='hzy_fast_login' 的標(biāo)簽。
3、申請(qǐng)的回調(diào)url中不允許出現(xiàn)?
錯(cuò)誤代碼集:
錯(cuò)誤碼 | 問(wèn)題 |
10001 | 用戶appid錯(cuò)誤 |
10002 | 所傳token與appid不匹配 |
10003 | 請(qǐng)求域名與注冊(cè)域名不匹配(有回調(diào)地址決定注冊(cè)域名) |
time out | 登錄超時(shí),需要重新登錄 |
附錄:
Php獲取信息代碼: 源碼http://test.open.51094.com/index.php
1、配置文件 open.config.php
內(nèi)容:
<?php
/**
*@ 注冊(cè)地址 http://open.51094.com
*@ QQ交流群:373703921
*@ 博客地址:http://www.51094.com
*@ 測(cè)試地址:http://open.51094.com/user/login.html
*
*@ author: hzy@51094.com
*
**/
define( 'APPID', '申請(qǐng)時(shí)得到的appid');
define( 'TOKEN', '申請(qǐng)時(shí)得到的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、返回頁(yè)面 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{
//第三方平臺(tái)提供的參數(shù)
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("第三方登錄返回結(jié)果:"+code );
if("".equals(code )||null==code ){
System.out.println("回調(diào)函數(shù)沒(méi)有執(zhí)行");
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);
//解析結(jié)果
JSONObject jsonObj = new JSONObject(url);
// 得到指定json key對(duì)象的value對(duì)象
//解析封裝對(duì)象
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發(fā)送GET方法的請(qǐng)求
*
* @param url
* 發(fā)送請(qǐng)求的URL
* @param param
* 請(qǐng)求參數(shù),請(qǐng)求參數(shù)應(yīng)該是 name1=value1&name2=value2 的形式。
* @return URL 所代表遠(yuǎn)程資源的響應(yīng)結(jié)果
*/
public static String sendGet(String url, String param) {String result = "";
BufferedReader in = null;
try {String urlNameString = url + "?" + param;
URL realUrl = new URL(urlNameString);
// 打開(kāi)和URL之間的連接
URLConnection connection = realUrl.openConnection();
// 設(shè)置通用的請(qǐng)求屬性
connection.setRequestProperty("accept", "*/*"); connection.setRequestProperty("connection", "Keep-Alive"); connection.setRequestProperty("user-agent","Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.1;SV1)");
// 建立實(shí)際的連接 connection.connect();
// 獲取所有響應(yīng)頭字段
Map<String, List<String>> map = connection.getHeaderFields();
// 遍歷所有的響應(yīng)頭字段
for (String key : map.keySet()) {System.out.println(key + "--->" + map.get(key));
}
// 定義 BufferedReader輸入流來(lái)讀取URL的響應(yīng)
in = new BufferedReader(new InputStreamReader(
connection.getInputStream()));
String line;
while ((line = in.readLine()) != null) {result += line;
}
} catch (Exception e) { System.out.println("發(fā)送GET請(qǐng)求出現(xiàn)異常!" + e);e.printStackTrace();
}
// 使用finally塊來(lái)關(guān)閉輸入流
finally { try { if (in != null) {in.close();
}
} catch (Exception e2) {e2.printStackTrace();
}
}
return result;
}
/**
* 向指定 URL 發(fā)送POST方法的請(qǐng)求
*
* @param url
* 發(fā)送請(qǐng)求的 URL
* @param param
* 請(qǐng)求參數(shù),請(qǐng)求參數(shù)應(yīng)該是 name1=value1&name2=value2 的形式。
* @return 所代表遠(yuǎn)程資源的響應(yīng)結(jié)果
*/
public static String sendPost(String url, String param) {PrintWriter out = null;
BufferedReader in = null;
String result = "";
try {URL realUrl = new URL(url);
// 打開(kāi)和URL之間的連接
URLConnection conn = realUrl.openConnection();
// 設(shè)置通用的請(qǐng)求屬性
conn.setRequestProperty("accept", "*/*"); conn.setRequestProperty("connection", "Keep-Alive"); conn.setRequestProperty("user-agent","Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.1;SV1)");
// 發(fā)送POST請(qǐng)求必須設(shè)置如下兩行
conn.setDoOutput(true);
conn.setDoInput(true);
// 獲取URLConnection對(duì)象對(duì)應(yīng)的輸出流
out = new PrintWriter(conn.getOutputStream());
// 發(fā)送請(qǐng)求參數(shù)
out.print(param);
// flush輸出流的緩沖
out.flush();
// 定義BufferedReader輸入流來(lái)讀取URL的響應(yīng)
in = new BufferedReader(
new InputStreamReader(conn.getInputStream()));
String line;
while ((line = in.readLine()) != null) {result += line;
}
} catch (Exception e) { System.out.println("發(fā)送 POST 請(qǐng)求出現(xiàn)異常!"+e);e.printStackTrace();
}
//使用finally塊來(lái)關(guān)閉輸出流、輸入流
finally{ try{ if(out!=null){out.close();
}
if(in!=null){in.close();
}
}
catch(IOException ex){ex.printStackTrace();
}
}
return result;
}
}
附上post寫(xiě)法和讀取方法:
//交換獲得值得方法,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頁(yè)面代碼
//接口登陸
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
{
//生成會(huì)員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);
}
}
}
新聞熱點(diǎn)
疑難解答
圖片精選
網(wǎng)友關(guān)注