hz-zhhq-app-service/greenH5modul/.svn/pristine/64/64110f577f193241278eb7c7b3a...

105 lines
3.9 KiB
Plaintext

package com.nationalelectric.greenH5.identityAuth.controller;
import java.io.File;
import java.io.IOException;
import java.io.UnsupportedEncodingException;
import java.nio.charset.Charset;
import java.sql.SQLException;
import java.util.HashMap;
import java.util.Map;
import javax.annotation.Resource;
import org.apache.http.client.ClientProtocolException;
import org.apache.http.client.methods.CloseableHttpResponse;
import org.apache.http.client.methods.HttpPost;
import org.apache.http.entity.mime.MultipartEntity;
import org.apache.http.entity.mime.content.FileBody;
import org.apache.http.entity.mime.content.StringBody;
import org.apache.http.impl.client.CloseableHttpClient;
import org.apache.http.impl.client.HttpClients;
import org.apache.http.util.EntityUtils;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import com.jysoft.weChat.util.HttpUtil;
import com.nationalelectric.greenH5.identityAuth.service.IdentityAuthService;
import com.nationalelectric.greenH5.identityAuth.util.PhotoUtil;
import com.nationalelectric.greenH5.identityAuth.util.SignGenerater;
import net.sf.json.JSONObject;
import java.sql.CallableStatement;
import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.Statement;
@Controller
@RequestMapping("/idAuth")
public class Test111Controller {
@Resource
private IdentityAuthService iAuthService;
@ResponseBody
@RequestMapping("test")
public String test() {
String base64img = PhotoUtil.fileToBase64("C:\\Users\\Feb\\Desktop\\test.jpg");
String sign = SignGenerater.getSign("赵斌", "34222419950221095X");
//创建默认的HttpClient
CloseableHttpClient httpclient = HttpClients.createDefault();
HttpPost request = new HttpPost("http://www.idverify.cn/identityCloud/api/webApi/identification/fastIdentify");
MultipartEntity reqEntity = new MultipartEntity();
try {
reqEntity.addPart("appId", new StringBody("app5KvQO16uQo7rWh8v", Charset.forName("UTF-8")));
reqEntity.addPart("name", new StringBody("赵斌", Charset.forName("UTF-8")));
reqEntity.addPart("idNo", new StringBody("34222419950221095X", Charset.forName("UTF-8")));
reqEntity.addPart("mode", new StringBody("8", Charset.forName("UTF-8")));
reqEntity.addPart("signatureType", new StringBody("MD5", Charset.forName("UTF-8")));
reqEntity.addPart("signature", new StringBody(sign, Charset.forName("UTF-8")));
reqEntity.addPart("photo", new FileBody(new File("C:\\Users\\Feb\\Desktop\\微信图片_20200213114413.jpg")));
} catch (UnsupportedEncodingException e1) {
e1.printStackTrace();
}
request.setEntity(reqEntity);
CloseableHttpResponse response;
String responseBody = "";
try {
response = httpclient.execute(request);
responseBody = EntityUtils.toString(response.getEntity(), "UTF-8");
} catch (ClientProtocolException e) {
e.printStackTrace();
} catch (IOException e) {
e.printStackTrace();
}
return responseBody;
}
// public static void main(String args[]){
// String className = "sgcc.nds.jdbc.driver.NdsDriver";
// String url = "jdbc:nds://192.168.199.23:18600/v_yx_oracle?appname=app_yxoracle";
// String usrName = "system";
// String pwd = "system";
// Connection conn = null;
// Statement smt = null;
// CallableStatement csmtTest = null;
// PreparedStatement psmt = null;
// ResultSet rs = null;
// try {
// Class.forName(className);
// conn = DriverManager.getConnection(url, usrName, pwd);
// String sql = "";
// smt = conn.createStatement();
// smt.execute("select name,desc_col from insert_tab where desc_col = '??????????????'");
// smt.close();
// conn.close();
// } catch (Exception e) {
// e.printStackTrace();
// }
// }
}