Pigcms中WeixinAction的简略版流程

if $this->ali = 0;

1、new wechat() //该类存于PigCms/lib/ORG/Wechat.class.php

2、list($content,$type) = $this->reply($data);

3、$weixin->response($content,$type);

 

reply($data)方法:

if($data['MsgType'] == 'image'){ //判断接收信息的类型

if($data['Event'] == 'SCAN'){ //判断事件类型

if($data['content'] == 'wechat_ip'){ //判断接收内容

return $this->keyword($key);  //$key就是$data['content']

 

keyword($key)方法:

switch($key){

case 'Home': …… break;

$data = M('keyword')->where('keyword' == $key)

if($data != false){

  如果存在$data['module'].'Reply'这个类,则实例化该类,return该类的方法

  如果不存在$data['module'].'Reply'这个类,则

    switch($data['module']){ case 'Img': …… break;

}else{

  //$data==false

  return $nokeywordReply;  

  或者  return array('...',transfer_customer_service);  //转客服

  或者  return array($this->chat($key),'text');

} 

 

chat($name)方法:

如:接入图灵机器人,返回文字(return'哈哈')

 

$weixin->response($content,$type)方法:

$xml = new SimpleXMLElement('<xml></xml>');

$this->data2xml($xml,$this->data); //$this->data已经有toUserName、fromUserName、MsgType等必须参数了

exit($xml->asXML());

posted @ 2016-06-30 19:20  D蓝叶  阅读(487)  评论(0编辑  收藏  举报