From b66952ad981bfa20516d5a5923e0a960fb438544 Mon Sep 17 00:00:00 2001 From: stakeswky <64798754+stakeswky@users.noreply.github.com> Date: Sat, 20 May 2023 17:04:12 +0800 Subject: [PATCH] Create useSearch.ts (#35) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 联网功能 --- src/service/plugins/useSearch.ts | 35 ++++++++++++++++++++++++++++++++ 1 file changed, 35 insertions(+) create mode 100644 src/service/plugins/useSearch.ts diff --git a/src/service/plugins/useSearch.ts b/src/service/plugins/useSearch.ts new file mode 100644 index 000000000..baab72b9e --- /dev/null +++ b/src/service/plugins/useSearch.ts @@ -0,0 +1,35 @@ +import axios from 'axios'; + +{/*Bing 搜索*/} +const BingSearch = async (wait_val: string) => { + const response = await axios.post("newbing中转服务器", { + prompt: wait_val, + }); + const result = response.data.result; + return result; +}; + + +{/*google 搜索*/} +const GoogleSearch = async (wait_val: string) => { + + const response = await axios.get('https://www.googleapis.com/customsearch/v1', { + params: { + key: google_api, + q: wait_val, + cx: searchEngineId, + start: 1, + num: 3, + dateRestrict: 'm[1]', //搜索结果限定为一个月内 + }, + }); + const results = response.data.items; + if (results !== null) { + const result = results.map((item: { snippet: string }) => item.snippet).join('\n'); + return result; + } + } +export { + BingSearch, + GoogleSearch +};