You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
91 lines
2.9 KiB
91 lines
2.9 KiB
3 years ago
|
/*
|
||
|
* Copyright (C), 2018-2021
|
||
|
* Project: starter
|
||
|
* FileName: WebTableDataModel
|
||
|
* Author: fr.open
|
||
|
* Date: 2021/12/16 8:17
|
||
|
*/
|
||
|
package com.fr.plugin.icjb.data;
|
||
|
|
||
|
import com.fanruan.api.data.open.BaseDataModel;
|
||
|
import com.fanruan.api.err.TableDataException;
|
||
|
import com.fr.base.Base64;
|
||
|
import com.fr.general.ComparatorUtils;
|
||
|
import com.fr.general.http.HttpToolbox;
|
||
|
import com.fr.json.JSONObject;
|
||
|
import com.fr.log.FineLoggerFactory;
|
||
|
import com.fr.stable.CodeUtils;
|
||
|
import com.fr.stable.ParameterProvider;
|
||
|
import com.fr.stable.StringUtils;
|
||
|
|
||
|
import java.io.IOException;
|
||
|
import java.util.ArrayList;
|
||
|
|
||
|
/**
|
||
|
* <Function Description><br>
|
||
|
* <WebTableDataModel>
|
||
|
*
|
||
|
* @author fr.open
|
||
|
* @since 1.0.0
|
||
|
*/
|
||
|
public abstract class WebTableDataModel extends BaseDataModel {
|
||
|
private static final long serialVersionUID = 5010918328453603247L;
|
||
|
protected ParameterProvider[] parameters;
|
||
|
protected String[] columnNames;
|
||
|
protected ArrayList valueList = null;
|
||
|
protected String host;
|
||
|
|
||
|
public WebTableDataModel(ParameterProvider[] parameters) {
|
||
|
this.parameters = parameters;
|
||
|
}
|
||
|
|
||
|
@Override
|
||
|
public int getColumnCount() throws TableDataException {
|
||
|
return this.columnNames.length;
|
||
|
}
|
||
|
|
||
|
@Override
|
||
|
public String getColumnName(int i) throws TableDataException {
|
||
|
return columnNames[i];
|
||
|
}
|
||
|
|
||
|
@Override
|
||
|
public int getRowCount() throws TableDataException {
|
||
|
init();
|
||
|
return valueList.size();
|
||
|
}
|
||
|
|
||
|
@Override
|
||
|
public Object getValueAt(int row, int col) throws TableDataException {
|
||
|
init();
|
||
|
return ((Object[]) valueList.get(row))[col];
|
||
|
}
|
||
|
|
||
|
@Override
|
||
|
public void release() throws Exception {
|
||
|
this.parameters = null;
|
||
|
}
|
||
|
|
||
|
protected abstract void init();
|
||
|
|
||
|
/**
|
||
|
* 获取访问令牌接口(Token)
|
||
|
*
|
||
|
* @param code
|
||
|
* @param secret
|
||
|
* @return
|
||
|
*/
|
||
|
protected String getAccessToken(String code, String secret, String clientId) throws IOException {
|
||
|
JSONObject resultJson;
|
||
|
String timestamp = String.valueOf(System.currentTimeMillis());
|
||
|
String sign = Base64.encode(CodeUtils.md5Encode(code + timestamp + secret, StringUtils.EMPTY, "MD5").getBytes());
|
||
|
String url = this.host + "token/signLogin?code=" + code + "&type=0&clientId=" + clientId + "×tamp=" + timestamp + "&sign=" + sign;
|
||
|
FineLoggerFactory.getLogger().info("icjb-UsersTableDataModel-getAccessToken-url:{}", url);
|
||
|
String result = HttpToolbox.get(url);
|
||
|
FineLoggerFactory.getLogger().info("icjb-UsersTableDataModel-getAccessToken-result:{}", result);
|
||
|
if (StringUtils.isNotBlank(result) && ComparatorUtils.equals(0, (resultJson = new JSONObject(result)).getInt("code"))) {
|
||
|
return resultJson.getJSONObject("data").getString("access_token");
|
||
|
}
|
||
|
throw new RuntimeException("icjb-UsersTableDataModel-getAccessToken 获取结果异常");
|
||
|
}
|
||
|
}
|