PgSoftService.php 2.9 KB

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