php – 用于生成要在Web服务身份验证中使用的访问令牌的函数

我需要一个PHP函数生成访问令牌以唯一标识用户.我将此令牌存储在名为“token”的额外列中,我将使用它来进行移动应用程序的身份验证.我在网上搜索它,所有结果都指的是推特或脸书.我需要在我的应用程序中.

我使用cakePHP后端和Android平台.

非常感谢.

解决方法:

使用guid: –

function getGUID(){
    if (function_exists('com_create_guid')){
        return com_create_guid();
    }else{
        mt_srand((double)microtime()*10000);//optional for PHP 4.2.0 and up.
        $charid = strtoupper(md5(uniqid(rand(), true)));
        $hyphen = chr(45);// "-"
        $uuid = chr(123)// "{"
            .substr($charid, 0, 8).$hyphen
            .substr($charid, 8, 4).$hyphen
            .substr($charid,12, 4).$hyphen
            .substr($charid,16, 4).$hyphen
            .substr($charid,20,12)
            .chr(125);// "}"
        return $uuid;
    }
}

$GUID = getGUID();
echo $GUID;

或参考此链接http://guid.us/GUID/PHP

相关文章

统一支付是JSAPI/NATIVE/APP各种支付场景下生成支付订单,返...
统一支付是JSAPI/NATIVE/APP各种支付场景下生成支付订单,返...
前言 之前做了微信登录,所以总结一下微信授权登录并获取用户...
FastAdmin是我第一个接触的后台管理系统框架。FastAdmin是一...
之前公司需要一个内部的通讯软件,就叫我做一个。通讯软件嘛...
统一支付是JSAPI/NATIVE/APP各种支付场景下生成支付订单,返...