Example #1
0
 /**
  * Get reply define by command content.
  *
  * @param $cmdType
  * @param $cmdBody
  * @return array
  */
 public static function getReplyDefine($app, $cmdType, $cmdBody)
 {
     if (isset($app) && isset($cmdType) && isset($cmdBody)) {
         $cmd = Command::match($cmdBody);
         if (!$cmd['texts']) {
             Log::error('invalid command content');
             return null;
         }
         $reply = self::where(['wechat_id' => $app['id'], 'cmd_type' => $cmdType, 'cmd_content' => $cmd['texts'][0]])->get()->first();
         if (!$reply) {
             Log::error('command content not found' . json_encode($cmd));
             return null;
         }
         $replyArr = ['event_id' => $reply['event_id'], 'is_prefix' => $reply['is_prefix'], 'reply_type' => $reply['reply_type'], 'event_code' => Event::getEventCode($reply['event_id']), 'is_activity_event' => Event::isActivity($reply['event_id']), 'reply_json' => json_decode(base64_decode($reply['reply_json']), true), 'cmd_original' => $cmdBody];
         if ($cmd['texts']) {
             $replyArr['cmd_text'] = $cmd['texts'][0];
         }
         if ($cmd['numbers']) {
             $replyArr['cmd_number'] = $cmd['numbers'];
         }
         return $replyArr;
     }
     return null;
 }