The application website for the third platform login interface: http://open.51094.com/
document:
To facilitate more development friends, I have specially integrated all the interfaces on the market that support third-party joint login. Login that used to require multiple developments can now be completed in just one time. There is no need to delay the progress of the project by waiting for review. Easy to use and easy to operate. The following is the specific usage method of this plug-in:
1. First log in to the website http://open.51094.com/.
2. Click the "Login" button in the upper right corner to log in. After logging in successfully, it will automatically jump to the management center.
3. After entering the management center, click the Create Application button, as shown below:
4. Select the application type as "Website Application", and after completion, jump to the application information filling page.
5. The information filling page is shown in the figure below. Fill in the application information correctly as required. After completion, click Create application to use it.
Parameter description:
Name: The abbreviation of the application
Details: Application description information, the number of words must not be less than 10 Chinese characters
Login successfully callback address:
The applicant receives the url of the user information, and we notify the applicant in the format of url+?+ parameters. Remember that the url you fill in cannot contain it?
Supported login methods:
Provide your own choice, default is to select all.
Create an application diagram
1. You can view the js address that the application needs to reference in the management center of the user center, as shown in the red box in the figure below:
2. Add the following js code to the page you need to log in
<script type="text/javascript" src="http://open.51094.com/user/myscript/153dee5be21e2.html"></script>
3. Add (<span id="hzy_fast_login"></span>) to the page tag as shown in the following figure
4. After successfully joining, you can see the corresponding login on the login page. As shown in the figure below.
Please use the second method of registering users after 2014-11-1
Plan 1 (deprecated)
Callback method | GET | |
Callback url | The login callback address filled in when applying for the application | |
Callback format | 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 | |
parameter | After obtaining the param parameter content, do url decoding first, and then performing json decoding to get the following content: | |
name | Log in to obtain user name | |
img | Avatar address | |
sex | gender | |
uniq | The only code obtained by a third party | |
from | Login sources such as qq, weibo, renren, etc. | |
Plan 2
Please refer to: http://test.open.51094.com/index.php
Callback method | GET | |
Callback url | The login callback address filled in when applying for the application | |
Callback format | http://url/user/hezuo.html?code=code | |
parameter | After obtaining the code parameter content, use the post method to request: url: http://open.51094.com/user/auth.html POST parameters: type:get_user_info code: the returned code value appid: The appid value applied (click the application name on the web page to obtain) token: The token value applied (click the application name on the web page to obtain) The information will be returned in the form of a json string. After obtaining the information, json_decode($str,true) will get the following content: (refer to the appendix for the acquisition method) | |
name | Log in to obtain user name | |
img | Avatar address | |
sex | gender | |
uniq | The only code obtained by a third party | |
from | Login sources such as qq, weibo, renren, etc. | |
This plug-in is a free plug-in and can be used for commercial purposes. Please mark the developer when using it.
Notes on using:
1. The domain name of the reference js page must be the same as the domain name of the callback address when applying.
2. The tag with id='hzy_fast_login' must be added to the page after the referenced js.
3. Is the requested callback url not allowed to appear?
Error code set:
Error code | question |
10001 | User appid error |
10002 | The token does not match the appid |
10003 | The requested domain name does not match the registered domain name (there is a callback address to determine the registered domain name) |
time out | Login timed out, need to log in again |
appendix:
Php obtains information code: Source code http://test.open.51094.com/index.php
1. Configuration file open.config.php
content:
<?php
/**
*@ Registered address http://open.51094.com
*@ QQ communication group: 373703921
*@ Blog address: http://www.51094.com
*@ Test address: http://open.51094.com/user/login.html
*
*@ author: [email protected]
*
**/
define( 'APPID', 'appid obtained when applying');
define( 'TOKEN', 'token value obtained when applying');
?>
2. Open class file 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. Return to the page back.php
<?php
include 'open51094.class.php';
$open = new open51094();
$code = $_GET['code'];
var_dump( $open->me($code) );
?>
JAVA obtains information code:
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{
// Parameters provided by third-party platforms
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("Third-party login returns result: "+code);
if("".equals(code )||null==code ){
System.out.println("The callback function is not executed");
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);
//Analysis results
JSONObject jsonObj = new JSONObject(url);
// Get the value object of the specified json key object
//Parse encapsulated object
return "Redirect";
}
}
}
HttpRequet class:
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 {/**
* Send a request to the specified URL for GET method
*
* @param url
* The URL to send the request
* @param param
* Request parameters, the request parameters should be in the form of name1=value1&name2=value2.
* @return URL Response results for the remote resource represented by
*/
public static String sendGet(String url, String param) {String result = "";
BufferedReader in = null;
try {String urlNameString = url + "?" + param;
URL realUrl = new URL(urlNameString);
// Open the connection to the URL
URLConnection connection = realUrl.openConnection();
// Set common request attributes
connection.setRequestProperty("accept", "*/*"); connection.setRequestProperty("connection", "Keep-Alive"); connection.setRequestProperty("user-agent","Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.1; SV1)");
// Create an actual connection connection.connect();
// Get all response header fields
Map<String, List<String>> map = connection.getHeaderFields();
// Iterate through all response header fields
for (String key : map.keySet()) {System.out.println(key + "-->" + map.get(key));
}
// Define the BufferedReader input stream to read the URL response
in = new BufferedReader(new InputStreamReader(
connection.getInputStream()));
String line;
while ((line = in.readLine()) != null) {result += line;
}
} catch (Exception e) { System.out.println("Exception occurred when sending GET request!" + e);e.printStackTrace();
}
// Use finally blocks to close the input stream
Finally { try { if (in != null) {in.close();
}
} catch (Exception e2) {e2.printStackTrace();
}
}
return result;
}
/**
* Send a request for POST method to the specified URL
*
* @param url
* The URL to send the request
* @param param
* Request parameters, the request parameters should be in the form of name1=value1&name2=value2.
* @return Response result of the remote resource represented
*/
public static String sendPost(String url, String param) {PrintWriter out = null;
BufferedReader in = null;
String result = "";
try {URL realUrl = new URL(url);
// Open the connection to the URL
URLConnection conn = realUrl.openConnection();
// Set common request attributes
conn.setRequestProperty("accept", "*/*"); conn.setRequestProperty("connection", "Keep-Alive"); conn.setRequestProperty("user-agent","Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.1; SV1)");
// The following two lines must be set to send a POST request
conn.setDoOutput(true);
conn.setDoInput(true);
// Get the output stream corresponding to the URLConnection object
out = new PrintWriter(conn.getOutputStream());
// Send request parameters
out.print(param);
// Buffer of flush output stream
out.flush();
// Define the BufferedReader input stream to read the URL response
in = new BufferedReader(
new InputStreamReader(conn.getInputStream()));
String line;
while ((line = in.readLine()) != null) {result += line;
}
} catch (Exception e) { System.out.println("Exception occurred when sending POST request!" +e);e.printStackTrace();
}
//Use finally blocks to close the output stream and input stream
Finally{ try{ if(out!=null){out.close();
}
if(in!=null){in.close();
}
}
catch(IOException ex){ex.printStackTrace();
}
}
return result;
}
}
Attach post writing and reading method:
//Exchange to obtain the worthy method, post method;
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;
}
//Accept the code to return the code page
//Interface login
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
{
// Generate member 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);
}
}
}