Esempio n. 1
0
<?php

/**
 * User: chao
 * Date: 2016/4/11
 * Time: 16:42
 */
header("Content-type: text/html; charset=utf-8");
require_once 'service.auth.php';
$auth = new AuthService();
//数据库操作
if (!isset($_POST['token'])) {
    if (isset($_POST['app_key']) && isset($_POST['app_secret'])) {
        $appkey = htmlspecialchars($_POST['app_key']);
        $appsecret = htmlspecialchars($_POST['app_secret']);
        $data = $auth->CheckAuth($appkey, $appsecret);
        $id = $data[0]['id'];
        if ($data[0]['id'] == false) {
            return false;
            //未授权的站点
        }
        $time = date('Y-m-d H-i-s', time());
        $token = md5(rand(1000, 100000) . $time . rand(1000, 100000));
        $lifetime = '';
        //可以设置存活期--永久使用即可
        $auth->SaveToken($id, $token);
        //保存token
        echo $token;
        //返回给授权站点
    }
} else {