java 后台 实名认证接口,聚合数据实名认证接口-java方法「建议收藏」

Java (85) 2023-05-29 12:12

Hi,大家好,我是编程小6,很荣幸遇见你,我把这些年在开发过程中遇到的问题或想法写出来,今天说一说java 后台 实名认证接口,聚合数据实名认证接口-java方法「建议收藏」,希望能够帮助你!!!。

();

m.put("realname", user_uname);

m.put("idcard", anchor_card);

m.put("key", APPKEY);

String s;try{

s= net("http://op.juhe.cn/idcard/query",m,"POST");returns;

}catch(Exception e) {//TODO Auto-generated catch block

e.printStackTrace();

}return "认证失败";

}/***

*@paramstrUrl 请求地址

*@paramparams 请求参数

*@parammethod 请求方法

*@return网络请求字符串

*@throwsException*/

public static String net(String strUrl, Map params,String method) throwsException {

HttpURLConnection conn= null;

BufferedReader reader= null;

String rs= null;try{

StringBuffer sb= newStringBuffer();if(method==null || method.equals("GET")){

strUrl= strUrl+"?"+urlencode(params);

}

URL url= newURL(strUrl);

conn=(HttpURLConnection) url.openConnection();if(method==null || method.equals("GET")){

conn.setRequestMethod("GET");

}else{

conn.setRequestMethod("POST");

conn.setDoOutput(true);

}

conn.setRequestProperty("User-agent", userAgent);

conn.setUseCaches(false);

conn.setConnectTimeout(DEF_CONN_TIMEOUT);

conn.setReadTimeout(DEF_READ_TIMEOUT);

conn.setInstanceFollowRedirects(false);

conn.connect();if (params!= null && method.equals("POST")) {try{

DataOutputStream out= newDataOutputStream(conn.getOutputStream());

out.writeBytes(urlencode(params));

}catch(Exception e) {//TODO: handle exception

}

}

InputStream is=conn.getInputStream();

reader= new BufferedReader(newInputStreamReader(is, DEF_CHATSET));

String strRead= null;while ((strRead = reader.readLine()) != null) {

sb.append(strRead);

}

rs=sb.toString();

}catch(IOException e) {

e.printStackTrace();

}finally{if (reader != null) {

reader.close();

}if (conn != null) {

conn.disconnect();

}

}returnrs;

}//将map型转为请求参数型

public static String urlencode(Mapdata) {

StringBuilder sb= newStringBuilder();for(Map.Entry i : data.entrySet()) {try{

sb.append(i.getKey()).append("=").append(URLEncoder.encode(i.getValue()+"","UTF-8")).append("&");

}catch(UnsupportedEncodingException e) {

e.printStackTrace();

}

}returnsb.toString();

}

}

发表回复