public function storeMessage($message, $event) { if ($event->room()->first() == null) { Chatroom::create(['name' => $event->title, 'event_id' => $event->id]); } return $event->room()->first()->messages()->create(['message' => $message, 'user_id' => \Auth::user()->id]); }
public function checkChatroom() { $input = Request::all(); $title = $input[1]; //$email = '*****@*****.**'; //$password = '******'; $result = Chatroom::where('title', $title)->get(); return $result->count(); }
/** * Games * Sport * Finance * Animals */ $app->get('chatrooms/{category}', function ($category) { $chatrooms = Chatroom::where('category', $category)->get(); return $chatrooms; }); $app->post('chatrooms', function (Request $request) { $chatroom = Chatroom::create($request->all()); return $chatroom; }); $app->post('chatrooms/{id}/chat', function (Request $request, $chatroomId) { $chatroom = Chatroom::find($chatroomId); $chat = new Chat($request->all()); $chatroom->chats()->save($chat); return $chat; }); $app->get('chatrooms/{id}/chat', function ($chatroomId) { return Chat::where('chatroom_id', $chatroomId)->get(); }); $app->post('login', function (Request $request) { $username = $request->input('username'); $password = $request->input('password'); if (areCredentialsCorrect($username, $password)) { return response()->json(["message" => "Login successful"], 200); } return response()->json(["message" => "Credentials are incorrect"], 400); });
/** * */ public function run() { $faker = Faker::create(); $roomIds = Chatroom::lists('id'); $userIds = User::lists('id'); foreach (range(1, 200) as $index) { Chatmessage::create(['message' => $faker->sentence(), 'user_id' => $faker->randomElement($userIds), 'chatroom_id' => $faker->randomElement($roomIds)]); } }
public function putChatroomFriends($wxuin, $post) { \DB::reconnect(); //确保获取了一个新的连接。 //循环执行心跳 $user = Login::where('wxuin', $wxuin)->where('status', 1)->first(); if (!$user) { $this->death(); } $cookies = json_decode($user->cookies); $url = 'https://webpush.weixin.qq.com/cgi-bin/mmwebwx-bin/webwxbatchgetcontact?type=ex&r=' . t(); $ret = CURL::send($url, ['Cookie' => urldecode(http_build_query($cookies, '', '; '))], [], ['ret' => 'all', 'post' => json_encode($post)]); $html = $ret->body; $cookies2 = toCookies($ret->cookies); $cookies = (object) ((array) $cookies2 + (array) $cookies); $html = iconv('UTF-8', 'UTF-8//IGNORE', $html); $data_arr = json_decode($html, true); foreach ($data_arr['ContactList'] as $k => $v) { //获取好友信息 $data_room = ['EncryChatRoomId' => $v['EncryChatRoomId'], 'Uin' => $v['Uin'], 'UserName' => $v['UserName'], 'NickName' => $v['NickName'], 'HeadImgUrl' => $v['HeadImgUrl'], 'RemarkName' => $v['RemarkName'], 'Sex' => $v['Sex'], 'Signature' => $v['Signature'], 'AttrStatus' => $v['AttrStatus'], 'Province' => $v['Province'], 'City' => $v['City']]; $rm = Chatroom::where('EncryChatRoomId', $v['EncryChatRoomId'])->where('UserName', $v['UserName'])->first(); //如果存在了就更新 if ($rm) { Chatroom::where('EncryChatRoomId', $v['EncryChatRoomId'])->where('UserName', $v['UserName'])->update($data_room); } else { $data_room_batch[] = $data_room; } } if (isset($data_room_batch)) { Chatroom::insert($data_room_batch); } }