phpDemo.php
<?php
header("content-type:text/html;charset=utf-8");
date_default_timezone_set('PRC');
 
	 /**
* Transfer wallet PHP Demo
	 * Class ngapi
	 * @version (PHP 5 >= 5.3.0, PHP 7)
	 * www.neapi.com
	 */
class newngapiDemo{
 
 
 
protected $sign_key = '*********'; // API account
protected $api_account = '*********'; // KEY key
 
	/**
	 * @var string
* Interface address
	 */
protected $register_url = 'http://domain/v1/user/register'; // Create a member account
protected $login_live_url = 'http://domain/v1/user/login'; // Get the game login address
protected $trans_url = 'http://domain/v1/user/trans'; // quota conversion
protected $balance_url = 'http://domain/v1/user/balance'; // Member game platform balance query
protected $all_credit_url = 'http://domain/v1/user/all-credit';// All platform balance query
protected $status_url = 'http://domain/v1/user/status'; // Quota conversion status query
protected $collect_url = 'http://domain/v1/user/record'; // Get game records
 
 
//Game platform type lowercase
	protected  $plat_type = 'ag';
 
protected $game_type_live = '1'; // Live entertainment
protected $game_type_slot = '2'; // Slot machine
protected  $game_type_lottery = '3';  // 彩票
protected  $game_type_sports = '4';   // 体育
protected  $game_type_esports = '5';  // 电竞
protected  $game_type_fishing = '6';  // 捕鱼
protected  $game_type_poker = '7';    // 棋牌
 
 
	/**
	 * @param $username
	 * @return mixed
* register
	 */
	public function register($username){
		$code = md5($this->sign_key.$this->api_account.$this->plat_type.$username);
		$data = array(
			"username"=>$username,
			"plat_type"=>$this->plat_type,
			"sign_key"=>$this->sign_key,
			"code"=>$code
		);
		$res = $this->sendRequest($this->register_url, $data);
		return $res;
	}
 
	/**
	 * @param $username
	 * @param int $isMobileUrl
	 * @param string $gameCode
	 * @return mixed
* Get the game login address
	 */
	public function login($username,$isMobileUrl=0,$gameCode=""){
		$code = md5($this->sign_key.$this->api_account.$username.$this->plat_type.$isMobileUrl);
		$data = array(
			"username"=>$username,
			"plat_type"=>$this->plat_type,
			"game_type"=>$this->game_type_live,
			"game_code"=>$gameCode,
			"sign_key"=>$this->sign_key,
			"is_mobile_url"=>$isMobileUrl,
			"code"=>$code
		);
		$res = $this->sendRequest($this->login_live_url, $data);
		return $res;
	}
 
	/**
	 * @param $username
	 * @param $money
	 * @param $client_transfer_id
	 * @return mixed
* Credit conversion
	 */
	public function trans($username,$money,$client_transfer_id){
		$code = md5($this->sign_key.$this->api_account.$username.$this->plat_type.$money.$client_transfer_id);
		$data = array(
			"username"=>$username,
			"plat_type"=>$this->plat_type,
			"money"=>$money,
			"client_transfer_id"=>$client_transfer_id,
			"sign_key"=>$this->sign_key,
			"code"=>$code
		);
 
		$res = $this->sendRequest($this->trans_url, $data);
		return $res;
	}
 
 
 
	/**
	 * @param $username
	 * @param $client_transfer_id
	 * @return mixed
* Check the transfer status
	 */
	public function status($username,$client_transfer_id){
		$code = md5($this->sign_key.$this->api_account.$username.$this->plat_type.$client_transfer_id);
		$data = array(
			"username"=>$username,
			"client_transfer_id"=>$client_transfer_id,
			"plat_type"=>$this->plat_type,
			"sign_key"=>$this->sign_key,
			"code"=>$code
		);
		$res = $this->sendRequest($this->status_url, $data);
		return $res;
	}
 
	/**
	 * @param $username
	 * @return mixed
* Get user balance
	 */
	public function balance($username){
		$code = md5($this->sign_key.$this->api_account.$username.$this->plat_type);
		$data = array(
			"username"=>$username,
			"plat_type"=>$this->plat_type,
			"sign_key"=>$this->sign_key,
			"code"=>$code
		);
		$res = $this->sendRequest($this->balance_url, $data);
		return $res;
	}
 
	/**
	 * @return mixed
* Obtain all platform quotas
	 */
	public function credit(){
		$code = md5($this->sign_key.$this->api_account);
		$data = array(
			"sign_key"=>$this->sign_key,
			"code"=>$code
		);
		$res = $this->sendRequest($this->all_credit_url, $data);
		return $res;
	}
 
	/**
	 * @param $startTime
	 * @param $endTime
	 * @param int $page
	 * @param int $limit
	 * @return mixed
* Get betting history
	 */
	public function record($startTime,$endTime,$page=1,$limit=15){
		$code = md5($this->sign_key.$this->api_account.$this->plat_type.$startTime.$endTime);
		$data = array(
			"plat_type"=>$this->plat_type,
			"page"=>$page,
			"limit"=>$limit,
			"startTime"=>$startTime,
			"endTime"=>$endTime,
			"game_type"=>$this->game_type_slot,
			"sign_key"=>$this->sign_key,
			"code"=>$code
		);
		$res = $this->sendRequest($this->collect_url, $data);
		return $res;
	}
 
	private function sendRequest($url,$post_data=array()){
		$ch = curl_init();
		curl_setopt($ch, CURLOPT_URL, $url);
		curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
		curl_setopt($ch, CURLOPT_POST, 1);
		curl_setopt($ch, CURLOPT_POSTFIELDS, $post_data);
		curl_setopt($ch, CURLOPT_CONNECTTIMEOUT, 60);
		curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, FALSE);
		curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, FALSE);
		$contents = curl_exec($ch);
		curl_close($ch);
 
		print_r($contents);
		exit();
		return json_decode ($contents, TRUE);
	}
 
}
 
//Use demo
$api = new newngapiDemo();
$res = $api->login("username");
print_r($res);
?>