一、关注显示内容,


  微信服务号与订阅号的区别相信大家也清楚了,我女朋友开了一个童装店,无证店,所以申请不到服务号,只能玩玩订阅号,在此记录开发过程。

   原计划每天晚上在家把基本功能实现,再照飘画猫般写个传说中的微商城,不全不要紧,主要是看的嘛。选上传这章讲的内容


   


点击订阅后,就会提示一条信息,点击显示中下界面。




 封装的代码来源于:鱼消失了 ,感谢作者的无私奉献。我只是站在别人的身上开发。3ks

 

 首先得申请为开发模式:不懂请查看官方给的教程吧。申请成功内容为



 废话这么多,上码吧.


  访问的控制类

   

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 public function index(){     /* 加载微信SDK */     import('@.ORG.ThinkWechat');     $weixin = new ThinkWechat();          /* 获取请求信息 */     $data = $weixin->request();     /* 获取回复信息 */     // 这里的回复信息是通过判断请求内容自行定制的, 不在 SDK范围内,请自行完成     list($content, $type) = $this->reply($data);          // 接收到的信息入不同的库     $this->weichat_data ( $data );          /* 响应当前请求 */     $weixin->response($content, $type); }

   响应代码


1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 //这里只对文本消息进行处理 private function reply($data){     if('text' == $data['MsgType']){         $text=$data["Content"];         if(is_numeric($text) && array_key_exists($text, $this->menu_info)){//如果在指定的编码内,则调用相应的方法             $method=$this->get_method($text);             $rdata=$this->$method();                              list($content, $type) = $rdata;         }else{             $content=$this->get_show_msg();             $type="text";         }         Log::write("content -> ".print_r($content,true));         $reply = array($content, $type);     } elseif('event' == $data['MsgType'] && 'subscribe' == $data['Event']){         //订阅写入数据表         $reply=$this->hello();         //$reply = array('欢迎您关注桂林小魔方童装公众助手! 打开我们的网站:http://aidemofang.com 可以了解最新的款式和价格.', 'text');     else {         exit;     }     return $reply; }

   前面的代码以后再说,先看 $reply=$this->hello();这个方法


1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 //欢迎页面 private function hello(){     //Logo     $datas[0][]     =   "欢迎关注桂林小魔方童装店";     $datas[0][]     =   "本小店位于湖光路(微笑堂后面第一条小巷)";     $datas[0][]     =   "http://www.aidemofang.com.img.800cdn.com/Public/home/images/logo_z.jpg";     $datas[0][]     =   'http://aidemofang.com';          //童装知识     $datas[1][]     =   "最新童装常识";     $datas[1][]     =   "最新宝宝童装常识资讯";     $datas[1][]     =   "";     $datas[1][]     =   'http://www.aidemofang.com/Article/index'          //最新款式     $datas[2][]     =   "最新童装款式";     $datas[2][]     =   "最新最潮的新款哦!!";     $datas[2][]     =   "";     $datas[2][]     =   'http://www.aidemofang.com/Product/news';               //进入到商城     $datas[3][]     =   "进入商城";     $datas[3][]     =   "点击我进入商城吧!!";     $datas[3][]     =   "";     $datas[3][]     =   'http://www.aidemofang.com';     //联系我们          //小提示     $datas[4][]     =   "小助手:回复?进入到主菜单。";     $datas[4][]     =   "";     $datas[4][]     =   "";     $datas[4][]     =   "";          return array($datas,"news"); }

   哈哈,看到这很恶心吧,全都是拼凑的.


好了,关注显示就到这里了,源码想等到把功能全部实现了后再上传。计划实现的内容如下

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 private $menu_info = array(     "1"     =>   array("method"=>"get_knowledge","msg"=>"最新知识  \n"),     "2"     =>   array("method"=>"get_new_style","msg"=>"最新童款  \n"),     "3"     =>   array("method"=>"go_shop","msg"=>"进入商城  \n"),     "4"     =>   array("method"=>"","msg"=>"幽默笑话  \n"),     "5"     =>   array("method"=>"","msg"=>"歌曲点播  \n"),     "6"     =>   array("method"=>"","msg"=>"最新歌曲榜  \n"),     "7"     =>   array("method"=>"","msg"=>"最新票房榜  \n"),     "9"     =>   array("method"=>"","msg"=>"影视信息检索  \n"),     "10"    =>   array("method"=>"","msg"=>"巴士电台  \n"),     "11"    =>   array("method"=>"","msg"=>"历史上的今天  \n"),     "12"    =>   array("method"=>"","msg"=>"成语字典  \n"),     "13"    =>   array("method"=>"","msg"=>"英汉互译  \n"),     "14"    =>   array("method"=>"","msg"=>"天气预报  \n"),     "15"    =>   array("method"=>"","msg"=>"公交查询  \n"),     "16"    =>  array("method"=>"","msg"=>"车次查询  \n"),     "17"    =>   array("method"=>"","msg"=>"周边搜索  \n"),     "18"    =>   array("method"=>"","msg"=>"查快递  \n"),     "19"    =>   array("method"=>"","msg"=>"股票查询  \n"),     "20"    =>  array("method"=>"","msg"=>"检索周边美食  \n"),     "21"    =>  array("method"=>"","msg"=>"今日吃什么  \n"),     "22"    =>  array("method"=>"","msg"=>"今日看什么  \n"),     "23"    =>   array("method"=>"","msg"=>"百度百科  \n"),     "24"    =>   array("method"=>"","msg"=>"手机归属地查询  \n"),     "25"    =>   array("method"=>"","msg"=>"身份证查询  \n"),     "26"    =>   array("method"=>"","msg"=>"成语字典  \n"),     "27"    =>   array("method"=>"","msg"=>"火车查询  \n"),     "28"    =>   array("method"=>"","msg"=>"今日彩票  \n"),     "29"    =>   array("method"=>"","msg"=>"黄金白银期货  \n"),     "30"    =>   array("method"=>"","msg"=>"今日空气质量  \n"),     "31"    =>  array("method"=>"","msg"=>"苹果序列号/IMEI号查询  \n") );


 当然基本都是通过调用API来实现的..ok



来源: http://www.xiuxiandou.com

相关内容

    暂无相关文章