CommonService.php 575 B

123456789101112131415161718192021222324
  1. <?php
  2. namespace App\Services;
  3. use App\Models\ThirdToken;
  4. class CommonService
  5. {
  6. public static function createToken($type, $type_id, $v = 1)
  7. {
  8. $key = mt_rand();
  9. $hash = hash_hmac("sha1", $v . mt_rand() . time(), $key, true);
  10. $token = str_replace('=', '', strtr(base64_encode($hash), '+/', '-_'));
  11. ThirdToken::create([
  12. 'type' => $type,
  13. 'type_id' => $type_id,
  14. 'token' => $token,
  15. 'expire_at' => date('Y-m-d H:i:s', time() + 7200),
  16. ]);
  17. return $token;
  18. }
  19. }