<?php
/*
* To change this license header, choose License Headers in Project Properties.
* To change this template file, choose Tools | Templates
* and open the template in the editor.
*/
//include_once '../config.php';
include_once('apiBaseClass.php');
class ethClass
{
public function __construct($userId) {
{
$this->userId = $_SESSION['USERID'];
}
else
{
$this->userId = $userId;
}
$this->apiurl = 'http://nodeapi.luckday.net/Gateway/ETHService.asmx/';
$this->siteno = 'C1000001';
$this->secretkey = 'pgZrBEymyfvIHJJi2XjIIsw=';
$this->iv = 'pgZrBEym';
$this->etherscankey = 'YG5AMHVGY1SHUQ95CJYXAVJSCJ57ZM6IAM';
$this->etherscanurl = 'https://api.etherscan.io/api?';
}
public function createAccount($accountName)
{
$service = 'CreateAddress';
$accountNo = $this->encrypt_tripledes($accountName);
$signature = md5(sha1($accountNo.$this->siteno));
$request = array('siteNo' => "$this->siteno",'account'=>"$accountNo",'signature'=>"$signature" );
$new_url = $this->apiurl.$service;
$response = $this->callCurl($new_url, $request);
if($res_decode['Status'] == 1)//10
{
$array = array('status'=>'success','message'=>$res_decode['Result']);
}
else
{
$array = array('status'=>'error','message'=>'API Error');
}
$this->insertCoinApiLog($request_log,$response,$this->req_time,'1'); //insert log;
}
public function getBalance($address,$walletType)
{
$service = 'GetBalance';
$enc_address = $this->encrypt_tripledes($address);
$signature = md5(sha1($enc_address.$walletType.$this->siteno));
$request = array('siteNo'=>"$this->siteno",'currency'=>"$walletType",'address'=>$enc_address,'signature'=>$signature);
$new_url = $this->apiurl.$service;
$response = $this->callCurl($new_url, $request);
if($res_decode['Status'] == 1)
{
$array = array('status'=>'success','message'=>$res_decode['Result']);
}
else
{
$array = array('status'=>'error','message'=>'API Error');
}
$this->insertCoinApiLog($request_log,$response,$this->req_time,'2'); //insert log;
}
public function transferCoin($fromAddress,$toAddress,$quantity,$walletType,$transId)
{
$service = 'Transfer';
$multiplier = 100000000;
$fromAddress = $this->encrypt_tripledes($fromAddress);
$toAddress = $this->encrypt_tripledes($toAddress);
$nValue = bcmul($quantity, $multiplier);
$nValue = $this->encrypt_tripledes($nValue);
$guid = $transId;
$signature = md5(sha1($walletType.$fromAddress.$guid.$nValue.$this->siteno.$toAddress));
$request = array('siteNo'=>"$this->siteno",'currency'=>"$walletType",'fromAddress'=>$fromAddress,
'toAddress'=>$toAddress,'nValue'=>$nValue,'guid'=>$guid,'signature'=>$signature);
$new_url = $this->apiurl.$service;
"Request URL : ".$new_url."<br>";
" Request Param : ".$request."<br>";
$response = $this->callCurl($new_url, $request);
$response;
if($res_decode['Status'] == 1)
{
$array = array('status'=>'success','message'=>$res_decode['Result']);
}
else
{
//$array = array('status'=>'error','message'=>'API Error');
$array = $res_decode;
}
$this->insertCoinApiLog($request_log,$response,$this->req_time,'3'); //insert log;
}
public function transferHistory($address,$fromDate,$toDate,$walletType,$page=1)
{
$service = 'GetTransferList';
$enc_address = $this->encrypt_tripledes($address);
$signature = md5(sha1($enc_address.$walletType.$toDate.$page.$this->siteno.$fromDate));
$request = array('siteNo'=>"$this->siteno",'currency'=>"$walletType",'address'=>$enc_address,
'startDate'=>$fromDate,'endDate'=>$toDate,'page'=>$page,'signature'=>$signature);
$new_url = $this->apiurl.$service;
$response = $this->callCurl($new_url, $request);
if($res_decode['Status'] == 1)
{
$array = array('status'=>'success','message'=>$res_decode['Result'],'count'=>$res_decode['Count']);
}
else
{
$array = array('status'=>'error','message'=>'API Error');
}
$this->insertCoinApiLog($request_log,$response,$this->req_time,'4'); //insert log;
}
public function getCoinPrice() //For ETH
{
//module=stats&action=ethprice&apikey=YourApiKeyToken
$requestUrl = $this->etherscanurl.'module=stats&action=ethprice&apikey='.$this->etherscankey;
if($rep['status'] == 1)
{
$array = array('status'=>'success','message'=>$rep['result']['ethusd']);
}
else
{
$array = array('status'=>'error','message'=>'Something Went Wrong..');
}
$this->insertCoinApiLog($request_log,$response,$this->req_time,'5'); //insert log;
}
public function getCnyConversion()
{
$url = 'https://data.fixer.io/api/convert?access_key=96adf4af98271d2de2db1a78a69de9c5&from=USD&to=CNY&amount=1';
//echo $getCongtent;
if($json_decode['success'] == true)
{
$array = array('status'=>'success','message'=>$json_decode['result']);
}
else
{
$array = array('status'=>'error','message'=>'Something Went Wrong..');
}
$this->insertCoinApiLog($request_log,$getCongtent,$this->req_time,'6'); //insert log;
}
public function getPublicTransactionList($address) //ETH
{
$requestUrl = $this->etherscanurl.'module=account&action=txlist&address=='.$address.''
. '&startblock=0&endblock=99999999&sort=asc&apikey='.$this->etherscankey;
$requestUrl = $this->etherscanurl.'module=account&action=txlist&address='.$address.'&startblock=0&endblock=99999999&sort=asc&apikey='.$this->etherscankey;
//echo $response;
if($rep['status'] == 1)
{
$array = array('status'=>'success','message'=>$rep['result']);
}
else
{
$array = array('status'=>'error','message'=>'Something Went Wrong..');
}
$this->insertCoinApiLog($request_log,$getCongtent,$this->req_time,'7'); //insert log;
}
protected function callCurl($url,$request)
{
//curl_setopt($ch, CURLOPT_HTTPHEADER, $header);
curl_setopt($ch, CURLOPT_CONNECTTIMEOUT
, 60); //Timeout
return $return;
}
private function encrypt_tripledes($input, $base64 = true)
{
$size = 8;
$input = $this->pkcs5_Pad($input, $size);
}
private function pkcs5_Pad($text)
{
$pad = 8 - (strlen($text) % 8);
}
/**
*
*inser coin transaction log
*/
private function insertCoinApiLog($request,$response,$req_time,$type)
{
$api = new api();
$ip = $_SERVER['REMOTE_ADDR'];
$playerId=$this->userId;
$conn = $api->getConn();
$stmt = $conn->prepare("INSERT INTO coin_api_log SET "
. "user_id = :user_id,"
. "type = :type,"
. "server = :server,"
. "header = :header,"
. "request = :request,"
. "response = :response,"
. "req_time = :req_time,"
. "res_time = :res_time,"
. "ip = :ip");
$stmt->bindParam(':user_id', $playerId,PDO::PARAM_STR);
$stmt->bindParam(':type', $type,PDO::PARAM_STR);
$stmt->bindParam(':server', $server,PDO::PARAM_STR);
$stmt->bindParam(':header', $headers,PDO::PARAM_STR);
$stmt->bindParam(':request', $request,PDO::PARAM_STR);
$stmt->bindParam(':response', $response,PDO::PARAM_STR);
$stmt->bindParam(':req_time', $req_time,PDO::PARAM_STR);
$stmt->bindParam(':res_time', $time,PDO::PARAM_STR);
$stmt->bindParam(':ip', $ip,PDO::PARAM_STR);
$stmt->execute();
}
}
?>