TokenModel.php 2.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657
  1. <?php
  2. namespace App\Models\Common;
  3. use App\Models\Model;
  4. /**
  5. * App\Models\Common\TokenModel
  6. *
  7. * @property int $id
  8. * @property string $user_name
  9. * @property string $nick_name
  10. * @property string $type
  11. * @property string $app_id
  12. * @property string $app_secret
  13. * @property int $update_at
  14. * @property string $access_token
  15. * @method static \Illuminate\Database\Eloquent\Builder|\App\Models\Common\TokenModel newModelQuery()
  16. * @method static \Illuminate\Database\Eloquent\Builder|\App\Models\Common\TokenModel newQuery()
  17. * @method static \Illuminate\Database\Eloquent\Builder|\App\Models\Common\TokenModel query()
  18. * @method static \Illuminate\Database\Eloquent\Builder|\App\Models\Common\TokenModel whereAccessToken($value)
  19. * @method static \Illuminate\Database\Eloquent\Builder|\App\Models\Common\TokenModel whereAppId($value)
  20. * @method static \Illuminate\Database\Eloquent\Builder|\App\Models\Common\TokenModel whereAppSecret($value)
  21. * @method static \Illuminate\Database\Eloquent\Builder|\App\Models\Common\TokenModel whereId($value)
  22. * @method static \Illuminate\Database\Eloquent\Builder|\App\Models\Common\TokenModel whereNickName($value)
  23. * @method static \Illuminate\Database\Eloquent\Builder|\App\Models\Common\TokenModel whereType($value)
  24. * @method static \Illuminate\Database\Eloquent\Builder|\App\Models\Common\TokenModel whereUpdateAt($value)
  25. * @method static \Illuminate\Database\Eloquent\Builder|\App\Models\Common\TokenModel whereUserName($value)
  26. * @mixin \Eloquent
  27. */
  28. class TokenModel extends Model
  29. {
  30. protected $table = 'public_access_token';
  31. protected $dateFormat = 'U';
  32. protected $fillable = ['access_token', 'updated_at'];
  33. protected $casts = [
  34. 'created_at' => 'integer',
  35. 'updated_at' => 'integer'
  36. ];
  37. /**
  38. * 获取access_token
  39. * @param string $public_id 公众号|小程序id
  40. * @return string access_token
  41. * @throws \Exception
  42. */
  43. public static function getToken(string $public_id)
  44. {
  45. $token = self::where('user_name', $public_id)->first();
  46. return $token->access_token ?? "";
  47. }
  48. }