Php GAPI.LOL API在打开游戏时抛出未知错误

Php GAPI.LOL API在打开游戏时抛出未知错误,php,mysql,laravel,api,Php,Mysql,Laravel,Api,我正在将gapi.lol API集成到一个网站中,这些示例都在核心PHP中,因此我不得不将它们重写为Laravel,因为网站使用的是框架。API没有支持团队,因此在需要时,我无法向任何人提问。我按照指示做了所有事情,但是,当打开一个游戏时出现问题,它抛出了一个未知错误! 以下是他们网站上关于如何集成API的指南 Importand when a player wins EGT jackpot, Our api server sends writeBet api call with game ID

我正在将gapi.lol API集成到一个网站中,这些示例都在核心PHP中,因此我不得不将它们重写为Laravel,因为网站使用的是框架。API没有支持团队,因此在需要时,我无法向任何人提问。我按照指示做了所有事情,但是,当打开一个游戏时出现问题,它抛出了一个未知错误! 以下是他们网站上关于如何集成API的指南

Importand when a player wins EGT jackpot, Our api server sends writeBet api call with game ID 2500 and your api server should answer with success message
Global jackpot will sends the id of the game player playing.

EXAMPLE
return $apiresult = array(
    "status" => "success",
    "error" => '',
    "login" => ExampleAccount,
    "balance" => PlayerBalance,
);


#1 Create users table (you can use your existing table)
                

-- ----------------------------
-- Table structure for users
-- ----------------------------
DROP TABLE IF EXISTS `users`;
    CREATE TABLE `users` (
      `id` bigint(20) NOT NULL AUTO_INCREMENT,
      `score` bigint(20) DEFAULT '0',
      `callback_key` varchar(64) CHARACTER SET utf8 DEFAULT NULL,
      PRIMARY KEY (`id`),
      KEY `ext` (`callback_key`) USING BTREE
    ) ENGINE=MyISAM AUTO_INCREMENT=2 DEFAULT CHARSET=latin1;

                

            
#2 Create table user_bets (save bet/wins)

-- ----------------------------
-- Table structure for user_bets
-- ----------------------------
DROP TABLE IF EXISTS `user_bets`;
CREATE TABLE `user_bets` (
  `id` bigint(20) NOT NULL AUTO_INCREMENT,
  `in` bigint(20) DEFAULT '0',
  `out` bigint(20) DEFAULT '0',
  `user_id` bigint(20) DEFAULT NULL,
  `date` datetime DEFAULT '1970-01-01 00:00:01',
  `game_id` bigint(20) DEFAULT NULL,
  PRIMARY KEY (`id`)
) ENGINE=MyISAM AUTO_INCREMENT=49 DEFAULT CHARSET=latin1;


#3 Create wallet
This is php example you can use any language you want.

if you use your own table do not forget to change the fields on mysql querys


header('Access-Control-Allow-Headers: *'); // This is only for test your wallet
header('Access-Control-Allow-Origin: *'); // This is only for test your wallet
header('Access-Control-Allow-Methods: POST'); // This is only for test your wallet
header('Access-Control-Max-Age: 1000'); // This is only for test your wallet

$db_host = "localhost"; // CHANGE THIS LINE
$db_name = "database"; // CHANGE THIS LINE
$db_user = "root"; // CHANGE THIS LINE
$db_password = "password"; // CHANGE THIS LINE


function sqlsafe($s)
{
    global $conn;
    $str = strval($s);
    return $conn->real_escape_string($str);
}

$inputJSON = file_get_contents('php://input');
if ($inputJSON != '') {
    $input = json_decode($inputJSON, TRUE); //convert JSON into array
    if (count($input) != '') {
        foreach ($input as $name => $value) {
            $_POST[$name] = $value;
        }
    }
} else {
    $apiresult = array(
        "status" => "fail",
        "error" => "101"
    );

    $response = json_encode($apiresult);
    echo $response;
    exit();
}

$conn = new mysqli($db_host, $db_user, $db_password, $db_name);
if ($conn->connect_error) {
    $apiresult = array(
        "status" => "fail",
        "error" => $conn->connect_error
    );
    echo json_encode($apiresult);
    exit();
}


$cmd = $_POST['cmd'];
$login = sqlsafe($_POST['login']);

if(isset($_POST['gameId'])){
    $gameId = $_POST['gameId'];
}

$balance = '1000';
$operationId = '100';
$key = sqlsafe($_POST['key']);

switch ($cmd) {
    case 'getBalance':
        $sql = "select `score` from `users` where `id`='$login' and callback_key='$key'";
        $result = $conn->query($sql);
        if ($result) {
            if ($result->num_rows > 0) {
                $userfound = true;
                $row = $result->fetch_assoc();
                $balance = floatval($row['score']) / 100.00;
                $apiresult = array(
                    "status" => "success",
                    "error" => "",
                    "login" => $login,
                    "balance" => $balance
                );
            } else {
                $userfound = false;
                $apiresult = array(
                    "status" => "fail",
                    "error" => "user_not_found1"
                );
                echo json_encode($apiresult);
                exit();
            }
        } else {
            $userfound = false;
            $apiresult = array(
                "status" => "fail",
                "error" => "user_not_found2"
            );
            echo json_encode($apiresult);
            exit();
        }

        if (!$userfound) {
            $apiresult = array(
                "status" => "fail",
                "error" => "user_not_found3"
            );

            $response = json_encode($apiresult);
            echo $response;
            exit();
        }
        break;
    case 'writeBet':
        $sql = "select `score` from `users` where `id`='$login'  and callback_key='$key'";
        $result = $conn->query($sql);
        $row = $result->fetch_assoc();
        $balance = floatval($row['score']) / 100.00;

        $winLose = $_POST['winLose'];
        $bet = $_POST['bet'];
        $out = $winLose + $bet;
        $gameId = $_POST['gameId'];

        if ($balance < $bet) {
            $apiresult = array(
                "status" => "fail",
                "error" => "fail_balance"
            );
            $response = json_encode($apiresult);
            echo $response;
            exit();
        }

        $winLose = (int)floor($winLose * 100 + 0.00001);
        $sql = "update `users` set `score` = (`score` + ($winLose)) where (`score`+($winLose)) >= 0 and `id`='$login'  and callback_key='$key'";
//writeLog($sql);
        $result = $conn->query($sql);
        if ($result) {

            $bet = (int)floor($bet * 100 + 0.00001);
            $out = (int)floor($out * 100 + 0.00001);

            $sql = "INSERT INTO user_bets set `in` =$bet, `out`=$out, game_id = $gameId, date=now(), user_id = $login";
            $result = $conn->query($sql);
            //echo $result;

            $sql = "select `score` from `users` where `id`='$login' and callback_key='$key'";
            $result = $conn->query($sql);
            $row = $result->fetch_assoc();
            $balance = floatval($row['score']) / 100.00;

            $apiresult = array(
                "status" => "success",
                "error" => '',
                "login" => $login,
                "balance" => $balance,
                "operationId" => $operationId
            );
        } else {
            $apiresult = array(
                "status" => "fail",
                "error" => "fail_balance " . $conn->error
            );
        }
        break;
}


$response = json_encode($apiresult);
echo $response;


#4 Create play page

require_once('lib/ApiClient.php'); //class for api calls

//AMATIC API VARIABLES
$API_URL = 'https://play.gapi.lol/api/games/post/';
$API_ID = 'API ID'; // CHANGE THIS LINE
$API_KEY = 'API KEY'; // CHANGE THIS LINE
$GAME_URL = 'https://play.gapi.lol/play/';

//YOUR API VARIABLES
$CALLBACK_URL = 'http://yourdomain.com/wallet.php'; // CHANGE THIS LINE URL FROM wallet.php yourdomain.com/wallet.php
$CALLBACK_KEY = '12345'; //change to api key of your wallet api
$parentid = "walletshop"; //change this to Hall ID on your server the user belongs to
$userid = "1"; // user from wallet API


//GAME INVIROMENT VARIABLES
$game = "arisingphoenix";// You can get all valid games with API 'action'=> 'getgames'
$lang = "en"; // Valid values: "en","de","es","ru","tr","cz","gr","ee"
$exiturl = "back.html"; // url to go to when player clicks exit. Your menu url for example.

if(isset($_GET['game']))
    $game = $_GET['game'];

//PREPARE API REQUEST
$params = array(
    'action'      => 'inituser',
    'api_id'      => $API_ID,
    'hash'        => $userid,
    'parenthash'  => $parentid,
    'callbackurl' => $CALLBACK_URL,
    'callbackkey' => $CALLBACK_KEY
);

//print_r($params);
$client = new ApiClient($API_URL,$API_KEY);
$resjson = $client->SendData($params);
if($resjson===false)
{
    echo 'ERROR:'.$client->lasterror;
}
else
{
    $resarray = json_decode($resjson,true);
    if($resarray['success']=='true') //API CALL WAS SUCCESSFUL
    {
        echo '
<iframe src="'.$GAME_URL.'?game='.$game.'&hash='.$userid.'&api_id='.$API_ID.'&lang='.$lang.'&exit='.$exiturl.'"
style="border: 0; position:fixed; top:0; left:0; right:0; bottom:0; width:100%; height:100%" allowfullscreen>
<iframe>';
    }
    else
    {
        echo 'error occured:'.$resarray['error'];
    }

}


//ApiClient.php


    class ApiClient {

    public $apiurl;
    public $apikey;
    public $lasterror;

    public function __construct($url = '', $key = '')
    {
        $this->apiurl = $url;
        $this->apikey = $key;
        $this->lasterror = '';
    }

    function SendData($params)
    {
        $this->lasterror = '';

        //CHECK FOR ERRORS
        if($this->apikey=='')
        {
            $this->lasterror = "API KEY NOT SET";
            return false;
        }
        if($this->apiurl=='')
        {
            $this->lasterror = "API URL NOT SET";
            return false;
        }
        if(count($params)==0)
        {
            $this->lasterror = "PARAMETERS NOT SET";
            return false;
        }
        if(!$this->is_assoc($params))
        {
            $this->lasterror = "WRONG PARAMETERS VARIABLE. MUST BE ASSOCIATIVE ARRAY";
            return false;
        }
        //END CHECKING FOR ERRORS

        $joinparams = '';

        $rand = md5(time());

        foreach ($params as $key => &$val) {
            if (is_array($val)) $val = implode(',', $val);
            $enc_val = urlencode($val);
            $post_params[] = $key.'='. $enc_val;
            $joinparams = $joinparams.$enc_val;
        }

        $post_params[] = 'callid'.'='. $rand; //add random unique call identifier
        $joinparams = $joinparams.$rand; //add it to sign

        $sign = hash_hmac("sha1",$joinparams,$this->apikey);
        $post_string = implode('&', $post_params).'&sign='.$sign;

        try{
            $ch = curl_init();
            curl_setopt($ch, CURLOPT_URL, $this->apiurl);
            curl_setopt($ch, CURLOPT_POSTFIELDS, $post_string);
            curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
            curl_setopt($ch, CURLOPT_USERAGENT, 'curl');
            curl_setopt($ch, CURLOPT_TIMEOUT, 15);

            $result = curl_exec($ch);
            if($result==false)
            {
                $this->lasterror = curl_error($ch);
                return false;
            }
        }
        catch (Exception $e)
        {
            $this->lasterror = "Exception :".$e->getMessage();
            return false;
        }

        curl_close($ch);

        return $result;
    }

    function is_assoc(array $array) {
        return (bool)count(array_filter(array_keys($array), 'is_string'));
    }
}

显示继续按钮:

本地主机上的错误


您自己做过什么来发现问题吗。目前这个问题似乎包含了很多代码,很难完全理解。你自己做了什么来发现问题吗。目前,这个问题似乎包含了很多代码,很难完全理解。
<?php

namespace App\Http\Controllers;

use App\Wallet;
use App\User_bet;
use App\User;
use App\GameUrl;
use App\Classes\ApiClient;
use Illuminate\Http\Request;

class WalletController extends Controller
{
    public function wallet(Request $request)
    {
        $inputJSON = file_get_contents('php://input');
        if ($inputJSON != '') {
            $input = json_decode($inputJSON, TRUE); //convert JSON into array
            if (count($input) != '') {
                foreach ($input as $name => $value) {
                    $request->$name = $value;
                }
            }
        } else {
            $apiresult = array(
                "status" => "fail",
                "error" => "101"
            );
        
            $response = json_encode($apiresult);
            echo $response;
            exit();
        }

        $cmd = $request->cmd;
        $login = $request->login;

        if($request->gameId){
            $gameId = $request->gameId;
        }

        $balance = '1000';
        $operationId = '100';
        $key = $request->key;



        switch ($cmd) {
            case 'getBalance':
                $user = auth()->user();
                if ($user) {
                        $userfound = true;
                        $balance = floatval($user->score) / 100.00;
                        $apiresult = array(
                            "status" => "success",
                            "error" => "",
                            "login" => $login,
                            "balance" => $balance
                        );
                   
                } else {
                    $userfound = false;
                    $apiresult = array(
                        "status" => "fail",
                        "error" => "user_not_found1"
                    );
                    echo json_encode($apiresult);
                    exit();
                }
        
                if (!$userfound) {
                    $apiresult = array(
                        "status" => "fail",
                        "error" => "user_not_found3"
                    );
        
                    $response = json_encode($apiresult);
                    echo $response;
                    exit();
                }
                break;
            case 'writeBet':
                $user = auth()->user();
                $balance = floatval($user->score) / 100.00;
        
                $winLose = $request->winLose;
                $bet = $request->bet;
                $out = $winLose + $bet;
                $gameId = $request->gameId;
        
                if ($balance < $bet) {
                    $apiresult = array(
                        "status" => "fail",
                        "error" => "fail_balance"
                    );
                    $response = json_encode($apiresult);
                    echo $response;
                    exit();
                }
        
                $winLose = (int)floor($winLose * 100 + 0.00001);
                $user = auth()->user();
                $user->score = $user->score +($winLose);
                if ($user->save()) {
        
                    $bet = (int)floor($bet * 100 + 0.00001);
                    $out = (int)floor($out * 100 + 0.00001);
                    $user_bet = new User_bet();
                    $user_bet->in = $bet;
                    $user_bet->out = $out;
                    $user_bet->game_id = $gameId;
                    $user_bet->date = now();
                    $user_bet->user_id = $login;
                    $user_bet->save();


        
                    $user = auth()->user();
                    $balance = floatval($user->score) / 100.00;
        
                    $apiresult = array(
                        "status" => "success",
                        "error" => '',
                        "login" => $login,
                        "balance" => $balance,
                        "operationId" => $operationId
                    );
                } else {
                    $apiresult = array(
                        "status" => "fail",
                        "error" => "fail_balance " . $conn->error
                    );
                }
                break;
        }
        

    }

    public function home(){
        return view('slot.home');
    }
    public function getgames()
    {
        $user = auth()->user();
      if($user){
        $API_URL = 'https://play.gapi.lol/api/games/post/'; 
        $API_KEY = 'LP8CGiNnTTyNxhb3BGxMcLMWdSOMGQRJ'; 
        
        $params = array(
            'api_id' => 'eErNZwJ36onh9qoq5sOek2zN8yWZZePe',
            'action' => 'getgames',    
            'callbackurl' => 'http://127.0.0.1:8000/api/slot/wallet ',
            'callbackkey' => 'SDFSD8FHSHD0N');
        
        $client = new ApiClient($API_URL,$API_KEY);
        $resjson = $client->SendData($params);
        // dd($resjson);
        $games =\json_decode($resjson);
       return response()-> json($games);
      }else{
          $error = "User not found".$url;
          return response()->json($error);
      }
        
        
    }


    public function getUrl($gameName)
    {
       //AMATIC API VARIABLES
        $API_URL = 'https://play.gapi.lol/api/games/post/';
        $API_ID = 'eErNZwJ36onh9qoq5sOek2zN8yWZZePe'; // API_ID
        $API_KEY = 'LP8CGiNnTTyNxhb3BGxMcLMWdSOMGQRJ'; // API_KEY
        $GAME_URL = 'https://play.gapi.lol/play/';

        //YOUR API VARIABLES
        $CALLBACK_URL = 'http://127.0.0.1:8000/api/slot/wallet'; // CHANGE THIS LINE URL FROM wallet.php yourdomain.com/wallet.php
        $CALLBACK_KEY = '12345'; //change to api key of your wallet api
        $parentid = "walletshop"; //change this to Hall ID on your server the user belongs to
        $userid = auth()->user()->id;


        //GAME INVIROMENT VARIABLES
        $game = $gameName;// You can get all valid games with API 'action'=> 'getgames'
        $lang = "en"; // Valid values: "en","de","es","ru","tr","cz","gr","ee"
        $exiturl = "http://127.0.0.1:8000/api/slot/home"; // url to go to when player clicks exit. Your menu url for example.
        
        //PREPARE API REQUEST
        $params = array(
            'action'      => 'inituser',
            'api_id'      => $API_ID,
            'hash'        => $userid,
            'parenthash'  => $parentid,
            'callbackurl' => $CALLBACK_URL,
            'callbackkey' => $CALLBACK_KEY
        );

        //print_r($params);
        $client = new ApiClient($API_URL,$API_KEY);
        $resjson = $client->SendData($params);
        if($resjson===false)
        {
            $error = 'ERROR:'.$client->lasterror;
            return \response()->json($error);
        }
        else
        {
            $resarray = json_decode($resjson,true);
            if($resarray['success']=='true') //API CALL WAS SUCCESSFUL
            {
                $URL =
        $GAME_URL.'?game='.$game.'&hash='.$userid.'&api_id='.$API_ID.'&lang='.$lang.'&exit='.$exiturl;
        $gameUrl = new GameUrl();
        $gameUrl->url = $URL;
        $gameUrl->user_id = \auth()->user()->id;
        if($gameUrl->save()){
            return response()->json($URL);
        }
        
            }
            else
            { 
               $error = 'error occured:'.$resarray['error'];
                return \response()->json($error);
            }

        }
    }
    public function play()
    {
        $user = auth()->user()->id;
        $gameUrl = GameUrl::where("user_id", $user)->latest()->first();
        $link= $gameUrl->url;
        return view('slot.play', compact('link'));
    }
}
```Game opening```