This is the exact code they give me in the Query examples with the fields i added. No matter what I cannot get it to work. There other examples work but not the 1 i need.
The error I get: {"error_code": 10, "message": "payment_list element incorrect keys", "details": ""}
However it works when I use their onsite execute program.
<?php
function post_api($url, $postfields) {
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, $url);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_FOLLOWLOCATION, true);
curl_setopt($ch, CURLOPT_POST, 1);
curl_setopt($ch, CURLOPT_POSTFIELDS, $postfields);
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, 0);
$result = curl_exec($ch);
return $result;
}
$confirmations = 3;
$callback = urlencode("https://website.ml/ipnbtc?id=2&email=email#gmail.com");
$fee = "low";
$rules = [
array('address'=>'btc1', 'qouta'=> 95),
array('address'=>'btc2', 'qouta'=> 5),
array('address'=>'btc2', 'qouta'=> 0)
];
$postfields = json_encode(array('type'=>"payment_distribution", 'payment_distribution'=> $rules ));
$data = post_api("https://bitaps.com/api/create/payment/smartcontract/". $callback . "?confirmations=" . $confirmations . "&fee_level=" . $fee, $postfields);
echo $data;
$respond = json_decode($data,true);
$address = $respond["address"]; // Bitcoin address to receive payments
$payment_code = $respond["payment_code"]; //Payment Code
$invoice = $respond["invoice"]; // Invoice to view payments and transactions
?>
Mistake in word qouta. Need quota
$rules = [
array('address'=>'btc1', 'quota'=> 95),
array('address'=>'btc2', 'quota'=> 5),
array('address'=>'btc2', 'quota'=> 0)
];
Related
how to send post data using curl in php array json
post curl param orderlist like an array
this is my code
<?php
class PostOrderPolicy extends CI_Controller{
public function index(){
$data = $this->getData();
foreach ($data as $key) {
$orderListt = array(
'orderDate' => $key['order_date'],
'IDNumber' => $key['IDnumber'],
'itemDescription' => $key['description']
);
$send = $this->sendData($orderListt, $key['resi_number']);
if ($send) {
$res["message"] = "Sukses";
}else{
$res["message"] = "Gagal";
}
}
//echo json_encode($res);
}
private function getData(){
$sql = "SELECT * FROM t_transaction WHERE status='00'";
return $this->db->query($sql)->result_array();
}
private function sendData($data){
$result = array();
$url = "https://contoh.co.id/createPolicy";
$res = array();
$sign = $this->getSign();
$upperSign = strtoupper($sign);
//$random = $this->getRandomStr();
$random = '049KN1PSOL16QHIF';
$batch = 'BATCH000002';
$dataArr = array(
'sign' => $upperSign,
'randomStr' => $random,
'batchNo' => $batch,
'orderList' => [$data]
);
$string = json_encode($dataArr);
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, $url);
curl_setopt($ch, CURLOPT_POST, true);
curl_setopt($ch, CURLOPT_CUSTOMREQUEST, "POST");
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, false);
curl_setopt($ch, CURLOPT_POSTFIELDS, $string);
curl_setopt($ch, CURLOPT_HTTPHEADER, array('Content-Type:application/json'));
$response = json_decode(curl_exec($ch), TRUE);
print_r($response);
print_r($string);
}
}
?>
but my result post field
[enter image description here][1]
[1]: https://i.stack.imgur.com/b7LEP.png
i want like this
[enter image description here][2]
[2]: https://i.stack.imgur.com/xExJ2.png
{"sign":"35EAF78F95A52DDA79FC9911559026F6","randomStr":"049KN1PSOL16QHIF","batchNo":"BATCH000002","orderList":[{"orderDate":"2020-07-01 11:00:00.000","resiNumber":"99875646957","itemDescription":"testing"},{"orderDate":"2020-07-01 ]11:00:00.000","IDNumber":"28929740170","itemDescription":"testing"}]}
Return response instead of outputting:
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
Execute the POST request:
$result = curl_exec($ch);
Close cURL resource:
curl_close($ch);
I have this code
I need a loop to be able to print all results which are 400-600 but I'm not able because I'm limited to only 100 shows per page and I need a loop/while to make the same request but changing the page and then print the result and I'm not able to make it, can someone explain me how to implement here a loop or to give me some examples?
<?php
include('config/config.php');
$ch = curl_init();
$username = '**************';
$password = ''**************';';
$hash = base64_encode($username . ':' . $password);
$headers = array(
'Authorization: Basic ' . $hash
);
$query = $connection->query("SELECT id_xyz_ro as prods FROM stock_prods where id_xyz_ro > 0");
$array = Array();
while($result = $query->fetch_assoc()){
$array[] = $result['prods'];
}
$connection->query('SET session group_concat_max_len=15000');
foreach($connection->query("SELECT GROUP_CONCAT(CONCAT('\'', id_xyz_ro, '\'')) as prods FROM stock_prods where id_xyz_ro > 0") as $row) {
}
$datas = array(
'id' => $array,
'itemsPerPage' => '100', //Only 100 because API it's limiting me at 100 shows per page
'currentPage' => '1' //Here I need to loop
);
$data = array(
'data' => $datas
);
set_time_limit(0);
$url = "www.xyz.net/api-3/product_offer/read";
curl_setopt($ch, CURLOPT_URL, $url);
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
curl_setopt($ch, CURLOPT_HEADER, false);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch, CURLOPT_POST, true);
curl_setopt($ch, CURLOPT_TIMEOUT, 60);
curl_setopt($ch, CURLOPT_CUSTOMREQUEST, "POST");
curl_setopt($ch, CURLOPT_POSTFIELDS, http_build_query($data));
curl_setopt($ch, CURLOPT_HTTPHEADER, $headers);
$result = curl_exec($ch);
print_r($result); //After loop I need to print results from all loops
?>
Thanks in advance
I am struggling using Binance's REST API. I have managed to get working GET request via query string such as pinging the server, ticker information, etc. My challenge now is performing POST request via query string using cURL. I have been scraping code from various places and referring back to the API to get pieces to work but I am unsure as to why I am getting this error returned from the result... {"code":-1102,"msg":"Mandatory parameter 'signature' was not sent, was empty/null, or malformed."}
(ERROR SHOWN ON WEBPAGE). I echo out the signature and its a load of gibberish so I would believe that the hash_hmac performed at the top would be working, but honestly I got pretty lucky making the GET request work. Does anyone have any suggestions as to why this would be broken? Thanks!
$apikey = "MYKEY";
$apisecret = "MYSECRET";
$timestamp = time()*1000; //get current timestamp in milliseconds
$signature = hash_hmac('sha256', "TRXBTC&type=market&side=buy&quantity=100.00&recvWindow=10000000000000000×tamp=".$timestamp, $apisecret);
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, "https://www.binance.com/api/v3/order/test");
curl_setopt($ch, CURLOPT_RETURNTRANSFER, TRUE);
curl_setopt($ch, CURLOPT_HEADER, FALSE);
curl_setopt($ch, CURLOPT_POST, TRUE);
curl_setopt($ch, CURLOPT_POSTFIELDS, "symbol=TRXBTC&type=market&side=buy&quantity=100.00&recvWindow=10000000000000000×tamp=".$timestamp);
curl_setopt($ch, CURLOPT_HTTPHEADER, array("Content-Type: application/x-www-form-urlencoded","X-MBX-APIKEY: ".$apikey,"signature: ".$signature));
$response = curl_exec($ch);
curl_close($ch);
echo $response;
As per their API docs:
SIGNED endpoints require an additional parameter, signature, to be sent in the query string or request body.
You are sending the signature via neither of these methods and are instead sending it through the header.
Change this:
curl_setopt($ch, CURLOPT_POSTFIELDS, "symbol=TRXBTC&type=market&side=buy&quantity=100.00&recvWindow=10000000000000000×tamp=".$timestamp);
curl_setopt($ch, CURLOPT_HTTPHEADER, array("Content-Type: application/x-www-form-urlencoded","X-MBX-APIKEY: ".$apikey,"signature: ".$signature));
To this:
curl_setopt($ch, CURLOPT_POSTFIELDS, "symbol=TRXBTC&type=market&side=buy&quantity=100.00&recvWindow=10000000000000000×tamp=" . $timestamp . "&signature=" . $signature);
curl_setopt($ch, CURLOPT_HTTPHEADER, array("Content-Type: application/x-www-form-urlencoded","X-MBX-APIKEY: ".$apikey));
<?php
$secret = "F................";
$key = "D.................";
$s_time = "timestamp=".time()*1000;
$sign=hash_hmac('SHA256', $s_time, $secret);
$url = "https://api.binance.com/api/v3/account?".$s_time.'&signature='.$sign;
$ch = curl_init($url);
curl_setopt($ch, CURLOPT_HTTPHEADER, array('X-MBX-APIKEY:'.$key));
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch, CURLOPT_FOLLOWLOCATION, 1);
curl_setopt($ch, CURLOPT_URL, $url);
$result = curl_exec($ch);
$result = json_decode($result, true);
echo '<pre>';
var_dump($result);
echo '</pre>';
?>
Here is an example, using php-curl-class
// Variables
// url, key and secret is on separate file, called using require once
$endPoint = "/api/v3/order/test";
$coin = "BTC";
$fiat = "EUR";
$symbol = $coin . "" . $fiat;
$side = "BUY";
$type = "LIMIT";
$timeInForce = "GTC";
$quantity = 1;
$price = 10000;
$timestamp = time();
// Constructing query arrays
queryArray = array(
"symbol" => $symbol,
"side" => $side,
"type" => $type,
"timeInForce" => $timeInForce,
"quantity" => $quantity,
"price" => $price,
"timestamp" => $timestamp*1000
);
$signature = hash_hmac("sha256", http_build_query($queryArray), $secret);
$signatureArray = array("signature" => $signature);
$curlArray = $queryArray + $signatureArray;
// Curl : setting header and POST
$curl->setHeader("Content-Type","application/x-www-form-urlencoded");
$curl->setHeader("X-MBX-APIKEY",$key);
$curl->post($url . "" . $endPoint, $curlArray);
if ($curl->error) {
echo 'Error: ' . $curl->errorCode . ': ' . $curl->errorMessage . "\n";
}
$order = $curl->response;
print_r($order);
I had the same problem, and nothing of above doesn't helped.
So I finaly figured out how to make order on my way.
So, maybe this helps someone.
function Kupovina($buy_parametri) {
$key = "xxxxxxxxxxxxxxx";
$secret = "xxxxxxxxxxxx";
$s_time = "timestamp=".time()*1000;
$timestamp = time()*1000; //get current timestamp in milliseconds
$sign = hash_hmac('sha256', $buy_parametri."×tamp=".$timestamp, $secret);
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, "https://api.binance.com/api/v3/order");
curl_setopt($ch, CURLOPT_RETURNTRANSFER, TRUE);
curl_setopt($ch, CURLOPT_HEADER, FALSE);
curl_setopt($ch, CURLOPT_POST, TRUE);
curl_setopt($ch, CURLOPT_POSTFIELDS, $buy_parametri."&".$s_time."&signature=".$sign);
curl_setopt($ch, CURLOPT_HTTPHEADER, array("Content-Type: application/x-www-form-urlencoded","X-MBX-APIKEY: ".$key));
$response = curl_exec($ch);
curl_close($ch);
return $response;
}
$buy_parametri = "symbol=BTCUSDT&type=market&side=buy&quantity=0.00086";
Call function:
Kupovina($buy_parametri);
In the following custom function...
function get_txtlocal_balance() {
$username = variable_get('sms_txtlocal_email');
$hash = variable_get('sms_txtlocal_password');
$data = array('username' => $username, 'hash' => $hash);
$ch = curl_init('http://api.txtlocal.com/balance/');
curl_setopt($ch, CURLOPT_POST, true);
curl_setopt($ch, CURLOPT_POSTFIELDS, $data);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
$response = curl_exec($ch);
curl_close($ch);
$balance = json_decode($response, true);
echo $balance['balance']['sms'];
}
I return a balance from a text local account. Now i try and echo this balance into place...
$balance = get_txtlocal_balance();
$title = 'SMS Integration - Current Balance: ' . $balance;
<span><?php echo $title;?></span>
But the returned value doesnt appear in the right place, it always returns are the top of the page, can anyone spot what im doing wrong?
Replace Below Code :
function get_txtlocal_balance() {
$username = variable_get('sms_txtlocal_email');
$hash = variable_get('sms_txtlocal_password');
$data = array('username' => $username, 'hash' => $hash);
$ch = curl_init('http://api.txtlocal.com/balance/');
curl_setopt($ch, CURLOPT_POST, true);
curl_setopt($ch, CURLOPT_POSTFIELDS, $data);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
$response = curl_exec($ch);
curl_close($ch);
$balance = json_decode($response, true);
return $balance['balance']['sms'];
}
I wanted to make an inline bot! and when i do this:
function sendResponse($url, $data){
$ch = curl_init();
//curl_setopt($ch, CURLOPT_HTTPHEADER, array('Content-Type: multipart/form-data'));
curl_setopt($ch, CURLOPT_URL, $url);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch, CURLOPT_FOLLOWLOCATION, 1);
curl_setopt($ch, CURLOPT_POST, 1);
curl_setopt($ch, CURLOPT_POSTFIELDS, array('inline_query_id' => $data['inline_query_id'], 'results' => json_encode($data['results'])));
$output = curl_exec($ch);
return $output;
}
It wont work, the error (with or without the header): {"ok":false,"error_code":400,"description":"[Error]: Bad request: Field \"message_text\" must be of type String"}
but when I do it like this:
function sendResponse($url, $data){
$ch = curl_init();
//curl_setopt($ch, CURLOPT_HTTPHEADER, array('Content-Type: multipart/form-data'));
curl_setopt($ch, CURLOPT_URL, $url.'?inline_query_id='.rawurlencode($data['inline_query_id']).'&results='.rawurlencode(json_encode($data['results'])));
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch, CURLOPT_FOLLOWLOCATION, 1);
//curl_setopt($ch, CURLOPT_POST, 1);
//curl_setopt($ch, CURLOPT_POSTFIELDS, $q);
$output = curl_exec($ch);
return $output;
}
It works ! the problem is the second method request URI will be too large so I cannot use it!
Any way I can send these data is okay with me! thanks!
and the code for making $data is here:
$result = connectWebsite(SITE_SEARCH_URL, urlencode($update['inline_query']['query']));
$result = json_decode($result);
$output = array();
$output['inline_query_id'] = $update['inline_query']['id'];
$i = 0;
foreach($result as $post){
$data = array();
$data['type'] = 'article';
$data['id'] = strval($post->ID);
$data['title'] = '('.$post->atypes.') '.$post->title;
if(strlen($post->content) > 2100)
$tmp = substr($post->content, 0, 2096).'...';
$data['message_text'] = '<b>'.$post->title.'</b>'.ucwords($post->genre, ',').$tmp;
$data['parse_mode'] = 'HTML';
if(strlen($post->content) > 200)
$tmp = substr($post->content, 0, 196).'...';
//$data['description'] = ucwords($post->genre, ',').' | '.$tmp;
$output['results'][$i] = $data;
$i++;
if($i == MAX_RESULTS)
break;
}
sendResponse(API_URL.'answerInlineQuery', $output);
It might help someone so I'll answer it myself.
the problem was the UTF-8 encoding
I replaced substr with mb_substr
besides at the first line I'v added this: mb_internal_encoding("UTF-8")
and ... the problem was solved. now I can send my inline query results (or any other command) without the URL length problem
Thanks everyone for your help