bourse stock
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

88 lines
2.7 KiB

<?php
namespace app\utility;
use think\facade\Log;
use GuzzleHttp\Client;
use GuzzleHttp\Exception\GuzzleException;
class ClientGo
{
public function giveawaysStock($code, $id, $marketType)
{
try {
$marketType = $marketType + 0; // 转成数字
$client = new Client();
$url = env('QUOTE.DEAL_BASE_URL') . '/order_sharepre/share_giveaways';
$response = $client->request("POST", $url, [
'json' => [
'code' => $code,
'id' => $id,
'stock' => $marketType,
],
]);
$body = $response->getBody()->getContents();
$res = json_decode($body, true);
Log::info('给交易推送数据 ' . json_encode([$res, [
'code' => $code,
'id' => $id,
'stock' => $marketType,
]]));
if (isset($res['code']) && $res['code'] == 200) {
return true;
}
return false;
} catch (\Exception $exception) {
Log::error('给交易推送数据异常1 ' . $exception->getMessage());
} catch (GuzzleException $e) {
Log::error('给交易推送数据异常2 ' . $e->getMessage());
}
return false;
}
// 给 go 行情 发送 source
public function updateIndiaSource($country, $stockCode, $source = 0)
{
try {
$responseArr = [
'new_ticker' => $stockCode, //新的股票代码
'locale' => $country,
'source' => $source,
'token' => 'asdfsnl123jlknl3nksdf32345ln98sdfsfs8891232nsdfsdfsdfsdxcfvbhnfgh',
];
$client = new Client();
$url = env('QUOTE.BASE_URL') . '/spots/php/update';
$response = $client->request("POST", $url, [
'json' => $responseArr
]);
$body = $response->getBody()->getContents();
$res = json_decode($body, true);
$responseArr['url'] = $url;
trace('---给行情推送数据---' . json_encode([$res, $responseArr]), 'error');
if (isset($res['code']) && $res['code'] == 200) {
return true;
}
trace('---给行情推送数据异常---' . json_encode([$res, $responseArr]), 'error');
return false;
} catch (\Exception $exception) {
trace('---给行情推送数据异常1---' . $exception->getMessage(), 'error');
} catch (GuzzleException $e) {
trace('---给行情推送数据异常2---' . $e->getMessage(), 'error');
}
return false;
}
}