eoLinker-API_Shop_《机动车合格证》二维码解码_API接口_C#调用示例代码
- 格式:docx
- 大小:11.79 KB
- 文档页数:4
eoLinker-API Shop 驾考题库-新 Java调用示例代码驾考题库-新公安部最新驾照考试题库,分科目一与科目二两种题型;包括小车、货车、客车与摩托车四类车型,涵盖C1、C2、A1、A2、A3、B1、B2、D、E、F等驾照类型。
该产品拥有以下APIs:1.获取题目信息2.获取驾考题库列表3.关键字获取题目注意,该示例代码仅适用于网站下API使用该产品前,您需要通过https:///#/api/detail/?productID=187申请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 requestMethod, 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("questionID", ""); //题目ID,从“获取驾考题目信息”API 获取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("page", ""); //页码(默认为1)params.put("pageSize", ""); //每页题目数量(默认为30)params.put("licenseType", ""); //驾照类型,0:小车(C1、C2),1:客车(A1、A3、B1),2:货车(A2、B2),3:摩托车(D、E、F)params.put("subjectType", ""); //科目类型,0:科目一,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("发送请求失败");}}}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("page", ""); //页码(默认为1)params.put("pageSize", ""); //每页题目数量(默认为30)params.put("licenseType", ""); //驾照类型,0:小车(C1、C2),1:客车(A1、A3、B1),2:货车(A2、B2),3:摩托车(D、E、F)params.put("subjectType", ""); //科目类型,0:科目一,1:科目四(文明考试)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("发送请求失败");}}}。
eoLinker-API Shop 标准中文电码查询 Java调用示例代码标准中文电码查询中文、电码之间相互转换该产品拥有以下APIs:1.中文转电码2.电码转中文注意,该示例代码仅适用于网站下API使用该产品前,您需要通过https:///#/api/detail/?productID=96申请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("chinese", ""); //中文内容,如“你好”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("code", ""); //电码内容,用英文逗号分割,如“0132,1170” 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 电视节目 C#调用示例代码电视节目央视及各地卫视的电视节目时间表,包括本周及下周的电视节目内容该产品拥有以下APIs:1.获取电视台分类2.获取电视频道3.获取电视节目的详情注意,该示例代码仅适用于网站下API使用该产品前,您需要通过https:///#/api/detail/?productID=129申请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/tv/queryCatego ry";Dictionary<string, string> param = new Dictionary<string, s tring>();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/tv/queryTVChannel";Dictionary<string, string> param = new Dictionary<string, s tring>();param.Add("categoryName", ""); //频道分类名称(从获取频道分类接口获得,如“央视”)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();}}}3.获取电视节目的详情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/tv/queryTVProg ram";Dictionary<string, string> param = new Dictionary<string, s tring>();param.Add("id", ""); //频道ID(从获取频道接口获得)param.Add("date", ""); //日期(格式:yyyy-mm-dd,如“2017-09-2 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();}}}。
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 POI检索 Java调用示例代码POI检索通过关键词查询在某个地区的POI信息,支持市级、区县级查询:比如在广州查询“银行”,接口将会输出所有银行的地理信息列表。
该产品拥有以下APIs:1.POI搜索2.周边POI搜索3.POI多边形搜索注意,该示例代码仅适用于网站下API使用该产品前,您需要通过https:///#/api/detail/?productID=97申请API服务1.POI搜索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 requestMethod, 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("keyWords", ""); //查询关键字(规则:多个关键字用“|”分割若不指定city,并且搜索的为泛词(例如“美食”)的情况下,返回的内容为城市列表以及此城市内有多少结果符合要求。
eoLinker-API Shop 新华字典 Python调用示例代码新华字典包含汉字的发音、部首、结构、笔顺、五笔、英文、解释、内容、多音字等。
该产品拥有以下APIs:1.新华字典查询注意,该示例代码仅适用于网站下API使用该产品前,您需要通过https:///#/api/detail/?productID=98申请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/dictionary/queryChineseWord" headers = Noneparams = {"apiKey":"your_api_key", #需要从获取"word":"" #要查询的字,如“口”}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 NBA赛事 C#调用示例代码NBA赛事NBA篮球赛事赛程相关信息该产品拥有以下APIs:1.按年份查询篮球赛事2.按球队查询篮球赛事3.按对战球队查询篮球赛事注意,该示例代码仅适用于网站下API使用该产品前,您需要通过https:///#/api/detail/?productID=125申请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/basketball/que ryBasketballMatchByYear";Dictionary<string, string> param = new Dictionary<string, s tring>();param.Add("year", ""); //年份(范围:2014~2017)param.Add("page", ""); //页码param.Add("pageSize", ""); //每页条数(最多40,默认20条)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/basketball/que ryBasketballMatchByTeam";Dictionary<string, string> param = new Dictionary<string, s tring>();param.Add("team", ""); //球队名称(如“火箭”)param.Add("page", ""); //页码param.Add("pageSize", ""); //每页条数(最多40,默认20条)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();}}}3.按对战球队查询篮球赛事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/basketball/que ryBasketballMatchByTeams";Dictionary<string, string> param = new Dictionary<string, s tring>();param.Add("team1", ""); //客队球队名称(如“火箭”)param.Add("team2", ""); //主队球队名称(如“马刺”)param.Add("page", ""); //页码param.Add("pageSize", ""); //每页条数(最多40,默认20条)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 银行卡信息查询(含归属地) PHP调用示例代码银行卡信息查询(含归属地)支持超30家主流银行归属地查询;支持国内外1200多家银行的银行卡信息查询,返回发卡行、编号、卡种、客服电话、卡样、官网、 Logo等信息,及时更新。
该产品拥有以下APIs:1.查询银行卡信息注意,该示例代码仅适用于网站下API使用该产品前,您需要通过https:///#/api/detail/?productID=191申请API服务1.查询银行卡信息<?php$method = "POST";$url = "https:///common/bank/queryCardDetail";$headers = NULL;$params = array("apiKey"=>"your_api_key", //需要从获取"bankcard"=>"", //银行卡号);$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-车牌识别 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 《机动车合格证》二维码解码 C#调用示例
代码
《机动车合格证》二维码解码
通过对《机动车合格证》上的加密二维码进行解码,获取包括车架号、品牌、厂家、发动机号等在内的车辆信息,可以用于《机动车合格证》真伪验证、保险快速录单、车贷快速录单、库存融资远程盘库等各种应用场景。
该产品拥有以下APIs:
1.《机动车合格证》二维码文本解码
注意,该示例代码仅适用于网站下API使用该产品前,您需要
通过https:///#/api/detail/?productID=216申请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:///ccdfeege/vin123";
Dictionary<string, string> param = new Dictionary<string, s tring>();
param.Add("apiKey", "your_api_key"); //需要从www.apishop.ne t获取
param.Add("encText", ""); //《机动车合格证》二维码未解码之前的密文,类似:ZCCCHGZ_V3.1 20091013#1280|C206A……
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(); }
}
}。