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

藏色散人
Release: 2023-03-14 08:30:01
Original
2597 people have browsed it

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));
Copy after login

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!

Related labels:
source:php.cn
Statement of this Website
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
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template