Home  >  Article  >  Backend Development  >  What should I do if the message returned by php WeChat is garbled?

What should I do if the message returned by php WeChat is garbled?

藏色散人
藏色散人Original
2021-11-30 11:06:412602browse

php The solution to the garbled message returned by WeChat: 1. Create a PHP sample file; 2. Encode it through the "urldecode(json_encode($message));" method.

What should I do if the message returned by php WeChat is garbled?

The operating environment of this article: windows7 system, PHP version 7.4, DELL G3 computer

php Why is the message returned by WeChat garbled? What to do?

Solution to garbled push messages sent by PHP WeChat

Use urlencode first because Chinese will be encoded when the array is converted to json Unicode cannot be recognized by the WeChat interface, so you need to encode it before json_encode, and then use urldecode to convert it back after conversion, so that what is transmitted to the interface is normal Chinese.

Reference code:


##

    $message = array(
      'touser'=>$touser,
      'msgtype'=>'text',
      'text'=>array('content'=>urlencode($text))
    );
    $message = urldecode(json_encode($message));

Recommended learning: "

PHP Video Tutorial"

The above is the detailed content of What should I do if the message returned by php WeChat is garbled?. For more information, please follow other related articles on the PHP Chinese website!

Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn