定制 olakunlevpn/token 二次开发

按需修改功能、优化性能、对接业务系统,提供一站式技术支持

邮箱:yvsm@zunyunkeji.com | QQ:316430983 | 微信:yvsm316

olakunlevpn/token

Composer 安装命令:

composer require olakunlevpn/token

包简介

Unique Token Generator For Laravel

README 文档

README

Laravel

Total Downloads

Laravel unique Token Generator

// Generate unique Token From Database.
$new_token = $token->Unique($table_name, $column_name, $size);

Installation

Require this package, with Composer, in the root directory of your project.

$ composer require olakunlevpn/token

Add the service provider to config/app.php in the providers array, or if you're using Laravel 5.5, this can be done via the automatic package discovery.

Olakunlevpn\Token\TokenServiceProvider::class

If you want you can use the facade. Add the reference in config/app.php to your aliases array.

'Token'=>\Olakunlevpn\Token\Facades\Facade::class

Documentation

★ New Token Trait ★

setup in model

To use new trait token you need to do some changes in the model that contain the token column.

One Column Token
One token Trait allow you to generate token for one columns in the table
  • To use one column token you need to add use OlakunlevpnToken; in the model .
  • In database we use default column called dt_token to replace with your column name add protected $DT_Column='column_name'; in the model .
  • Token settings are set by default to this value ['type' => DT_Unique, 'size' => 40, 'special_chr' => false] to replace with your custom settings add protected $DT_settings=['type'=>DT_Unique,'size'=>60,'special_chr'=>false]; in the model .
  • you should know that we use custom constants for our token type
  Const DT_Unique = 'Unique'; 
  Const DT_UniqueNum = 'UniqueNumber'; 
  Const DT_UniqueStr = 'UniqueString';
  Const DT_Random = 'Random';
  Const DT_RandomNum = 'RandomNumber';
  Const DT_RandomStr = 'RandomString';
  • after preparing the model to use our trait token in your code you can set the token with your custom column and settings like this
           $user=User::first();
           $user->setToken();
           $user->save();
  • you can use your custom settings in setToken(); function like this
           $user=User::first();
           $user->setToken(DT_UniqueStr,100,false);
           $user->save();
  • you can set your custom column in the function
           $user=User::first();
           $user->setToken(DT_UniqueStr,100,false,'column_name');
           $user->save();
  • To get model query with token you can use WithToken() . $user=User::WithToken()->get();
  • To get model query with no tokens you can use flag false in WithToken() $user=User::WithToken(false)->get();
Multi Column Token
Multi token allow you to generate tokens for multi columns in the same table
  • To use multi column token you need to add use OlakunlevpnMultiToken; in the model .
  • Columns settings are not set by default so you need to make your custom settings in the model
  protected $DMT_columns=[
        'unique_id'=>['type'=>DT_Unique,'size'=>60,'special_chr'=>false],
        'unique_uid'=>['type'=>DT_Unique,'size'=>30,'special_chr'=>false],
    ];
  • you should know that we use custom constants for our token type
      Const DT_Unique = 'Unique'; 
      Const DT_UniqueNum = 'UniqueNumber'; 
      Const DT_UniqueStr = 'UniqueString';
      Const DT_Random = 'Random';
      Const DT_RandomNum = 'RandomNumber';
      Const DT_RandomStr = 'RandomString';
    • after preparing the model to use our trait multi token in your code you can set the tokens with only one function
               $user=User::first();
               $user->setTokens();
               $user->save();

★ The old way ★

Generate unique token

With this package you can generate unqiue token not repated in database just by using unique($table_name,$column_name,$size) Function $table_name is the table name in database , $column_name is the column name in the table, $size is token size.

Generate unique string token

generate unique strings token with the same signature of unique token with function UniqueString($table_name,$column_name,$size).

Generate unique integer token

generate unique integers token with the same signature of unique token with function UniqueNumber($table_name,$column_name,$size).

Generate random token

generate random token with function Random($size) and $size is the size of token length.

Generate random integer token

generate random integer token with function RandomNumber($size) and $size is the size of token length.

Generate random string token

generate random string token with function RandomString($size) and $size is the size of token length.

Special Characters

use true to allow special characters in your token !@#$%^&*() in all functions just like Random($size,true).

Examples

Here you can see an example of just how simple this package is to use.

Unique Token

// Generate unique token not rebeated in database table with column name 
Token::Unique($table_name, $column_name, 10 );
//Result: fCWih6TDAf


// Generate unique integer token not rebeated in database table with column name
Token::UniqueNumber($table_name, $column_name, 10 );
//Result: 9647307239


// Generate unique string token not rebeated in database table with column name
Token::UniqueString($table_name, $column_name, 10 );
//Result: SOUjkyAyxC


//You can use special characters just add "true" to the function
Token::Unique($table_name, $column_name, 10,true );
//Result: H@klU$u^3z

Random Token (not unique)

$size=10;
// Generate random token 
Token::Random($size);

// Generate random integer token
Token::RandomNumber($size);

// Generate random string token
Token::RandomString($size);

//You can use special characters just add "true" to the function
Token::Random($size,true);

License

MIT © Olakunlevpn

olakunlevpn/token 适用场景与选型建议

olakunlevpn/token 是一款 基于 PHP 开发的 Composer 扩展包,目前已累计 2 次下载、GitHub Stars 达 0, 最近一次更新时间为 2020 年 04 月 03 日, 在 PHP 生态内属于活跃度较高的组件。

它主要适用于以下技术方向: 「laravel」 「token」 「generate」 「PHP token」 「token generator」 「unique token」 等业务场景。在实际项目中,围绕这些方向常见需要落地的问题包括:接口对接、性能调优、并发安全、与既有框架(Laravel / ThinkPHP / Yii / Webman 等)的兼容适配,以及生产环境的日志埋点与稳定性保障。

我们在过去多个企业项目中使用过 olakunlevpn/token 或与其功能相近的方案,如果你在选型或落地过程中遇到问题,例如 版本兼容、二次改造、私有化封装、与内部系统对接、生产 BUG 排查,欢迎联系我们协助评估。

围绕 olakunlevpn/token 我们能提供哪些服务?
定制开发 / 二次开发

基于 olakunlevpn/token 在你已有业务上做功能扩展、字段裁剪、UI 适配、与内部账号 / 权限 / 日志系统的深度对接。

BUG 修复 & 性能优化

线上偶发问题、内存泄漏、慢查询、并发异常等排查修复;针对高流量场景做缓存、队列、索引层面的调优。

项目外包 & 长期维护

承接完整的项目从需求 → 设计 → 开发 → 上线 → 长期运维;也可按月提供技术保姆服务。

yvsm@zunyunkeji.com QQ:316430983 微信:yvsm316 西安尊云信息科技 · 专注 PHP / Go / 分布式系统研发

统计信息

  • 总下载量: 2
  • 月度下载量: 0
  • 日度下载量: 0
  • 收藏数: 0
  • 点击次数: 10
  • 依赖项目数: 0
  • 推荐数: 0

GitHub 信息

  • Stars: 0
  • Watchers: 1
  • Forks: 0
  • 开发语言: PHP

其他信息

  • 授权协议: MIT
  • 更新时间: 2020-04-03