php微信輸出亂碼的解決辦法:1、使用urlencode進行編碼;2、通過“urldecode(json_encode($message));”方式轉(zhuǎn)換編碼即可。

如何解決php 微信輸出亂碼?
PHP微信發(fā)送推送消息亂碼的解決方法

先用urlencode是因為中文在數(shù)組轉(zhuǎn)json時會被編碼為unicode,微信接口無法識別,所以得在json_encode前先來個編碼,等轉(zhuǎn)換后再用urldecode轉(zhuǎn)回來,這樣傳輸給接口的就是正常的中文了。
參考代碼:
$message = array(
'touser'=>$touser,
'msgtype'=>'text',
'text'=>array('content'=>urlencode($text))
);
$message = urldecode(json_encode($message));





