300字范文,内容丰富有趣,生活中的好帮手!
300字范文 > php 微信上传多图片不显示不出来 php - 微信群发图文 content中图片显示不出

php 微信上传多图片不显示不出来 php - 微信群发图文 content中图片显示不出

时间:2019-11-14 13:26:30

相关推荐

php 微信上传多图片不显示不出来 php - 微信群发图文 content中图片显示不出

ringa_lee-04-10 17:57:191楼

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./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./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;

}

本内容不代表本网观点和政治立场,如有侵犯你的权益请联系我们处理。
网友评论
网友评论仅供其表达个人看法,并不表明网站立场。