Skip to content

Commit

Permalink
fix some problems
Browse files Browse the repository at this point in the history
  • Loading branch information
angl committed Aug 30, 2019
1 parent b120c9f commit 34d9e25
Showing 1 changed file with 22 additions and 20 deletions.
42 changes: 22 additions & 20 deletions zhihu.php
Original file line number Diff line number Diff line change
@@ -1,35 +1,37 @@
<?php


require_once('workflows.php');
$zh_url = "http://www.zhihu.com";

$wf = new Workflows();

$orig = "{query}";
$orig = "你好";
$opptions = array(
CURLOPT_HTTPHEADER => array(
'User-Agent: Mozilla/5.0 (Macintosh; Intel Mac OS X 10_10_5) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/44.0.2403.157 Safari/537.36'
)
);

$data = $wf->request( "https://www.zhihu.com/autocomplete?max_matches=10&use_similar=0&token=".urlencode( $orig ) ,$opptions);

var_dump($data);
$data = json_decode( $data );
$data = $data[0];

for( $i=1; $i<count($data); $i++) {
$item = $data[$i];


if( $item[0] == "question" ) {
$link = "$zh_url/$item[0]/$item[3]";
} else {
$link = "$zh_url/$item[0]/$item[2]";
$data = $wf->request("https://www.zhihu.com/api/v4/search_v3?t=general&q=" . urlencode($orig), $opptions);
$data = json_decode($data, true);

$paging = $data['paging'];
$results = $data['data'];

foreach ($results as $key => $item) {
if ($item['type'] !== 'search_result') continue;
//search result
if ($item['object']['type'] == 'article') {
$link = "https://zhuanlan.zhihu.com/p/" . $item['object']['id'];
} elseif ($item['object']['type'] == 'question') {
$link = "https://www.zhihu.com/question/" . $item['object']['id'];
} elseif ($item['object']['type'] == 'answer') {
$link = "https://www.zhihu.com/question/" . $item['object']['question']['id'] . '/answer/'. $item['object']['id'];
}

$icon = "appicons/$item[0].png";

$wf->result( $int++.'.'.time(), $link , $item[1], "[$item[0]] $item[1]", $icon );
$title = strip_tags($item['highlight']['title']);
$desc = strip_tags($item['highlight']['description']);
$icon = 'appicons/' . $item['object']['type'] . '.png';
$wf->result($int++ . '.' . time(), $link, $title, "$desc", $icon);
}

echo $wf->toxml();

0 comments on commit 34d9e25

Please sign in to comment.