| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124 |
- <?php
- namespace App\Game\Services;
- use App\Util;
- use GuzzleHttp\Client;
- class PPlayService
- {
- protected $baseUrl;
- public $secretKey;
- public $providerId;
- public $secureLogin;
- public function __construct()
- {
- $this->baseUrl = "https://api-spe-11.pragmaticplay.net/IntegrationService/v3/http/CasinoGameAPI";
- $this->secretKey = "mvxCnuKq8A4GsjUn";
- $this->providerId = "PragmaticPlay";
- $this->secureLogin = "btcsms_bitcosmos";
- }
- function generateHash($params)
- {
- ksort($params);
- // $queryString = http_build_query($params);
- $queryString = '';
- foreach ($params as $key => $value) {
- $queryString .= $key . '=' . $value . '&';
- }
- // 去掉最后一个多余的 '&'
- $queryString = rtrim($queryString, '&');
- $secretKey = $this->secretKey;
- $queryStringWithSecret = $queryString . $secretKey;
- return md5($queryStringWithSecret);
- }
- function checkHash($params)
- {
- $hash = @$params['hash'];
- unset($params['hash']);
- if(isset($params['providerId'])){
- return ($hash == $this->generateHash($params)) && ($params['providerId'] == $this->providerId);
- }
- return $hash == $this->generateHash($params);
- }
- // 发送POST请求
- protected function postRequest($endpoint, $data,$json = true)
- {
- $data['secureLogin'] = $this->secureLogin;
- $data['hash'] = $this->generateHash($data);
- $post = http_build_query($data);
- $headers = ['Content-Type' => 'application/x-www-form-urlencoded'];
- $rs = Util::curlPost2($this->baseUrl . $endpoint,$post,true,$headers);
- Util::WriteLog('24680_pp_rs', $post);
- Util::WriteLog('24680_pp_rs', $rs);
- if(!$json){
- return $rs;
- }
- return json_decode($rs, true);
- }
- public function getCasinoGames()
- {
- $data = [];
- return $this->postRequest('/getCasinoGames/',$data);
- }
- public function getLobbyGames()
- {
- $data = ['categories'=>'all'];
- return $this->postRequest('/getLobbyGames/',$data);
- }
- public function closeSession($externalPlayerId,$gameId,$clearHistory=0)
- {
- $data = [
- 'externalPlayerId' => $externalPlayerId,
- 'gameId' => $gameId,
- 'clearHistory' => $clearHistory
- ];
- return $this->postRequest('/closeSession/',$data);
- }
- public function cancelRound($externalPlayerId,$gameId,$roundId)
- {
- $data = [
- 'externalPlayerId' => $externalPlayerId,
- 'gameId' => $gameId,
- 'roundId' => $roundId
- ];
- return $this->postRequest('/cancelRound/',$data);
- }
- public function heartbeatCheck()
- {
- return file_get_contents($this->baseUrl.'/health/heartbeatCheck');
- }
- public function getLaunchURL($symbol,$token,$playerId,$currency='BRL',$lang='pt')
- {
- $data = [
- 'symbol' => $symbol,
- 'language' => $lang,
- 'token' => $token,
- 'externalPlayerId' => $playerId,
- 'currency' => $currency,
- 'lobbyUrl' => route('pp.lobby')
- ];
- return $this->postRequest('/game/url',$data);
- }
- }
|