|
@@ -20,27 +20,41 @@ class BehaviorRepository
|
|
|
public function __construct(Behavior $behavior)
|
|
|
{
|
|
|
$this->behavior = $behavior;
|
|
|
+ //初始化virus域名
|
|
|
+ $this->client = new Client([
|
|
|
+ 'base_url' => config('constants.VIRUS_URL'),
|
|
|
+ 'timeout' => 3
|
|
|
+ ]);
|
|
|
}
|
|
|
|
|
|
public function index($request)
|
|
|
{
|
|
|
try {
|
|
|
- $app = config('constants.VIRUS_APP_ID');
|
|
|
$signKey = [
|
|
|
'app' => config('constants.VIRUS_APP_ID')
|
|
|
];
|
|
|
ksort($signKey);
|
|
|
$signKey = urldecode(http_build_query($signKey));
|
|
|
$sign = md5(config('constants.VIRUS_APP_SECRET') . $signKey);
|
|
|
- $url = config('constants.VIRUS_URL') . '/behaviorList';
|
|
|
- $array = [
|
|
|
- 'json' => ['app' => $app,'sign' => $sign], 'query' => [], 'http_errors' => false, 'headers' => ['Authorization' => "Bearer " . JWTAuth::getToken()]
|
|
|
- ];
|
|
|
|
|
|
- return http($url, $array, 'get');
|
|
|
- } catch (\Exception $e) {
|
|
|
- return [];
|
|
|
+ $response = $this->client->request('GET', '/behaviorList', [
|
|
|
+ 'headers' => [
|
|
|
+ 'Content-Type' => 'application/json',
|
|
|
+ 'app' => config('constants.VIRUS_APP_ID'),
|
|
|
+ 'sign' => $sign
|
|
|
+ ]
|
|
|
+ ]);
|
|
|
+ $res = json_decode($response->getBody()->getContents(), true);
|
|
|
+ $res = $res ? $res['behaviors'] : [];
|
|
|
+ }catch (RequestException $exception){
|
|
|
+ $res = [
|
|
|
+ 'returnCode' => '-1',
|
|
|
+ 'errMsg' => '网络超时'.$exception->getMessage()
|
|
|
+ ];
|
|
|
}
|
|
|
+
|
|
|
+ return $res;
|
|
|
+
|
|
|
}
|
|
|
|
|
|
public function create($request)
|