LaneWeChat

PHP微信开发框架,高效开发微信公众号应用。简洁而又轻量

GitHub下载 查看手册

被动给用户发送消息

Visits: 25024 Date: 2014-08-20 17:26:53 Power By 李轩Lane

    

 1、类简介:用户输入文本、图片、语音、音乐、视频等消息,以及关注、取消关注,上报地理位置等事件后,服务器被动给出应答。


        2、使用命名空间:use LaneWeChat\Core\ResponsePassive;


        3、参数:  $fromusername = "谁发给你的?(用户的openId)"  在变量$request['fromusername']中


                 $tousername = "你的公众号Id";                 在变量$require['tousername']中


                 $mediaId = "通过上传多媒体文件,得到的id。";


        4、发送文本

                ResponsePassive::text($fromusername, $tousername, '文本消息内容');


        5、发送图片

                ResponsePassive::image($fromusername, $tousername, $mediaId);


        6、发送语音

                ResponsePassive::voice($fromusername, $tousername, $mediaId);


        7、发送视频

                ResponsePassive::video($fromusername, $tousername, $mediaId, '视频标题', '视频描述');


        8、发送音乐

                ResponsePassive::music($fromusername, $tousername, '音乐标题', '音乐描述', '音乐链接', '高质量音乐链接,WIFI环境优先使用该链接播放音乐', '缩略图的媒体id,通过上传多媒体文件,得到的id');


        9、发送图文

            1)创建图文消息内容

                $tuwenList = array();

                $tuwenList[] = array('title'=>'标题1', 'description'=>'描述1', 'pic_url'=>'图片URL1', 'url'=>'点击跳转URL1');

                $tuwenList[] = array('title'=>'标题2', 'description'=>'描述2', 'pic_url'=>'图片URL2', 'url'=>'点击跳转URL2');

            2)构建图文消息格式

                $itemList = array();

                foreach($tuwenList as $tuwen){

                    $itemList[] = ResponsePassive::newsItem($tuwen['title'], $tuwen['description'], $tuwen['pic_url'], $tuwen['url']);

                }

            3)发送图文消息

                ResponsePassive::news($fromusername, $tousername, $itemList);


Reply: bensissy On 2015-04-14 18:00:46

为什么$request['fromusername'] 获取不了什么东西呢

回复

Reply: luoning On 2015-04-15 17:59:26

此处的创建图文消息内容与构建图文消息格式,均使用 $tuwenList = array(); 这个......

回复

Reply: Lane On 2015-04-17 16:51:43

$request['fromusername'] 是用户的openId,如果没有值,证明交互失败。你可以先通过http://mp.weixin.qq.com/debug/ 调试,调试中看到formUserName有值,则$request['fromusername'] 肯定可以获取到值

回复

Reply: wordyhuang On 2015-08-04 15:14:40

图文发送里有个bug,public static function newsItem($title, $description, $picUrl, $url) picUrl与url写反了。

回复

Reply: sywee On 2016-01-08 19:09:32

怎么解决呢?

回复

Reply: yoyo On 2016-02-23 15:52:53

请问,文件lanewechat 怎么调用呢? 比如我用sae 把文件上面上去了,有个文件夹lanewechat .但是我想在这个外面的文件夹调用,index.php 里面 调用,接受用户的你好,回复 hello. 该怎么写代码呢,找了很久都没找到相关信息,只有 include 和 什么命名空间。 导入下面怎么写呢,还有微信那面认证网址 是那里呢?

回复

Reply: shiren On 2016-05-14 11:38:54

我也是在学习,一头雾水 你会了吗 教教我被 QQ295928

回复

Add Comment
©2014~time() lanewechat.lanecn.com , All rights reserved. Power By LaneWeChat 微信PHP开发框架.  京ICP备14005030号-1