实现
//时间戳13位毫秒
private function getMillisecond() {
list($s1,$s2) = explode(' ',microtime());
return (float)sprintf('%.0f',(floatval($s1) + floatval($s2)) * 1000);
}
// 组装参数
private function gysscPost1($url,$data)
{
// $data['timestamp'] = '1694402111964';
$data['timestamp'] = $this->getMillisecond();
$data['v'] = '1.0';
$data['appKey'] = $this->appKey;
$data['method'] = $data['method'];
$data['token'] = $this->token;
$data['format'] = 'json';
$data['paramType'] = 'json';
$contractBytes = $data['contractBytes']; // 上传pdf的文件地址
unset($data['contractBytes']);
ksort($data);
$data['sign'] = $sign_str;
$res = $this->curl1('http://39.101.164.226:8073/openapi', $data,$contractBytes);
$result = $this->decrypt($res); //解密
return $result;
}
public function curl1($url, $post,$contractBytes,$is_json = false,$aHeader='')
{
$ch = curl_init();
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_POST, true);
curl_setopt($ch, CURLOPT_HEADER, false);
curl_setopt($ch, CURLOPT_SAFE_UPLOAD, true);
curl_setopt($ch, CURLOPT_IPRESOLVE, CURL_IPRESOLVE_V4);
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, false);
curl_setopt($ch, CURLOPT_URL, $url);
// 重点是下面 传参
$post['contractBytes']= curl_file_create($contractBytes, mime_content_type($contractBytes), time() . 'pdf');
curl_setopt($ch, CURLOPT_POSTFIELDS, $post);
curl_setopt($ch, CURLOPT_HTTPHEADER, array(
'Content-Type: multipart/form-data',
$aHeader
));
// 返回结果
$result = curl_exec($ch);
if($result != false)
{
curl_close($ch);
return $result;
} else {
$error = curl_errno($ch);
curl_close($ch);
return "curl出错,错误码:$error";
}
}