|
|
|
@ -2,6 +2,7 @@ package com.dsideal.QingLong.DataShare.Model;
|
|
|
|
|
|
|
|
|
|
import com.dsideal.QingLong.Util.CommonUtil;
|
|
|
|
|
import com.dsideal.QingLong.Util.PgUtil;
|
|
|
|
|
import com.dsideal.QingLong.Util.RsaUtils;
|
|
|
|
|
import com.jfinal.kit.Kv;
|
|
|
|
|
import com.jfinal.kit.StrKit;
|
|
|
|
|
import com.jfinal.plugin.activerecord.Db;
|
|
|
|
@ -338,6 +339,51 @@ public class DataShareModel {
|
|
|
|
|
String sql = "select * from t_datashare_system where redirect_url=?";
|
|
|
|
|
return Db.findFirst(sql, redirect_url) != null;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* 第三方系统,根据用户名密码获取token
|
|
|
|
|
*
|
|
|
|
|
* @param user_name 分配的用户名
|
|
|
|
|
* @param pwd 分配的密码
|
|
|
|
|
* @return 获取到的token, 如果用户名与密码无效,则返回null
|
|
|
|
|
*/
|
|
|
|
|
public String getToken(String user_name, String pwd) {
|
|
|
|
|
String sql = "select * from t_datashare_system where user_name=? and pwd=?";
|
|
|
|
|
Record record = Db.findFirst(sql, user_name, pwd);
|
|
|
|
|
if (record == null) return null;
|
|
|
|
|
return RsaUtils.encryptedDataOnJava(user_name + " " + System.currentTimeMillis(), RsaUtils.PUBLICKEY);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* 验证token是否正确
|
|
|
|
|
*
|
|
|
|
|
* @param token 要验证的token
|
|
|
|
|
* @return
|
|
|
|
|
*/
|
|
|
|
|
public Record checkToken(String token) {
|
|
|
|
|
Record record = new Record();
|
|
|
|
|
try {
|
|
|
|
|
String decryptedData = RsaUtils.decryptDataOnJava(token, RsaUtils.PRIVATEKEY);
|
|
|
|
|
String[] x = decryptedData.split(" ");
|
|
|
|
|
String time = x[1];
|
|
|
|
|
//判断时间戳是否超时,与当前时间相差60*8分钟
|
|
|
|
|
if (System.currentTimeMillis() - Long.parseLong(time) > 1000 * 60 * 8) {
|
|
|
|
|
record.set("message", "票据超时!");
|
|
|
|
|
record.set("success", false);
|
|
|
|
|
} else {
|
|
|
|
|
//计算两个时间戳之间的差值,单位为秒
|
|
|
|
|
long diff = (System.currentTimeMillis() - Long.parseLong(time)) / 1000;
|
|
|
|
|
System.out.println("票据有效,时间差为:" + diff + "秒");
|
|
|
|
|
record.set("message", "票据有效,时间差为:" + diff + "秒");
|
|
|
|
|
record.set("success", true);
|
|
|
|
|
}
|
|
|
|
|
} catch (Exception e) {
|
|
|
|
|
record.set("success", false);
|
|
|
|
|
record.set("message", "票据无效!");
|
|
|
|
|
}
|
|
|
|
|
return record;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|