私域电商软件及相关增值服务提供商    

免费试用

微信接口推送图文消息,微信接口推送图文消息如

2017-04-18|HiShop
导读:微信接口推送图文消息,微信接口推送图文消息如何实现?以下是小编整理的微信接口推送图文消息如何实现的内容,供有需要的网友们学习和参考。谢谢阅读。 我们定义图文消息的回...

  微信接口推送图文消息,微信接口推送图文消息如何实现?以下是小编整理的微信接口推送图文消息如何实现的内容,供有需要的网友们学习和参考。谢谢阅读。

微信接口推送图文消息,微信接口推送图文消息如

  我们定义图文消息的回复代码实现如下:

  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模板中,组装一个图文消息。组装时,将object中的发送、接收方互换位置,计算出图文项的个数。

  而在构造图文消息并使用图文回复的代码如下所示:

  if (strstr($keyword, "单图文")){

  $content = array();

  $content[] = array("Title"=>"单图文标题", "Description"=>"单图文内容", "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标题", "Description"=>"", "PicUrl"=>"http://discuz.comli.com/weixin/weather/icon/cartoon.jpg", "Url" =>"http://m.cnblogs.com/?u=txw1958");

  $content[] = array("Title"=>"多图文2标题", "Description"=>"", "PicUrl"=>"http://d.hiphotos.bdimg.com/wisegame/pic/item/f3529822720e0cf3ac9f1ada0846f21fbe09aaa3.jpg", "Url" =>"http://m.cnblogs.com/?u=txw1958");

  $content[] = array("Title"=>"多图文3标题", "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);

  }

  以上是小编整理的微信接口推送图文消息,希望对您有帮助,如果您想了解更多微信素材,请多多关注Hi商学院!

TAGS:
推荐阅读