1.实现一个ItsClient 客户端用来实例化调用验证功能public class ItsClient {private static final String routing = "/v1.0/sectoken/otp_validation";// ! HTTPS消息验证地址private String httpsVerifyUrl = "";// ! otp ipAddr private String ipAddr = "";// ! otp port private String port = "";// ! otp appID private String appID = "";// ! otp appKey private String appKey = "";// ! 错误码private int errorCode = 0;// ! 错误消息private String errorMessage = "";TreeMap
}
//获取错误码
public int GetErrorCode() {
return this.errorCode;}public void SetError(int errorCode, String extMessage) {this.errorCode = errorCode;this.errorMessage = this.errorCodeTable.get(this.errorCode).toString() + extMessage;}
public static String SHA1(String decript) throws NoSuchAlgorithmException {String ret = "";MessageDigest sha1 = MessageDigest.getInstance("SHA1");byte[] sha1bytes = sha1.digest(decript.getBytes());if (sha1bytes != null) {ret = new BASE64Encoder().encode(sha1bytes);}return ret;}public String EncodeJson(TreeMappublic class HttpsClient {final static HostnameVerifier doNotVerifier = new HostnameVerifier() {public boolean verify(String hostname, SSLSession session) {return true;}};/*** @brief 发送请求* @param httpsUrl 请求的地址* @param postStr 请求的数据* @throws Exception*/ public String post(String httpsUrl, String postStr) throws Exception {HttpsURLConnection conn = null;StringBuffer recvBuff = new StringBuffer();String resData = "";try {conn = (HttpsURLConnection) (new URL(httpsUrl)).openConnection();conn.setHostnameVerifier(doNotVerifier);conn.setDoInput(true);conn.setDoOutput(true);conn.setRequestMethod("POST");conn.setRequestProperty("Content-Type", " application/json");conn.setRequestProperty("Content-Length", String.valueOf(postStr.getBytes("utf-8").length));conn.setUseCaches(false);//设置为utf-8可以解决服务器接收时读取的数据中文乱码问题conn.getOutputStream().write(postStr.getBytes("utf-8"));conn.getOutputStream().flush();conn.getOutputStream().close();BufferedReader in = new BufferedReader(new InputStreamReader(conn.getInputStream()));String line;while ((line = in.readLine()) != null) {recvBuff.append(line);}resData = recvBuff.toString();return resData;} catch (MalformedURLException ex) {throw ex;} catch (IOException ex) {throw ex;} catch (Exception ex) {throw ex;}}}
3.实现Its一个配置用来配置Its服务器信息接口访问地址
public class ItsConf {// ITS服务器地址 1.1.1.1 或 xxx.xxx.com的形式private static String ipAddr = "";// ITS服务器端口private static String port = "";// OTP服务的AppID private static String otpAppID = "";// OTP服务的AppKey private static String otpAppKey = "";public static String GetIpAddr() {return ipAddr;}public static String GetPort() {return port;}public static String GetOtpAppID() {return otpAppID;}public static String GetOtpAppKey() {return otpAppKey;}}4.接下来就是LoginContorller 完成口令认证//username 用户名//code动态口令密码ItsClient itsClient = new ItsClient();if(itsClient.AuthOtp(username, code)){//认证成功,跳转页面}
5.登陆页面就省略了,自己完成吧
以上就是本文的全部内容,希望对大家的学习有所帮助,也希望大家多多支持脚本之家。
您可能感兴趣的文章:详解java实现简单扫码登录功能(模仿微信网页版扫码)使用weixin-java-tools完成微信授权登录、微信支付的示例JAVA爬虫实现自动登录淘宝第三方网站微信登录java代码实现java使用google身份验证器实现动态口令验证的示例
