这是我将文本消息发送到android GCM的方式,首先我用PHP编码中文字符
$message = array("msg" => urlencode($msg));
$url = 'https://android.googleapis.com/gcm/send';
$fields = array(
'registration_ids' => $registrationIDs,
'data' => array( "message" => $message ),
);
$headers = array(
'Authorization: key=' . $api_key,
'Content-Type: application/json;');
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, $url);
curl_setopt( $ch, CURLOPT_POST, true );
curl_setopt( $ch, CURLOPT_HTTPHEADER, $headers);
curl_setopt( $ch, CURLOPT_RETURNTRANSFER, true );
curl_setopt( $ch, CURLOPT_POSTFIELDS, json_encode( $fields ) );
$result = curl_exec($ch);
curl_close($ch);
当消息发送到android端时,symobal,数字和英文都保持正常,但是,中文字符不是,如何解决?感谢
msg = URLDecoder.decode(intent.getStringExtra("message"), "UTF-8");
答案 0 :(得分:1)
尝试设置将php标头字符集设置为UTF-8并查看它是否有效。
答案 1 :(得分:1)
我发现问题不是由php或android引起的
实际上在我的输入表格中省略了
<meta type="utf-8">
那是粗心的错误
答案 2 :(得分:1)
添加到html头:
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />