WeChat group text and images, which are not displayed in the content

Source: Internet
Author: User
{Code ...}} {code ...} double quotation marks-& amp; gt; escape with single quotation marks. the data packet sent is as follows: the text in the sent content can show that the image cannot be displayed. I hope you can give me some ideas, if you have any questions, thank you {

"Filter": {"is_to_all": false, "group_id": 100}, "msgtype": "mpnews", "mpnews": {"media_id": "hSRQJiYXXfH7lsqUenEjxX3mxYkDJVOPr2r1Amn32eGe-GvCtj-5PG2h5vi8U7uW "}, "article": {"thumb_media_id": "vPkv7wRG38KhZvpKLNHMEANEG_I6pWiUtY7-ljHFGF0MSpD90hBN4TilIsEPMvWK", "title": "test", "author": "test", "content ": "Test 

}

$data = urldecode(json_encode($data));

Double quotation marks-> single quotation marks escape. the data packet sent is the same as above. after being sent, the text in the content cannot display the image. I hope you can give me some ideas and have any questions. thank you.

Reply content:

{

"Filter": {"is_to_all": false, "group_id": 100}, "msgtype": "mpnews", "mpnews": {"media_id": "hSRQJiYXXfH7lsqUenEjxX3mxYkDJVOPr2r1Amn32eGe-GvCtj-5PG2h5vi8U7uW "}, "article": {"thumb_media_id": "vPkv7wRG38KhZvpKLNHMEANEG_I6pWiUtY7-ljHFGF0MSpD90hBN4TilIsEPMvWK", "title": "test", "author": "test", "content ": "Test 

}

$data = urldecode(json_encode($data));

Double quotation marks-> single quotation marks escape. the data packet sent is the same as above. after being sent, the text in the content cannot display the image. I hope you can give me some ideas and have any questions. thank you.

Htmlspecialchars_decode ($ data ['article'] ['content'], ENT_QUOTES );

Images in the content must also be uploaded to the service before they can be displayed. you can use regular expressions to match the images and upload them to the desired address.
For details, refer to the following method.

Public function upload_weixin_img ($ content, $ res_id) {$ img = array (); preg_match_all ('\'] *?> \ '', $ Content, $ img); // directly return the original content if (! Isset ($ img [0]) |! $ Img [0]) {return $ content;} // if an image exists, extract the image content and upload it $ pattern = ''; foreach ($ img [0] as $ k => $ v) {$ html = $ v; preg_match ($ pattern, $ html, $ matches ); if ($ matches [1]) {// Create a ing in the joined table $ filter = array ('res _ id' => $ res_id, 'Old _ src' => $ matches [1]); $ info = _ model ('material _ img_relation ')-> read ($ filter); if ($ info) {$ content = str_replace ($ matches [1], $ info ['new _ src'], $ content);} else {$ matche_str = $ matches [1]; // replace the image path $ str = str_replace (SITE_URL. '/static/upload', '', $ matches [1]); $ str = UPLOAD_PATH. $ str; // upload an image $ url =' https://api.weixin.qq.com/cgi-bin/media/uploadimg?access_token= '. $ This-> access_token; $ data = array ('media' => new CURLFile ($ str),); $ result = an_curl ($ url, $ data, true ); // replace the file path and change the original content if (isset ($ result ['errcode']) & $ result ['errcode'] = 40001) {$ this-> check_app_params (); $ url =' https://api.weixin.qq.com/cgi-bin/media/uploadimg?access_token= '. $ This-> access_token; $ data = array ('media' => new CURLFile ($ str),); $ result = an_curl ($ url, $ data, true );} $ new_src = $ result ['URL']; $ data = array ('res _ id' => $ res_id, 'old _ src' => $ matche_str, 'New _ src' => $ new_src); _ model ('material _ img_relation')-> create ($ data); $ content = str_replace ($ matches [1], $ new_src, $ content) ;}} return $ content ;}

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.