GamePhoneVerityCode.php 2.7 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394
  1. <?php
  2. namespace App\Models;
  3. use App\Game\WebChannelConfig;
  4. use App\Util;
  5. use Illuminate\Database\Eloquent\Model;
  6. use Illuminate\Support\Facades\DB;
  7. class GamePhoneVerityCode extends Model
  8. {
  9. public function addCode($UserID, $Code, $PhoneNum, $Ip)
  10. {
  11. $now = date('Y-m-d H:i:s');
  12. $data = [
  13. 'UserID' => $UserID,
  14. 'PhoneNum' => $PhoneNum,
  15. 'Code' => $Code,
  16. 'CreateDate' => $now,
  17. 'Ip' => $Ip,
  18. 'Channel'=>AccountsInfo::query()->where('UserID',$UserID)->value('Channel'),
  19. ];
  20. DB::connection('write')->table('QPTreasureDB.dbo.GamePhoneVerityCode')
  21. ->updateOrInsert(['PhoneNum'=>"$PhoneNum"],$data);
  22. return true;
  23. }
  24. // 验证 一个手机号对应的IP,只能发10次OTP,超过10次,则这个IP,无论使用任何的手机号,在今日无法再次发送OTP,24点过后次日立即解除限制
  25. public function verifyIp($Ip)
  26. {
  27. $count = DB::connection('write')->table('QPTreasureDB.dbo.GamePhoneVerityCode')
  28. ->whereDate('CreateDate', date('Y-m-d'))
  29. ->where('Ip', $Ip)
  30. ->count();
  31. if ($count > 10) {
  32. return true;
  33. }
  34. return false;
  35. }
  36. //
  37. /**
  38. * 验证验证码 flag =》true 验证间隔日期 false=》验证验证码
  39. * @param $phone
  40. * @param string $code
  41. * @param bool $flag
  42. * @return int
  43. */
  44. public static function verifyCode($phone, $code = '', $flag = false)
  45. {
  46. if ($flag) {
  47. $first = DB::connection('write')->table('QPTreasureDB.dbo.GamePhoneVerityCode')
  48. ->where('PhoneNum', $phone)
  49. ->orderByDesc('CreateDate')
  50. ->first();
  51. if ($first) {
  52. // 60 秒后发送一次验证码
  53. if (time() - strtotime($first->CreateDate) < 60) {
  54. return 2;
  55. }
  56. }
  57. return 0;
  58. } else {
  59. $first = DB::connection('write')->table('QPTreasureDB.dbo.GamePhoneVerityCode')
  60. ->where('PhoneNum', $phone)
  61. ->where('Code', $code)
  62. ->orderByDesc('CreateDate')
  63. ->first();
  64. // 验证码或手机号错误
  65. if (!$first) {
  66. return 1;
  67. }
  68. // 验证码过期
  69. // if (time() - strtotime($first->CreateDate) > 600) {
  70. // return 3;
  71. // }
  72. \Log::info('timeCheck',[time(),date('Y-m-d H:i:s'),strtotime(date('Y-m-d H:i:s')),'ssstime',$first->CreateDate,strtotime($first->CreateDate)]);
  73. return $first->Code;
  74. }
  75. }
  76. }