$cOntent= 'live';
$email = '[email protected]';
$myHttp = new MyHttp();
$data = array(
'tenantid' => UserLogicModel::getTenantId(),//tenant id
'suject' => $subject,
'text' => base64_encode($content),
'tomail' => $email,
'attachmentPath' => $attachmentPath, //"attachmentPath":"/usr/local/files/job offer notice.doc",
'attachmentName' => $attachmentName, //"attachmentName":"Entry offer notice.doc"
);
$json_data = json_encode($data);
$params = "params=".$json_data;
$res = $myHttp->send(Dict::$STATIC_SEND_MAIL_URL, $params, "POST", "");
class MyHttp {
//Send network request
public function send($url,$data,$method,$token){
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, $url);
curl_setopt($ch, CURLOPT_CUSTOMREQUEST, $method);
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, FALSE);
curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, FALSE);
curl_setopt($ch, CURLOPT_USERAGENT, 'Mozilla/5.0 (compatible; MSIE 5.01; Windows NT 5.0)');
curl_setopt($ch, CURLOPT_FOLLOWLOCATION, 1);
curl_setopt($ch, CURLOPT_AUTOREFERER, 1);
curl_setopt($ch, CURLOPT_POSTFIELDS, $data);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
//$header = array(
// 'u:1234567777',
// 't:1234568888',
//);
curl_setopt($ch, CURLOPT_HTTPHEADER, array('token:$token'));
$tmpInfo = curl_exec($ch);
if (curl_errno($ch)) {
return curl_error($ch);
}
$stat=curl_getinfo($ch,CURLINFO_HTTP_CODE); //I know the HTTPSTAT code~
curl_close($ch);
switch ($stat) {
case '200':
if(empty($tmpInfo))
$tmpInfo='{"stat":"ok"}';
break;
default:
#code...
break;
}
if(empty($tmpInfo))
$tmpInfo="";
//Record the communication data with the api interface to the log
\Think\Log::write("http $method req[$stat]:res($tmpInfo)",'ALERT');
return $tmpInfo;
}
The above is the curl code for requesting the java interface. No matter how I ask, I add specified charset=UTF-8, java side
$head = array("Content-Type: application/json;charset=UTF-8"); //Solve the garbled problem of Java interface and directly throw json data
curl_setopt($ch, CURLOPT_HTTPHEADER,$head);
After adding this code, the parameters will not be accepted immediately.
Reply content:
$cOntent= 'live';
$email = '[email protected]';
$myHttp = new MyHttp();
$data = array(
'tenantid' => UserLogicModel::getTenantId(),//tenant id
'suject' => $subject,
'text' => base64_encode($content),
'tomail' => $email,
'attachmentPath' => $attachmentPath, //"attachmentPath":"/usr/local/files/job offer notice.doc",
'attachmentName' => $attachmentName, //"attachmentName":"Entry offer notice.doc"
);
$json_data = json_encode($data);
$params = "params=".$json_data;
$res = $myHttp->send(Dict::$STATIC_SEND_MAIL_URL, $params, "POST", "");
class MyHttp {
//Send network request
public function send($url,$data,$method,$token){
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, $url);
curl_setopt($ch, CURLOPT_CUSTOMREQUEST, $method);
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, FALSE);
curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, FALSE);
curl_setopt($ch, CURLOPT_USERAGENT, 'Mozilla/5.0 (compatible; MSIE 5.01; Windows NT 5.0)');
curl_setopt($ch, CURLOPT_FOLLOWLOCATION, 1);
curl_setopt($ch, CURLOPT_AUTOREFERER, 1);
curl_setopt($ch, CURLOPT_POSTFIELDS, $data);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
//$header = array(
// 'u:1234567777',
// 't:1234568888',
//);
curl_setopt($ch, CURLOPT_HTTPHEADER, array('token:$token'));
$tmpInfo = curl_exec($ch);
if (curl_errno($ch)) {
return curl_error($ch);
}
$stat=curl_getinfo($ch,CURLINFO_HTTP_CODE); //I know the HTTPSTAT code~
curl_close($ch);
switch ($stat) {
case '200':
if(empty($tmpInfo))
$tmpInfo='{"stat":"ok"}';break;
default:
#code...
break;
}
if(empty($tmpInfo))
$tmpInfo="";
//Record the communication data with the api interface to the log
\Think\Log::write("http $method req[$stat]:res($tmpInfo)",'ALERT');
return $tmpInfo;
}
The above is the curl code for requesting the java interface. No matter how I ask, I add specified charset=UTF-8, java side
$head = array("Content-Type: application/json;charset=UTF-8"); //Solve the garbled problem of Java interface and directly throw json data
curl_setopt($ch, CURLOPT_HTTPHEADER,$head);
After adding this code, the parameters will not be accepted immediately.
In fact, it should be possible. I don’t know if your java interface stipulates that it must be in json format. If so, then modify this sentence:
$params = "params=".$json_data; //This is a string because you added params=this in front, so you can try sending $json_data directly