· 5 years ago · Feb 12, 2020, 08:44 AM
1<?php
2
3$access_id = "*****";
4$secret_key = "*****";
5$actual_amount = "0.01335296";
6$coin_type = "BTC";
7$coin_address = "1NDjU9dKJpcuPFopTCwm5sK3UZKFf79vrv";
8
9$params = array(
10 "access_id" => $access_id,
11 "actual_amount" => $actual_amount,
12 "coin_type" => $coin_type,
13 "coin_address" => $coin_address,
14 "tonce" => round(microtime(true) * 1000),
15 "transfer_method" => "onchain",
16);
17
18print(send_request("https://api.coinex.com/v1/balance/coin/withdraw", $params, get_sign($params, $secret_key)));
19
20function get_sign($params, $secret_key){
21 ksort($params);
22 $pre_sign_ls = [];
23 foreach ($params as $key => $val){
24 array_push($pre_sign_ls, "$key=$val");
25 }
26 array_push($pre_sign_ls, "secret_key=$secret_key");
27 $pre_sign_str = join("&", $pre_sign_ls);
28
29 return strtoupper(md5($pre_sign_str));
30}
31
32function send_request($url, $params, $sign){
33 $headers = [
34 'authorization:' . $sign,
35 'Content-type: application/json'
36 ];
37
38 $params = json_encode($params);
39
40 $ch = curl_init($url);
41 curl_setopt($ch, CURLOPT_POST, 1);
42 curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
43 curl_setopt($ch, CURLOPT_POSTFIELDS, $params);
44 curl_setopt($ch,CURLOPT_HTTPHEADER, $headers);
45 $output = curl_exec($ch);
46 return $output;
47}