Exemple #1
0
 public function index()
 {
     if (isset($_GET['echostr'])) {
         WeiXin::valid();
     } else {
         $msg = WeiXin::getMsg();
         $type = strtolower($msg['MsgType']);
         $username = $msg['FromUserName'];
         //哪个用户给你发的消息,这个$username是微信加密之后的,但是每个用户都是一一对应的
         switch ($type) {
             //文本
             case 'text':
                 if ($msg['Content'] == 'Hello2BizUser') {
                     //微信用户第一次关注你的账号的时候,你的公众账号就会受到一条内容为'Hello2BizUser'的消息
                     $reply = WeiXin::makeText('欢迎你关注奇艺果公众平台');
                 } else {
                     //这里就是用户输入了文本信息
                     $keyword = $msg['Content'];
                     //用户的文本消息内容
                     $arrayCon = array(array("Title" => "奇艺果网", "Description" => "买衣服,买抱枕,买手机壳到奇艺", "PicUrl" => "http://http://www.artqiyi.com/themes/default/images/logo.jpg", "Url" => "http://http://www.artqiyi.com/"));
                     $reply = WeiXin::makeNews($arrayCon);
                 }
                 break;
                 //链接
             //链接
             case 'link':
                 $reply = WeiXin::makeLink();
                 break;
                 //视频
             //视频
             case 'video':
                 $reply = WeiXin::makeVideo();
                 break;
                 //语音
             //语音
             case 'voice':
                 $reply = WeiXin::makeVoice();
                 break;
                 //图片
             //图片
             case 'image':
                 $reply = WeiXin::makeImage();
                 break;
                 //地理位置
             //地理位置
             case 'location':
                 //数据入库
                 $results['location_x'] = $msg['Location_X'];
                 $results['location_y'] = $msg['Location_Y'];
                 $results['openid'] = $msg['FromUserName'];
                 $results['createtime'] = $msg['CreateTime'];
                 WeixinUserLocation::addWeixinUserLocation($results);
                 //回复处理
                 WeiXin::makeLocation();
                 break;
             case 'event':
                 $reply = WeiXin::makeEvent($msg['Event']);
                 break;
             default:
                 # code...
                 break;
         }
         WeiXin::reply($reply);
     }
 }