您好,欢迎来到三六零分类信息网!老站,搜索引擎当天收录,欢迎发信息

微信群发图文,content中图片显示不出

2025/7/19 8:40:35发布16次查看
{
filter: { is_to_all: false, group_id: 100}, msgtype: mpnews, mpnews: { media_id: hsrqjiyxxfh7lsquenejxx3mxykdjvopr2r1amn32ege-gvctj-5pg2h5vi8u7uw}, article: { thumb_media_id: vpkv7wrg38khzvpklnhmeaneg_i6pwiuty7-ljhfgf0mspd90hbn4tilisepmvwk, title: 测试, author: 测试, content: 测试<img src=\http://www.baidu.com/ceshi/images/boaaa7z7ibob76sw7qp7k3s73qip4w.jpg\ width=\100%\ alt=\ejqbuvgjyv72epyjvs8fsiiql7pcogm3dtqyuay9jnu\/>, digest: digest, content_source_url: }

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

做了双引号->单引号的转义,发送的data数据包如上,发送后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: 测试, author: 测试, content: 测试<img src=\http://www.baidu.com/ceshi/images/boaaa7z7ibob76sw7qp7k3s73qip4w.jpg\ width=\100%\ alt=\ejqbuvgjyv72epyjvs8fsiiql7pcogm3dtqyuay9jnu\/>, digest: digest, content_source_url: }

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

做了双引号->单引号的转义,发送的data数据包如上,发送后content中的文字能显示图片不能显示,希望大家能给我一点思路,哪里还有问题,谢谢
htmlspecialchars_decode($data['article'] ['content'], ent_quotes);
content里面的图片也需要上传到微信服务才能显示出来,可以用正则匹配出来图片,上传一下换取微信的地址。
具体的可以参照下边这个方法
public function upload_weixin_img($content, $res_id) { $img = array(); preg_match_all('\']*?>\'', $content, $img); // 如果没有图片信息 直接返回原内容 if (!isset($img[0]) || !$img[0]) { return $content; } // 如果存在图片,取出图片内容,进行上传 $pattern =''; foreach ($img[0] as $k=>$v) { $html = $v; preg_match($pattern, $html, $matches); if ($matches[1]) { //在关联表创建对应关系 $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]; // 进行图片路径替换 $str = str_replace(site_url.'/static/upload', '', $matches[1]); $str = upload_path.$str; // 上传图片 $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); // 替换文件路径,改变原内容 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; }
该用户其它信息

VIP推荐

免费发布信息,免费发布B2B信息网站平台 - 三六零分类信息网 沪ICP备09012988号-2
企业名录 Product