eoLinker-API_Shop_成语大全_API接口_C#调用示例代码
eoLinker-API_Shop_今日热门新闻查询_API接口_C#调用示例代码
eoLinker-API Shop 今日热门新闻查询 C#调用示例代码今日热门新闻查询提供最新最及时的新闻信息,包含头条、新闻、财经、体育、娱乐、军事、教育、科技、NBA、股票、星座、女性、健康、育儿等频道,20分钟更新一次;由于数据量较大,如出现请求超时,请多请求一次。
该产品拥有以下APIs:1.查询新闻频道2.新闻获取注意,该示例代码仅适用于网站下API使用该产品前,您需要通过https:///#/api/detail/?productID=92申请API服务1.查询新闻频道using System;using System.Collections.Generic;using System.IO;using ;using System.Text;using System.Web.Script.Serialization;namespace apishop_sdk{class Program{/*** 转发请求到目的主机* @param method string 请求方法* @param url string 请求地址* @param params Dictionary<string,string> 请求参数* @param headers Dictionary<string,string> 请求头* @return string**/static string apishop_send_request(string method, string url, D ictionary<string, string> param, Dictionary<string, string> headers){string result = string.Empty;try{string paramData = "";if (param != null && param.Count > 0){StringBuilder sbuilder = new StringBuilder();foreach (var item in param){if (sbuilder.Length > 0){sbuilder.Append("&");}sbuilder.Append(item.Key + "=" + item.Value);}paramData = sbuilder.ToString();}method = method.ToUpper();if (method == "GET"){url = string.Format("{0}?{1}", url, paramData);}HttpWebRequest wbRequest = (HttpWebRequest)WebRequest.C reate(url);if (method == "GET"){wbRequest.Method = "GET";}else if (method == "POST"){wbRequest.Method = "POST";wbRequest.ContentType = "application/x-www-form-url encoded";wbRequest.ContentLength = Encoding.UTF8.GetByteCoun t(paramData);using (Stream requestStream = wbRequest.GetRequestS tream()){using (StreamWriter swrite = new StreamWriter(r equestStream)){swrite.Write(paramData);}}}HttpWebResponse wbResponse = (HttpWebResponse)wbRequest. GetResponse();using (Stream responseStream = wbResponse.GetResponseSt ream()){using (StreamReader sread = new StreamReader(respon seStream)){result = sread.ReadToEnd();}}}catch{return "";}return result;}class Response{public string statusCode;}static void Main(string[] args){string method = "POST";string url = "https:///common/news/getNewsCh annel";Dictionary<string, string> param = new Dictionary<string, s tring>();param.Add("apiKey", "your_api_key"); //需要从www.apishop.ne t获取Dictionary<string, string> headers = null;string result = apishop_send_request(method, url, param, he aders);if (result == ""){//返回内容异常,发送请求失败Console.WriteLine("发送请求失败");return;}Response res = new JavaScriptSerializer().Deserialize<Respo nse>(result);if (res.statusCode == "000000"){//状态码为000000, 说明请求成功Console.WriteLine(string.Format("请求成功: {0}", resul t));}else{//状态码非000000, 说明请求失败Console.WriteLine(string.Format("请求失败: {0}", resul t));}Console.ReadLine();}}}2.新闻获取using System;using System.Collections.Generic;using System.IO;using ;using System.Text;using System.Web.Script.Serialization;namespace apishop_sdk{class Program{/*** 转发请求到目的主机* @param method string 请求方法* @param url string 请求地址* @param params Dictionary<string,string> 请求参数* @param headers Dictionary<string,string> 请求头* @return string**/static string apishop_send_request(string method, string url, D ictionary<string, string> param, Dictionary<string, string> headers){string result = string.Empty;try{string paramData = "";if (param != null && param.Count > 0){StringBuilder sbuilder = new StringBuilder();foreach (var item in param){if (sbuilder.Length > 0){sbuilder.Append("&");}sbuilder.Append(item.Key + "=" + item.Value); }paramData = sbuilder.ToString();}method = method.ToUpper();if (method == "GET"){url = string.Format("{0}?{1}", url, paramData);}HttpWebRequest wbRequest = (HttpWebRequest)WebRequest.C reate(url);if (method == "GET"){wbRequest.Method = "GET";}else if (method == "POST"){wbRequest.Method = "POST";wbRequest.ContentType = "application/x-www-form-url encoded";wbRequest.ContentLength = Encoding.UTF8.GetByteCoun t(paramData);using (Stream requestStream = wbRequest.GetRequestS tream()){using (StreamWriter swrite = new StreamWriter(r equestStream)){swrite.Write(paramData);}}}HttpWebResponse wbResponse = (HttpWebResponse)wbRequest. GetResponse();using (Stream responseStream = wbResponse.GetResponseSt ream()){using (StreamReader sread = new StreamReader(respon seStream)){result = sread.ReadToEnd();}}}catch{return "";}return result;}class Response{public string statusCode;}static void Main(string[] args){string method = "POST";string url = "https:///common/news/getNews"; Dictionary<string, string> param = new Dictionary<string, s tring>();param.Add("apiKey", "your_api_key"); //需要从www.apishop.ne t获取param.Add("channel", ""); //新闻频道,如"头条"param.Add("num", ""); //数量,最大40,默认10param.Add("start", ""); //开始位置,默认为0Dictionary<string, string> headers = null;string result = apishop_send_request(method, url, param, he aders);if (result == ""){//返回内容异常,发送请求失败Console.WriteLine("发送请求失败");return;}Response res = new JavaScriptSerializer().Deserialize<Respo nse>(result);if (res.statusCode == "000000"){//状态码为000000, 说明请求成功Console.WriteLine(string.Format("请求成功: {0}", resul t));}else{//状态码非000000, 说明请求失败Console.WriteLine(string.Format("请求失败: {0}", resul t));}Console.ReadLine();}}}。
eoLinker-API_Shop_淘宝热词查询_API接口_Python调用示例代码
eoLinker-API Shop 淘宝热词查询 Python调用示例代码淘宝热词查询根据用户输入的关键词,实时查询该词在全站的搜索排名,协助商家全面掌控搜索关键词近期的市场排名,分布特征等。
该产品拥有以下APIs:1.淘宝热搜查询注意,该示例代码仅适用于网站下API使用该产品前,您需要通过https:///#/api/detail/?productID=212申请API服务1.淘宝热搜查询#!/usr/bin/env python# -*- coding: utf-8 -*-# 测试环境: python2.7# 安装requests依赖 => pip install requests/ easy_install requests# 导入requests依赖import requestsimport jsonimport sysreload(sys)sys.setdefaultencoding('utf-8')def apishop_send_request(method, url, params=None, headers=None):'''转发请求到目的主机@param method str 请求方法@param url str 请求地址@param params dict 请求参数@param headers dict 请求头'''method = str.upper(method)if method == 'POST':return requests.post(url=url, data=params, headers=headers)elif method == 'GET':return requests.get(url=url, params=params, headers=headers)else:return Nonemethod = "POST"url = "https:///common/shopping/queryTBRelatedHotWords" headers = Noneparams = {"apiKey":"your_api_key", #需要从获取"keyword":"" #查询关键字}result = apishop_send_request(method=method, url=url, params=params, he aders=headers)if result:body = result.textresponse = json.loads(body)status_code = response["statusCode"]if (status_code == '000000'):# 状态码为000000, 说明请求成功print('请求成功:%s' % (body,))else:# 状态码非000000, 说明请求失败print('请求失败: %s' % (body,))else:# 返回内容异常,发送请求失败print('发送请求失败')。
eoLinker-API_Shop_手机号归属地查询_API接口_Python调用示例代码
eoLinker-API Shop 手机号归属地查询 Python调用示例代码手机号归属地查询根据中国大陆手机号获取归属地信息。
该产品拥有以下APIs:1.根据手机号获取归属地信息注意,该示例代码仅适用于网站下API使用该产品前,您需要通过https:///#/api/detail/?productID=72申请API服务1.根据手机号获取归属地信息#!/usr/bin/env python# -*- coding: utf-8 -*-# 测试环境: python2.7# 安装requests依赖 => pip install requests/ easy_install requests# 导入requests依赖import requestsimport jsonimport sysreload(sys)sys.setdefaultencoding('utf-8')def apishop_send_request(method, url, params=None, headers=None):'''转发请求到目的主机@param method str 请求方法@param url str 请求地址@param params dict 请求参数@param headers dict 请求头'''method = str.upper(method)if method == 'POST':return requests.post(url=url, data=params, headers=headers)elif method == 'GET':return requests.get(url=url, params=params, headers=headers)else:return Nonemethod = "POST"url = "https:///communication/phone/getLocationByPhoneNu m"headers = Noneparams = {"apiKey":"your_api_key", #需要从获取"phoneNum":"" #目标手机号或手机号前7位}result = apishop_send_request(method=method, url=url, params=params, he aders=headers)if result:body = result.textresponse = json.loads(body)status_code = response["statusCode"]if (status_code == '000000'):# 状态码为000000, 说明请求成功print('请求成功:%s' % (body,))else:# 状态码非000000, 说明请求失败print('请求失败: %s' % (body,))else:# 返回内容异常,发送请求失败print('发送请求失败')。
eoLinker-API_Shop_股票行情数据_API接口_Python调用示例代码
eoLinker-API Shop 股票行情数据 Python调用示例代码股票行情数据支持证券全市场行情数据,实时数据,K线数据,分笔数据,市场股票代码信息,历史数据等等,满足证券投资分析使用。
该产品拥有以下APIs:1.股票k线2.实时行情查询3.查询股票列表4.查询股票市场5.分笔6.分时查询7.指数实时报价8.组合行情查询9.综合排名注意,该示例代码仅适用于网站下API使用该产品前,您需要通过https:///#/api/detail/?productID=168申请API服务1.股票k线#!/usr/bin/env python# -*- coding: utf-8 -*-# 测试环境: python2.7# 安装requests依赖 => pip install requests/ easy_install requests# 导入requests依赖import requestsimport jsonimport sysreload(sys)sys.setdefaultencoding('utf-8')def apishop_send_request(method, url, params=None, headers=None):'''转发请求到目的主机@param method str 请求方法@param url str 请求地址@param params dict 请求参数@param headers dict 请求头'''method = str.upper(method)if method == 'POST':return requests.post(url=url, data=params, headers=headers)elif method == 'GET':return requests.get(url=url, params=params, headers=headers)else:return Nonemethod = "POST"url = "https:///mlhexpsz/stock/kline"headers = Noneparams = {"apiKey":"your_api_key", #需要从获取"stock_code":"" #股票代码"period":"" #1:1分钟 2:5分钟 3:15分钟 4:30分钟 5:60分钟 6:日k 线 7:周k线 8:月k线"request_num":"" #请求行数"position_str":"" #定位串,默认-1 从头开始}result = apishop_send_request(method=method, url=url, params=params, he aders=headers)if result:body = result.textresponse = json.loads(body)status_code = response["statusCode"]if (status_code == '000000'):# 状态码为000000, 说明请求成功print('请求成功:%s' % (body,))else:# 状态码非000000, 说明请求失败print('请求失败: %s' % (body,))else:# 返回内容异常,发送请求失败print('发送请求失败')2.实时行情查询#!/usr/bin/env python# -*- coding: utf-8 -*-# 测试环境: python2.7# 安装requests依赖 => pip install requests/ easy_install requests# 导入requests依赖import requestsimport jsonimport sysreload(sys)sys.setdefaultencoding('utf-8')def apishop_send_request(method, url, params=None, headers=None):'''转发请求到目的主机@param method str 请求方法@param url str 请求地址@param params dict 请求参数@param headers dict 请求头'''method = str.upper(method)if method == 'POST':return requests.post(url=url, data=params, headers=headers)elif method == 'GET':return requests.get(url=url, params=params, headers=headers)else:return Nonemethod = "POST"url = "https:///mlhexpsz/stock/realtime"headers = Noneparams = {"apiKey":"your_api_key", #需要从获取"stock_code":"" #股票代码}result = apishop_send_request(method=method, url=url, params=params, he aders=headers)if result:body = result.textresponse = json.loads(body)status_code = response["statusCode"]if (status_code == '000000'):# 状态码为000000, 说明请求成功print('请求成功:%s' % (body,))else:# 状态码非000000, 说明请求失败print('请求失败: %s' % (body,))else:# 返回内容异常,发送请求失败print('发送请求失败')3.查询股票列表#!/usr/bin/env python# -*- coding: utf-8 -*-# 测试环境: python2.7# 安装requests依赖 => pip install requests/ easy_install requests# 导入requests依赖import requestsimport jsonimport sysreload(sys)sys.setdefaultencoding('utf-8')def apishop_send_request(method, url, params=None, headers=None):'''转发请求到目的主机@param method str 请求方法@param url str 请求地址@param params dict 请求参数@param headers dict 请求头'''method = str.upper(method)if method == 'POST':return requests.post(url=url, data=params, headers=headers)elif method == 'GET':return requests.get(url=url, params=params, headers=headers)else:return Nonemethod = "POST"url = "https:///mlhexpsz/stock/list"headers = Noneparams = {"apiKey":"your_api_key", #需要从获取"stock_type":"" #市场类别"request_num":"" #定位串,传空默认为20"position_str":"" #起始位空,从应答中获取}result = apishop_send_request(method=method, url=url, params=params, he aders=headers)if result:body = result.textresponse = json.loads(body)status_code = response["statusCode"]if (status_code == '000000'):# 状态码为000000, 说明请求成功print('请求成功:%s' % (body,))else:# 状态码非000000, 说明请求失败print('请求失败: %s' % (body,))else:# 返回内容异常,发送请求失败print('发送请求失败')4.查询股票市场#!/usr/bin/env python# -*- coding: utf-8 -*-# 测试环境: python2.7# 安装requests依赖 => pip install requests/ easy_install requests# 导入requests依赖import requestsimport jsonimport sysreload(sys)sys.setdefaultencoding('utf-8')def apishop_send_request(method, url, params=None, headers=None):'''转发请求到目的主机@param method str 请求方法@param url str 请求地址@param params dict 请求参数@param headers dict 请求头'''method = str.upper(method)if method == 'POST':return requests.post(url=url, data=params, headers=headers) elif method == 'GET':return requests.get(url=url, params=params, headers=headers) else:return Nonemethod = "POST"url = "https:///mlhexpsz/stock/market"headers = Noneparams = {"apiKey":"your_api_key", #需要从获取}result = apishop_send_request(method=method, url=url, params=params, he aders=headers)if result:body = result.textresponse = json.loads(body)status_code = response["statusCode"]if (status_code == '000000'):# 状态码为000000, 说明请求成功print('请求成功:%s' % (body,))else:# 状态码非000000, 说明请求失败print('请求失败: %s' % (body,))else:# 返回内容异常,发送请求失败print('发送请求失败')5.分笔#!/usr/bin/env python# -*- coding: utf-8 -*-# 测试环境: python2.7# 安装requests依赖 => pip install requests/ easy_install requests# 导入requests依赖import requestsimport jsonimport sysreload(sys)sys.setdefaultencoding('utf-8')def apishop_send_request(method, url, params=None, headers=None):'''转发请求到目的主机@param method str 请求方法@param url str 请求地址@param params dict 请求参数@param headers dict 请求头'''method = str.upper(method)if method == 'POST':return requests.post(url=url, data=params, headers=headers)elif method == 'GET':return requests.get(url=url, params=params, headers=headers)else:return Nonemethod = "POST"url = "https:///mlhexpsz/stock/tick"headers = Noneparams = {"apiKey":"your_api_key", #需要从获取"stock_code":"" #股票代码"request_num":"" #请求参数}result = apishop_send_request(method=method, url=url, params=params, he aders=headers)if result:body = result.textresponse = json.loads(body)status_code = response["statusCode"]if (status_code == '000000'):# 状态码为000000, 说明请求成功print('请求成功:%s' % (body,))else:# 状态码非000000, 说明请求失败print('请求失败: %s' % (body,))else:# 返回内容异常,发送请求失败print('发送请求失败')6.分时查询#!/usr/bin/env python# -*- coding: utf-8 -*-# 测试环境: python2.7# 安装requests依赖 => pip install requests/ easy_install requests# 导入requests依赖import requestsimport jsonimport sysreload(sys)sys.setdefaultencoding('utf-8')def apishop_send_request(method, url, params=None, headers=None):'''转发请求到目的主机@param method str 请求方法@param url str 请求地址@param params dict 请求参数@param headers dict 请求头'''method = str.upper(method)if method == 'POST':return requests.post(url=url, data=params, headers=headers)elif method == 'GET':return requests.get(url=url, params=params, headers=headers)else:return Nonemethod = "POST"url = "https:///mlhexpsz/stock/trend"headers = Noneparams = {"apiKey":"your_api_key", #需要从获取"stock_code":"" #股票代码}result = apishop_send_request(method=method, url=url, params=params, he aders=headers)if result:body = result.textresponse = json.loads(body)status_code = response["statusCode"]if (status_code == '000000'):# 状态码为000000, 说明请求成功print('请求成功:%s' % (body,))else:# 状态码非000000, 说明请求失败print('请求失败: %s' % (body,))else:# 返回内容异常,发送请求失败print('发送请求失败')7.指数实时报价#!/usr/bin/env python# -*- coding: utf-8 -*-# 测试环境: python2.7# 安装requests依赖 => pip install requests/ easy_install requests# 导入requests依赖import requestsimport jsonimport sysreload(sys)sys.setdefaultencoding('utf-8')def apishop_send_request(method, url, params=None, headers=None):'''转发请求到目的主机@param method str 请求方法@param url str 请求地址@param params dict 请求参数@param headers dict 请求头'''method = str.upper(method)if method == 'POST':return requests.post(url=url, data=params, headers=headers)elif method == 'GET':return requests.get(url=url, params=params, headers=headers)else:return Nonemethod = "POST"url = "https:///mlhexpsz/stock/index"headers = Noneparams = {"apiKey":"your_api_key", #需要从获取"stock_code":"" #代码}result = apishop_send_request(method=method, url=url, params=params, he aders=headers)if result:body = result.textresponse = json.loads(body)status_code = response["statusCode"]if (status_code == '000000'):# 状态码为000000, 说明请求成功print('请求成功:%s' % (body,))else:# 状态码非000000, 说明请求失败print('请求失败: %s' % (body,))else:# 返回内容异常,发送请求失败print('发送请求失败')8.组合行情查询#!/usr/bin/env python# -*- coding: utf-8 -*-# 测试环境: python2.7# 安装requests依赖 => pip install requests/ easy_install requests# 导入requests依赖import requestsimport jsonimport sysreload(sys)sys.setdefaultencoding('utf-8')def apishop_send_request(method, url, params=None, headers=None):'''转发请求到目的主机@param method str 请求方法@param url str 请求地址@param params dict 请求参数@param headers dict 请求头'''method = str.upper(method)if method == 'POST':return requests.post(url=url, data=params, headers=headers)elif method == 'GET':return requests.get(url=url, params=params, headers=headers)else:return Nonemethod = "POST"url = "https:///mlhexpsz/stock/comb"headers = Noneparams = {"apiKey":"your_api_key", #需要从获取"stock_code":"" #股票代码}result = apishop_send_request(method=method, url=url, params=params, he aders=headers)if result:body = result.textresponse = json.loads(body)status_code = response["statusCode"]if (status_code == '000000'):# 状态码为000000, 说明请求成功print('请求成功:%s' % (body,))else:# 状态码非000000, 说明请求失败print('请求失败: %s' % (body,))else:# 返回内容异常,发送请求失败print('发送请求失败')9.综合排名#!/usr/bin/env python# -*- coding: utf-8 -*-# 测试环境: python2.7# 安装requests依赖 => pip install requests/ easy_install requests# 导入requests依赖import requestsimport jsonimport sysreload(sys)sys.setdefaultencoding('utf-8')def apishop_send_request(method, url, params=None, headers=None):'''转发请求到目的主机@param method str 请求方法@param url str 请求地址@param params dict 请求参数@param headers dict 请求头'''method = str.upper(method)if method == 'POST':return requests.post(url=url, data=params, headers=headers) elif method == 'GET':return requests.get(url=url, params=params, headers=headers) else:return Nonemethod = "POST"url = "https:///mlhexpsz/stock/sort"headers = Noneparams = {"apiKey":"your_api_key", #需要从获取"stock_type":"" #股票类别,参考市场查询返回值"sort_type":"" #排序类别}result = apishop_send_request(method=method, url=url, params=params, he aders=headers)if result:body = result.textresponse = json.loads(body)status_code = response["statusCode"]if (status_code == '000000'):# 状态码为000000, 说明请求成功print('请求成功:%s' % (body,))else:# 状态码非000000, 说明请求失败print('请求失败: %s' % (body,))else:# 返回内容异常,发送请求失败print('发送请求失败')。
eoLinker-API_Shop_成语大全_API接口_PHP调用示例代码
eoLinker-API Shop 成语大全 PHP调用示例代码成语大全包含发音、解释、出自典故、近义词、反义词、例句等数据,可进行成语接龙、成语竞猜等游戏开发。
该产品拥有以下APIs:1.成语搜索2.查询成语详情注意,该示例代码仅适用于网站下API使用该产品前,您需要通过https:///#/api/detail/?productID=93申请API服务1.成语搜索<?php$method = "POST";$url = "https:///common/chengyu/searchChengyu"; $headers = NULL;$params = array("keyWord"=>"" //关键字,如"蛇");$result = apishop_curl($method, $url, $headers, $params);If ($result) {$body = json_decode($result["body"], TRUE);$status_code = $body["statusCode"];If ($status_code == "000000") {//状态码为000000, 说明请求成功echo "请求成功:" . $result["body"];} else {//状态码非000000, 说明请求失败echo "请求失败:" . $result["body"];}} else {//返回内容异常,发送请求失败,以下可根据业务逻辑自行修改echo "发送请求失败";}/*** 转发请求到目的主机* @param $method string 请求方法* @param $URL string 请求地址* @param null $headers 请求头* @param null $param 请求参数* @return array|bool*/function apishop_curl(&$method, &$URL, &$headers = NULL, &$param = NULL) {// 初始化请求$require = curl_init($URL);// 判断是否HTTPS$isHttps = substr($URL, 0, 8) == "https://" ? TRUE : FALSE;// 设置请求方式switch ($method) {case "GET":curl_setopt($require, CURLOPT_CUSTOMREQUEST, "GET");break;case "POST":curl_setopt($require, CURLOPT_CUSTOMREQUEST, "POST");break;default:return FALSE;}if ($param) {curl_setopt($require, CURLOPT_POSTFIELDS, $param);}if ($isHttps) {// 跳过证书检查curl_setopt($require, CURLOPT_SSL_VERIFYPEER, FALSE);// 检查证书中是否设置域名curl_setopt($require, CURLOPT_SSL_VERIFYHOST, 2);}if ($headers) {// 设置请求头curl_setopt($require, CURLOPT_HTTPHEADER, $headers);}// 返回结果不直接输出curl_setopt($require, CURLOPT_RETURNTRANSFER, TRUE);// 重定向curl_setopt($require, CURLOPT_FOLLOWLOCATION, TRUE);// 把返回头包含再输出中curl_setopt($require, CURLOPT_HEADER, TRUE);// 发送请求$response = curl_exec($require);// 获取头部长度$headerSize = curl_getinfo($require, CURLINFO_HEADER_SIZE);// 关闭请求curl_close($require);if ($response) {// 返回头部字符串$header = substr($response, 0, $headerSize);// 返回体$body = substr($response, $headerSize);// 过滤隐藏非法字符$bodyTemp = json_encode(array(0 => $body));$bodyTemp = str_replace("", "", $bodyTemp);$bodyTemp = json_decode($bodyTemp, TRUE);$body = trim($bodyTemp[0]);// 将返回结果头部转成数组$respondHeaders = array();$header_rows = array_filter(explode(PHP_EOL, $header), "trim"); foreach ($header_rows as $row) {$keylen = strpos($row, ":");if ($keylen) {$respondHeaders[] = array("key" => substr($row, 0, $keylen),"value" => trim(substr($row, $keylen + 1)));}}return array("headers" => $respondHeaders,"body" => $body);} else {return FALSE;}}2.查询成语详情<?php$method = "POST";$url = "https:///common/chengyu/getChengyuDetail"; $headers = NULL;$params = array("chengyu"=>"" //要查询的成语,如“打草惊蛇”);$result = apishop_curl($method, $url, $headers, $params);If ($result) {$body = json_decode($result["body"], TRUE);$status_code = $body["statusCode"];If ($status_code == "000000") {//状态码为000000, 说明请求成功echo "请求成功:" . $result["body"];} else {//状态码非000000, 说明请求失败echo "请求失败:" . $result["body"];}} else {//返回内容异常,发送请求失败,以下可根据业务逻辑自行修改echo "发送请求失败";}/*** 转发请求到目的主机* @param $method string 请求方法* @param $URL string 请求地址* @param null $headers 请求头* @param null $param 请求参数* @return array|bool*/function apishop_curl(&$method, &$URL, &$headers = NULL, &$param = NULL) {// 初始化请求$require = curl_init($URL);// 判断是否HTTPS$isHttps = substr($URL, 0, 8) == "https://" ? TRUE : FALSE;// 设置请求方式switch ($method) {case "GET":curl_setopt($require, CURLOPT_CUSTOMREQUEST, "GET");break;case "POST":curl_setopt($require, CURLOPT_CUSTOMREQUEST, "POST");break;default:return FALSE;}if ($param) {curl_setopt($require, CURLOPT_POSTFIELDS, $param);}if ($isHttps) {// 跳过证书检查curl_setopt($require, CURLOPT_SSL_VERIFYPEER, FALSE);// 检查证书中是否设置域名curl_setopt($require, CURLOPT_SSL_VERIFYHOST, 2);}if ($headers) {// 设置请求头curl_setopt($require, CURLOPT_HTTPHEADER, $headers);}// 返回结果不直接输出curl_setopt($require, CURLOPT_RETURNTRANSFER, TRUE);// 重定向curl_setopt($require, CURLOPT_FOLLOWLOCATION, TRUE);// 把返回头包含再输出中curl_setopt($require, CURLOPT_HEADER, TRUE);// 发送请求$response = curl_exec($require);// 获取头部长度$headerSize = curl_getinfo($require, CURLINFO_HEADER_SIZE);// 关闭请求curl_close($require);if ($response) {// 返回头部字符串$header = substr($response, 0, $headerSize);// 返回体$body = substr($response, $headerSize);// 过滤隐藏非法字符$bodyTemp = json_encode(array(0 => $body));$bodyTemp = str_replace("", "", $bodyTemp);$bodyTemp = json_decode($bodyTemp, TRUE);$body = trim($bodyTemp[0]);// 将返回结果头部转成数组$respondHeaders = array();$header_rows = array_filter(explode(PHP_EOL, $header), "trim"); foreach ($header_rows as $row) {$keylen = strpos($row, ":");if ($keylen) {$respondHeaders[] = array("key" => substr($row, 0, $keylen),"value" => trim(substr($row, $keylen + 1)));}}return array("headers" => $respondHeaders,"body" => $body);} else {return FALSE;}}。
新版eoLinker_API_Shop_股票行情数据_API接口_PHP调用示例代码.doc
eoLinker-API Shop 股票行情数据 PHP调用示例代码股票行情数据支持证券全市场行情数据,实时数据,K线数据,分笔数据,市场股票代码信息,历史数据等等,满足证券投资分析使用。
该产品拥有以下APIs:1.股票k线2.实时行情查询3.查询股票列表4.查询股票市场5.分笔6.分时查询7.指数实时报价8.组合行情查询9.综合排名注意,该示例代码仅适用于网站下API使用该产品前,您需要通过https:///#/api/detail/?productID=168申请API服务1.股票k线<?php$method = "POST";$url = "https:///mlhexpsz/stock/kline";$headers = NULL;$params = array("apiKey"=>"your_api_key", //需要从获取"stock_code"=>"", //股票代码"period"=>"", //1:1分钟 2:5分钟 3:15分钟 4:30分钟 5:60分钟 6:日k线 7:周k线 8:月k线"request_num"=>"", //请求行数"position_str"=>"", //定位串,默认-1 从头开始);$result = apishop_curl($method, $url, $headers, $params);If ($result) {$body = json_decode($result["body"], TRUE);$status_code = $body["statusCode"];If ($status_code == "000000") {//状态码为000000, 说明请求成功echo "请求成功:" . $result["body"];} else {//状态码非000000, 说明请求失败echo "请求失败:" . $result["body"];}} else {//返回内容异常,发送请求失败,以下可根据业务逻辑自行修改echo "发送请求失败";}/*** 转发请求到目的主机* @param $method string 请求方法* @param $URL string 请求地址* @param null $headers 请求头* @param null $param 请求参数* @return array|bool*/function apishop_curl(&$method, &$URL, &$headers = NULL, &$param = NULL) {// 初始化请求$require = curl_init($URL);// 判断是否HTTPS$isHttps = substr($URL, 0, 8) == "https://" ? TRUE : FALSE;// 设置请求方式switch ($method) {case "GET":curl_setopt($require, CURLOPT_CUSTOMREQUEST, "GET");break;case "POST":curl_setopt($require, CURLOPT_CUSTOMREQUEST, "POST");break;default:return FALSE;}if ($param) {curl_setopt($require, CURLOPT_POSTFIELDS, $param);}if ($isHttps) {// 跳过证书检查curl_setopt($require, CURLOPT_SSL_VERIFYPEER, FALSE);// 检查证书中是否设置域名curl_setopt($require, CURLOPT_SSL_VERIFYHOST, 2);}if ($headers) {// 设置请求头curl_setopt($require, CURLOPT_HTTPHEADER, $headers);}// 返回结果不直接输出curl_setopt($require, CURLOPT_RETURNTRANSFER, TRUE);// 重定向curl_setopt($require, CURLOPT_FOLLOWLOCATION, TRUE);// 把返回头包含再输出中curl_setopt($require, CURLOPT_HEADER, TRUE);// 发送请求$response = curl_exec($require);// 获取头部长度$headerSize = curl_getinfo($require, CURLINFO_HEADER_SIZE);// 关闭请求curl_close($require);if ($response) {// 返回头部字符串$header = substr($response, 0, $headerSize);// 返回体$body = substr($response, $headerSize);// 过滤隐藏非法字符$bodyTemp = json_encode(array(0 => $body));$bodyTemp = str_replace("", "", $bodyTemp);$bodyTemp = json_decode($bodyTemp, TRUE);$body = trim($bodyTemp[0]);// 将返回结果头部转成数组$respondHeaders = array();$header_rows = array_filter(explode(PHP_EOL, $header), "trim"); foreach ($header_rows as $row) {$keylen = strpos($row, ":");if ($keylen) {$respondHeaders[] = array("key" => substr($row, 0, $keylen),"value" => trim(substr($row, $keylen + 1)));}}return array("headers" => $respondHeaders,"body" => $body);} else {return FALSE;}}2.实时行情查询<?php$method = "POST";$url = "https:///mlhexpsz/stock/realtime";$headers = NULL;$params = array("apiKey"=>"your_api_key", //需要从获取"stock_code"=>"", //股票代码);$result = apishop_curl($method, $url, $headers, $params);If ($result) {$body = json_decode($result["body"], TRUE);$status_code = $body["statusCode"];If ($status_code == "000000") {//状态码为000000, 说明请求成功echo "请求成功:" . $result["body"];} else {//状态码非000000, 说明请求失败echo "请求失败:" . $result["body"];}} else {//返回内容异常,发送请求失败,以下可根据业务逻辑自行修改echo "发送请求失败";}/*** 转发请求到目的主机* @param $method string 请求方法* @param $URL string 请求地址* @param null $headers 请求头* @param null $param 请求参数* @return array|bool*/function apishop_curl(&$method, &$URL, &$headers = NULL, &$param = NULL) {// 初始化请求$require = curl_init($URL);// 判断是否HTTPS$isHttps = substr($URL, 0, 8) == "https://" ? TRUE : FALSE;// 设置请求方式switch ($method) {case "GET":curl_setopt($require, CURLOPT_CUSTOMREQUEST, "GET");break;case "POST":curl_setopt($require, CURLOPT_CUSTOMREQUEST, "POST");break;default:return FALSE;}if ($param) {curl_setopt($require, CURLOPT_POSTFIELDS, $param);}if ($isHttps) {// 跳过证书检查curl_setopt($require, CURLOPT_SSL_VERIFYPEER, FALSE);// 检查证书中是否设置域名curl_setopt($require, CURLOPT_SSL_VERIFYHOST, 2);}if ($headers) {// 设置请求头curl_setopt($require, CURLOPT_HTTPHEADER, $headers);}// 返回结果不直接输出curl_setopt($require, CURLOPT_RETURNTRANSFER, TRUE);// 重定向curl_setopt($require, CURLOPT_FOLLOWLOCATION, TRUE);// 把返回头包含再输出中curl_setopt($require, CURLOPT_HEADER, TRUE);// 发送请求$response = curl_exec($require);// 获取头部长度$headerSize = curl_getinfo($require, CURLINFO_HEADER_SIZE);// 关闭请求curl_close($require);if ($response) {// 返回头部字符串$header = substr($response, 0, $headerSize);// 返回体$body = substr($response, $headerSize);// 过滤隐藏非法字符$bodyTemp = json_encode(array(0 => $body));$bodyTemp = str_replace("", "", $bodyTemp);$bodyTemp = json_decode($bodyTemp, TRUE);$body = trim($bodyTemp[0]);// 将返回结果头部转成数组$respondHeaders = array();$header_rows = array_filter(explode(PHP_EOL, $header), "trim"); foreach ($header_rows as $row) {$keylen = strpos($row, ":");if ($keylen) {$respondHeaders[] = array("key" => substr($row, 0, $keylen),"value" => trim(substr($row, $keylen + 1)) );}}return array("headers" => $respondHeaders,"body" => $body);} else {return FALSE;}}3.查询股票列表<?php$method = "POST";$url = "https:///mlhexpsz/stock/list"; $headers = NULL;$params = array("apiKey"=>"your_api_key", //需要从获取 "stock_type"=>"", //市场类别"request_num"=>"", //定位串,传空默认为20 "position_str"=>"", //起始位空,从应答中获取);$result = apishop_curl($method, $url, $headers, $params);If ($result) {$body = json_decode($result["body"], TRUE);$status_code = $body["statusCode"];If ($status_code == "000000") {//状态码为000000, 说明请求成功echo "请求成功:" . $result["body"];} else {//状态码非000000, 说明请求失败echo "请求失败:" . $result["body"];}} else {//返回内容异常,发送请求失败,以下可根据业务逻辑自行修改echo "发送请求失败";}/*** 转发请求到目的主机* @param $method string 请求方法* @param $URL string 请求地址* @param null $headers 请求头* @param null $param 请求参数* @return array|bool*/function apishop_curl(&$method, &$URL, &$headers = NULL, &$param = NULL) {// 初始化请求$require = curl_init($URL);// 判断是否HTTPS$isHttps = substr($URL, 0, 8) == "https://" ? TRUE : FALSE;// 设置请求方式switch ($method) {case "GET":curl_setopt($require, CURLOPT_CUSTOMREQUEST, "GET");break;case "POST":curl_setopt($require, CURLOPT_CUSTOMREQUEST, "POST");break;default:return FALSE;}if ($param) {curl_setopt($require, CURLOPT_POSTFIELDS, $param);}if ($isHttps) {// 跳过证书检查curl_setopt($require, CURLOPT_SSL_VERIFYPEER, FALSE);// 检查证书中是否设置域名curl_setopt($require, CURLOPT_SSL_VERIFYHOST, 2);}if ($headers) {// 设置请求头curl_setopt($require, CURLOPT_HTTPHEADER, $headers);}// 返回结果不直接输出curl_setopt($require, CURLOPT_RETURNTRANSFER, TRUE);// 重定向curl_setopt($require, CURLOPT_FOLLOWLOCATION, TRUE);// 把返回头包含再输出中curl_setopt($require, CURLOPT_HEADER, TRUE);// 发送请求$response = curl_exec($require);// 获取头部长度$headerSize = curl_getinfo($require, CURLINFO_HEADER_SIZE);// 关闭请求curl_close($require);if ($response) {// 返回头部字符串$header = substr($response, 0, $headerSize);// 返回体$body = substr($response, $headerSize);// 过滤隐藏非法字符$bodyTemp = json_encode(array(0 => $body));$bodyTemp = str_replace("", "", $bodyTemp);$bodyTemp = json_decode($bodyTemp, TRUE);$body = trim($bodyTemp[0]);// 将返回结果头部转成数组$respondHeaders = array();$header_rows = array_filter(explode(PHP_EOL, $header), "trim"); foreach ($header_rows as $row) {$keylen = strpos($row, ":");if ($keylen) {$respondHeaders[] = array("key" => substr($row, 0, $keylen),"value" => trim(substr($row, $keylen + 1)));}}return array("headers" => $respondHeaders,"body" => $body);} else {return FALSE;}}4.查询股票市场<?php$method = "POST";$url = "https:///mlhexpsz/stock/market";$headers = NULL;$params = array("apiKey"=>"your_api_key", //需要从获取);$result = apishop_curl($method, $url, $headers, $params);If ($result) {$body = json_decode($result["body"], TRUE);$status_code = $body["statusCode"];If ($status_code == "000000") {//状态码为000000, 说明请求成功echo "请求成功:" . $result["body"];} else {//状态码非000000, 说明请求失败echo "请求失败:" . $result["body"];}} else {//返回内容异常,发送请求失败,以下可根据业务逻辑自行修改echo "发送请求失败";}/*** 转发请求到目的主机* @param $method string 请求方法* @param $URL string 请求地址* @param null $headers 请求头* @param null $param 请求参数* @return array|bool*/function apishop_curl(&$method, &$URL, &$headers = NULL, &$param = NULL) {// 初始化请求$require = curl_init($URL);// 判断是否HTTPS$isHttps = substr($URL, 0, 8) == "https://" ? TRUE : FALSE;// 设置请求方式switch ($method) {case "GET":curl_setopt($require, CURLOPT_CUSTOMREQUEST, "GET");break;case "POST":curl_setopt($require, CURLOPT_CUSTOMREQUEST, "POST");break;default:return FALSE;}if ($param) {curl_setopt($require, CURLOPT_POSTFIELDS, $param);}if ($isHttps) {// 跳过证书检查curl_setopt($require, CURLOPT_SSL_VERIFYPEER, FALSE);// 检查证书中是否设置域名curl_setopt($require, CURLOPT_SSL_VERIFYHOST, 2);}if ($headers) {// 设置请求头curl_setopt($require, CURLOPT_HTTPHEADER, $headers);}// 返回结果不直接输出curl_setopt($require, CURLOPT_RETURNTRANSFER, TRUE);// 重定向curl_setopt($require, CURLOPT_FOLLOWLOCATION, TRUE);// 把返回头包含再输出中curl_setopt($require, CURLOPT_HEADER, TRUE);// 发送请求$response = curl_exec($require);// 获取头部长度$headerSize = curl_getinfo($require, CURLINFO_HEADER_SIZE);// 关闭请求curl_close($require);if ($response) {// 返回头部字符串$header = substr($response, 0, $headerSize);// 返回体$body = substr($response, $headerSize);// 过滤隐藏非法字符$bodyTemp = json_encode(array(0 => $body));$bodyTemp = str_replace("", "", $bodyTemp);$bodyTemp = json_decode($bodyTemp, TRUE);$body = trim($bodyTemp[0]);// 将返回结果头部转成数组$respondHeaders = array();$header_rows = array_filter(explode(PHP_EOL, $header), "trim"); foreach ($header_rows as $row) {$keylen = strpos($row, ":");if ($keylen) {$respondHeaders[] = array("key" => substr($row, 0, $keylen),"value" => trim(substr($row, $keylen + 1)));}}return array("headers" => $respondHeaders,"body" => $body);} else {return FALSE;}}5.分笔<?php$method = "POST";$url = "https:///mlhexpsz/stock/tick";$headers = NULL;$params = array("apiKey"=>"your_api_key", //需要从获取"stock_code"=>"", //股票代码"request_num"=>"", //请求参数);$result = apishop_curl($method, $url, $headers, $params);If ($result) {$body = json_decode($result["body"], TRUE);$status_code = $body["statusCode"];If ($status_code == "000000") {//状态码为000000, 说明请求成功echo "请求成功:" . $result["body"];} else {//状态码非000000, 说明请求失败echo "请求失败:" . $result["body"];}} else {//返回内容异常,发送请求失败,以下可根据业务逻辑自行修改echo "发送请求失败";}/*** 转发请求到目的主机* @param $method string 请求方法* @param $URL string 请求地址* @param null $headers 请求头* @param null $param 请求参数* @return array|bool*/function apishop_curl(&$method, &$URL, &$headers = NULL, &$param = NULL) {// 初始化请求$require = curl_init($URL);// 判断是否HTTPS$isHttps = substr($URL, 0, 8) == "https://" ? TRUE : FALSE;// 设置请求方式switch ($method) {case "GET":curl_setopt($require, CURLOPT_CUSTOMREQUEST, "GET");break;case "POST":curl_setopt($require, CURLOPT_CUSTOMREQUEST, "POST");break;default:return FALSE;}if ($param) {curl_setopt($require, CURLOPT_POSTFIELDS, $param);}if ($isHttps) {// 跳过证书检查curl_setopt($require, CURLOPT_SSL_VERIFYPEER, FALSE);// 检查证书中是否设置域名curl_setopt($require, CURLOPT_SSL_VERIFYHOST, 2);}if ($headers) {// 设置请求头curl_setopt($require, CURLOPT_HTTPHEADER, $headers);}// 返回结果不直接输出curl_setopt($require, CURLOPT_RETURNTRANSFER, TRUE);// 重定向curl_setopt($require, CURLOPT_FOLLOWLOCATION, TRUE);// 把返回头包含再输出中curl_setopt($require, CURLOPT_HEADER, TRUE);// 发送请求$response = curl_exec($require);// 获取头部长度$headerSize = curl_getinfo($require, CURLINFO_HEADER_SIZE);// 关闭请求curl_close($require);if ($response) {// 返回头部字符串$header = substr($response, 0, $headerSize);// 返回体$body = substr($response, $headerSize);// 过滤隐藏非法字符$bodyTemp = json_encode(array(0 => $body));$bodyTemp = str_replace("", "", $bodyTemp);$bodyTemp = json_decode($bodyTemp, TRUE);$body = trim($bodyTemp[0]);// 将返回结果头部转成数组$respondHeaders = array();$header_rows = array_filter(explode(PHP_EOL, $header), "trim"); foreach ($header_rows as $row) {$keylen = strpos($row, ":");if ($keylen) {$respondHeaders[] = array("key" => substr($row, 0, $keylen),"value" => trim(substr($row, $keylen + 1)) );}}return array("headers" => $respondHeaders,"body" => $body);} else {return FALSE;}}6.分时查询<?php$method = "POST";$url = "https:///mlhexpsz/stock/trend"; $headers = NULL;$params = array("apiKey"=>"your_api_key", //需要从获取 "stock_code"=>"", //股票代码);$result = apishop_curl($method, $url, $headers, $params);If ($result) {$body = json_decode($result["body"], TRUE);$status_code = $body["statusCode"];If ($status_code == "000000") {//状态码为000000, 说明请求成功echo "请求成功:" . $result["body"];} else {//状态码非000000, 说明请求失败echo "请求失败:" . $result["body"];}} else {//返回内容异常,发送请求失败,以下可根据业务逻辑自行修改echo "发送请求失败";}/*** 转发请求到目的主机* @param $method string 请求方法* @param $URL string 请求地址* @param null $headers 请求头* @param null $param 请求参数* @return array|bool*/function apishop_curl(&$method, &$URL, &$headers = NULL, &$param = NULL) {// 初始化请求$require = curl_init($URL);// 判断是否HTTPS$isHttps = substr($URL, 0, 8) == "https://" ? TRUE : FALSE;// 设置请求方式switch ($method) {case "GET":curl_setopt($require, CURLOPT_CUSTOMREQUEST, "GET");break;case "POST":curl_setopt($require, CURLOPT_CUSTOMREQUEST, "POST");break;default:return FALSE;}if ($param) {curl_setopt($require, CURLOPT_POSTFIELDS, $param);}if ($isHttps) {// 跳过证书检查curl_setopt($require, CURLOPT_SSL_VERIFYPEER, FALSE);// 检查证书中是否设置域名curl_setopt($require, CURLOPT_SSL_VERIFYHOST, 2);}if ($headers) {// 设置请求头curl_setopt($require, CURLOPT_HTTPHEADER, $headers);}// 返回结果不直接输出curl_setopt($require, CURLOPT_RETURNTRANSFER, TRUE);// 重定向curl_setopt($require, CURLOPT_FOLLOWLOCATION, TRUE);// 把返回头包含再输出中curl_setopt($require, CURLOPT_HEADER, TRUE);// 发送请求$response = curl_exec($require);// 获取头部长度$headerSize = curl_getinfo($require, CURLINFO_HEADER_SIZE);// 关闭请求curl_close($require);if ($response) {// 返回头部字符串$header = substr($response, 0, $headerSize);// 返回体$body = substr($response, $headerSize);// 过滤隐藏非法字符$bodyTemp = json_encode(array(0 => $body));$bodyTemp = str_replace("", "", $bodyTemp);$bodyTemp = json_decode($bodyTemp, TRUE);$body = trim($bodyTemp[0]);// 将返回结果头部转成数组$respondHeaders = array();$header_rows = array_filter(explode(PHP_EOL, $header), "trim"); foreach ($header_rows as $row) {$keylen = strpos($row, ":");if ($keylen) {$respondHeaders[] = array("key" => substr($row, 0, $keylen),"value" => trim(substr($row, $keylen + 1)));}}return array("headers" => $respondHeaders,"body" => $body);} else {return FALSE;}}7.指数实时报价<?php$method = "POST";$url = "https:///mlhexpsz/stock/index";$headers = NULL;$params = array("apiKey"=>"your_api_key", //需要从获取"stock_code"=>"", //代码);$result = apishop_curl($method, $url, $headers, $params);If ($result) {$body = json_decode($result["body"], TRUE);$status_code = $body["statusCode"];If ($status_code == "000000") {//状态码为000000, 说明请求成功echo "请求成功:" . $result["body"];} else {//状态码非000000, 说明请求失败echo "请求失败:" . $result["body"];}} else {//返回内容异常,发送请求失败,以下可根据业务逻辑自行修改echo "发送请求失败";}/*** 转发请求到目的主机* @param $method string 请求方法* @param $URL string 请求地址* @param null $headers 请求头* @param null $param 请求参数* @return array|bool*/function apishop_curl(&$method, &$URL, &$headers = NULL, &$param = NULL) {// 初始化请求$require = curl_init($URL);// 判断是否HTTPS$isHttps = substr($URL, 0, 8) == "https://" ? TRUE : FALSE;// 设置请求方式switch ($method) {case "GET":curl_setopt($require, CURLOPT_CUSTOMREQUEST, "GET");break;case "POST":curl_setopt($require, CURLOPT_CUSTOMREQUEST, "POST");break;default:return FALSE;}if ($param) {curl_setopt($require, CURLOPT_POSTFIELDS, $param);}if ($isHttps) {// 跳过证书检查curl_setopt($require, CURLOPT_SSL_VERIFYPEER, FALSE);// 检查证书中是否设置域名curl_setopt($require, CURLOPT_SSL_VERIFYHOST, 2);}if ($headers) {// 设置请求头curl_setopt($require, CURLOPT_HTTPHEADER, $headers);}// 返回结果不直接输出curl_setopt($require, CURLOPT_RETURNTRANSFER, TRUE);// 重定向curl_setopt($require, CURLOPT_FOLLOWLOCATION, TRUE);// 把返回头包含再输出中curl_setopt($require, CURLOPT_HEADER, TRUE);// 发送请求$response = curl_exec($require);// 获取头部长度$headerSize = curl_getinfo($require, CURLINFO_HEADER_SIZE);// 关闭请求curl_close($require);if ($response) {// 返回头部字符串$header = substr($response, 0, $headerSize);// 返回体$body = substr($response, $headerSize);// 过滤隐藏非法字符$bodyTemp = json_encode(array(0 => $body));$bodyTemp = str_replace("", "", $bodyTemp);$bodyTemp = json_decode($bodyTemp, TRUE);$body = trim($bodyTemp[0]);// 将返回结果头部转成数组$respondHeaders = array();$header_rows = array_filter(explode(PHP_EOL, $header), "trim"); foreach ($header_rows as $row) {$keylen = strpos($row, ":");if ($keylen) {$respondHeaders[] = array("key" => substr($row, 0, $keylen),"value" => trim(substr($row, $keylen + 1)));}}return array("headers" => $respondHeaders,"body" => $body);} else {return FALSE;}}8.组合行情查询<?php$method = "POST";$url = "https:///mlhexpsz/stock/comb";$headers = NULL;$params = array("apiKey"=>"your_api_key", //需要从获取"stock_code"=>"", //股票代码);$result = apishop_curl($method, $url, $headers, $params);If ($result) {$body = json_decode($result["body"], TRUE);$status_code = $body["statusCode"];If ($status_code == "000000") {//状态码为000000, 说明请求成功echo "请求成功:" . $result["body"];} else {//状态码非000000, 说明请求失败echo "请求失败:" . $result["body"];}} else {//返回内容异常,发送请求失败,以下可根据业务逻辑自行修改echo "发送请求失败";}/*** 转发请求到目的主机* @param $method string 请求方法* @param $URL string 请求地址* @param null $headers 请求头* @param null $param 请求参数* @return array|bool*/function apishop_curl(&$method, &$URL, &$headers = NULL, &$param = NULL) {// 初始化请求$require = curl_init($URL);// 判断是否HTTPS$isHttps = substr($URL, 0, 8) == "https://" ? TRUE : FALSE;// 设置请求方式switch ($method) {case "GET":curl_setopt($require, CURLOPT_CUSTOMREQUEST, "GET");break;case "POST":curl_setopt($require, CURLOPT_CUSTOMREQUEST, "POST");break;default:return FALSE;}if ($param) {curl_setopt($require, CURLOPT_POSTFIELDS, $param);}if ($isHttps) {// 跳过证书检查curl_setopt($require, CURLOPT_SSL_VERIFYPEER, FALSE);// 检查证书中是否设置域名curl_setopt($require, CURLOPT_SSL_VERIFYHOST, 2);}if ($headers) {// 设置请求头curl_setopt($require, CURLOPT_HTTPHEADER, $headers);}// 返回结果不直接输出curl_setopt($require, CURLOPT_RETURNTRANSFER, TRUE);// 重定向curl_setopt($require, CURLOPT_FOLLOWLOCATION, TRUE);// 把返回头包含再输出中curl_setopt($require, CURLOPT_HEADER, TRUE);// 发送请求$response = curl_exec($require);// 获取头部长度$headerSize = curl_getinfo($require, CURLINFO_HEADER_SIZE);// 关闭请求curl_close($require);if ($response) {// 返回头部字符串$header = substr($response, 0, $headerSize);// 返回体$body = substr($response, $headerSize);// 过滤隐藏非法字符$bodyTemp = json_encode(array(0 => $body));$bodyTemp = str_replace("", "", $bodyTemp);$bodyTemp = json_decode($bodyTemp, TRUE);$body = trim($bodyTemp[0]);// 将返回结果头部转成数组$respondHeaders = array();$header_rows = array_filter(explode(PHP_EOL, $header), "trim"); foreach ($header_rows as $row) {$keylen = strpos($row, ":");if ($keylen) {$respondHeaders[] = array("key" => substr($row, 0, $keylen),"value" => trim(substr($row, $keylen + 1)) );}}return array("headers" => $respondHeaders,"body" => $body);} else {return FALSE;}}9.综合排名<?php$method = "POST";$url = "https:///mlhexpsz/stock/sort"; $headers = NULL;$params = array("apiKey"=>"your_api_key", //需要从获取 "stock_type"=>"", //股票类别,参考市场查询返回值"sort_type"=>"", //排序类别);$result = apishop_curl($method, $url, $headers, $params);If ($result) {$body = json_decode($result["body"], TRUE);$status_code = $body["statusCode"];If ($status_code == "000000") {//状态码为000000, 说明请求成功echo "请求成功:" . $result["body"];} else {//状态码非000000, 说明请求失败echo "请求失败:" . $result["body"];}} else {//返回内容异常,发送请求失败,以下可根据业务逻辑自行修改echo "发送请求失败";}/*** 转发请求到目的主机* @param $method string 请求方法* @param $URL string 请求地址* @param null $headers 请求头* @param null $param 请求参数* @return array|bool*/function apishop_curl(&$method, &$URL, &$headers = NULL, &$param = NULL) {// 初始化请求$require = curl_init($URL);// 判断是否HTTPS$isHttps = substr($URL, 0, 8) == "https://" ? TRUE : FALSE;// 设置请求方式switch ($method) {case "GET":curl_setopt($require, CURLOPT_CUSTOMREQUEST, "GET");break;case "POST":curl_setopt($require, CURLOPT_CUSTOMREQUEST, "POST");break;default:return FALSE;}if ($param) {curl_setopt($require, CURLOPT_POSTFIELDS, $param);}if ($isHttps) {// 跳过证书检查curl_setopt($require, CURLOPT_SSL_VERIFYPEER, FALSE);// 检查证书中是否设置域名curl_setopt($require, CURLOPT_SSL_VERIFYHOST, 2);}if ($headers) {// 设置请求头curl_setopt($require, CURLOPT_HTTPHEADER, $headers);}// 返回结果不直接输出curl_setopt($require, CURLOPT_RETURNTRANSFER, TRUE);// 重定向curl_setopt($require, CURLOPT_FOLLOWLOCATION, TRUE);// 把返回头包含再输出中curl_setopt($require, CURLOPT_HEADER, TRUE);// 发送请求$response = curl_exec($require);// 获取头部长度$headerSize = curl_getinfo($require, CURLINFO_HEADER_SIZE);// 关闭请求curl_close($require);if ($response) {// 返回头部字符串$header = substr($response, 0, $headerSize);// 返回体$body = substr($response, $headerSize);// 过滤隐藏非法字符$bodyTemp = json_encode(array(0 => $body));$bodyTemp = str_replace("", "", $bodyTemp);$bodyTemp = json_decode($bodyTemp, TRUE);$body = trim($bodyTemp[0]);// 将返回结果头部转成数组$respondHeaders = array();$header_rows = array_filter(explode(PHP_EOL, $header), "trim"); foreach ($header_rows as $row) {$keylen = strpos($row, ":");if ($keylen) {$respondHeaders[] = array("key" => substr($row, 0, $keylen),"value" => trim(substr($row, $keylen + 1)));}}return array("headers" => $respondHeaders,"body" => $body);} else {return FALSE;}}。
使用eoLinker进行API接口自动化测试高级模式
使用eoLinker进行API接口自动化测试——高级模式(代码)eoLinker是目前第一个支持在线API自动化测试的平台,eoLinker AMS提供了两种自动化测试方案:1.简易模式:全UI界面,无需编写任何代码即可完成稍复杂的API测试工作2.高级模式:代码界面,通过编写极少的Javascript代码,即可实现强大的API自动化测试一般而言,自动化测试涉及以下几个方面:1.自由设定API测试顺序;2.API之间存在数据关联,比如后面接口的请求参数会绑定前面接口的返回结果等;3.支持对返回结果进行校验;4.支持对数据进行处理,比如在测试登录接口时对密码进行加密等;5.支持高级的代码用例,可以用代码来实现控制测试流程的目的,一般语言有js;6.eoLinker支持上述提到的所有功能,并且是目前全球唯一一款支持UI界面创建自动化测试的产品,用于自动化测试非常方便,并且用户体验相比于Postman等工具要好许多。
本篇主要用于记录高级(代码)模式的自动化测试。
高级自动化测试教程:请点击这里。
(/#/article?ID=379)一. 单例和用例单例是自动化测试下面的一个基本单位,通俗地讲,单例也就是“单个API 的测试条件和结果”。
比如有一个用户登录接口,传递abc和123作为请求参数,然后返回”OK”作为成功的结果。
用例则是多个单例的合集,一个用例可以包含1~无限个的单例,并且把这些单例按顺序组合起来。
比如测试完整的用户登录流程(注册-登录-判断登录状态-退出登录)。
注意:在高级模式中,单例将以代码的形式集中在用例中,因此形式上看并不像简易模式中拥有明显的单例和用例的概念。
我们在用例列表页面,新增用例时选择用例类型为高级[代码模式] 即可创建一个高级用例:二.环境变量和Postman一样,eoLinker也提供了环境变量的功能,帮助用户快速对测试API的环境进行切换,而不需要对API进行修改(比如开发和生产环境的参数和地址可能不同)。
eoLinker-API_Shop_区块链今日快讯_API接口_PHP调用示例代码
eoLinker-API Shop 区块链今日快讯 PHP调用示例代码区块链今日快讯包括比特币、以太坊等热门区块链信息以及最新的相关资讯,实时更新。
该产品拥有以下APIs:1.获取区块链快讯列表2.搜索区块链快讯注意,该示例代码仅适用于网站下API使用该产品前,您需要通过https:///#/api/detail/?productID=185申请API服务1.获取区块链快讯列表<?php$method = "POST";$url = "https:///common/coin/getNewsList";$headers = NULL;$params = array("apiKey"=>"your_api_key", //需要从获取"page"=>"", //页码(默认为1)"pageSize"=>"", //每页条数(范围[10,40],默认每页10条));$result = apishop_curl($method, $url, $headers, $params);If ($result) {$body = json_decode($result["body"], TRUE);$status_code = $body["statusCode"];If ($status_code == "000000") {//状态码为000000, 说明请求成功echo "请求成功:" . $result["body"];} else {//状态码非000000, 说明请求失败echo "请求失败:" . $result["body"];}} else {//返回内容异常,发送请求失败,以下可根据业务逻辑自行修改echo "发送请求失败";}/*** 转发请求到目的主机* @param $method string 请求方法* @param $URL string 请求地址* @param null $headers 请求头* @param null $param 请求参数* @return array|bool*/function apishop_curl(&$method, &$URL, &$headers = NULL, &$param = NULL) {// 初始化请求$require = curl_init($URL);// 判断是否HTTPS$isHttps = substr($URL, 0, 8) == "https://" ? TRUE : FALSE;// 设置请求方式switch ($method) {case "GET":curl_setopt($require, CURLOPT_CUSTOMREQUEST, "GET");break;case "POST":curl_setopt($require, CURLOPT_CUSTOMREQUEST, "POST");break;default:return FALSE;}if ($param) {curl_setopt($require, CURLOPT_POSTFIELDS, $param);}if ($isHttps) {// 跳过证书检查curl_setopt($require, CURLOPT_SSL_VERIFYPEER, FALSE);// 检查证书中是否设置域名curl_setopt($require, CURLOPT_SSL_VERIFYHOST, 2);}if ($headers) {// 设置请求头curl_setopt($require, CURLOPT_HTTPHEADER, $headers);}// 返回结果不直接输出curl_setopt($require, CURLOPT_RETURNTRANSFER, TRUE);// 重定向curl_setopt($require, CURLOPT_FOLLOWLOCATION, TRUE);// 把返回头包含再输出中curl_setopt($require, CURLOPT_HEADER, TRUE);// 发送请求$response = curl_exec($require);// 获取头部长度$headerSize = curl_getinfo($require, CURLINFO_HEADER_SIZE);// 关闭请求curl_close($require);if ($response) {// 返回头部字符串$header = substr($response, 0, $headerSize);// 返回体$body = substr($response, $headerSize);// 过滤隐藏非法字符$bodyTemp = json_encode(array(0 => $body));$bodyTemp = str_replace("", "", $bodyTemp);$bodyTemp = json_decode($bodyTemp, TRUE);$body = trim($bodyTemp[0]);// 将返回结果头部转成数组$respondHeaders = array();$header_rows = array_filter(explode(PHP_EOL, $header), "trim"); foreach ($header_rows as $row) {$keylen = strpos($row, ":");if ($keylen) {$respondHeaders[] = array("key" => substr($row, 0, $keylen),"value" => trim(substr($row, $keylen + 1)));}}return array("headers" => $respondHeaders,"body" => $body);} else {return FALSE;}}2.搜索区块链快讯<?php$method = "POST";$url = "https:///common/coin/searchNews";$headers = NULL;$params = array("apiKey"=>"your_api_key", //需要从获取"keyword"=>"", //搜索关键字"page"=>"", //页码(默认为1)"pageSize"=>"", //每页条数(范围[10,40],默认每页10条));$result = apishop_curl($method, $url, $headers, $params);If ($result) {$body = json_decode($result["body"], TRUE);$status_code = $body["statusCode"];If ($status_code == "000000") {//状态码为000000, 说明请求成功echo "请求成功:" . $result["body"];} else {//状态码非000000, 说明请求失败echo "请求失败:" . $result["body"];}} else {//返回内容异常,发送请求失败,以下可根据业务逻辑自行修改echo "发送请求失败";}/*** 转发请求到目的主机* @param $method string 请求方法* @param $URL string 请求地址* @param null $headers 请求头* @param null $param 请求参数* @return array|bool*/function apishop_curl(&$method, &$URL, &$headers = NULL, &$param = NULL) {// 初始化请求$require = curl_init($URL);// 判断是否HTTPS$isHttps = substr($URL, 0, 8) == "https://" ? TRUE : FALSE;// 设置请求方式switch ($method) {case "GET":curl_setopt($require, CURLOPT_CUSTOMREQUEST, "GET");break;case "POST":curl_setopt($require, CURLOPT_CUSTOMREQUEST, "POST");break;default:return FALSE;}if ($param) {curl_setopt($require, CURLOPT_POSTFIELDS, $param);}if ($isHttps) {// 跳过证书检查curl_setopt($require, CURLOPT_SSL_VERIFYPEER, FALSE);// 检查证书中是否设置域名curl_setopt($require, CURLOPT_SSL_VERIFYHOST, 2);}if ($headers) {// 设置请求头curl_setopt($require, CURLOPT_HTTPHEADER, $headers);}// 返回结果不直接输出curl_setopt($require, CURLOPT_RETURNTRANSFER, TRUE);// 重定向curl_setopt($require, CURLOPT_FOLLOWLOCATION, TRUE);// 把返回头包含再输出中curl_setopt($require, CURLOPT_HEADER, TRUE);// 发送请求$response = curl_exec($require);// 获取头部长度$headerSize = curl_getinfo($require, CURLINFO_HEADER_SIZE);// 关闭请求curl_close($require);if ($response) {// 返回头部字符串$header = substr($response, 0, $headerSize);// 返回体$body = substr($response, $headerSize);// 过滤隐藏非法字符$bodyTemp = json_encode(array(0 => $body));$bodyTemp = str_replace("", "", $bodyTemp);$bodyTemp = json_decode($bodyTemp, TRUE);$body = trim($bodyTemp[0]);// 将返回结果头部转成数组$respondHeaders = array();$header_rows = array_filter(explode(PHP_EOL, $header), "trim"); foreach ($header_rows as $row) {$keylen = strpos($row, ":");if ($keylen) {$respondHeaders[] = array("key" => substr($row, 0, $keylen),"value" => trim(substr($row, $keylen + 1)));}}return array("headers" => $respondHeaders,"body" => $body);} else {return FALSE;}}。
eoLinker-API_Shop_OCR-车牌识别_API接口_Python调用示例代码
eoLinker-API Shop OCR-车牌识别 Python调用示例代码OCR-车牌识别车牌识别服务能自动地从图片中定位车牌图片区域,识别出其中包含的车牌信息。
该产品拥有以下APIs:1.车牌识别注意,该示例代码仅适用于网站下API使用该产品前,您需要通过https:///#/api/detail/?productID=207申请API服务1.车牌识别#!/usr/bin/env python# -*- coding: utf-8 -*-# 测试环境: python2.7# 安装requests依赖 => pip install requests/ easy_install requests# 导入requests依赖import requestsimport jsonimport sysreload(sys)sys.setdefaultencoding('utf-8')def apishop_send_request(method, url, params=None, headers=None):'''转发请求到目的主机@param method str 请求方法@param url str 请求地址@param params dict 请求参数@param headers dict 请求头'''method = str.upper(method)if method == 'POST':return requests.post(url=url, data=params, headers=headers)elif method == 'GET':return requests.get(url=url, params=params, headers=headers)else:return Nonemethod = "POST"url = "https:///common/ocr/ocrVehiclePlate"headers = Noneparams = {"apiKey":"your_api_key", #需要从获取"imgBASE64":"" #图片的base64编码内容(图片大小应小于2M)"multi_crop":"" #当设成1时,会做多crop预测,只有当多crop返回的结果一致,并且置信度>0.9时,才返回结果。
eoLinker-API_Shop_商品评价分析_API接口_C#调用示例代码
eoLinker-API Shop 商品评价分析 C#调用示例代码商品评价分析用于分析消费者反馈的评价、点评内容,同时也可对类似微博的口语化、短文本进行分析。
该产品拥有以下APIs:1.商品评价分析注意,该示例代码仅适用于网站下API使用该产品前,您需要通过https:///#/api/detail/?productID=208申请API服务1.商品评价分析using System;using System.Collections.Generic;using System.IO;using ;using System.Text;using System.Web.Script.Serialization;namespace apishop_sdk{class Program{/*** 转发请求到目的主机* @param method string 请求方法* @param url string 请求地址* @param params Dictionary<string,string> 请求参数* @param headers Dictionary<string,string> 请求头* @return string**/static string apishop_send_request(string method, string url, D ictionary<string, string> param, Dictionary<string, string> headers){string result = string.Empty;try{string paramData = "";if (param != null && param.Count > 0){StringBuilder sbuilder = new StringBuilder();foreach (var item in param){if (sbuilder.Length > 0){sbuilder.Append("&");}sbuilder.Append(item.Key + "=" + item.Value);}paramData = sbuilder.ToString();}method = method.ToUpper();if (method == "GET"){url = string.Format("{0}?{1}", url, paramData);}HttpWebRequest wbRequest = (HttpWebRequest)WebRequest.C reate(url);if (method == "GET"){wbRequest.Method = "GET";}else if (method == "POST"){wbRequest.Method = "POST";wbRequest.ContentType = "application/x-www-form-url encoded";wbRequest.ContentLength = Encoding.UTF8.GetByteCoun t(paramData);using (Stream requestStream = wbRequest.GetRequestS tream()){using (StreamWriter swrite = new StreamWriter(r equestStream)){swrite.Write(paramData);}}}HttpWebResponse wbResponse = (HttpWebResponse)wbRequest. GetResponse();using (Stream responseStream = wbResponse.GetResponseSt ream()){using (StreamReader sread = new StreamReader(respon seStream)){result = sread.ReadToEnd();}}}catch{return "";}return result;}class Response{public string statusCode;}static void Main(string[] args){string method = "POST";string url = "https:///common/ai/reviewAnaly sis";Dictionary<string, string> param = new Dictionary<string, s tring>();param.Add("apiKey", "your_api_key"); //需要从www.apishop.ne t获取param.Add("text", ""); //待分析商品评价内容param.Add("type", ""); //商品分类(0:服装,1:美妆,2:零食,3:奶粉, 4:纸尿裤,5:鞋类,6:住宅家具,7:床上用品),如‘0’Dictionary<string, string> headers = null;string result = apishop_send_request(method, url, param, he aders);if (result == ""){//返回内容异常,发送请求失败Console.WriteLine("发送请求失败");return;}Response res = new JavaScriptSerializer().Deserialize<Respo nse>(result);if (res.statusCode == "000000"){//状态码为000000, 说明请求成功Console.WriteLine(string.Format("请求成功: {0}", resul t));}else{//状态码非000000, 说明请求失败Console.WriteLine(string.Format("请求失败: {0}", resul t));}Console.ReadLine(); }}}。
eoLinker-API_Shop_快递物流查询_API接口_Python调用示例代码
eoLinker-API Shop 快递物流查询 Python调用示例代码快递物流查询自动识别快递公司,提供包括申通、顺丰、圆通、韵达、中通、汇通、EMS、天天、国通、德邦、宅急送等几百家快递物流公司单号查询接口。
该产品拥有以下APIs:1.获取快递公司2.查询快递信息注意,该示例代码仅适用于网站下API使用该产品前,您需要通过https:///#/api/detail/?productID=103申请API服务1.获取快递公司#!/usr/bin/env python# -*- coding: utf-8 -*-# 测试环境: python2.7# 安装requests依赖 => pip install requests/ easy_install requests# 导入requests依赖import requestsimport jsonimport sysreload(sys)sys.setdefaultencoding('utf-8')def apishop_send_request(method, url, params=None, headers=None):'''转发请求到目的主机@param method str 请求方法@param url str 请求地址@param params dict 请求参数@param headers dict 请求头'''method = str.upper(method)if method == 'POST':return requests.post(url=url, data=params, headers=headers)elif method == 'GET':return requests.get(url=url, params=params, headers=headers)else:return Nonemethod = "POST"url = "https:///common/express/getExpressCompany" headers = Noneparams = {"apiKey":"your_api_key", #需要从获取}result = apishop_send_request(method=method, url=url, params=params, he aders=headers)if result:body = result.textresponse = json.loads(body)status_code = response["statusCode"]if (status_code == '000000'):# 状态码为000000, 说明请求成功print('请求成功:%s' % (body,))else:# 状态码非000000, 说明请求失败print('请求失败: %s' % (body,))else:# 返回内容异常,发送请求失败print('发送请求失败')2.查询快递信息#!/usr/bin/env python# -*- coding: utf-8 -*-# 测试环境: python2.7# 安装requests依赖 => pip install requests/ easy_install requests# 导入requests依赖import requestsimport jsonimport sysreload(sys)sys.setdefaultencoding('utf-8')def apishop_send_request(method, url, params=None, headers=None):'''转发请求到目的主机@param method str 请求方法@param url str 请求地址@param params dict 请求参数@param headers dict 请求头'''method = str.upper(method)if method == 'POST':return requests.post(url=url, data=params, headers=headers)elif method == 'GET':return requests.get(url=url, params=params, headers=headers)else:return Nonemethod = "POST"url = "https:///common/express/getExpressInfo"headers = Noneparams = {"apiKey":"your_api_key", #需要从获取"expressNumber":"" #快递单号"expressType":"" #快递公司,不填默认自动识别}result = apishop_send_request(method=method, url=url, params=params, he aders=headers)if result:body = result.textresponse = json.loads(body)status_code = response["statusCode"]if (status_code == '000000'):# 状态码为000000, 说明请求成功print('请求成功:%s' % (body,))else:# 状态码非000000, 说明请求失败print('请求失败: %s' % (body,))else:# 返回内容异常,发送请求失败print('发送请求失败')。
eoLinker-API_Shop_京东热词查询_API接口_Java调用示例代码
eoLinker-API Shop 京东热词查询 Java调用示例代码京东热词查询京东商品关键词搜索排名查询工具,可根据任意商品关键词,全站实时获取,搜索关注度最高的商品关键词,协助商家及时掌握:买家搜索习惯和买家需求。
该产品拥有以下APIs:1.京东热搜查询注意,该示例代码仅适用于网站下API使用该产品前,您需要通过https:///#/api/detail/?productID=211申请API服务1.京东热搜查询package net.apishop.www.controller;import java.io.DataOutputStream;import java.io.IOException;import java.io.InputStream;import java.io.UnsupportedEncodingException;import .HttpURLConnection;import .MalformedURLException;import .URL;import .URLEncoder;import java.util.HashMap;import java.util.Map;import com.alibaba.fastjson.JSONObject;/*** httpUrlConnection访问远程接口工具*/public class Api{/*** 方法体说明:向远程接口发起请求,返回字节流类型结果* param url 接口地址* param requestMethod 请求方式* param params 传递参数重点:参数值需要用Base64进行转码* return InputStream 返回结果*/public static InputStream httpRequestToStream(String url, String re questMethod, Map<String, String> params){InputStream is = null;try{String parameters = "";boolean hasParams = false;// 将参数集合拼接成特定格式,如name=zhangsan&age=24for (String key : params.keySet()){String value = URLEncoder.encode(params.get(key), "UTF-8");parameters += key + "=" + value + "&";hasParams = true;}if (hasParams){parameters = parameters.substring(0, parameters.length() - 1);}// 请求方式是否为getboolean isGet = "get".equalsIgnoreCase(requestMethod);// 请求方式是否为postboolean isPost = "post".equalsIgnoreCase(requestMethod);if (isGet){url += "?" + parameters;}URL u = new URL(url);HttpURLConnection conn = (HttpURLConnection) u.openConnecti on();// 请求的参数类型(使用restlet框架时,为了兼容框架,必须设置Con tent-Type为“”空)conn.setRequestProperty("Content-Type", "application/octet-stream");// conn.setRequestProperty("Content-Type", "application/x-w ww-form-urlencoded");// 设置连接超时时间conn.setConnectTimeout(50000);// 设置读取返回内容超时时间conn.setReadTimeout(50000);// 设置向HttpURLConnection对象中输出,因为post方式将请求参数放在http正文内,因此需要设置为ture,默认falseif (isPost){conn.setDoOutput(true);}// 设置从HttpURLConnection对象读入,默认为trueconn.setDoInput(true);// 设置是否使用缓存,post方式不能使用缓存if (isPost){conn.setUseCaches(false);}// 设置请求方式,默认为GETconn.setRequestMethod(requestMethod);// post方式需要将传递的参数输出到conn对象中if (isPost){DataOutputStream dos = new DataOutputStream(conn.getOut putStream());dos.writeBytes(parameters);dos.flush();dos.close();}// 从HttpURLConnection对象中读取响应的消息// 执行该语句时才正式发起请求is = conn.getInputStream();}catch(UnsupportedEncodingException e){e.printStackTrace();}catch(MalformedURLException e){e.printStackTrace();}catch(IOException e){e.printStackTrace();}return is;}public static void main(String args[]){String url = "https:///common/postcode/getPostCo deByAddr";String requestMethod = "POST";Map<String, String> params = new HashMap<String, String>(); params.put("apiKey","your_api_key"); //需要从获取params.put("keyword", ""); //搜索关键字String result = null;try{InputStream is = httpRequestToStream(url, requestMethod, pa rams);byte[] b = new byte[is.available()];is.read(b);result = new String(b);}catch(IOException e){e.printStackTrace();}if (result != null){JSONObject jsonObject = JSONObject.parseObject(result);String status_code = jsonObject.getString("statusCode");if (status_code == "000000"){// 状态码为000000, 说明请求成功System.out.println("请求成功:" + jsonObject.getString("resu lt"));}else{// 状态码非000000, 说明请求失败System.out.println("请求失败:" + jsonObject.getString("desc "));}}else{// 返回内容异常,发送请求失败,以下可根据业务逻辑自行修改System.out.println("发送请求失败");}}}。
成语api
成语API是一款在线成语查询工具,提供成语查询、成语接龙、成语解析等功能,帮助用户学习和掌握成语知识。
该工具支持多种输入方式,如拼音、英文、数字等,用户可以方便地输入所需的成语,并获取相应的解释、出处、例句等信息。
在成语API中,用户可以输入单个成语进行查询,也可以输入前几个字或后几个字进行模糊查询。
该工具还支持长文本查询,用户可以将需要查询的成语连在一起输入,系统会根据上下文进行匹配。
此外,成语API还提供了成语接龙功能,用户可以通过输入一个成语,系统会自动生成下一个成语,帮助用户进行成语的积累和学习。
在成语API中,每个成语都有详细的解释和出处,可以帮助用户更好地理解成语的含义和用法。
同时,该工具还提供了丰富的成语示例,用户可以学习如何将成语应用到实际的语境中。
此外,成语API还支持多语种输入,用户可以使用不同的语言输入成语,系统会自动将其翻译成中文并进行解释。
除了提供查询和解释功能外,成语API还支持一些互动性的功能,如成语填空、成语填词等。
这些功能可以帮助用户更好地理解和掌握成语的使用方法,同时也可以提高用户的兴趣和参与度。
总之,成语API是一款非常实用的在线成语查询工具,可以帮助用户学习和掌握成语知识。
该工具提供了丰富的功能和资源,可以帮助用户更好地理解和应用成语,提高自己的语言能力和文化素养。
同时,该工具也适合各种年龄段和水平的用户使用,无论是学生、教师还是普通用户,都可以从中受益。
需要注意的是,虽然成语API提供了许多有用的功能和资源,但它仍然存在一些局限性。
例如,该工具可能无法涵盖所有类型的成语,对于一些特殊的成语用法和历史背景可能无法提供详细的解释。
因此,在使用该工具时,建议用户结合其他资源和方法进行学习,以获得更全面和准确的信息。
eoLinker-API_Shop_成语大全_API接口_Java调用示例代码
eoLinker-API Shop 成语大全 Java调用示例代码成语大全包含发音、解释、出自典故、近义词、反义词、例句等数据,可进行成语接龙、成语竞猜等游戏开发。
该产品拥有以下APIs:1.成语搜索2.查询成语详情注意,该示例代码仅适用于网站下API使用该产品前,您需要通过https:///#/api/detail/?productID=93申请API服务1.成语搜索package net.apishop.www.controller;import java.io.DataOutputStream;import java.io.IOException;import java.io.InputStream;import java.io.UnsupportedEncodingException;import .HttpURLConnection;import .MalformedURLException;import .URL;import .URLEncoder;import java.util.HashMap;import java.util.Map;import com.alibaba.fastjson.JSONObject;/*** httpUrlConnection访问远程接口工具*/public class Api{/*** 方法体说明:向远程接口发起请求,返回字节流类型结果* param url 接口地址* param requestMethod 请求方式* param params 传递参数重点:参数值需要用Base64进行转码* return InputStream 返回结果*/public static InputStream httpRequestToStream(String url, String re questMethod, Map<String, String> params){InputStream is = null;try{String parameters = "";boolean hasParams = false;// 将参数集合拼接成特定格式,如name=zhangsan&age=24for (String key : params.keySet()){String value = URLEncoder.encode(params.get(key), "UTF-8");parameters += key + "=" + value + "&";hasParams = true;}if (hasParams){parameters = parameters.substring(0, parameters.length() - 1);}// 请求方式是否为getboolean isGet = "get".equalsIgnoreCase(requestMethod);// 请求方式是否为postboolean isPost = "post".equalsIgnoreCase(requestMethod);if (isGet){url += "?" + parameters;}URL u = new URL(url);HttpURLConnection conn = (HttpURLConnection) u.openConnecti on();// 请求的参数类型(使用restlet框架时,为了兼容框架,必须设置Con tent-Type为“”空)conn.setRequestProperty("Content-Type", "application/octet-stream");// conn.setRequestProperty("Content-Type", "application/x-w ww-form-urlencoded");// 设置连接超时时间conn.setConnectTimeout(50000);// 设置读取返回内容超时时间conn.setReadTimeout(50000);// 设置向HttpURLConnection对象中输出,因为post方式将请求参数放在http正文内,因此需要设置为ture,默认falseif (isPost){conn.setDoOutput(true);}// 设置从HttpURLConnection对象读入,默认为trueconn.setDoInput(true);// 设置是否使用缓存,post方式不能使用缓存if (isPost){conn.setUseCaches(false);}// 设置请求方式,默认为GETconn.setRequestMethod(requestMethod);// post方式需要将传递的参数输出到conn对象中if (isPost){DataOutputStream dos = new DataOutputStream(conn.getOut putStream());dos.writeBytes(parameters);dos.flush();dos.close();}// 从HttpURLConnection对象中读取响应的消息// 执行该语句时才正式发起请求is = conn.getInputStream();}catch(UnsupportedEncodingException e){e.printStackTrace();}catch(MalformedURLException e){e.printStackTrace();}catch(IOException e){e.printStackTrace();}return is;}public static void main(String args[]){String url = "https:///common/postcode/getPostCo deByAddr";String requestMethod = "POST";Map<String, String> params = new HashMap<String, String>(); params.put("keyWord", ""); //关键字,如"蛇"String result = null;try{InputStream is = httpRequestToStream(url, requestMethod, pa rams);byte[] b = new byte[is.available()];is.read(b);result = new String(b);}catch(IOException e){e.printStackTrace();}if (result != null){JSONObject jsonObject = JSONObject.parseObject(result);String status_code = jsonObject.getString("statusCode");if (status_code == "000000"){// 状态码为000000, 说明请求成功System.out.println("请求成功:" + jsonObject.getString("resu lt"));}else{// 状态码非000000, 说明请求失败System.out.println("请求失败:" + jsonObject.getString("desc "));}}else{// 返回内容异常,发送请求失败,以下可根据业务逻辑自行修改System.out.println("发送请求失败");}}}2.查询成语详情package net.apishop.www.controller;import java.io.DataOutputStream;import java.io.IOException;import java.io.InputStream;import java.io.UnsupportedEncodingException;import .HttpURLConnection;import .MalformedURLException;import .URL;import .URLEncoder;import java.util.HashMap;import java.util.Map;import com.alibaba.fastjson.JSONObject;/*** httpUrlConnection访问远程接口工具*/public class Api{/*** 方法体说明:向远程接口发起请求,返回字节流类型结果* param url 接口地址* param requestMethod 请求方式* param params 传递参数重点:参数值需要用Base64进行转码* return InputStream 返回结果*/public static InputStream httpRequestToStream(String url, String re questMethod, Map<String, String> params){InputStream is = null;try{String parameters = "";boolean hasParams = false;// 将参数集合拼接成特定格式,如name=zhangsan&age=24for (String key : params.keySet()){String value = URLEncoder.encode(params.get(key), "UTF-8");parameters += key + "=" + value + "&";hasParams = true;}if (hasParams){parameters = parameters.substring(0, parameters.length() - 1);}// 请求方式是否为getboolean isGet = "get".equalsIgnoreCase(requestMethod);// 请求方式是否为postboolean isPost = "post".equalsIgnoreCase(requestMethod);if (isGet){url += "?" + parameters;}URL u = new URL(url);HttpURLConnection conn = (HttpURLConnection) u.openConnecti on();// 请求的参数类型(使用restlet框架时,为了兼容框架,必须设置Con tent-Type为“”空)conn.setRequestProperty("Content-Type", "application/octet-stream");// conn.setRequestProperty("Content-Type", "application/x-w ww-form-urlencoded");// 设置连接超时时间conn.setConnectTimeout(50000);// 设置读取返回内容超时时间conn.setReadTimeout(50000);// 设置向HttpURLConnection对象中输出,因为post方式将请求参数放在http正文内,因此需要设置为ture,默认falseif (isPost){conn.setDoOutput(true);}// 设置从HttpURLConnection对象读入,默认为trueconn.setDoInput(true);// 设置是否使用缓存,post方式不能使用缓存if (isPost){conn.setUseCaches(false);}// 设置请求方式,默认为GETconn.setRequestMethod(requestMethod);// post方式需要将传递的参数输出到conn对象中if (isPost){DataOutputStream dos = new DataOutputStream(conn.getOut putStream());dos.writeBytes(parameters);dos.flush();dos.close();}// 从HttpURLConnection对象中读取响应的消息// 执行该语句时才正式发起请求is = conn.getInputStream();}catch(UnsupportedEncodingException e){e.printStackTrace();}catch(MalformedURLException e){e.printStackTrace();}catch(IOException e){e.printStackTrace();}return is;}public static void main(String args[]){String url = "https:///common/postcode/getPostCo deByAddr";String requestMethod = "POST";Map<String, String> params = new HashMap<String, String>(); params.put("chengyu", ""); //要查询的成语,如“打草惊蛇”String result = null;try{InputStream is = httpRequestToStream(url, requestMethod, pa rams);byte[] b = new byte[is.available()];is.read(b);result = new String(b);}catch(IOException e){e.printStackTrace();}if (result != null){JSONObject jsonObject = JSONObject.parseObject(result);String status_code = jsonObject.getString("statusCode");if (status_code == "000000"){// 状态码为000000, 说明请求成功System.out.println("请求成功:" + jsonObject.getString("resu lt"));}else{// 状态码非000000, 说明请求失败System.out.println("请求失败:" + jsonObject.getString("desc "));}}else{// 返回内容异常,发送请求失败,以下可根据业务逻辑自行修改 System.out.println("发送请求失败");}}}。
eoLinker-API_Shop_周公解梦_API接口_Python调用示例代码
eoLinker-API Shop 周公解梦 Python调用示例代码周公解梦周公解梦大全,周公解梦查询,免费周公解梦。
该产品拥有以下APIs:1.获取梦的类型2.通过类型获取解梦的详情3.搜索解梦详情注意,该示例代码仅适用于网站下API使用该产品前,您需要通过https:///#/api/detail/?productID=126申请API服务1.获取梦的类型#!/usr/bin/env python# -*- coding: utf-8 -*-# 测试环境: python2.7# 安装requests依赖 => pip install requests/ easy_install requests# 导入requests依赖import requestsimport jsonimport sysreload(sys)sys.setdefaultencoding('utf-8')def apishop_send_request(method, url, params=None, headers=None):'''转发请求到目的主机@param method str 请求方法@param url str 请求地址@param params dict 请求参数@param headers dict 请求头'''method = str.upper(method)if method == 'POST':return requests.post(url=url, data=params, headers=headers)elif method == 'GET':return requests.get(url=url, params=params, headers=headers)else:return Nonemethod = "POST"url = "https:///common/dream/getDreamTypes"headers = Noneparams = {"apiKey":"your_api_key", #需要从获取}result = apishop_send_request(method=method, url=url, params=params, he aders=headers)if result:body = result.textresponse = json.loads(body)status_code = response["statusCode"]if (status_code == '000000'):# 状态码为000000, 说明请求成功print('请求成功:%s' % (body,))else:# 状态码非000000, 说明请求失败print('请求失败: %s' % (body,))else:# 返回内容异常,发送请求失败print('发送请求失败')2.通过类型获取解梦的详情#!/usr/bin/env python# -*- coding: utf-8 -*-# 测试环境: python2.7# 安装requests依赖 => pip install requests/ easy_install requests# 导入requests依赖import requestsimport jsonimport sysreload(sys)sys.setdefaultencoding('utf-8')def apishop_send_request(method, url, params=None, headers=None):'''转发请求到目的主机@param method str 请求方法@param url str 请求地址@param params dict 请求参数@param headers dict 请求头'''method = str.upper(method)if method == 'POST':return requests.post(url=url, data=params, headers=headers)elif method == 'GET':return requests.get(url=url, params=params, headers=headers)else:return Nonemethod = "POST"url = "https:///common/dream/queryDreamDetailByType" headers = Noneparams = {"apiKey":"your_api_key", #需要从获取"type":"" #梦的类型(从获取梦的类型接口获得)"page":"" #页码"pageSize":"" #每页条数(最多20条,默认10)}result = apishop_send_request(method=method, url=url, params=params, he aders=headers)if result:body = result.textresponse = json.loads(body)status_code = response["statusCode"]if (status_code == '000000'):# 状态码为000000, 说明请求成功print('请求成功:%s' % (body,))else:# 状态码非000000, 说明请求失败print('请求失败: %s' % (body,))else:# 返回内容异常,发送请求失败print('发送请求失败')3.搜索解梦详情#!/usr/bin/env python# -*- coding: utf-8 -*-# 测试环境: python2.7# 安装requests依赖 => pip install requests/ easy_install requests# 导入requests依赖import requestsimport jsonimport sysreload(sys)sys.setdefaultencoding('utf-8')def apishop_send_request(method, url, params=None, headers=None):'''转发请求到目的主机@param method str 请求方法@param url str 请求地址@param params dict 请求参数@param headers dict 请求头'''method = str.upper(method)if method == 'POST':return requests.post(url=url, data=params, headers=headers)elif method == 'GET':return requests.get(url=url, params=params, headers=headers)else:return Nonemethod = "POST"url = "https:///common/dream/searchDreamDetail"headers = Noneparams = {"apiKey":"your_api_key", #需要从获取"keyword":"" #关键字}result = apishop_send_request(method=method, url=url, params=params, he aders=headers)if result:body = result.textresponse = json.loads(body)status_code = response["statusCode"]if (status_code == '000000'):# 状态码为000000, 说明请求成功print('请求成功:%s' % (body,))else:# 状态码非000000, 说明请求失败print('请求失败: %s' % (body,))else:# 返回内容异常,发送请求失败print('发送请求失败')。
eoLinker-API_Shop_常见疾病查询_API接口_Python调用示例代码
eoLinker-API Shop 常见疾病查询 Python调用示例代码常见疾病查询提供所患疾病的病因、症状、检查、用药、治疗、并发症等方面的详细分析资料该产品拥有以下APIs:1.获取疾病部位列表2.通过部位获取疾病列表3.关键字获取疾病列表4.获取疾病列表5.查询疾病信息6.通过症状获取疾病列表注意,该示例代码仅适用于网站下API使用该产品前,您需要通过https:///#/api/detail/?productID=215申请API服务1.获取疾病部位列表#!/usr/bin/env python# -*- coding: utf-8 -*-# 测试环境: python2.7# 安装requests依赖 => pip install requests/ easy_install requests# 导入requests依赖import requestsimport jsonimport sysreload(sys)sys.setdefaultencoding('utf-8')def apishop_send_request(method, url, params=None, headers=None):'''转发请求到目的主机@param method str 请求方法@param url str 请求地址@param params dict 请求参数@param headers dict 请求头'''method = str.upper(method)if method == 'POST':return requests.post(url=url, data=params, headers=headers)elif method == 'GET':return requests.get(url=url, params=params, headers=headers)else:return Nonemethod = "POST"url = "https:///common/disease/queryDiseaseSiteList" headers = Noneparams = {"apiKey":"your_api_key", #需要从获取}result = apishop_send_request(method=method, url=url, params=params, he aders=headers)if result:body = result.textresponse = json.loads(body)status_code = response["statusCode"]if (status_code == '000000'):# 状态码为000000, 说明请求成功print('请求成功:%s' % (body,))else:# 状态码非000000, 说明请求失败print('请求失败: %s' % (body,))else:# 返回内容异常,发送请求失败print('发送请求失败')2.通过部位获取疾病列表#!/usr/bin/env python# -*- coding: utf-8 -*-# 测试环境: python2.7# 安装requests依赖 => pip install requests/ easy_install requests# 导入requests依赖import requestsimport jsonimport sysreload(sys)sys.setdefaultencoding('utf-8')def apishop_send_request(method, url, params=None, headers=None):'''转发请求到目的主机@param method str 请求方法@param url str 请求地址@param params dict 请求参数@param headers dict 请求头'''method = str.upper(method)if method == 'POST':return requests.post(url=url, data=params, headers=headers)elif method == 'GET':return requests.get(url=url, params=params, headers=headers)else:return Nonemethod = "POST"url = "https:///common/disease/queryDiseaseListBySite" headers = Noneparams = {"apiKey":"your_api_key", #需要从获取"page":"" #当前页码(默认1)"pageSize":"" #该页疾病数量(默认15)"site":"" #发病部位}result = apishop_send_request(method=method, url=url, params=params, he aders=headers)if result:body = result.textresponse = json.loads(body)status_code = response["statusCode"]if (status_code == '000000'):# 状态码为000000, 说明请求成功print('请求成功:%s' % (body,))else:# 状态码非000000, 说明请求失败print('请求失败: %s' % (body,))else:# 返回内容异常,发送请求失败print('发送请求失败')3.关键字获取疾病列表#!/usr/bin/env python# -*- coding: utf-8 -*-# 测试环境: python2.7# 安装requests依赖 => pip install requests/ easy_install requests# 导入requests依赖import requestsimport jsonimport sysreload(sys)sys.setdefaultencoding('utf-8')def apishop_send_request(method, url, params=None, headers=None):'''转发请求到目的主机@param method str 请求方法@param url str 请求地址@param params dict 请求参数@param headers dict 请求头'''method = str.upper(method)if method == 'POST':return requests.post(url=url, data=params, headers=headers)elif method == 'GET':return requests.get(url=url, params=params, headers=headers)else:return Nonemethod = "POST"url = "https:///common/disease/queryDiseaseListByKeyword "headers = Noneparams = {"apiKey":"your_api_key", #需要从获取"page":"" #当前页码(默认1)"pageSize":"" #该页疾病数量(默认15)"keyword":"" #关键字}result = apishop_send_request(method=method, url=url, params=params, he aders=headers)if result:body = result.textresponse = json.loads(body)status_code = response["statusCode"]if (status_code == '000000'):# 状态码为000000, 说明请求成功print('请求成功:%s' % (body,))else:# 状态码非000000, 说明请求失败print('请求失败: %s' % (body,))else:# 返回内容异常,发送请求失败print('发送请求失败')4.获取疾病列表#!/usr/bin/env python# -*- coding: utf-8 -*-# 测试环境: python2.7# 安装requests依赖 => pip install requests/ easy_install requests# 导入requests依赖import requestsimport jsonimport sysreload(sys)sys.setdefaultencoding('utf-8')def apishop_send_request(method, url, params=None, headers=None):'''转发请求到目的主机@param method str 请求方法@param url str 请求地址@param params dict 请求参数@param headers dict 请求头'''method = str.upper(method)if method == 'POST':return requests.post(url=url, data=params, headers=headers) elif method == 'GET':return requests.get(url=url, params=params, headers=headers) else:return Nonemethod = "POST"url = "https:///common/disease/queryDiseaseList" headers = Noneparams = {"apiKey":"your_api_key", #需要从获取"page":"" #当前页码(默认1)"pageSize":"" #该页疾病数量(默认15)}result = apishop_send_request(method=method, url=url, params=params, he aders=headers)if result:body = result.textresponse = json.loads(body)status_code = response["statusCode"]if (status_code == '000000'):# 状态码为000000, 说明请求成功print('请求成功:%s' % (body,))else:# 状态码非000000, 说明请求失败print('请求失败: %s' % (body,))else:# 返回内容异常,发送请求失败print('发送请求失败')5.查询疾病信息#!/usr/bin/env python# -*- coding: utf-8 -*-# 测试环境: python2.7# 安装requests依赖 => pip install requests/ easy_install requests# 导入requests依赖import requestsimport jsonimport sysreload(sys)sys.setdefaultencoding('utf-8')def apishop_send_request(method, url, params=None, headers=None):'''转发请求到目的主机@param method str 请求方法@param url str 请求地址@param params dict 请求参数@param headers dict 请求头'''method = str.upper(method)if method == 'POST':return requests.post(url=url, data=params, headers=headers)elif method == 'GET':return requests.get(url=url, params=params, headers=headers)else:return Nonemethod = "POST"url = "https:///common/disease/queryDiseaseInfo" headers = Noneparams = {"apiKey":"your_api_key", #需要从获取"diseaseID":"" #疾病ID}result = apishop_send_request(method=method, url=url, params=params, he aders=headers)if result:body = result.textresponse = json.loads(body)status_code = response["statusCode"]if (status_code == '000000'):# 状态码为000000, 说明请求成功print('请求成功:%s' % (body,))else:# 状态码非000000, 说明请求失败print('请求失败: %s' % (body,))else:# 返回内容异常,发送请求失败print('发送请求失败')6.通过症状获取疾病列表#!/usr/bin/env python# -*- coding: utf-8 -*-# 测试环境: python2.7# 安装requests依赖 => pip install requests/ easy_install requests# 导入requests依赖import requestsimport jsonimport sysreload(sys)sys.setdefaultencoding('utf-8')def apishop_send_request(method, url, params=None, headers=None):'''转发请求到目的主机@param method str 请求方法@param url str 请求地址@param params dict 请求参数@param headers dict 请求头'''method = str.upper(method)if method == 'POST':return requests.post(url=url, data=params, headers=headers)elif method == 'GET':return requests.get(url=url, params=params, headers=headers)else:return Nonemethod = "POST"url = "https:///common/disease/queryDiseaseListBySymptom "headers = Noneparams = {"apiKey":"your_api_key", #需要从获取"symptom":"" #症状,多个症状间用空格隔开"page":"" #当前页面(默认1)"pageSize":"" #该页疾病数量(默认15)}result = apishop_send_request(method=method, url=url, params=params, he aders=headers)if result:body = result.textresponse = json.loads(body)status_code = response["statusCode"]if (status_code == '000000'):# 状态码为000000, 说明请求成功print('请求成功:%s' % (body,))else:# 状态码非000000, 说明请求失败print('请求失败: %s' % (body,))else:# 返回内容异常,发送请求失败print('发送请求失败')。
eoLinker-API_Shop_京东热词查询_API接口_Python调用示例代码
eoLinker-API Shop 京东热词查询 Python调用示例代码京东热词查询京东商品关键词搜索排名查询工具,可根据任意商品关键词,全站实时获取,搜索关注度最高的商品关键词,协助商家及时掌握:买家搜索习惯和买家需求。
该产品拥有以下APIs:1.京东热搜查询注意,该示例代码仅适用于网站下API使用该产品前,您需要通过https:///#/api/detail/?productID=211申请API服务1.京东热搜查询#!/usr/bin/env python# -*- coding: utf-8 -*-# 测试环境: python2.7# 安装requests依赖 => pip install requests/ easy_install requests# 导入requests依赖import requestsimport jsonimport sysreload(sys)sys.setdefaultencoding('utf-8')def apishop_send_request(method, url, params=None, headers=None):'''转发请求到目的主机@param method str 请求方法@param url str 请求地址@param params dict 请求参数@param headers dict 请求头'''method = str.upper(method)if method == 'POST':return requests.post(url=url, data=params, headers=headers)elif method == 'GET':return requests.get(url=url, params=params, headers=headers)else:return Nonemethod = "POST"url = "https:///common/shopping/queryJDRelatedHotWords" headers = Noneparams = {"apiKey":"your_api_key", #需要从获取"keyword":"" #搜索关键字}result = apishop_send_request(method=method, url=url, params=params, he aders=headers)if result:body = result.textresponse = json.loads(body)status_code = response["statusCode"]if (status_code == '000000'):# 状态码为000000, 说明请求成功print('请求成功:%s' % (body,))else:# 状态码非000000, 说明请求失败print('请求失败: %s' % (body,))else:# 返回内容异常,发送请求失败print('发送请求失败')。
新版eoLinker_API_Shop_股票行情数据_API接口_Java调用示例代码.doc
eoLinker-API Shop 股票行情数据 Java调用示例代码股票行情数据支持证券全市场行情数据,实时数据,K线数据,分笔数据,市场股票代码信息,历史数据等等,满足证券投资分析使用。
该产品拥有以下APIs:1.股票k线2.实时行情查询3.查询股票列表4.查询股票市场5.分笔6.分时查询7.指数实时报价8.组合行情查询9.综合排名注意,该示例代码仅适用于网站下API使用该产品前,您需要通过https:///#/api/detail/?productID=168申请API服务1.股票k线package net.apishop.www.controller;import java.io.DataOutputStream;import java.io.IOException;import java.io.InputStream;import java.io.UnsupportedEncodingException;import .HttpURLConnection;import .MalformedURLException;import .URL;import .URLEncoder;import java.util.HashMap;import java.util.Map;import com.alibaba.fastjson.JSONObject;/*** httpUrlConnection访问远程接口工具*/public class Api{/*** 方法体说明:向远程接口发起请求,返回字节流类型结果* param url 接口地址* param requestMethod 请求方式* param params 传递参数重点:参数值需要用Base64进行转码* return InputStream 返回结果*/public static InputStream httpRequestToStream(String url, String re questMethod, Map<String, String> params){InputStream is = null;try{String parameters = "";boolean hasParams = false;// 将参数集合拼接成特定格式,如name=zhangsan&age=24for (String key : params.keySet()){String value = URLEncoder.encode(params.get(key), "UTF-8");parameters += key + "=" + value + "&";hasParams = true;}if (hasParams){parameters = parameters.substring(0, parameters.length() - 1);}// 请求方式是否为getboolean isGet = "get".equalsIgnoreCase(requestMethod);// 请求方式是否为postboolean isPost = "post".equalsIgnoreCase(requestMethod);if (isGet){url += "?" + parameters;}URL u = new URL(url);HttpURLConnection conn = (HttpURLConnection) u.openConnecti on();// 请求的参数类型(使用restlet框架时,为了兼容框架,必须设置Con tent-Type为“”空)conn.setRequestProperty("Content-Type", "application/octet-stream");// conn.setRequestProperty("Content-Type", "application/x-w ww-form-urlencoded");// 设置连接超时时间conn.setConnectTimeout(50000);// 设置读取返回内容超时时间conn.setReadTimeout(50000);// 设置向HttpURLConnection对象中输出,因为post方式将请求参数放在http正文内,因此需要设置为ture,默认falseif (isPost){conn.setDoOutput(true);}// 设置从HttpURLConnection对象读入,默认为trueconn.setDoInput(true);// 设置是否使用缓存,post方式不能使用缓存if (isPost){conn.setUseCaches(false);}// 设置请求方式,默认为GETconn.setRequestMethod(requestMethod);// post方式需要将传递的参数输出到conn对象中if (isPost){DataOutputStream dos = new DataOutputStream(conn.getOut putStream());dos.writeBytes(parameters);dos.flush();dos.close();}// 从HttpURLConnection对象中读取响应的消息// 执行该语句时才正式发起请求is = conn.getInputStream();}catch(UnsupportedEncodingException e){e.printStackTrace();}catch(MalformedURLException e){e.printStackTrace();}catch(IOException e){e.printStackTrace();}return is;}public static void main(String args[])String url = "https:///common/postcode/getPostCo deByAddr";String requestMethod = "POST";Map<String, String> params = new HashMap<String, String>(); params.put("apiKey","your_api_key"); //需要从获取params.put("stock_code", ""); //股票代码params.put("period", ""); //1:1分钟 2:5分钟 3:15分钟 4:30分钟5:60分钟 6:日k线 7:周k线 8:月k线params.put("request_num", ""); //请求行数params.put("position_str", ""); //定位串,默认-1 从头开始String result = null;try{InputStream is = httpRequestToStream(url, requestMethod, pa rams);byte[] b = new byte[is.available()];is.read(b);result = new String(b);}catch(IOException e){e.printStackTrace();}if (result != null){JSONObject jsonObject = JSONObject.parseObject(result);String status_code = jsonObject.getString("statusCode");if (status_code == "000000"){// 状态码为000000, 说明请求成功System.out.println("请求成功:" + jsonObject.getString("resu lt"));}else{// 状态码非000000, 说明请求失败System.out.println("请求失败:" + jsonObject.getString("desc "));}}else{// 返回内容异常,发送请求失败,以下可根据业务逻辑自行修改System.out.println("发送请求失败");}}2.实时行情查询package net.apishop.www.controller;import java.io.DataOutputStream;import java.io.IOException;import java.io.InputStream;import java.io.UnsupportedEncodingException;import .HttpURLConnection;import .MalformedURLException;import .URL;import .URLEncoder;import java.util.HashMap;import java.util.Map;import com.alibaba.fastjson.JSONObject;/*** httpUrlConnection访问远程接口工具*/public class Api{/*** 方法体说明:向远程接口发起请求,返回字节流类型结果* param url 接口地址* param requestMethod 请求方式* param params 传递参数重点:参数值需要用Base64进行转码* return InputStream 返回结果*/public static InputStream httpRequestToStream(String url, String re questMethod, Map<String, String> params){InputStream is = null;try{String parameters = "";boolean hasParams = false;// 将参数集合拼接成特定格式,如name=zhangsan&age=24for (String key : params.keySet()){String value = URLEncoder.encode(params.get(key), "UTF-8");parameters += key + "=" + value + "&";hasParams = true;}if (hasParams){parameters = parameters.substring(0, parameters.length() - 1);}// 请求方式是否为getboolean isGet = "get".equalsIgnoreCase(requestMethod);// 请求方式是否为postboolean isPost = "post".equalsIgnoreCase(requestMethod);if (isGet){url += "?" + parameters;}URL u = new URL(url);HttpURLConnection conn = (HttpURLConnection) u.openConnecti on();// 请求的参数类型(使用restlet框架时,为了兼容框架,必须设置Con tent-Type为“”空)conn.setRequestProperty("Content-Type", "application/octet-stream");// conn.setRequestProperty("Content-Type", "application/x-w ww-form-urlencoded");// 设置连接超时时间conn.setConnectTimeout(50000);// 设置读取返回内容超时时间conn.setReadTimeout(50000);// 设置向HttpURLConnection对象中输出,因为post方式将请求参数放在http正文内,因此需要设置为ture,默认falseif (isPost){conn.setDoOutput(true);}// 设置从HttpURLConnection对象读入,默认为trueconn.setDoInput(true);// 设置是否使用缓存,post方式不能使用缓存if (isPost){conn.setUseCaches(false);}// 设置请求方式,默认为GETconn.setRequestMethod(requestMethod);// post方式需要将传递的参数输出到conn对象中if (isPost){DataOutputStream dos = new DataOutputStream(conn.getOut putStream());dos.writeBytes(parameters);dos.flush();dos.close();}// 从HttpURLConnection对象中读取响应的消息// 执行该语句时才正式发起请求is = conn.getInputStream();}catch(UnsupportedEncodingException e){e.printStackTrace();}catch(MalformedURLException e){e.printStackTrace();}catch(IOException e){e.printStackTrace();}return is;}public static void main(String args[]){String url = "https:///common/postcode/getPostCo deByAddr";String requestMethod = "POST";Map<String, String> params = new HashMap<String, String>(); params.put("apiKey","your_api_key"); //需要从获取params.put("stock_code", ""); //股票代码String result = null;try{InputStream is = httpRequestToStream(url, requestMethod, pa rams);byte[] b = new byte[is.available()];is.read(b);result = new String(b);}catch(IOException e){e.printStackTrace();}if (result != null){JSONObject jsonObject = JSONObject.parseObject(result);String status_code = jsonObject.getString("statusCode");if (status_code == "000000"){// 状态码为000000, 说明请求成功System.out.println("请求成功:" + jsonObject.getString("resu lt"));}else{// 状态码非000000, 说明请求失败System.out.println("请求失败:" + jsonObject.getString("desc "));}}else{// 返回内容异常,发送请求失败,以下可根据业务逻辑自行修改System.out.println("发送请求失败");}}}3.查询股票列表package net.apishop.www.controller;import java.io.DataOutputStream;import java.io.IOException;import java.io.InputStream;import java.io.UnsupportedEncodingException;import .HttpURLConnection;import .MalformedURLException;import .URL;import .URLEncoder;import java.util.HashMap;import java.util.Map;import com.alibaba.fastjson.JSONObject;/*** httpUrlConnection访问远程接口工具*/public class Api{/*** 方法体说明:向远程接口发起请求,返回字节流类型结果* param url 接口地址* param requestMethod 请求方式* param params 传递参数重点:参数值需要用Base64进行转码* return InputStream 返回结果*/public static InputStream httpRequestToStream(String url, String re questMethod, Map<String, String> params){InputStream is = null;try{String parameters = "";boolean hasParams = false;// 将参数集合拼接成特定格式,如name=zhangsan&age=24for (String key : params.keySet()){String value = URLEncoder.encode(params.get(key), "UTF-8");parameters += key + "=" + value + "&";hasParams = true;}if (hasParams){parameters = parameters.substring(0, parameters.length() - 1);}// 请求方式是否为getboolean isGet = "get".equalsIgnoreCase(requestMethod);// 请求方式是否为postboolean isPost = "post".equalsIgnoreCase(requestMethod);if (isGet){url += "?" + parameters;}URL u = new URL(url);HttpURLConnection conn = (HttpURLConnection) u.openConnecti on();// 请求的参数类型(使用restlet框架时,为了兼容框架,必须设置Con tent-Type为“”空)conn.setRequestProperty("Content-Type", "application/octet-stream");// conn.setRequestProperty("Content-Type", "application/x-w ww-form-urlencoded");// 设置连接超时时间conn.setConnectTimeout(50000);// 设置读取返回内容超时时间conn.setReadTimeout(50000);// 设置向HttpURLConnection对象中输出,因为post方式将请求参数放在http正文内,因此需要设置为ture,默认falseif (isPost){conn.setDoOutput(true);}// 设置从HttpURLConnection对象读入,默认为trueconn.setDoInput(true);// 设置是否使用缓存,post方式不能使用缓存if (isPost){conn.setUseCaches(false);}// 设置请求方式,默认为GETconn.setRequestMethod(requestMethod);// post方式需要将传递的参数输出到conn对象中if (isPost){DataOutputStream dos = new DataOutputStream(conn.getOut putStream());dos.writeBytes(parameters);dos.flush();dos.close();}// 从HttpURLConnection对象中读取响应的消息// 执行该语句时才正式发起请求is = conn.getInputStream();}catch(UnsupportedEncodingException e){e.printStackTrace();}catch(MalformedURLException e){e.printStackTrace();}catch(IOException e){e.printStackTrace();}return is;}public static void main(String args[])String url = "https:///common/postcode/getPostCo deByAddr";String requestMethod = "POST";Map<String, String> params = new HashMap<String, String>(); params.put("apiKey","your_api_key"); //需要从获取params.put("stock_type", ""); //市场类别params.put("request_num", ""); //定位串,传空默认为20 params.put("position_str", ""); //起始位空,从应答中获取String result = null;try{InputStream is = httpRequestToStream(url, requestMethod, pa rams);byte[] b = new byte[is.available()];is.read(b);result = new String(b);}catch(IOException e){e.printStackTrace();}if (result != null){JSONObject jsonObject = JSONObject.parseObject(result);String status_code = jsonObject.getString("statusCode");if (status_code == "000000"){// 状态码为000000, 说明请求成功System.out.println("请求成功:" + jsonObject.getString("resu lt"));}else{// 状态码非000000, 说明请求失败System.out.println("请求失败:" + jsonObject.getString("desc "));}}else{// 返回内容异常,发送请求失败,以下可根据业务逻辑自行修改System.out.println("发送请求失败");}}4.查询股票市场package net.apishop.www.controller;import java.io.DataOutputStream;import java.io.IOException;import java.io.InputStream;import java.io.UnsupportedEncodingException;import .HttpURLConnection;import .MalformedURLException;import .URL;import .URLEncoder;import java.util.HashMap;import java.util.Map;import com.alibaba.fastjson.JSONObject;/*** httpUrlConnection访问远程接口工具*/public class Api{/*** 方法体说明:向远程接口发起请求,返回字节流类型结果* param url 接口地址* param requestMethod 请求方式* param params 传递参数重点:参数值需要用Base64进行转码* return InputStream 返回结果*/public static InputStream httpRequestToStream(String url, String re questMethod, Map<String, String> params){InputStream is = null;try{String parameters = "";boolean hasParams = false;// 将参数集合拼接成特定格式,如name=zhangsan&age=24for (String key : params.keySet()){String value = URLEncoder.encode(params.get(key), "UTF-8");parameters += key + "=" + value + "&";hasParams = true;}if (hasParams){parameters = parameters.substring(0, parameters.length() - 1);}// 请求方式是否为getboolean isGet = "get".equalsIgnoreCase(requestMethod);// 请求方式是否为postboolean isPost = "post".equalsIgnoreCase(requestMethod);if (isGet){url += "?" + parameters;}URL u = new URL(url);HttpURLConnection conn = (HttpURLConnection) u.openConnecti on();// 请求的参数类型(使用restlet框架时,为了兼容框架,必须设置Con tent-Type为“”空)conn.setRequestProperty("Content-Type", "application/octet-stream");// conn.setRequestProperty("Content-Type", "application/x-w ww-form-urlencoded");// 设置连接超时时间conn.setConnectTimeout(50000);// 设置读取返回内容超时时间conn.setReadTimeout(50000);// 设置向HttpURLConnection对象中输出,因为post方式将请求参数放在http正文内,因此需要设置为ture,默认falseif (isPost){conn.setDoOutput(true);}// 设置从HttpURLConnection对象读入,默认为trueconn.setDoInput(true);// 设置是否使用缓存,post方式不能使用缓存if (isPost){conn.setUseCaches(false);}// 设置请求方式,默认为GETconn.setRequestMethod(requestMethod);// post方式需要将传递的参数输出到conn对象中if (isPost){DataOutputStream dos = new DataOutputStream(conn.getOut putStream());dos.writeBytes(parameters);dos.flush();dos.close();}// 从HttpURLConnection对象中读取响应的消息// 执行该语句时才正式发起请求is = conn.getInputStream();}catch(UnsupportedEncodingException e){e.printStackTrace();}catch(MalformedURLException e){e.printStackTrace();}catch(IOException e){e.printStackTrace();}return is;}public static void main(String args[]){String url = "https:///common/postcode/getPostCo deByAddr";String requestMethod = "POST";Map<String, String> params = new HashMap<String, String>(); params.put("apiKey","your_api_key"); //需要从获取String result = null;try{InputStream is = httpRequestToStream(url, requestMethod, pa rams);byte[] b = new byte[is.available()];is.read(b);result = new String(b);}catch(IOException e){e.printStackTrace();}if (result != null){JSONObject jsonObject = JSONObject.parseObject(result);String status_code = jsonObject.getString("statusCode");if (status_code == "000000"){// 状态码为000000, 说明请求成功System.out.println("请求成功:" + jsonObject.getString("resu lt"));}else{// 状态码非000000, 说明请求失败System.out.println("请求失败:" + jsonObject.getString("desc "));}}else{// 返回内容异常,发送请求失败,以下可根据业务逻辑自行修改System.out.println("发送请求失败");}}}5.分笔package net.apishop.www.controller;import java.io.DataOutputStream;import java.io.IOException;import java.io.InputStream;import java.io.UnsupportedEncodingException;import .HttpURLConnection;import .MalformedURLException;import .URL;import .URLEncoder;import java.util.HashMap;import java.util.Map;import com.alibaba.fastjson.JSONObject;/*** httpUrlConnection访问远程接口工具*/public class Api{/*** 方法体说明:向远程接口发起请求,返回字节流类型结果* param url 接口地址* param requestMethod 请求方式* param params 传递参数重点:参数值需要用Base64进行转码* return InputStream 返回结果*/public static InputStream httpRequestToStream(String url, String re questMethod, Map<String, String> params){InputStream is = null;try{String parameters = "";boolean hasParams = false;// 将参数集合拼接成特定格式,如name=zhangsan&age=24for (String key : params.keySet()){String value = URLEncoder.encode(params.get(key), "UTF-8");parameters += key + "=" + value + "&";hasParams = true;}if (hasParams){parameters = parameters.substring(0, parameters.length() - 1);}// 请求方式是否为getboolean isGet = "get".equalsIgnoreCase(requestMethod);// 请求方式是否为postboolean isPost = "post".equalsIgnoreCase(requestMethod);if (isGet){url += "?" + parameters;}URL u = new URL(url);HttpURLConnection conn = (HttpURLConnection) u.openConnecti on();// 请求的参数类型(使用restlet框架时,为了兼容框架,必须设置Con tent-Type为“”空)conn.setRequestProperty("Content-Type", "application/octet-stream");// conn.setRequestProperty("Content-Type", "application/x-w ww-form-urlencoded");// 设置连接超时时间conn.setConnectTimeout(50000);// 设置读取返回内容超时时间conn.setReadTimeout(50000);// 设置向HttpURLConnection对象中输出,因为post方式将请求参数放在http正文内,因此需要设置为ture,默认falseif (isPost){conn.setDoOutput(true);}// 设置从HttpURLConnection对象读入,默认为trueconn.setDoInput(true);// 设置是否使用缓存,post方式不能使用缓存if (isPost){conn.setUseCaches(false);}// 设置请求方式,默认为GETconn.setRequestMethod(requestMethod);// post方式需要将传递的参数输出到conn对象中if (isPost){DataOutputStream dos = new DataOutputStream(conn.getOut putStream());dos.writeBytes(parameters);dos.flush();dos.close();}// 从HttpURLConnection对象中读取响应的消息// 执行该语句时才正式发起请求is = conn.getInputStream();}catch(UnsupportedEncodingException e){e.printStackTrace();}catch(MalformedURLException e){e.printStackTrace();}catch(IOException e){e.printStackTrace();}return is;}public static void main(String args[]){String url = "https:///common/postcode/getPostCo deByAddr";String requestMethod = "POST";Map<String, String> params = new HashMap<String, String>(); params.put("apiKey","your_api_key"); //需要从获取params.put("stock_code", ""); //股票代码params.put("request_num", ""); //请求参数String result = null;try{InputStream is = httpRequestToStream(url, requestMethod, pa rams);byte[] b = new byte[is.available()];is.read(b);result = new String(b);}catch(IOException e){e.printStackTrace();}if (result != null){JSONObject jsonObject = JSONObject.parseObject(result);String status_code = jsonObject.getString("statusCode");if (status_code == "000000"){// 状态码为000000, 说明请求成功System.out.println("请求成功:" + jsonObject.getString("resu lt"));}else{// 状态码非000000, 说明请求失败System.out.println("请求失败:" + jsonObject.getString("desc "));}}else{// 返回内容异常,发送请求失败,以下可根据业务逻辑自行修改System.out.println("发送请求失败");}}}6.分时查询package net.apishop.www.controller;import java.io.DataOutputStream;import java.io.IOException;import java.io.InputStream;import java.io.UnsupportedEncodingException;import .HttpURLConnection;import .MalformedURLException;import .URL;import .URLEncoder;import java.util.HashMap;import java.util.Map;import com.alibaba.fastjson.JSONObject;/*** httpUrlConnection访问远程接口工具*/public class Api{/*** 方法体说明:向远程接口发起请求,返回字节流类型结果* param url 接口地址* param requestMethod 请求方式* param params 传递参数重点:参数值需要用Base64进行转码* return InputStream 返回结果*/public static InputStream httpRequestToStream(String url, String re questMethod, Map<String, String> params){InputStream is = null;try{String parameters = "";boolean hasParams = false;// 将参数集合拼接成特定格式,如name=zhangsan&age=24for (String key : params.keySet()){String value = URLEncoder.encode(params.get(key), "UTF-8");parameters += key + "=" + value + "&";hasParams = true;}if (hasParams){parameters = parameters.substring(0, parameters.length() - 1);}// 请求方式是否为getboolean isGet = "get".equalsIgnoreCase(requestMethod);// 请求方式是否为postboolean isPost = "post".equalsIgnoreCase(requestMethod);if (isGet){url += "?" + parameters;}URL u = new URL(url);HttpURLConnection conn = (HttpURLConnection) u.openConnecti on();// 请求的参数类型(使用restlet框架时,为了兼容框架,必须设置Con tent-Type为“”空)conn.setRequestProperty("Content-Type", "application/octet-stream");// conn.setRequestProperty("Content-Type", "application/x-w ww-form-urlencoded");// 设置连接超时时间conn.setConnectTimeout(50000);// 设置读取返回内容超时时间conn.setReadTimeout(50000);// 设置向HttpURLConnection对象中输出,因为post方式将请求参数放在http正文内,因此需要设置为ture,默认falseif (isPost){conn.setDoOutput(true);}// 设置从HttpURLConnection对象读入,默认为trueconn.setDoInput(true);// 设置是否使用缓存,post方式不能使用缓存if (isPost){conn.setUseCaches(false);}// 设置请求方式,默认为GETconn.setRequestMethod(requestMethod);// post方式需要将传递的参数输出到conn对象中if (isPost){DataOutputStream dos = new DataOutputStream(conn.getOut putStream());dos.writeBytes(parameters);dos.flush();dos.close();// 从HttpURLConnection对象中读取响应的消息// 执行该语句时才正式发起请求is = conn.getInputStream();}catch(UnsupportedEncodingException e){e.printStackTrace();}catch(MalformedURLException e){e.printStackTrace();}catch(IOException e){e.printStackTrace();}return is;}public static void main(String args[]){String url = "https:///common/postcode/getPostCo deByAddr";String requestMethod = "POST";Map<String, String> params = new HashMap<String, String>(); params.put("apiKey","your_api_key"); //需要从获取params.put("stock_code", ""); //股票代码String result = null;try{InputStream is = httpRequestToStream(url, requestMethod, pa rams);byte[] b = new byte[is.available()];is.read(b);result = new String(b);}catch(IOException e){e.printStackTrace();}if (result != null){JSONObject jsonObject = JSONObject.parseObject(result);String status_code = jsonObject.getString("statusCode");if (status_code == "000000")// 状态码为000000, 说明请求成功System.out.println("请求成功:" + jsonObject.getString("resu lt"));}else{// 状态码非000000, 说明请求失败System.out.println("请求失败:" + jsonObject.getString("desc "));}}else{// 返回内容异常,发送请求失败,以下可根据业务逻辑自行修改System.out.println("发送请求失败");}}}7.指数实时报价package net.apishop.www.controller;import java.io.DataOutputStream;import java.io.IOException;import java.io.InputStream;import java.io.UnsupportedEncodingException;import .HttpURLConnection;import .MalformedURLException;import .URL;import .URLEncoder;import java.util.HashMap;import java.util.Map;import com.alibaba.fastjson.JSONObject;/*** httpUrlConnection访问远程接口工具*/public class Api{/*** 方法体说明:向远程接口发起请求,返回字节流类型结果* param url 接口地址* param requestMethod 请求方式* param params 传递参数重点:参数值需要用Base64进行转码* return InputStream 返回结果*/public static InputStream httpRequestToStream(String url, String re questMethod, Map<String, String> params){InputStream is = null;try{String parameters = "";boolean hasParams = false;// 将参数集合拼接成特定格式,如name=zhangsan&age=24for (String key : params.keySet()){String value = URLEncoder.encode(params.get(key), "UTF-8");parameters += key + "=" + value + "&";hasParams = true;}if (hasParams){parameters = parameters.substring(0, parameters.length() - 1);}// 请求方式是否为getboolean isGet = "get".equalsIgnoreCase(requestMethod);// 请求方式是否为postboolean isPost = "post".equalsIgnoreCase(requestMethod);if (isGet){url += "?" + parameters;}URL u = new URL(url);HttpURLConnection conn = (HttpURLConnection) u.openConnecti on();// 请求的参数类型(使用restlet框架时,为了兼容框架,必须设置Con tent-Type为“”空)conn.setRequestProperty("Content-Type", "application/octet-stream");// conn.setRequestProperty("Content-Type", "application/x-w ww-form-urlencoded");// 设置连接超时时间conn.setConnectTimeout(50000);// 设置读取返回内容超时时间conn.setReadTimeout(50000);// 设置向HttpURLConnection对象中输出,因为post方式将请求参数放在http正文内,因此需要设置为ture,默认falseif (isPost){conn.setDoOutput(true);}// 设置从HttpURLConnection对象读入,默认为trueconn.setDoInput(true);// 设置是否使用缓存,post方式不能使用缓存if (isPost){conn.setUseCaches(false);}// 设置请求方式,默认为GETconn.setRequestMethod(requestMethod);// post方式需要将传递的参数输出到conn对象中if (isPost){DataOutputStream dos = new DataOutputStream(conn.getOut putStream());dos.writeBytes(parameters);dos.flush();dos.close();}// 从HttpURLConnection对象中读取响应的消息// 执行该语句时才正式发起请求is = conn.getInputStream();}catch(UnsupportedEncodingException e){e.printStackTrace();}catch(MalformedURLException e){e.printStackTrace();}catch(IOException e){e.printStackTrace();}return is;}public static void main(String args[]){String url = "https:///common/postcode/getPostCo deByAddr";String requestMethod = "POST";Map<String, String> params = new HashMap<String, String>(); params.put("apiKey","your_api_key"); //需要从获取params.put("stock_code", ""); //代码String result = null;try{InputStream is = httpRequestToStream(url, requestMethod, pa rams);byte[] b = new byte[is.available()];is.read(b);result = new String(b);}catch(IOException e){e.printStackTrace();}if (result != null){JSONObject jsonObject = JSONObject.parseObject(result);String status_code = jsonObject.getString("statusCode");if (status_code == "000000"){// 状态码为000000, 说明请求成功System.out.println("请求成功:" + jsonObject.getString("resu lt"));}else{// 状态码非000000, 说明请求失败System.out.println("请求失败:" + jsonObject.getString("desc "));}}else{// 返回内容异常,发送请求失败,以下可根据业务逻辑自行修改System.out.println("发送请求失败");}}}8.组合行情查询package net.apishop.www.controller;import java.io.DataOutputStream;。
eoLinker-API_Shop_手机号归属地查询_API接口_C#调用示例代码
eoLinker-API Shop 手机号归属地查询 C#调用示例代码手机号归属地查询根据中国大陆手机号获取归属地信息。
该产品拥有以下APIs:1.根据手机号获取归属地信息注意,该示例代码仅适用于网站下API使用该产品前,您需要通过https:///#/api/detail/?productID=72申请API服务1.根据手机号获取归属地信息using System;using System.Collections.Generic;using System.IO;using ;using System.Text;using System.Web.Script.Serialization;namespace apishop_sdk{class Program{/*** 转发请求到目的主机* @param method string 请求方法* @param url string 请求地址* @param params Dictionary<string,string> 请求参数* @param headers Dictionary<string,string> 请求头* @return string**/static string apishop_send_request(string method, string url, D ictionary<string, string> param, Dictionary<string, string> headers){string result = string.Empty;try{string paramData = "";if (param != null && param.Count > 0){StringBuilder sbuilder = new StringBuilder();foreach (var item in param){if (sbuilder.Length > 0){sbuilder.Append("&");}sbuilder.Append(item.Key + "=" + item.Value);}paramData = sbuilder.ToString();}method = method.ToUpper();if (method == "GET"){url = string.Format("{0}?{1}", url, paramData);}HttpWebRequest wbRequest = (HttpWebRequest)WebRequest.C reate(url);if (method == "GET"){wbRequest.Method = "GET";}else if (method == "POST"){wbRequest.Method = "POST";wbRequest.ContentType = "application/x-www-form-url encoded";wbRequest.ContentLength = Encoding.UTF8.GetByteCoun t(paramData);using (Stream requestStream = wbRequest.GetRequestS tream()){using (StreamWriter swrite = new StreamWriter(r equestStream)){swrite.Write(paramData);}}}HttpWebResponse wbResponse = (HttpWebResponse)wbRequest. GetResponse();using (Stream responseStream = wbResponse.GetResponseSt ream()){using (StreamReader sread = new StreamReader(respon seStream)){result = sread.ReadToEnd();}}}catch{return "";}return result;}class Response{public string statusCode;}static void Main(string[] args){string method = "POST";string url = "https:///communication/phone/g etLocationByPhoneNum";Dictionary<string, string> param = new Dictionary<string, s tring>();param.Add("apiKey", "your_api_key"); //需要从www.apishop.ne t获取param.Add("phoneNum", ""); //目标手机号或手机号前7位Dictionary<string, string> headers = null;string result = apishop_send_request(method, url, param, he aders);if (result == ""){//返回内容异常,发送请求失败Console.WriteLine("发送请求失败");return;}Response res = new JavaScriptSerializer().Deserialize<Respo nse>(result);if (res.statusCode == "000000"){//状态码为000000, 说明请求成功Console.WriteLine(string.Format("请求成功: {0}", resul t));}else{//状态码非000000, 说明请求失败Console.WriteLine(string.Format("请求失败: {0}", resul t));}Console.ReadLine();}}}。
- 1、下载文档前请自行甄别文档内容的完整性,平台不提供额外的编辑、内容补充、找答案等附加服务。
- 2、"仅部分预览"的文档,不可在线预览部分如存在完整性等问题,可反馈申请退款(可完整预览的文档不适用该条件!)。
- 3、如文档侵犯您的权益,请联系客服反馈,我们会尽快为您处理(人工客服工作时间:9:00-18:30)。
eoLinker-API Shop 成语大全 C#调用示例代码成语大全包含发音、解释、出自典故、近义词、反义词、例句等数据,可进行成语接龙、成语竞猜等游戏开发。
该产品拥有以下APIs:1.成语搜索2.查询成语详情注意,该示例代码仅适用于网站下API使用该产品前,您需要通过https:///#/api/detail/?productID=93申请API服务1.成语搜索using System;using System.Collections.Generic;using System.IO;using ;using System.Text;using System.Web.Script.Serialization;namespace apishop_sdk{class Program{/*** 转发请求到目的主机* @param method string 请求方法* @param url string 请求地址* @param params Dictionary<string,string> 请求参数* @param headers Dictionary<string,string> 请求头* @return string**/static string apishop_send_request(string method, string url, D ictionary<string, string> param, Dictionary<string, string> headers){string result = string.Empty;try{string paramData = "";if (param != null && param.Count > 0){StringBuilder sbuilder = new StringBuilder();foreach (var item in param){if (sbuilder.Length > 0){sbuilder.Append("&");}sbuilder.Append(item.Key + "=" + item.Value);}paramData = sbuilder.ToString();}method = method.ToUpper();if (method == "GET"){url = string.Format("{0}?{1}", url, paramData);}HttpWebRequest wbRequest = (HttpWebRequest)WebRequest.C reate(url);if (method == "GET"){wbRequest.Method = "GET";}else if (method == "POST"){wbRequest.Method = "POST";wbRequest.ContentType = "application/x-www-form-url encoded";wbRequest.ContentLength = Encoding.UTF8.GetByteCoun t(paramData);using (Stream requestStream = wbRequest.GetRequestS tream()){using (StreamWriter swrite = new StreamWriter(r equestStream)){swrite.Write(paramData);}}}HttpWebResponse wbResponse = (HttpWebResponse)wbRequest. GetResponse();using (Stream responseStream = wbResponse.GetResponseSt ream()){using (StreamReader sread = new StreamReader(respon seStream)){result = sread.ReadToEnd();}}}catch{return "";}return result;}class Response{public string statusCode;}static void Main(string[] args){string method = "POST";string url = "https:///common/chengyu/search Chengyu";Dictionary<string, string> param = new Dictionary<string, s tring>();param.Add("keyWord", ""); //关键字,如"蛇"Dictionary<string, string> headers = null;string result = apishop_send_request(method, url, param, he aders);if (result == ""){//返回内容异常,发送请求失败Console.WriteLine("发送请求失败");return;}Response res = new JavaScriptSerializer().Deserialize<Respo nse>(result);if (res.statusCode == "000000"){//状态码为000000, 说明请求成功Console.WriteLine(string.Format("请求成功: {0}", resul t));}else{//状态码非000000, 说明请求失败Console.WriteLine(string.Format("请求失败: {0}", resul t));}Console.ReadLine();}}}2.查询成语详情using System;using System.Collections.Generic;using System.IO;using ;using System.Text;using System.Web.Script.Serialization;namespace apishop_sdk{class Program{/*** 转发请求到目的主机* @param method string 请求方法* @param url string 请求地址* @param params Dictionary<string,string> 请求参数* @param headers Dictionary<string,string> 请求头* @return string**/static string apishop_send_request(string method, string url, D ictionary<string, string> param, Dictionary<string, string> headers){string result = string.Empty;try{string paramData = "";if (param != null && param.Count > 0){StringBuilder sbuilder = new StringBuilder();foreach (var item in param){if (sbuilder.Length > 0){sbuilder.Append("&");}sbuilder.Append(item.Key + "=" + item.Value); }paramData = sbuilder.ToString();}method = method.ToUpper();if (method == "GET"){url = string.Format("{0}?{1}", url, paramData);}HttpWebRequest wbRequest = (HttpWebRequest)WebRequest.C reate(url);if (method == "GET"){wbRequest.Method = "GET";}else if (method == "POST"){wbRequest.Method = "POST";wbRequest.ContentType = "application/x-www-form-url encoded";wbRequest.ContentLength = Encoding.UTF8.GetByteCoun t(paramData);using (Stream requestStream = wbRequest.GetRequestS tream()){using (StreamWriter swrite = new StreamWriter(r equestStream)){swrite.Write(paramData);}}}HttpWebResponse wbResponse = (HttpWebResponse)wbRequest. GetResponse();using (Stream responseStream = wbResponse.GetResponseSt ream()){using (StreamReader sread = new StreamReader(respon seStream)){result = sread.ReadToEnd();}}}catch{return "";}return result;}class Response{public string statusCode;}static void Main(string[] args){string method = "POST";string url = "https:///common/chengyu/getChengyuDetail";Dictionary<string, string> param = new Dictionary<string, s tring>();param.Add("chengyu", ""); //要查询的成语,如“打草惊蛇” Dictionary<string, string> headers = null;string result = apishop_send_request(method, url, param, he aders);if (result == ""){//返回内容异常,发送请求失败Console.WriteLine("发送请求失败");return;}Response res = new JavaScriptSerializer().Deserialize<Respo nse>(result);if (res.statusCode == "000000"){//状态码为000000, 说明请求成功Console.WriteLine(string.Format("请求成功: {0}", resul t));}else{//状态码非000000, 说明请求失败Console.WriteLine(string.Format("请求失败: {0}", resul t));}Console.ReadLine();}}}。