微信接口推送圖文消息,微信接口推送圖文消息如
微信接口推送圖文消息,微信接口推送圖文消息如何實(shí)現(xiàn)?以下是小編整理的微信接口推送圖文消息如何實(shí)現(xiàn)的內(nèi)容,供有需要的網(wǎng)友們學(xué)習(xí)和參考。謝謝閱讀。
我們定義圖文消息的回復(fù)代碼實(shí)現(xiàn)如下:
private function transmitNews($object, $newsArray)
{
if(!is_array($newsArray)){
return;
}
$itemTpl = "
";
$item_str = "";
foreach ($newsArray as $item){
$item_str .= sprintf($itemTpl, $item['Title'], $item['Description'], $item['PicUrl'], $item['Url']);
}
$xmlTpl = "";
$result = sprintf($xmlTpl, $object->FromUserName, $object->ToUserName, time(), count($newsArray));
return $result;
}
上述代碼中,先將各item連接形成item_str,再將item_str賦值到xml模板中,組裝一個(gè)圖文消息。組裝時(shí),將object中的發(fā)送、接收方互換位置,計(jì)算出圖文項(xiàng)的個(gè)數(shù)。
而在構(gòu)造圖文消息并使用圖文回復(fù)的代碼如下所示:
if (strstr($keyword, "單圖文")){
$content = array();
$content[] = array("Title"=>"單圖文標(biāo)題", "Description"=>"單圖文內(nèi)容", "PicUrl"=>"http://discuz.comli.com/weixin/weather/icon/cartoon.jpg", "Url" =>"http://m.cnblogs.com/?u=txw1958");
}else if (strstr($keyword, "圖文") || strstr($keyword, "多圖文")){
$content = array();
$content[] = array("Title"=>"多圖文1標(biāo)題", "Description"=>"", "PicUrl"=>"http://discuz.comli.com/weixin/weather/icon/cartoon.jpg", "Url" =>"http://m.cnblogs.com/?u=txw1958");
$content[] = array("Title"=>"多圖文2標(biāo)題", "Description"=>"", "PicUrl"=>"http://d.hiphotos.bdimg.com/wisegame/pic/item/f3529822720e0cf3ac9f1ada0846f21fbe09aaa3.jpg", "Url" =>"http://m.cnblogs.com/?u=txw1958");
$content[] = array("Title"=>"多圖文3標(biāo)題", "Description"=>"", "PicUrl"=>"http://g.hiphotos.bdimg.com/wisegame/pic/item/18cb0a46f21fbe090d338acc6a600c338644adfd.jpg", "Url" =>"http://m.cnblogs.com/?u=txw1958");
}
if(is_array($content)){
if (isset($content[0]['PicUrl'])){
$result = $this->transmitNews($object, $content);
}else if (isset($content['MusicUrl'])){
$result = $this->transmitMusic($object, $content);
}
}else{
$result = $this->transmitText($object, $content);
}
以上是小編整理的微信接口推送圖文消息,希望對(duì)您有幫助,如果您想了解更多微信素材,請(qǐng)多多關(guān)注Hi商學(xué)院!