<?php include './../XYWeChat.php'; $touser = "******"; $templateId = "BuKHPrOTOugbRch34tTskaKEoPdAJyN8r-4N19lGtJE"; $data = array('title' => array('value' => '测试消息。', 'color' => '#0A0A0A'), 'time' => array('value' => time(), 'color' => '#CCCCCC')); $url = "http://www.xyser.com/XYWeChat/demo/oauth.php"; //发送模板消息 $arr = \XYWeChat\TemplateMessage::sendTemplateMessage($data, $touser, $templateId, $url); print_r($arr);
/** * 向用户推送模板消息 * @param $data = array( * 'first'=>array('value'=>'您好,您已成功消费。', 'color'=>'#0A0A0A') * 'keynote1'=>array('value'=>'巧克力', 'color'=>'#CCCCCC') * 'keynote2'=>array('value'=>'39.8元', 'color'=>'#CCCCCC') * 'keynote3'=>array('value'=>'2014年9月16日', 'color'=>'#CCCCCC') * 'keynote3'=>array('value'=>'欢迎再次购买。', 'color'=>'#173177') * ); * @param $touser 接收方的OpenId。 * @param $templateId 模板Id。在公众平台线上模板库中选用模板获得ID * @param $url URL * @param string $topcolor 顶部颜色, 可以为空。默认是红色 * @return array("errcode"=>0, "errmsg"=>"ok", "msgid"=>200228332} "errcode"是0则表示没有出错 * * 注意:推送后用户到底是否成功接受,微信会向公众号推送一个消息。 */ public function sendTempMessage($data, $touser, $templateId, $url, $topcolor = '#FF0000') { vendor('XYWeChat.XYWeChat'); $ret = \XYWeChat\TemplateMessage::sendTemplateMessage($data, $touser, $templateId, $url, $topcolor = '#FF0000'); return $ret; }
/** * @descrpition 文本 * @param $request * @return array */ public static function text(&$request) { if ($request['content'] == '模板消息') { $touser = "******"; $templateId = "BuKHPrOTOugbRch34tTskaKEoPdAJyN8r-4N19lGtJE"; $data = array('title' => array('value' => '测试消息。', 'color' => '#0A0A0A'), 'time' => array('value' => time(), 'color' => '#CCCCCC')); $url = "http://www.xyser.com/XYWeChat/demo/oauth.php"; //发送模板消息 $arr = \XYWeChat\TemplateMessage::sendTemplateMessage($data, $touser, $templateId, $url); //exit(); } $content = '收到文本消息:' . $request['content']; return ResponsePassive::text($request['fromusername'], $request['tousername'], $content); }