标签:
1 private function get_stock_info($stock_id){ 2 3 $nodes_url2="http://hq.sinajs.cn/list=".$stock_id; 4 if($debug_mode)echo "URL2 is ".$nodes_url2."<br>"; 5 $file_content2 = file_get_contents($nodes_url2); 6 $dadan_array3=‘‘; 7 8 $dadan_array3=split(";",$file_content2); 9 for($dn=0;$dn<sizeof($dadan_array3);$dn++){ 10 $dadan_array2=‘‘; 11 $dadan_array2=split(",",$dadan_array3[$dn]); 12 ${"stock_name".$dn}=iconv(‘GB2312‘, ‘UTF-8‘, $dadan_array2[0]); 13 $dadan_array4=split("\"",${"stock_name".$dn}); 14 ${"stock_id".$dn}=substr($dadan_array4[0],-9,8); 15 ${"stock_name".$dn}=$dadan_array4[1]; 16 ${"open_price".$dn}=$dadan_array2[1]; 17 ${"ytd_close_price".$dn}=$dadan_array2[2]; 18 ${"high_price".$dn}=$dadan_array2[4]; 19 ${"current_price".$dn}=$dadan_array2[3]; 20 ${"low_price".$dn}=$dadan_array2[5]; 21 ${"amount_number".$dn}=$dadan_array2[8]; 22 ${"amount_price".$dn}=$dadan_array2[9]; 23 ${"stock_time".$dn}=$dadan_array2[30]." ".$dadan_array2[31]; 24 } 25 $subject=""; 26 for($xxx=0;$xxx<sizeof($dadan_array3)-1;$xxx++){ 27 $info[0]=${"current_price".$xxx}-0; 28 $info[1]=number_format(${"current_price".$xxx}-${"open_price".$xxx},2);//changes 29 $info[2]=number_format($info[1]/$info[0]*100,2);//changes rate 30 $info[3]=‘-‘; 31 $info[4]=${"ytd_close_price".$xxx}; 32 $info[5]=${"high_price".$xxx}; 33 $info[6]=${"low_price".$xxx}; 34 $info[7]=number_format(($info[5]+$info[6])/2,2);//average price 35 $info[8]=${"open_price".$xxx}; 36 $info[9]=${"amount_number".$xxx}; 37 $info[10]=‘-‘;//现手 38 $info[11]=‘-‘;//换手 39 $info[12]=‘-‘;//量比 40 $info[13]=‘‘;// 41 $info[14]=number_format(${"amount_price".$xxx}/10000,2);//成交金额 42 $info[15]=${"stock_name".$xxx}; 43 $info[16]=${"stock_id".$xxx}; 44 $chengjiao=$info[9]/100; 45 $highest=$info[5]+0; 46 $lowest=$info[6]+0; 47 $now_date=${"stock_time".$xxx};; 48 // if($info[16])$subject.=$now_date." ".$info[16]."(".$info[15]."), 当前价:".$info[0].",涨跌:".$info[1]."(".$info[2]."%),市盈率: ".$info[3]." ,最高价: ".$info[5]." ,均价: ".$info[7]." ,总手: ".$info[9]." ,换手: ".$info[11]."%,成交量: ".$chengjiao."(手),昨收: ".$info[4]." ,最低价: ".$info[6].",开盘: ".$info[8]." ,现手: ".$info[10]." ,量比: ".$info[12]." ,成交金额: ".$info[14]."(万元)。 "; 49 if($info[16]){ 50 $stock_number=str_replace("sz","",$stock_id); 51 $stock_number=str_replace("sh","",$stock_number); 52 if(substr($stock_id,0,2)=="sz"){ 53 $cat="股票(深市)"; 54 } 55 else{ 56 $cat="股票(沪市)"; 57 } 58 $subject.=$now_date." ".$info[16]."(".$info[15]."), 当前价:".$info[0].",涨跌:".$info[1]."(".$info[2]."%),最高价: ".$info[5]." ,均价: ".$info[7]." ,总手: ".$info[9]." ,成交量: ".$chengjiao."(手),昨收: ".$info[4]." ,最低价: ".$info[6].",开盘: ".$info[8]." ,成交金额: ".$info[14]."(万元)。"."\n"; 59 if($stock_id!="sh000001,sz399001"){ 60 $subject.="如果您还想了解更多信息,请输入以下数字来查看:"."\n"; 61 $subject.="[1] 查看该股票的新闻"."\n"; 62 $subject.="[2] 查看该股票的股评"."\n"; 63 $subject.="[3] 查看该股票的公司情况"."\n"; 64 } 65 } 66 } 67 return $subject; 68 }
1 case "gupiao": 2 $contentStr = $this->get_stock_info($stock_id); 3 $this->weixin_output($contentStr,$textTpl,$fromUsername,$toUsername,$time); 4 break;
标签:
原文地址:http://www.cnblogs.com/qianzhiyan/p/4739208.html