为了账号安全,请及时绑定邮箱和手机立即绑定

解析请求,PHP/Laravel

解析请求,PHP/Laravel

PHP
眼眸繁星 2024-01-19 15:07:39
该接口用于门禁设备上报人员通行记录,经我(第三方平台)调用该接口给人脸识别终端或人脸识别门禁终端。呼叫方向:人脸识别终端或人脸识别门禁终端调用第三方平台的API。请求描述:请求方法:POST 请求 URL:/LAPI/V1.0/System/Event/Notification/PersonVerification 内容类型:text/plain请求示例:{    "Reference": "204.2.1.20:5118/LAPI/V1.0/System/Event/Subscription/0","Seq": 5, "DeviceCode": "210235C3R13202000093",    "Timestamp": 1564735558,     "NotificationType": 1,     "FaceInfoNum": 1,     "FaceInfoList": [        {            "ID": 5,             "Timestamp": 1564707615,             "CapSrc": 1,             "FeatureNum": 0,             "FeatureList": [                {                    "FeatureVersion": "",                     "Feature": ""                },                 {                    "FeatureVersion": "",                     "Feature": ""                }            ],             “Temperature”: 36.5,            “MaskFlag”: 1,            "PanoImage": {                "Name": "1564707615_1_86.jpg",                 "Size": 101780,                 "Data": "…"            },             "FaceImage": {                "Name": "1564707615_2_86.jpg",                 "Size": 35528,                 "Data": "…"            },             "FaceArea": {                "LeftTopX": 4981,                 "LeftTopY": 3744,                 "RightBottomX": 8250,                 "RightBottomY": 5583            }        }    ], 我正在使用 Laravel,当我尝试 $request->all() 时,我得到了 [],当我dump( $request->getContent() ); 转储时,我得到了下面的结果似乎我需要""从请求的开头和结尾删除才能进行 json_decode(),但无论我使用什么字符串函数 - preg_replace、substring 等 - 都没有改变,当我尝试 $content[0] 时,我得到了,但{不是", $content[-1] 我得到了\n,$content[-2] 我得到了}有人能指出我错在哪里吗?
查看完整描述

1 回答

?
冉冉说

TA贡献1877条经验 获得超1个赞

看起来这是Content-Type标题问题。但这应该是一个正确的解决方案:


  $find = ['/"""/', '/\\\n/', '/“/', '/”/'];

  $replace = ['', '', '"', '"'];


  $output = preg_replace($find, $replace, $your_input);


  // now the $output is ready to be decoded

  $decoded = json_decode($output);

  $v = var_dump($decoded); 

查看完整回答
反对 回复 2024-01-19
  • 1 回答
  • 0 关注
  • 29 浏览

添加回答

举报

0/150
提交
取消
意见反馈 帮助中心 APP下载
官方微信