您好,欢迎访问一九零五行业门户网

api - PHP调用java发邮件的服务,收件箱发现部分乱码,麻烦大家给我看看,谢谢

$content = '活生生的'; $email = 'test_email@gmail.com'; $myhttp = new myhttp(); $data = array( 'tenantid' => userlogicmodel::gettenantid(),//租户id 'suject' => $subject, 'text' => base64_encode($content), 'tomail' => $email, 'attachmentpath' => $attachmentpath, //attachmentpath:/usr/local/files/入职offer通知.doc, 'attachmentname' => $attachmentname, //attachmentname:入职offer通知.doc ); $json_data = json_encode($data); $params = params=.$json_data; $res = $myhttp->send(dict::$static_send_mail_url, $params, post, );

class myhttp { //发送网络请求 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); //我知道httpstat码哦~ curl_close($ch); switch ($stat) { case '200': if(empty($tmpinfo)) $tmpinfo='{stat:ok}'; break; default: # code... break; } if(empty($tmpinfo)) $tmpinfo=; //记录与api接口之间的通信数据到日志 \think\log::write(http $method req[$stat]:res($tmpinfo),'alert'); return $tmpinfo; }

上面是请求java接口的curl代码,无论我怎么求里面加指定charset=utf-8,java端
$head = array(content-type: application/json;charset=utf-8); //解决java接口乱码问题,直接抛送json数据 curl_setopt($ch, curlopt_httpheader,$head); 加上这句代码,马上就接受不到参数.

回复内容: $content = '活生生的'; $email = 'test_email@gmail.com'; $myhttp = new myhttp(); $data = array( 'tenantid' => userlogicmodel::gettenantid(),//租户id 'suject' => $subject, 'text' => base64_encode($content), 'tomail' => $email, 'attachmentpath' => $attachmentpath, //attachmentpath:/usr/local/files/入职offer通知.doc, 'attachmentname' => $attachmentname, //attachmentname:入职offer通知.doc ); $json_data = json_encode($data); $params = params=.$json_data; $res = $myhttp->send(dict::$static_send_mail_url, $params, post, );

class myhttp { //发送网络请求 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); //我知道httpstat码哦~ curl_close($ch); switch ($stat) { case '200': if(empty($tmpinfo)) $tmpinfo='{stat:ok}'; break; default: # code... break; } if(empty($tmpinfo)) $tmpinfo=; //记录与api接口之间的通信数据到日志 \think\log::write(http $method req[$stat]:res($tmpinfo),'alert'); return $tmpinfo; }

上面是请求java接口的curl代码,无论我怎么求里面加指定charset=utf-8,java端
$head = array(content-type: application/json;charset=utf-8); //解决java接口乱码问题,直接抛送json数据 curl_setopt($ch, curlopt_httpheader,$head); 加上这句代码,马上就接受不到参数.

其实应该是可以得,不知道你的java接口是不是规定了必须是json格式的,如果是,那么你这一句修改下:
$params = params=.$json_data; //你这是一个string,因为你前面加了params=这个,所以你直接把$json_data传送过去试试
其它类似信息

推荐信息