테스트 사이트 - 개발 중인 베타 버전입니다

네이버 api 카페 글쓰기 에서 한글이 깨져서 올라갑니다. 해결 방법좀 알려주세요. 채택완료

얼뚱 8년 전 조회 4,358

네이버 api 카페 글쓰기 에서 한글이 깨져서 올라갑니다. 해결 방법좀 알려주세요.

 

로근인 후 카페에 직접 쓰는 페이지 소스 올려봅니다.

 

$client_id = G5_NAVER_OAUTH_CLIENT_ID; // 오픈 API 키 발급받은 client ID $client_secret = G5_NAVER_OAUTH_SECRET_KEY; // 오픈 API 키 발급받은 client secrete $authorize_url = 'https://nid.naver.com/oauth2.0/authorize">https://nid.naver.com/oauth2.0/authorize'; $access_token_url = 'https://nid.naver.com/oauth2.0/token">https://nid.naver.com/oauth2.0/token';

// 오픈 API 키 등록 시 입력한 callback 주소, tutorial에서는 "도메인주소/callback.php". $callback_uri = 'http://www.formebnm.co.kr/plugin/naver/callback.php?service=naverc">http://www.formebnm.co.kr/plugin/naver/callback.php?service=naverc'; $index_uri = 'http://www.formebnm.co.kr/plugin/naver/blog_write.php">http://www.formebnm.co.kr/plugin/naver/blog_write.php'; // tutorial에서는 "도메인주소/index.php"

$cafe_id = "xxxxxxxxxx"; $board_id = "x";

function generate_state(){  $mt = microtime();  $rand = mt_rand();  return md5($mt . $rand); }

$bo_table = get_session('nb_bo_table'); $wr_id = get_session('nb_wr_id');

if($_SESSION['access_token']) {  header("Content-Type: text/html; charset=UTF-8");  $bo_table = get_session('nb_bo_table');  $wr_id = get_session('nb_wr_id');    $sql = "select * from ".$g5['write_prefix'].$bo_table." where wr_id = ".$wr_id."";  $row = sql_fetch($sql);

 $subject = $row['wr_subject'];  $content = $row['wr_content'];    $token = $_SESSION['access_token']; // 네이버 로그인 API호출로 받은 접근 토큰값    $header = "Bearer ".$token; // Bearer 다음에 공백 추가  $clubid = $cafe_id;// 카페의 고유 ID값  $menuid = $board_id; // 카페 게시판 id    $url = "https://openapi.naver.com/v1/cafe/".$clubid."/menu/".$menuid."/articles";       $postvars = array(   'subject' => urlencode($subject),   'content' => urlencode($content)  );

 $postvars_string = "";

 foreach($postvars as $key => $value) {   $postvars_string .= $key. "=". $value. "&";  }  $postvars_string = rtrim($postvars_string, '&');

 $is_post = true;    $ch = curl_init();  curl_setopt($ch, CURLOPT_URL, $url);  curl_setopt($ch, CURLOPT_POST, count($postvars));  curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);  curl_setopt($ch,CURLOPT_POSTFIELDS, $postvars_string);  $headers[] = "Authorization: ".$header;  curl_setopt($ch, CURLOPT_HTTPHEADER, $headers);  $response = curl_exec ($ch);  $status_code = curl_getinfo($ch, CURLINFO_HTTP_CODE);  curl_close ($ch);    if($status_code == 200) {   alert_close('정상적으로 게시 되었습니다.');  } else {   echo "Error 내용:".$response;   exit;  } } ?>

 

 

댓글을 작성하려면 로그인이 필요합니다.

답변 3개

채택된 답변
+20 포인트
t
8년 전

</p><p><span style="color: rgb(72, 72, 72); font-family: 돋움, Dotum, sans-serif; font-size: 14.004px;"> $postvars = array(</span><br style="color: rgb(72, 72, 72); font-family: 돋움, Dotum, sans-serif; font-size: 14.004px;"><span style="color: rgb(72, 72, 72); font-family: 돋움, Dotum, sans-serif; font-size: 14.004px;">  'subject' => </span><span style="color: rgb(72, 72, 72); font-family: 돋움, Dotum, sans-serif; font-size: 14.004px;">urlencode(</span><span style="color: rgb(72, 72, 72); font-family: 돋움, Dotum, sans-serif; font-size: 14.004px;">urlencode($subject)),</span></p><p><span style="color: rgb(72, 72, 72); font-family: 돋움, Dotum, sans-serif; font-size: 14.004px;">  'content' => </span><span style="color: rgb(72, 72, 72); font-family: 돋움, Dotum, sans-serif; font-size: 14.004px;">urlencode(</span><span style="color: rgb(72, 72, 72); font-family: 돋움, Dotum, sans-serif; font-size: 14.004px;">urlencode($content))</span></p><p><span style="color: rgb(72, 72, 72); font-family: 돋움, Dotum, sans-serif; font-size: 14.004px;"> );</span> </p><p>

로 하시면됩니다.

 

저도 해결하고 나서 어이가 없네요 ㅎㅎㅎ.......

로그인 후 평가할 수 있습니다

댓글을 작성하려면 로그인이 필요합니다.

8년 전

전체 다시 저장 해 봐도 변동이 없네요.. ㅠㅠ 답변 감사합니다. 

로그인 후 평가할 수 있습니다

댓글을 작성하려면 로그인이 필요합니다.

8년 전

해당 php 파일을 전문에디터로 열어서 인코딩을 utf-8 로 다시 저장하여 사용해 보세요. 

로그인 후 평가할 수 있습니다

댓글을 작성하려면 로그인이 필요합니다.

답변을 작성하려면 로그인이 필요합니다.

로그인