PgSoftTestService.php 2.5 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091
  1. <?php
  2. namespace App\Game\Services;
  3. use App\Util;
  4. use GuzzleHttp\Client;
  5. class PgSoftTestService
  6. {
  7. protected $client;
  8. protected $baseUrl;
  9. public $secretKey;
  10. public $token;
  11. public $salt;
  12. public function __construct()
  13. {
  14. $this->client = new Client();
  15. $this->baseUrl = "https://api.pg-bo.me";
  16. $this->secretKey = "98d2e7bd8d6a49588a68ee25f0072e4f";
  17. $this->token = "I-226f37ece4604f19a926c0cd709a995c";
  18. $this->salt = "ec064b935d794d49b8a31062420d451a";
  19. }
  20. function generateGUID() {
  21. // Generate 16 random bytes
  22. $data = openssl_random_pseudo_bytes(16);
  23. // Set the version to 4 (random UUID)
  24. $data[6] = chr(ord($data[6]) & 0x0f | 0x40);
  25. // Set the variant to DCE 1.1
  26. $data[8] = chr(ord($data[8]) & 0x3f | 0x80);
  27. // Format the byte data into a GUID string
  28. return vsprintf('%s%s-%s-%s-%s-%s%s%s', str_split(bin2hex($data), 4));
  29. }
  30. // 发送POST请求
  31. protected function postRequest($endpoint, $data,$json = true)
  32. {
  33. $post = http_build_query($data);
  34. $headers = ['Content-Type' => 'application/x-www-form-urlencoded'];
  35. $rs = Util::curlPost2($this->baseUrl . $endpoint.'?trace_id='.$this->generateGUID(),$post,true,$headers);
  36. Util::WriteLog('24680_pg_rs', $post);
  37. Util::WriteLog('24680_pg_rs', $rs);
  38. if(!$json){
  39. return $rs;
  40. }
  41. return json_decode($rs, true);
  42. }
  43. public function getGamesList($lang='pt',$currency='BRL')
  44. {
  45. $data = [
  46. 'operator_token' => $this->token,
  47. 'secret_key' => $this->secretKey,
  48. 'currency' => $currency,
  49. 'language' => $lang,
  50. 'status' => 1
  51. ];
  52. return $this->postRequest('/external/Game/v2/Get',$data);
  53. }
  54. public function getLaunchURLHTML($gameId,$playerId,$ip='',$lang='zh')
  55. {
  56. ///external-game-launcher/api/v1/GetLaunchURLHTML
  57. $extraArgs = [
  58. 'btt' => 1,
  59. 'ops' => $playerId,
  60. 'l' => $lang,
  61. ];
  62. $data = [
  63. 'operator_token' => $this->token,
  64. 'path' => "/{$gameId}/index.html",
  65. 'extra_args' => http_build_query($extraArgs),
  66. 'url_type' => 'game-entry',
  67. 'client_ip' => $ip
  68. ];
  69. return $this->postRequest('/external-game-launcher/api/v1/GetLaunchURLHTML',$data,false);
  70. }
  71. public function verifySession($token,$secretKey)
  72. {
  73. return $token == $this->token && $secretKey == $this->secretKey;
  74. }
  75. }