function http_post_raw ($url, $data = null)
{$ch = curl_init ();
curl_setopt ($ch, CURLOPT_URL, $url);
curl_setopt ($ch, CURLOPT_SSL_VERIFYPEER, false);
curl_setopt ($ch, CURLOPT_SSL_VERIFYHOST, false);
curl_setopt ($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt ($ch, CURLOPT_POST, 1);
curl_setopt ($ch, CURLOPT_POSTFIELDS, $data);
$result = curl_exec ($ch);
if ($result === false) {echo 'Curl error:' . curl_error ($ch) . PHP_EOL;
}
return $result;
}
/** Get 或 Post 请求
* @param $url
* @param null $data 为 null 时,为 post 方法
*
* @return mixed
*/
function http ($url, $data = null)
{$ch = curl_init ();
curl_setopt ($ch, CURLOPT_HTTPHEADER, array ('Content-Type: application/JSON'));
curl_setopt ($ch, CURLOPT_URL, $url);
curl_setopt ($ch, CURLOPT_SSL_VERIFYPEER, false);
curl_setopt ($ch, CURLOPT_SSL_VERIFYHOST, false);
if (!empty ($data)) {curl_setopt ($ch, CURLOPT_POST, 1);
curl_setopt ($ch, CURLOPT_POSTFIELDS, $data);
}
curl_setopt ($ch, CURLOPT_RETURNTRANSFER, 1);
$output = curl_exec ($ch);
curl_close ($ch);
return $output;
}
Artisan::command ('test', function () {
// $sign = "MEUCIQDuuxpZFFl7 xmHu2 k9 eXBM3 C2 r+3 hbhzwxfPeBZMW5 MbwIgc6 m6 hTEFAR2 HEfIYbp9 vqRYNGupNm+a2 AMsxtdxpJ4 a=";
$data2 = [/* "b_height" => [
"126365",
"126373"
],
"b_time" => [
"2019-05-10 13:15:40",
"2019-05-10 13:15:50"
],*/
"chain_id" => "ch_tencent_testchain",
"mch_pubkey" => "A4 SKuIl4 goInX41 TdPH7 W4+8 uvN99 aZ5 NBP2 zMnlN/fC",
"mch_id" => "gbcT7 TQ9 zmPUGDnSAm",
"timestamp" => strval (time ()),
"t_hash"=>"e6 afa839 d5877 e140 b43501408 d99 ed0 d86 e0 d5 de118 c93 a91 e2 ed2 e396951 de",
"page_limit" => 10,
"page_no" => 1,
"sign_type" => "ECDSA",
"version" => "2.0"
];
$sign = "MEUCIQDuuxpZFFl7 xmHu2 k9 eXBM3 C2 r+3 hbhzwxfPeBZMW5 MbwIgc6 m6 hTEFAR2 HEfIYbp9 vqRYNGupNm+a2 AMsxtdxpJ4 a=";
ksort ($data2);
$param = "";
foreach ($data2 as $key=>$item){if (is_array ($item)){$param .= $key."=".json_encode ($item, JSON_UNESCAPED_SLASHES)."&";
}else{$param .= $key."=".$item."&";}
}
$param = trim ($param,"&");
// dd ($param);
//$param = urlencode ($param);
var_dump ($param);
$JSON_data = JSON_encode (["text"=>$param]);
$sign_res = http ("http://192.168.1.252:8080/calc/sign",$JSON_data);
//dd ($sign_res);
$sign_res = JSON_decode ($sign_res,true);
//dd ($sign_res);
$data2 ["mch_sign"] = $sign_res ["result"]["sign"];
$data = JSON_encode ($data2, JSON_UNESCAPED_SLASHES);
var_dump ($data);
// sleep (2);
//exit ();
$res = http_post_raw ("http://123.207.249.116:15903/Iss_Query", $data);
var_dump ($res);
});