public function test() { $users = User::all(); $ids = []; $notice; if (Input::get('type') === 0) { foreach ($users as $u) { if ($u->hxid && $u->gender == 0) { $ids[] = $u->hxid; $notice = Notice::create(array('userId' => $u->_id, 'title' => Input::get('title') ? Input::get('title') : '', 'content' => Input::get('msg') ? Input::get('msg') : '', 'wishId' => '', 'noticeUrl' => Input::get('url') ? Input::get('url') : '', 'type' => 0)); } } } elseif (Input::get('type') === 1) { foreach ($users as $u) { if ($u->hxid && $u->gender == 1) { $ids[] = $u->hxid; $notice = Notice::create(array('userId' => $u->_id, 'title' => Input::get('title') ? Input::get('title') : '', 'content' => Input::get('msg') ? Input::get('msg') : '', 'wishId' => '', 'noticeUrl' => Input::get('url') ? Input::get('url') : '', 'type' => 0)); } } } else { foreach ($users as $u) { if ($u->hxid) { $ids[] = $u->hxid; $notice = Notice::create(array('userId' => $u->_id, 'title' => Input::get('title') ? Input::get('title') : '', 'content' => Input::get('msg') ? Input::get('msg') : '', 'wishId' => '', 'noticeUrl' => Input::get('url') ? Input::get('url') : '', 'type' => 0)); } } } $token = $this->getHxToken(); $uri = "https://a1.easemob.com/tongjo/wishes/messages"; $data = array('target_type' => 'users', 'target' => $ids, 'msg' => array('type' => 'txt', 'msg' => Input::get('msg') ? Input::get('msg') : '你的心愿被摘取啦!'), 'ext' => $notice->toArray()); $header = array(); array_push($header, 'Accept:application/json'); array_push($header, 'Content-Type:application/json'); array_push($header, 'Authorization: Bearer ' . $token); $ch = curl_init(); curl_setopt($ch, CURLOPT_URL, $uri); curl_setopt($ch, CURLOPT_POST, 1); curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1); curl_setopt($ch, CURLOPT_POSTFIELDS, json_encode($data)); curl_setopt($ch, CURLOPT_HTTPHEADER, $header); $return = curl_exec($ch); curl_close($ch); print_r($return); }
public function update(Request $request) { $user = $this->auth(); $wish = Wish::find(Input::get("_id")); if (!$wish) { return $this->outputError('心愿不存在', 2); } if ($wish->creatorId != $user->_id) { return $this->outputError('只有创建者可以修改心愿', 3); } $wish->update(Input::get()); if ($request->has('isPicked')) { if ($request->input('isPicked') == 0) { $wish->pickerId = ""; $wish->isPicked = 0; $wish->save(); } } $v = $wish; $creator = User::find($v->creatorId); $creator->school; unset($creator->schoolId); $v->creatorUser = $creator; $picker = User::find($v->pickerId); if ($picker) { $picker->school; unset($picker->schoolId); $v->pickerUser = $picker; } if (Input::get('isCompleted') == 1) { $notice = Notice::create(array('userId' => $wish->pickerId, 'title' => 'wishes', 'wishId' => $wish->_id, 'noticeUrl' => '', 'content' => '你摘的心愿被完成啦!', 'type' => 2)); $token = $this->getHxToken(); $uri = "https://a1.easemob.com/tongjo/wishes/messages"; $data = array('target_type' => 'users', 'target' => [$wish->picker->hxid], 'msg' => array('type' => 'txt', 'msg' => '你摘的心愿被完成啦!'), 'ext' => $notice->toArray()); $header = array(); array_push($header, 'Accept:application/json'); array_push($header, 'Content-Type:application/json'); array_push($header, 'Authorization: Bearer ' . $token); $ch = curl_init(); curl_setopt($ch, CURLOPT_URL, $uri); curl_setopt($ch, CURLOPT_POST, 1); curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1); curl_setopt($ch, CURLOPT_POSTFIELDS, json_encode($data)); curl_setopt($ch, CURLOPT_HTTPHEADER, $header); $return = curl_exec($ch); curl_close($ch); } return $this->output($v); }