Пример #1
0
 public function run()
 {
     $moreRequestMessage = getMoreRequestMessage();
     $this->fromusername = $moreRequestMessage["fromusername"];
     $this->tousername = $moreRequestMessage["tousername"];
     $this->msgtype = $moreRequestMessage["msgtype"];
     //是否开启菜单
     if (!!$this->config->item("ismenu")) {
         $access_token = get_access_token();
         createmenu($access_token);
     }
     //判断消息类型
     switch ($this->msgtype) {
         case 'event':
             //判断事件类型
             $this->event = $moreRequestMessage["event"];
             $this->handleEventMessage($this->event);
             break;
         case 'text':
             $keyMessage = getKeyRequestTextMessage();
             $content = $keyMessage['content'];
             $this->responseTextMessage($content);
             break;
         case 'image':
             $keyMessage = getKeyRequestImageMessage();
             $picurl = $keyMessage['picurl'];
             $mediaid = $keyMessage['mediaid'];
             $this->responseImageMessage($picurl, $mediaid);
             break;
         case 'location':
             $keyMessage = getKeyRequestLocationMessage();
             $location_x = $keyMessage['location_x'];
             $location_y = $keyMessage['location_y'];
             $scale = $keyMessage['scale'];
             $label = $keyMessage['label'];
             $this->responseLocationMessage($location_x, $location_y, $scale, $label);
             break;
         case 'link':
             $keyMessage = getKeyRequestLinkMessage();
             $title = $keyMessage['title'];
             $description = $keyMessage['description'];
             $url = $keyMessage['url'];
             $this->responseLinkMessage($title, $description, $url);
             break;
         case 'voice':
             $keyMessage = getKeyRequestVoiceMessage();
             $mediaid = $keyMessage['mediaid'];
             $format = $keyMessage['format'];
             $this->responseVoiceMessage($mediaid, $format);
             break;
         default:
             $this->responseUnknownMessage();
             break;
     }
 }
Пример #2
0
/**
 * 自定义的错误处理函数,将 PHP 错误通过文本消息回复显示
 * @param  int $level   错误代码
 * @param  string $msg  错误内容
 * @param  string $file 产生错误的文件
 * @param  int $line    产生错误的行数
 * @return void
 */
function errorHandler($level, $msg, $file, $line)
{
    $error_type = array(E_WARNING => 'Warning', E_NOTICE => 'Notice', E_USER_ERROR => 'User Error', E_USER_WARNING => 'User Warning', E_USER_NOTICE => 'User Notice', E_STRICT => 'Strict', E_RECOVERABLE_ERROR => 'Recoverable Error', E_DEPRECATED => 'Deprecated', E_USER_DEPRECATED => 'User Deprecated');
    $moreRequestMessage = getMoreRequestMessage();
    $fromusername = $moreRequestMessage["fromusername"];
    $tousername = $moreRequestMessage["tousername"];
    $errorMessage = "PHP报错了:\n" . $error_type[$level] . ":\n" . $msg . "\nFILE:\n" . $file . "\nLINE:\n" . $line;
    sendTextMessage($fromusername, $tousername, $errorMessage);
}
Пример #3
0
 public function handleEventMessage($event)
 {
     switch ($event) {
         //关注事件
         case 'subscribe':
             //
             $keyMessage = getMoreRequestMessage();
             $fromusername = $keyMessage['fromusername'];
             $this->responseSubscribeEvent($fromusername);
             // $this->responseSubscribeEvent();
             break;
             //取消关注事件
         //取消关注事件
         case 'unsubscribe':
             $this->responseUnsubscribeEvent();
             break;
             //二维码扫描
         //二维码扫描
         case 'SCAN':
             $keyMessage = getKeyRequestQrcodeMessage();
             $eventKey = $keyMessage['eventKey'];
             $ticket = $keyMessage['ticket'];
             $this->responseScanEvent($eventKey, $ticket);
             break;
             //地理位置上报
         //地理位置上报
         case 'LOCATION':
             $keyMessage = getKeyRequestAdvancedLocationMessage();
             $latitude = $keyMessage['latitude'];
             $longitude = $keyMessage['longitude'];
             $precision = $keyMessage['precision'];
             $this->responseLocationEvent($latitude, $longitude, $precision);
             break;
             //菜单点击
         //菜单点击
         case 'CLICK':
             //获得被点击菜单的Eventkey
             $keyMessage = getKeyRequestClickMessage();
             $eventKey = $keyMessage['eventkey'];
             //根据不同类型的Eventkey,做不同的处理
             $this->responseClickMenuEvent($eventKey);
             break;
     }
 }