Commit 0de786d6 authored by wuxiaoli's avatar wuxiaoli

修复获取实时股票信息

parent 696012ee
......@@ -2047,21 +2047,34 @@ function curl($url){
*/
if (!function_exists('toMarket')){
function toMarket($code){
if($code == '000001'){
return 'SZ';
}
if(in_array(substr($code, 0, 1),array('6', '9'))){
return 'SH';
}
if(in_array(substr($code, 0, 1),array('0', '2', '3'))){
return 'SZ';
}
if(in_array(substr($code, 0, 1),array('4', '8'))){
return 'BJ';
if(strlen($code) === 5){//如果不符合上述简单规则,可能需要更复杂的逻辑或数据查询
return "HK";
}else if (strlen($code) === 6){//A股暂时假设6位代码
if($code == '000001'){
return 'SZ';
}
if(in_array(substr($code, 0, 1),array('6', '9'))){
return 'SH';
}
if(in_array(substr($code, 0, 1),array('0', '2', '3'))){
return 'SZ';
}
if(in_array(substr($code, 0, 1),array('4', '8'))){
return 'BJ';
}
}
}
}
//腾讯数据解析
if(!function_exists('jsonQuotation')) {
function jsonQuotation($item) {
$item[0] = isset($item[0])?substr(str_replace('v_','', $item[0]), 0, 2):'';//交易所代号
$item[80] = isset($item[30]) ? strtotime($item[30]) : time();
return $item;
}
}
/******************************************************************************************/
if(!function_exists('toPinyin')) {
function toPinyin($zh){
......
......@@ -242,17 +242,10 @@ if (!function_exists('getEndDay')) {
}
if (!function_exists('z_market')) {
function z_market($code,$market="HK")
function z_market($code,$market="")
{
$res = \think\Db::name('admin_config')->where(array('name' => 'market_data_in'))->value('value');
//判断股票前缀
/*if(toMarket($code)){
$market = toMarket($code);
};*/
$code=strtolower($market).$code;
//判断股票是否
switch ($res) {
case 1:
$res = qq_market($code);
......@@ -296,7 +289,6 @@ if (!function_exists('getEndDay')) {
switch ($res) {
case 1:
$res = explode(',', $code);
$count = count($res);
foreach ($res as $v) {
$d .= fenxi($v) . ',';
......@@ -308,16 +300,9 @@ if (!function_exists('getEndDay')) {
break;
}
for ($i = 0; $i < $count; $i++) {
$k = $i * 53;
for ($n = 1; $n <= 53; $n++) {
$num = $n + $k;
$data[$i][$n] = $tmd[$num];
}
$data[$i][0] = '';
$data[$i] = qq_to_api($data[$i]);
foreach ($tmd as $k=>$v){
$data[$k][0] = '';
$data[$k] = qq_to_api($v);
}
break;
......@@ -377,7 +362,6 @@ if (!function_exists('getEndDay')) {
default:
$res = explode(',', $code);
$count = count($res);
foreach ($res as $v) {
$d .= fenxi($v) . ',';
......@@ -385,16 +369,9 @@ if (!function_exists('getEndDay')) {
$tmd = qq_market_b($d);
for ($i = 0; $i < $count; $i++) {
$k = $i * 53;
for ($n = 1; $n <= 53; $n++) {
$num = $n + $k;
$data[$i][$n] = $tmd[$num];
}
$data[$i][0] = '';
$data[$i] = qq_to_api($data[$i]);
foreach ($tmd as $k=>$v){
$data[$k][0] = '';
$data[$k] = qq_to_api($v);
}
break;
......@@ -976,40 +953,48 @@ if (!function_exists('getEndDay')) {
if (!function_exists('')) {
function fenxi($code)
{
switch (substr($code, 0, 1)) {
case '0':
$d = 'sz' . $code;
break;
case '3':
$d = 'sz' . $code;
break;
if(strlen($code) === 5){//港股
case '1':
$d = 'sz' . $code;
break;
$d = 'hk' . $code;
case '2':
$d = 'sz' . $code;
break;
}else if(strlen($code) === 6){//A股
switch (substr($code, 0, 1)) {
case '0':
$d = 'sz' . $code;
break;
case '6':
$d = 'sh' . $code;
break;
case '3':
$d = 'sz' . $code;
break;
case '5':
$d = 'sh' . $code;
break;
case '1':
$d = 'sz' . $code;
break;
case '9':
$d = 'sh' . $code;
break;
case '2':
$d = 'sz' . $code;
break;
default:
$d = $code;
break;
case '6':
$d = 'sh' . $code;
break;
case '5':
$d = 'sh' . $code;
break;
case '9':
$d = 'sh' . $code;
break;
default:
$d = $code;
break;
}
}
return $d;
}
}
......@@ -1208,9 +1193,19 @@ if (!function_exists('getEndDay')) {
curl_setopt($ch, CURLOPT_HEADER, 0);
$output = curl_exec($ch);
curl_close($ch);
$t2 = explode('~', mb_convert_encoding($output, 'utf-8', 'gbk'));
unset($t2[0]);
return $t2;
$str = mb_convert_encoding($output, 'utf-8', 'gbk');
$str = str_replace(array("\r\n", "\r", "\n"), "", $str);
$t2 = explode('";', $str);
$json = [];
foreach ($t2 as $key => $val) {
$array = explode("~", $val);
if(isset($array[2])&&isset($array[3])&&isset($array[4])){
$json[] = jsonQuotation(explode("~", $val));
}else{
continue;
}
}
return $json;
}
}
......
......@@ -326,6 +326,7 @@ class Position extends Model{
$data[0]['lid'] = $lid;
$data[0]['soruce'] = $soure;
$data[0]['login_name'] = $user;
$data[0]['market'] = toMarket($stockinfo["code"]);
$data[0]['gupiao_code'] = $stockinfo["code"];
$data[0]['gupiao_name'] = $stockinfo["name"];
$data[0]['count'] = $count;
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment