<?php
include('config/koneksi.php');

$sql_provider = mysqli_query($conn,"SELECT * FROM `tb_tripayapi` WHERE cuid = 1") or die(mysqli_error());
$sp = mysqli_fetch_array($sql_provider);
$urlRequest = $sp['urlRequest'];
$secureLogin = $sp['api_key']; //apikey
$secretKey = $sp['secret_key']; //brandID
        		    
$getUser = mysqli_query($conn,"SELECT * FROM `tb_user` WHERE level = 'user' ORDER BY cuid ASC") or die(mysqli_error());
while($gu = mysqli_fetch_array($getUser)){
    $userID = $gu['cuid'];
    $extplayer = $gu['extplayer'];
    
    					$params = 'currency=IDR&externalPlayerId='.$extplayer.'&secureLogin='.$secureLogin.$secretKey;
				        $hashNeed = md5($params);
				        $curl = curl_init();
				                    
				        curl_setopt_array($curl, array(
				            CURLOPT_URL => $urlRequest.'IntegrationService/v3/http/CasinoGameAPI/player/account/create',
				            CURLOPT_RETURNTRANSFER => true,
				            CURLOPT_ENCODING => "",
				            CURLOPT_MAXREDIRS => 10,
				            CURLOPT_TIMEOUT => 0,
				            CURLOPT_FOLLOWLOCATION => true,
				            CURLOPT_HTTP_VERSION => CURL_HTTP_VERSION_1_1,
				            CURLOPT_CUSTOMREQUEST => "POST",
				            CURLOPT_POSTFIELDS => "secureLogin=".$secureLogin."&externalPlayerId=".$extplayer."&currency=IDR&hash=".$hashNeed,
				            CURLOPT_HTTPHEADER => array(
				                "Content-Type: application/x-www-form-urlencoded",
				                "Cache-Control: no-cache"
				            ),
				        ));
				                    
				        $response = curl_exec($curl);
				        echo $response;
				        curl_close($curl);
				        $hasil = json_decode($response, true);
				        $PlayerId = $hasil['playerId'];
				        $inserPlayer = mysqli_query($conn,"UPDATE `tb_ppplayer` SET `playerid` = '$PlayerId' WHERE externalPlayerId = '$extplayer'") or die(mysqli_error());
}
?>