TelegramAppService.php 931 B

123456789101112131415161718192021222324252627282930313233343536373839404142
  1. <?php
  2. namespace App\Game\Services;
  3. use App\Game\Telegram\TelegramUser;
  4. class TelegramAppService
  5. {
  6. protected $client;
  7. protected $baseUrl;
  8. public $secretKey;
  9. public $token;
  10. public $salt;
  11. public function __construct()
  12. {
  13. }
  14. /**
  15. * @param string $hash
  16. * @return TelegramUser
  17. */
  18. public static function decodeHash(string $hash){
  19. $data=[];
  20. parse_str(urldecode($hash),$data);
  21. if(isset($data['user'])){
  22. $user=json_decode($data['user'],true);
  23. $user['chat_instance']=$data['chat_instance'];
  24. $user['chat_type']=$data['chat_type'];
  25. $teleUser=TelegramUser::query()->where('id',$user['id'])->first();
  26. if(!$teleUser)$teleUser=TelegramUser::create($user);
  27. $teleUser->increment('enter_times',1);
  28. // dd($teleUser);
  29. return $teleUser;
  30. }
  31. dd($data);
  32. }
  33. }