PPlayService.php 3.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124
  1. <?php
  2. namespace App\Game\Services;
  3. use App\Util;
  4. use GuzzleHttp\Client;
  5. class PPlayService
  6. {
  7. protected $baseUrl;
  8. public $secretKey;
  9. public $providerId;
  10. public $secureLogin;
  11. public function __construct()
  12. {
  13. $this->baseUrl = "https://api-spe-11.pragmaticplay.net/IntegrationService/v3/http/CasinoGameAPI";
  14. $this->secretKey = "mvxCnuKq8A4GsjUn";
  15. $this->providerId = "PragmaticPlay";
  16. $this->secureLogin = "btcsms_bitcosmos";
  17. }
  18. function generateHash($params)
  19. {
  20. ksort($params);
  21. // $queryString = http_build_query($params);
  22. $queryString = '';
  23. foreach ($params as $key => $value) {
  24. $queryString .= $key . '=' . $value . '&';
  25. }
  26. // 去掉最后一个多余的 '&'
  27. $queryString = rtrim($queryString, '&');
  28. $secretKey = $this->secretKey;
  29. $queryStringWithSecret = $queryString . $secretKey;
  30. return md5($queryStringWithSecret);
  31. }
  32. function checkHash($params)
  33. {
  34. $hash = @$params['hash'];
  35. unset($params['hash']);
  36. if(isset($params['providerId'])){
  37. return ($hash == $this->generateHash($params)) && ($params['providerId'] == $this->providerId);
  38. }
  39. return $hash == $this->generateHash($params);
  40. }
  41. // 发送POST请求
  42. protected function postRequest($endpoint, $data,$json = true)
  43. {
  44. $data['secureLogin'] = $this->secureLogin;
  45. $data['hash'] = $this->generateHash($data);
  46. $post = http_build_query($data);
  47. $headers = ['Content-Type' => 'application/x-www-form-urlencoded'];
  48. $rs = Util::curlPost2($this->baseUrl . $endpoint,$post,true,$headers);
  49. Util::WriteLog('24680_pp_rs', $post);
  50. Util::WriteLog('24680_pp_rs', $rs);
  51. if(!$json){
  52. return $rs;
  53. }
  54. return json_decode($rs, true);
  55. }
  56. public function getCasinoGames()
  57. {
  58. $data = [];
  59. return $this->postRequest('/getCasinoGames/',$data);
  60. }
  61. public function getLobbyGames()
  62. {
  63. $data = ['categories'=>'all'];
  64. return $this->postRequest('/getLobbyGames/',$data);
  65. }
  66. public function closeSession($externalPlayerId,$gameId,$clearHistory=0)
  67. {
  68. $data = [
  69. 'externalPlayerId' => $externalPlayerId,
  70. 'gameId' => $gameId,
  71. 'clearHistory' => $clearHistory
  72. ];
  73. return $this->postRequest('/closeSession/',$data);
  74. }
  75. public function cancelRound($externalPlayerId,$gameId,$roundId)
  76. {
  77. $data = [
  78. 'externalPlayerId' => $externalPlayerId,
  79. 'gameId' => $gameId,
  80. 'roundId' => $roundId
  81. ];
  82. return $this->postRequest('/cancelRound/',$data);
  83. }
  84. public function heartbeatCheck()
  85. {
  86. return file_get_contents($this->baseUrl.'/health/heartbeatCheck');
  87. }
  88. public function getLaunchURL($symbol,$token,$playerId,$currency='BRL',$lang='pt')
  89. {
  90. $data = [
  91. 'symbol' => $symbol,
  92. 'language' => $lang,
  93. 'token' => $token,
  94. 'externalPlayerId' => $playerId,
  95. 'currency' => $currency,
  96. 'lobbyUrl' => route('pp.lobby')
  97. ];
  98. return $this->postRequest('/game/url',$data);
  99. }
  100. }