You cannot select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
44 lines
1.2 KiB
PHP
44 lines
1.2 KiB
PHP
<?php
|
|
|
|
namespace Workerman\Lib;
|
|
/**
|
|
* Created by PhpStorm.
|
|
* User: Administrator
|
|
* Date: 2019/6/13
|
|
* Time: 17:14
|
|
* ***************
|
|
* 备注
|
|
* ***************
|
|
* Come on
|
|
*/
|
|
class Tool
|
|
{
|
|
|
|
/*
|
|
* http CURL POST
|
|
*
|
|
*/
|
|
public static function post($url, $data, $type = 'json')
|
|
{
|
|
$curl = curl_init();
|
|
curl_setopt($curl, CURLOPT_URL, $url);
|
|
curl_setopt($curl, CURLOPT_RETURNTRANSFER, true);
|
|
curl_setopt($curl, CURLOPT_POST, true);
|
|
if ($type === 'data') {
|
|
curl_setopt($curl, CURLOPT_SSL_VERIFYPEER, false);
|
|
curl_setopt($curl, CURLOPT_POSTFIELDS, $data);
|
|
curl_setopt($curl, CURLOPT_FOLLOWLOCATION, true);
|
|
}
|
|
if ($type === 'json') {
|
|
$data_string = json_encode($data, JSON_UNESCAPED_UNICODE);
|
|
curl_setopt($curl, CURLOPT_HTTPHEADER, [
|
|
'Content-Type: application/json; charset=utf-8',
|
|
'Content-Length: ' . strlen($data_string)
|
|
]);
|
|
curl_setopt($curl, CURLOPT_POSTFIELDS, $data_string);
|
|
}
|
|
$r = curl_exec($curl);
|
|
curl_close($curl);
|
|
return $r;
|
|
}
|
|
} |