本文整理汇总了PHP中Illuminate\Http\Request::getContent方法的典型用法代码示例。如果您正苦于以下问题:PHP Request::getContent方法的具体用法?PHP Request::getContent怎么用?PHP Request::getContent使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Illuminate\Http\Request
的用法示例。
在下文中一共展示了Request::getContent方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: store
/**
* Store a newly created order in storage.
*
* @param \Illuminate\Http\Request $request
* @return \Illuminate\Http\Response
*/
public function store(Request $request)
{
if ($request->getContent() == null) {
$response = [Config::get('enum.message') => Config::get('enum.nullRequest')];
return (new Response($response, 400))->header('Content-Type', 'json');
}
if (!$this->authService->validJson($request->getContent())) {
$response = [Config::get('enum.message') => Config::get('enum.invalidJson')];
return (new Response($response, 400))->header('Content-Type', 'json');
}
$data = json_decode($request->getContent(), true);
$validator = Validator::make($data, $this->orderService->orderRules());
if ($validator->fails()) {
return (new Response($validator->messages(), 400))->header('Content-Type', 'json');
}
foreach ($data['Products'] as $product) {
$productValidator = Validator::make($product, $this->orderService->orderProductRules());
if ($productValidator->fails()) {
return (new Response($productValidator->messages(), 400))->header('Content-Type', 'json');
}
}
$this->orderService->createOrder($data);
$response = [Config::get('enum.message') => Config::get('enum.successOrder')];
return (new Response($response, 201))->header('Content-Type', 'json');
}
示例2: getIterator
/**
* @inheritdoc
*/
public function getIterator()
{
$content = $this->request->getContent();
$array = json_decode($content, true);
if (is_null($array)) {
throw new RequestException('Payload could not be parsed from json');
}
return new \ArrayIterator($array);
}
示例3: handle
/**
* Handle an incoming request.
*
* @param \Illuminate\Http\Request $request
* @param \Closure $next
* @return mixed
*/
public function handle($request, Closure $next)
{
if ($request->isJson()) {
if (in_array($request->getMethod(), self::PARSED_METHODS)) {
if (strlen($request->getContent()) != 0) {
$request->merge(json_decode($request->getContent(), true));
}
}
}
return $next($request);
}
示例4: store
/**
* Store a newly created resource in storage.
*
* @param Request $request
* @return Response
*/
public function store(Request $request)
{
$action = new \App\Action();
$action->fromJson($request->getContent());
$user_id = $action->user_id;
if (!$user_id) {
$user_id = $request->cookie('tr_guid');
if (!$user_id) {
$user_id = $this->as->generateUserId();
}
$action->user_id = $user_id;
}
$this->as->setRequestData($action, $request);
$this->as->setDefaults($action);
try {
$action->validate();
} catch (\Exception $e) {
return $this->error($e);
}
$referral_code = $this->as->generateReferralCode($action);
$action->referral_code = $referral_code;
try {
$rv = $this->as->storeAction($action);
} catch (\Exception $e) {
return $this->error($e);
}
$response_data = ['user_id' => $user_id, 'referral_code' => $referral_code, 'is_new' => $rv['is_new'], 'counter' => $rv['counter'], 'action' => $rv['action']->toArray()];
$response_json = json_encode($response_data);
return response($response_json)->header('Content-Type', 'application/json');
}
示例5: store
/**
* Store a newly created resource in storage.
*
* @param Request $request
* @return Response
*/
public function store(Request $request)
{
//
//Log::info('$request=<' . $request . '>');
if ($request->isMethod('post')) {
$bodyContent = $request->getContent();
//Log::info('$bodyContent=<' . $bodyContent . '>');
$bodyJson = json_decode($bodyContent);
$keyPath = $this->keyRoot_ . $bodyJson->token . '/pubKey.pem';
$fp = fopen($keyPath, 'r');
$pubKeyMem = fread($fp, 8192);
fclose($fp);
$pubkeyid = openssl_pkey_get_public($pubKeyMem);
$token = $bodyJson->token;
$sign = $bodyJson->sign;
$ok = openssl_verify($token, hex2bin($sign), $pubkeyid, "sha256");
openssl_free_key($pubkeyid);
if ($ok == 1) {
$profilePath = $this->keyRoot_ . $bodyJson->token . '/profile';
//Log::info('$bodyJson->payload=<' . json_encode($bodyJson->payload) . '>');
file_put_contents($profilePath, json_encode($bodyJson->payload));
return response()->json(['status' => 'success']);
} else {
return response()->json(['status' => 'failure']);
}
}
}
示例6: validatePoll
public function validatePoll(Request $request, $eid)
{
$data = json_decode($request->getContent());
$pollArray = $data->polloptions;
//json list of poll options
if (!empty($pollArray)) {
$poll = new Poll();
$poll->eid = $eid;
$poll->polltype = 'date';
$saveflag = $poll->save();
if ($saveflag) {
foreach ($pollArray as $poll_index) {
$poll_options = new PollOption();
$poll_options->pid = $poll['pid'];
$poll_options->option = $poll_index->option;
try {
PollOption::savePollOption($poll_options);
} catch (Exception $e) {
print '<script type="text/javascript">';
print 'alert( There have been issues adding options to your poll please
check home page for details)';
print '</script>';
}
}
} else {
print '<script type="text/javascript">';
print 'alert("Unable to save poll to database")';
print '</script>';
}
}
}
示例7: handle
/**
* Handle an incoming request.
*
* @param Request $request
* @param Closure $next
*
* @return mixed
*/
public function handle($request, Closure $next)
{
$validationResult = Spec::define(['content-hash' => PrimitiveTypeConstraint::forType(ScalarTypes::SCALAR_STRING), 'authorization' => PrimitiveTypeConstraint::forType(ScalarTypes::SCALAR_STRING)], [], ['content-hash', 'authorization'])->check(array_map(function ($entry) {
return $entry[0];
}, $request->headers->all()));
if ($validationResult->failed()) {
return ApiResponse::makeFromSpec($validationResult)->toResponse();
}
$authorization = str_replace('Hash ', '', $request->headers->get('Authorization'));
$content = $request->getContent();
try {
$pair = $this->finder->byPublicId($authorization, KeyPairTypes::TYPE_HMAC);
$hasher = new HmacHasher();
$verificationResult = $hasher->verify($request->headers->get('Content-Hash'), $content . Carbon::now()->format($this->format), $pair->getSecretKey());
if ($verificationResult) {
$request->attributes->set(static::ATTRIBUTE_KEYPAIR, $pair);
return $next($request);
}
return ApiResponse::create([], ApiResponse::STATUS_INVALID, ['HMAC content hash does not match the expected hash.'])->toResponse();
} catch (ModelNotFoundException $ex) {
if ($ex->getModel() === KeyPair::class) {
return ApiResponse::create([], ApiResponse::STATUS_INVALID, ['Unable to locate public ID. Check your credentials'])->toResponse();
}
throw $ex;
}
}
示例8: jsonadd
public function jsonadd(Request $request)
{
$data = json_decode($request->getContent(), true);
foreach ($data as $d) {
$apt = new AirportsAPI();
$depicao = Airport::where('icao', $d['depicao'])->get();
$arricao = Airport::where('icao', $d['arricao'])->get();
if ($depicao->isEmpty()) {
$apt->addFromDB($d['depicao']);
}
if ($arricao->isEmpty()) {
$apt->addFromDB($d['arricao']);
}
$entry = new Schedule();
$entry->code = $d['code'];
$entry->flightnum = $d['flightnum'];
$entry->depicao = $d['depicao'];
$entry->arricao = $d['arricao'];
$entry->route = $d['route'];
$entry->aircraft = $d['aircraft'];
$entry->type = $d['type'];
$entry->daysofweek = $d['daysofweek'];
$entry->enabled = $d['enabled'];
$entry->save();
}
}
示例9: make
/**
* @param Request $request
* @param $processor
* @param string $protocol
* @return Response
*/
public static function make($request, $processor, $protocol)
{
$readTransport = new TMemoryBuffer($request->getContent());
$writeTransport = new TMemoryBuffer();
switch ($protocol) {
case 'json':
$readProtocol = new TJSONProtocol($readTransport);
$writeProtocol = new TJSONProtocol($writeTransport);
break;
case 'binary':
$readProtocol = new TBinaryProtocol($readTransport);
$writeProtocol = new TBinaryProtocol($writeTransport);
break;
case 'compact':
$readProtocol = new TCompactProtocol($readTransport);
$writeProtocol = new TCompactProtocol($writeTransport);
break;
default:
throw new UnexpectedValueException();
}
$readTransport->open();
$writeTransport->open();
$processor->process($readProtocol, $writeProtocol);
$readTransport->close();
$writeTransport->close();
$content = $writeTransport->getBuffer();
return new Response($content, 200, ['Content-Type' => 'application/x-thrift', 'Access-Control-Allow-Origin' => $request->header('origin')]);
}
示例10: switchRespMsg
/**
* 根据消息的类型,回复不同内容
* @param Request $request
* @return null
*/
public function switchRespMsg(Request $request)
{
//获取POST数据包
$postStr = $request->getContent();
Log::info($postStr);
if (!empty($postStr)) {
libxml_disable_entity_loader(true);
$postObj = simplexml_load_string($postStr, 'SimpleXMLElement', LIBXML_NOCDATA);
$fromUsername = $postObj->FromUserName;
$toUsername = $postObj->ToUserName;
$msgType = $postObj->MsgType;
$content = trim($postObj->Content);
if ($msgType == "text") {
return ResponseMsgService::responseTextMsg($fromUsername, $toUsername, $content);
}
if ($msgType == "event") {
$event = $postObj->Event;
Log::info("====event===" . $event);
if ($event == "subscribe") {
$respStr = "您好,我是郭世杰,欢迎关注我的微信个人公众号";
return ResponseMsgService::responseTextMsg($fromUsername, $toUsername, $respStr);
}
if ($event == "CLICK") {
$eventKey = $postObj->EventKey;
return $this->responseMenuMsg($fromUsername, $toUsername, $eventKey);
}
}
return null;
} else {
Log::info("Post Xml data is null");
return null;
}
}
示例11: notify
public function notify(Request $request)
{
\Log::debug('payment_notify', ['request' => $request]);
$input = XML::parse($request->getContent());
if ($input['return_code'] == 'SUCCESS') {
$order = Order::where('wx_out_trade_no', $input['out_trade_no'])->firstOrFail();
$address_id = $order->address_id;
# 当前订单收货地址id
if ($order->isPaid()) {
return 'FAIL';
}
$order->update(['wx_transaction_id' => $input['transaction_id'], 'cash_payment' => floatval($input['total_fee']) / 100.0]);
$order->paid();
/* 发送消息提醒 */
$default_address = Address::where(['id' => $address_id])->first();
$phone = $default_address->phone;
$msg = '尊敬的顾客您好!您的订单已经收到,易康商城将尽快为您安排发货,如有任何问题可以拨打客服电话400-1199-802进行咨询,感谢您的惠顾!';
\MessageSender::sendMessage($phone, $msg);
// if ($phone = env('ORDER_ADMIN_PHONE')) {
// \Log::error($phone);
// \MessageSender::sendMessage($phone, $order->toOrderMessageString());
// }
$result = \Wechat::paymentNotify();
return $result;
}
return 'FAIL';
}
示例12: handle
/**
* Handle an incoming request.
*
* @param \Illuminate\Http\Request $request
* @param \Closure $next
* @return mixed
*/
public function handle($request, Closure $next)
{
if (0 === strpos($request->headers->get('CONTENT_TYPE'), 'application/json') and Request::isMethod('post')) {
$request->request = new ParameterBag((array) json_decode($request->getContent(), true));
}
return $next($request);
}
示例13: store
public function store(Request $request)
{
// grab credentials from the request
$input_data = json_decode($request->getContent(), true);
$arrayReturn = array();
try {
$credentials = ['email' => $input_data['email'], 'password' => $input_data['password'], 'confirmed' => 1];
//$user_role = array_key_exists('role', $input_data) ? $input_data['role'] : 'user';
// attempt to verify the credentials and create a token for the user
if (!($token = JWTAuth::attempt($credentials))) {
return ResponseMessage::invalidCredentials();
}
// Checks Roles
$user = JWTAuth::setToken($token)->authenticate();
//$isQueryFromAdmin = $user->is('query') && $user_role == 'admin';
/*if (!$user->is($user_role) && !$isQueryFromAdmin) {
return response()->json(
['error' => 'invalid_credentials'], 401
);
}*/
} catch (JWTException $e) {
// something went wrong whilst attempting to encode the token
return response()->json(['error' => 'could_not_create_token', 'message' => $e->getMessage()], 500);
}
// all good so return the token
$arrayReturn = compact('token');
$arrayReturn["user"] = $this->usersRepo->parserResult($user)['data'];
return response()->json($arrayReturn);
}
示例14: isValidRequest
/**
* Validate the github payload and signature.
*
* If you're wondering why the md5, see the link below.
* @see http://php.net/manual/en/function.hash-hmac.php#111435
*
* @param \Illuminate\Http\Request $request
* @return bool
*/
private function isValidRequest($request)
{
$signature = $request->server('HTTP_X_HUB_SIGNATURE');
$secret = env('WEBHOOK_SECRET');
list($algo, $expectedHash) = explode('=', $signature, 2);
$payloadHash = hash_hmac($algo, $request->getContent(), $secret);
return md5($expectedHash) === md5($payloadHash);
}
示例15: handle
/**
* Handle an incoming request.
*
* @param \Illuminate\Http\Request $request
* @param \Closure $next
*
* @throws \Symfony\Component\HttpKernel\Exception\BadRequestHttpException
*
* @return mixed
*/
public function handle(Request $request, Closure $next)
{
// prevent body sizes of more than 1 MB
if (mb_strlen($request->getContent(), '8bit') > 1048576) {
throw new HttpException(413);
}
return $next($request);
}