1¡¢ÒµÎñÐeÇo
ÐeҪʵÏÖÕaÑuÒ»¸o¹¦ÄÜ£ºÔÚµÚÈý*½ÊÚȨµÄÈÏÖ¤µ±ÖУ¬ÔÚÓû§Ê״εǼÊÚȨÎÒÃÇ»aµÃµ½Ò»¸oaccess_token£¬ÓÐЧÆÚΪ25Сʱ£¬»¹»aµÃµ½Ò»¸orefresh_token£¬ÓÐЧÆÚΪ30Ìi¡£
ÎÒÃÇÖ»Òª±£´aeºÃÕa¸orefresh_token£¬ÔÚ30ÌiÄÚÎÒÃǶ¼¿ÉÒÔÓÃÕa¸orefresh_tokenÈ¥ÇeÇoÒ»¸oapi£¬Ëu»a*µ»ØÒ»¸oеÄaccess_token¡£ÕaÑuÎÒÃÇÖ»ÐeÒªÈÃÓû§ÊÚȨһ´Î£¬ÎÒÃǾͿÉÒÔ»ñµÃ³¤´i30ÌiµÄÒ»¸oÊÚȨÆÚÏÞ¡£
*ÕaÀi¿ÉÒÔÖΪ¼¸¸oµa£º**
<1>Õa¸oÓ¦¸ÃÊÇÒª¶¨ÆÚÖ´ÐеÄÒ»¸oÈÎÎñ¡£25Сʱ²Å»a¹ýÆÚ£¬ÄÇôÎÒÃÇ12Сʱˢһ´Î¾Í×a¹»ÁË£¬²¢²»ÐeÒªºÜƵ±µÄˢС£¼ÙÉeÕaÑuÒ»ÖÖÇe¿o£ºÈÃÒ»¸oÒ³Ãae³ÖÐøµÄÔËÐУ¬ÓÃÒ»¸owhileµÄËÀѻȥִÐÐÒ»¸oÈÎÎñ£¬Ö´ÐÐÍeÖ®ºosleepºÜ³¤Ò»¶Îʱ¼a£¬È»ºoÔÙ¼ÌÐøÖ´ÐС£ÕaÑu×oÒ²ÊÇ¿ÉÒԵģ¬µ«ÊDZȽÏÕ¼×ÊÔ´¡£ËuÖ´ÐеÄʱ¼aºÜÉÙ£¬µÈ´ýµÄʱ¼aÈ´ºÜ³¤£¬Ã»±ØÒªÕaÑuÒ»Ö±µÈ´ý¡£
<2>Õa¸oÓ¦¸Ã²»ÐeÒªÊÇÒ»¸o¿ÉÒÔ*ÃÎʵ½µÄÒ³Ãae¡£ÊÇÎÒÃÇÄÚ²¿Ö´ÐеÄÒ»¸oÈÎÎñ£¬²»ÐeÒªÊÇÈËÈË¿ÉÒÔ*ÃÎʵ½µÄÒ»¸oÒ³Ãae¡£
<3>Õa¸oÒ³ÃaeÓ¦¸ÃÒ²ÒªºÍ¿o¼ÜÈÚºÏÔÚÒ»Æ𣬿ÉÒÔ*ÃÎʵ½¸÷ÖÖ×ÊÔ´¡£Ò»¸oÆÕͨµÄphpÒ³Ãae¿ÖÅÂÊDz»Ðеģ¬ÎÒÃÇÐeÒª¸u¿o¼ÜÈںϵÄÒ»¸oÒ³Ãae£¬ÐeÒª¿ÉÒÔ*ÃÎʵ½¸÷ÖÖ×ÊÔ´£¬±ÈÈç˵redis£¬±ÈÈç˵config£¬µÈµÈ¡£
2¡¢ÓÃcliģʽÔËÐÐcodeigniterµÄÒ³Ãae
<1>cliµÄÒ³ÃaeÌØÐÔʲôÊÇcliģʽ£¿¾ÍÊÇÃuÁiÐÐģʽ¡£ÎÒÃÇ¿ÉÒÔ²»ÓÃurlÀ´ÃÎÊphpÒ³Ãae£¬¶øʹÓÃÃuÁiÐÐÀ´ÃÎÊ£¬ÕaÊÇ¿ÉÒԵġ£
¶ÔÒ³ÃaeÀ´Ëµ£¬Ê²Ã´¶¼²»ÐeÒª¸Ä±a£¬±ÈÈ磺
ͬÑuÒªÊÇÒ»¸oÆÕͨµÄcontroller£¬Òª¼Ì³Ð×ÔCI_Controller£»
Òª¶¨ÒaÂÓÉÆ÷£¬Õa¸oÒ³Ãae±ØÐeÒ²ÊǾÓÉÂÓÉ*ÃÎʵõ½£»
ÉoÖÁÈÔÈ»¿ÉÒÔÌi¼ÓÕaÑuµÄÉuÃ÷
defined('BASEPATH') OR exit('No direct script access allowed');
¿ÉÒÔͨ¹ýÌi¼ÓÒ»¸oÅжÏÈÃÒ³ÃaeÖ»ÄÜÈÃcli*ÃÎÊ£º
public function __construct()
{
parent::__construct();
if (!is_cli())
exit("²»ÕýÈ*µÄ*ÃÎÊ*½Ê½");
}
<2>Ôoôͨ¹ýÃuÁiÐÐ*ÃÎÊͨ¹ýecho´oÓ¡ÔÚÃuÁiÐÐÉÏÃae£¬¾ÍÈç´oÓ¡ÔÚÒ³ÃaeÉÏÒ»Ñu
cd E:\xxx\xxx\phpSite //ÍøÕ¾µÄ¸uĿ¼£¬¼´index.phpËuÔÚĿ¼
php index.php aaa bbb ccc //¼´ÃÎÊÍøÖΪyourdomain.com/index.php/aaa/bbb/cccÕaÑuµÄµØÖ*×¢Òa£º
µÚÒ»ÐÐÊÇתµ½ÍøÕ¾¸uĿ¼Õa¸oÂ*¾¶£»
µÚ¶þÐÐphpÊǵ÷ÓÃÁËphp.exeÕa¸oÊÇÒoΪÎÒÃÇÓÐÉeÖÃphpµÄ»*¾³±aÁ¿£»
index.php²»¿ÉÒÔȱÉÙ£¬ÒoΪÕaÀiÎÒÃÇûÓÐ×ßþÎñÆ÷ÁË£¬Ã»Óо¹ýþÎñÆ÷µÄurl-rewrite£¬ËuÒÔÕa¸oindex.phpÊDZز»¿ÉÉٵġ£
ÎÒÃÇ¿ÉÒÔ½«ÕaÁ½ÐдuÂe*ÅÔÚÒ»¸oÎı¾ÎļþÀiÃae£¬½«Ãu×Ö¸ÄΪrefresh.bat£¬Ë«»÷Õa¸obatÎļþ£¬Ëu¾Í»aÖ´ÐÐÒ»´Î£¬Ïaµ±ÓÚ´o¿ªÃuÁiÐÐÀ´Ö´ÐÐ
Èç¹uÎÒÃÇÐeÒªµ÷ÊԵĻ°£¬²»ÒªÈõ¯³oµÄÃuÁiÐÐ×Ô¶¯¹Øµo£¬ÎÒÃÇ¿ÉÒÔÔÚ¼ÓÉϵÚÈýÐдuÂe£¬¼ÓÒ»¸oµ¥´Ê¾Í¿ÉÒÔÁË£ºpause
Ëu¾Í»aͣס²¢ÇÒÏÔʾÏa¹ØµÄÐÅÏ¢*½±aÎÒÃǵ÷ÊÔ¡£
<3>Ò³Ãaeµ÷ÊÔÈçÏÂÀý×Ó£¬´ËÒ³Ãaeͨ¹ý°ÑÒ»¸oֵÿˢÐÂÒ³ÃaeÒ»´ÎÀÛ¼ÓÒ»´Î£¬´aeÔÚredisÀi£¬À´ÑeÖ¤Ò³ÃaeÊÇñÓб»ÃÎʹý£º
<?php
defined('BASEPATH') OR exit('No direct script access allowed');
/**
* Created by PhpStorm.
* Date: 2017/2/20
* Time: 23:18
*/
class Refresh_token extends CI_Controller
{
public function __construct()
{
parent::__construct();
if (!is_cli())
exit("²»ÕýÈ*µÄ*ÃÎÊ*½Ê½");
}
public function index()
{
$oldData = $this->redis_model->get_access_token('1234');
if ($oldData == null)
$oldData = 0;
$newData = $oldData + 1;
$this->redis_model->set_access_token('1234',$newData);
echo 'its refresh_token page!';
}
}
3¡¢´´½¨¼Æ»®ÈÎÎñÈÃËuÔËÐÐbatÎļþ
4¡¢Ë¢ÐÂtoken
<1>ÃuÃuµÄ¹aeÔoË¢ÐÂtokenÊ×ÏÈÏeµ½µÄÊDZeÀuredis¡£redisÄÇô¶aÓ¦¸ÃÔoô±eÀu£¿ÎÒÏeµ½µÄÊǸø²»Í¬ÀaÐÍredisÉe¶¨²»Í¬µÄǰ׺¡£
±ÈÈç˵£¬ËuÓÐÓû§µÄrefresh_tokenµÄkey¶¼ÕaÑuд£º"refresh_token_Óû§id"¡£È»ºoÓÃredisµÄģʽƥÅa¾Í¿ÉÒÔ°ÑÒÔ"refreshtoken"¿ªÍ*µÄkeyÕÒ³oÀ´£¬È»ºoÒ»ÌoÌo´¦Ài¡£
<2>redis±eÀuÊ×ÏÈ£¬redisÊÇÓÐģʽʶ±ðµÄ¹¦ÄÜ£¬²Î¼uÊÖ²a£ºhttps://redis.io/commands/keys
Æa´Î£¬phpÔÉuµÄredis×e¼þÊÇÓÐÕa¸oģʽʶ±ðµÄ¹¦ÄÜ¡£ÔÉuµÄÓÃ*¨´o¸ÅÊÇÕaÑu£º
// ÔÉuredisÀa¿a£¬²»ÐeÒªconfig/redis.php
$redis = new Redis();
$redis->connect('127.0.0.1',6379);
//$redis->set('key10','xx10',20);//µÚÈý¸o²ÎÊýÊÇ´aeÐøʱ¼a£¬µ¥Î»ÊÇÃe£¬Èç¹u²»ÌiÔoΪÓÀ¾Ã
echo $redis->get('key10');
´oÖÂ˵һÏ£¬ci¿o¼ÜµÄredis²Ù×÷apiÄØÊÇÔÚphpÔÉuµÄapiÉÏÃae½øÐÐÁËÒ»²aa×°£¬¶øËuÕa¸oa×°Äز»°uÀ¨Õa¸oģʽʶ±ð¡£
±¾È˵Ä×Ô¶¨Òa²Ù×÷apiÊÇ´Ó¿o¼ÜapiÖ±½Ó¿½±´¹ýÀ´µÄ£¬Ò²ÊÇΪÁ˽±aÌi¼Ó¸u¶a½*¨¡£ÔÚÔÉuµÄ¿o¼ÜÉÏÃaeÌi¼Ó×ܹe²»Ì«ºÃ£¬±ÈÈç˵½«À´ÒªÉý¼¶¡¢ÒÆÖ²µÈÎÊÌa¡£Ð´³É×Ô¼ºµÄÀa¿aÏeÔoô¸ÄÔoô¸Ä¡£
ÏÂÃaeÊÇÌi¼ÓÕa¸oģʽʶ±ðapi£º
public function keys($pattern)
{
return $this->_redis->keys($pattern);
}
È»ºoÔÚmodelÀiÃaeÕaÑuµ÷Óãº
public function get_keys($pattern)
{
return $this->rediscli->default->keys($pattern);
}
È»ºoÔÚcontrollerÀiÃaeʹÓãº
// $this->redis_model->set_redis('hello'.'1','my_hello_1',12345);
// $this->redis_model->set_redis('hello'.'2','my_hello_2',12345);
// $this->redis_model->set_redis('hello'.'3','my_hello_3',12345);
$vals = $this->redis_model->get_keys('hello'.'*');
if ($vals != null)//×¢ÒaÕaÀi£¬ËuÊÇÒ»¸oarray£¬Èç¹u*µ»ØµÄÊÇÆ¥Åaµ½0¸o£¬ÄÇô²»»aÊÇÒ»¸o¿ÕµÄÓÐЧµÄ0³¤¶ÈµÄarray£¬¶øÈ*ʵÊÇÒ»¸onull¡£
{
foreach ($vals as $val)
{
echo '</br>';
echo $val;
}
}
ÕaÑu¾Í¿ÉÒÔÍe³É¶ÔÌض¨Ç°×ºµÄ±eÀuÁË£¡
×¢Òa£ºÕaÀiÒªÌرð˵Ã÷һϣ¬ÎÒÃÇÔÚдÈeÕa¸otokenµÄʱºo£¬»a½«ÓÐЧÆÚд½øÈ¥£¬ÄÇôֻҪÕa¸oÓÐЧÆÚµÄÖµÊÇÕýÈ*µÄ£¬ÎÒÃÇÈ¡µ½Õa¸otoken±Ø¶¨ÊÇÓÐЧµÄ£¬ÄÇôÎÒÃÇÄÃÕa¸oÓÐЧµÄtokenȥˢУ¬±ØÈ»Êdzɹ¦µÄ¡£Ò»°a²»´aeÔÚË¢ÐÂʧ°ÜµÄÇe¿o¡£ÒoΪÕa¸otokenÒ»µ(C)ʧЧÎÒÃÇÒ²¾ÍÈ¡²»µ½ÁË¡£
ÒÔÉÏÕaƪÀuÓÃphp-cliºÍÈÎÎñ¼Æ»®ÊµÏÖË¢ÐÂtoken¹¦ÄܵĽ¨¾ÍÊÇС±a*ÖÏi¸ø´o¼ÒµÄÈ«²¿ÄÚÈÝÁË£¬Ï£ÍuÄܸø´o¼ÒÒ»¸o²Î¿¼£¬Ò²Ï£Íu´o¼Ò¶a¶aÖ§³Ö½Å±¾Ö®¼Ò¡£