14 changed files with 384 additions and 160 deletions
@ -0,0 +1,26 @@ |
|||
package com.qs.serve.common.config.properties; |
|||
|
|||
import lombok.Getter; |
|||
import lombok.Setter; |
|||
import org.springframework.boot.context.properties.ConfigurationProperties; |
|||
import org.springframework.stereotype.Component; |
|||
|
|||
import java.util.ArrayList; |
|||
import java.util.List; |
|||
|
|||
/** |
|||
* @Author: YenHex |
|||
* @Date: 2021/3/3 |
|||
* @Version: 1.0 |
|||
**/ |
|||
@Getter |
|||
@Setter |
|||
@Component |
|||
@ConfigurationProperties(prefix = "project.seeyon") |
|||
public class SeeYonProperties { |
|||
|
|||
private Boolean enable; |
|||
|
|||
private String url; |
|||
|
|||
} |
@ -0,0 +1,130 @@ |
|||
package com.qs.serve.common.util; |
|||
|
|||
import com.alibaba.fastjson.JSONObject; |
|||
import com.qs.serve.common.model.dto.R; |
|||
import org.apache.http.HttpEntity; |
|||
import org.apache.http.ParseException; |
|||
import org.apache.http.client.ClientProtocolException; |
|||
import org.apache.http.client.HttpClient; |
|||
import org.apache.http.client.methods.CloseableHttpResponse; |
|||
import org.apache.http.client.methods.HttpGet; |
|||
import org.apache.http.client.methods.HttpPost; |
|||
import org.apache.http.entity.StringEntity; |
|||
import org.apache.http.impl.client.CloseableHttpClient; |
|||
import org.apache.http.impl.client.HttpClientBuilder; |
|||
import org.apache.http.impl.client.HttpClients; |
|||
import org.apache.http.protocol.HTTP; |
|||
import org.apache.http.util.EntityUtils; |
|||
|
|||
import java.io.IOException; |
|||
import java.util.HashMap; |
|||
|
|||
/** |
|||
* @author YenHex |
|||
* @since 2022/11/23 |
|||
*/ |
|||
public class HttpUtil { |
|||
|
|||
private final static String CONTENT_TYPE = "application/json"; |
|||
private final static String CHARSET = "UTF-8"; |
|||
private final static String EN_CONING = "UTF-8"; |
|||
|
|||
public static String doPost(String url, String jsonStr, HashMap<String,String> headers) { |
|||
CloseableHttpClient client = HttpClientBuilder.create().build(); |
|||
CloseableHttpResponse response = null; |
|||
try { |
|||
//设post请求
|
|||
HttpPost post = new HttpPost(url); |
|||
//创建请求实体传参
|
|||
StringEntity postingString = new StringEntity(jsonStr,CHARSET); |
|||
postingString.setContentEncoding(EN_CONING); |
|||
//设置post请求参数
|
|||
post.setEntity(postingString); |
|||
post.addHeader(HTTP.CONTENT_TYPE,CONTENT_TYPE); |
|||
if (headers != null) { |
|||
for (String key : headers.keySet()) { |
|||
post.addHeader(key,headers.get(key)); |
|||
} |
|||
} |
|||
//执行post请求
|
|||
response = client.execute(post); |
|||
//访问成功状态码为200
|
|||
if (response.getStatusLine().getStatusCode() == 200) { |
|||
return EntityUtils.toString(response.getEntity()); |
|||
} |
|||
} catch (IOException e) { |
|||
e.printStackTrace(); |
|||
}finally { |
|||
try { |
|||
client.close(); |
|||
if(response!=null){ |
|||
response.close(); |
|||
} |
|||
} catch (IOException e) { |
|||
e.printStackTrace(); |
|||
} |
|||
} |
|||
return null; |
|||
} |
|||
|
|||
public static String doGet(String url, HashMap<String,String> headers) { |
|||
CloseableHttpClient httpclient = HttpClients.createDefault(); |
|||
try { |
|||
HttpGet httpget = new HttpGet(url); |
|||
httpget.addHeader(HTTP.CONTENT_TYPE,CONTENT_TYPE); |
|||
if (headers != null) { |
|||
for (String key : headers.keySet()) { |
|||
httpget.addHeader(key,headers.get(key)); |
|||
} |
|||
} |
|||
CloseableHttpResponse response = httpclient.execute(httpget); |
|||
try { |
|||
if (response.getStatusLine().getStatusCode() == 200) { |
|||
return EntityUtils.toString(response.getEntity()); |
|||
} |
|||
} finally { |
|||
response.close(); |
|||
} |
|||
} catch (ClientProtocolException e) { |
|||
e.printStackTrace(); |
|||
} catch (ParseException e) { |
|||
e.printStackTrace(); |
|||
} catch (IOException e) { |
|||
e.printStackTrace(); |
|||
} finally { |
|||
try { |
|||
httpclient.close(); |
|||
} catch (IOException e) { |
|||
e.printStackTrace(); |
|||
} |
|||
} |
|||
return null; |
|||
} |
|||
|
|||
public static String createUrl(HashMap<String,String> param){ |
|||
StringBuilder sb = new StringBuilder(); |
|||
for (String key : param.keySet()) { |
|||
sb.append("&"+key+"="+param.get(key)); |
|||
} |
|||
return sb.toString(); |
|||
} |
|||
|
|||
public static R<String> doGetResult(String url,HashMap<String,String> headers){ |
|||
String result = HttpUtil.doGet(url,headers); |
|||
JSONObject jsonObject = JSONObject.parseObject(result); |
|||
Integer status = jsonObject.getInteger("status"); |
|||
String msg = jsonObject.getString("msg"); |
|||
String data = jsonObject.getString("data"); |
|||
return new R(status,msg,data); |
|||
} |
|||
|
|||
public static R<String> doPostResult(String url, String jsonStr, HashMap<String,String> headers){ |
|||
String result = HttpUtil.doPost(url,jsonStr,headers); |
|||
JSONObject jsonObject = JSONObject.parseObject(result); |
|||
Integer status = jsonObject.getInteger("status"); |
|||
String msg = jsonObject.getString("msg"); |
|||
String data = jsonObject.getString("data"); |
|||
return new R(status,msg,data); |
|||
} |
|||
|
|||
} |
@ -1,49 +0,0 @@ |
|||
package com.qs.serve.common.util; |
|||
|
|||
import com.alibaba.fastjson.JSON; |
|||
import com.seeyon.client.CTPRestClient; |
|||
import com.seeyon.client.CTPServiceClientManager; |
|||
import lombok.Getter; |
|||
import lombok.extern.slf4j.Slf4j; |
|||
import org.springframework.beans.factory.annotation.Value; |
|||
import org.springframework.context.annotation.Bean; |
|||
import org.springframework.context.annotation.Configuration; |
|||
import org.springframework.context.annotation.Scope; |
|||
|
|||
import java.util.HashMap; |
|||
import java.util.Map; |
|||
|
|||
/** |
|||
* @Author JcYen |
|||
* @Date 2021/5/21 |
|||
*/ |
|||
@Slf4j |
|||
@Configuration |
|||
public class SeeYonUtil { |
|||
|
|||
public static String restUrl = "http://192.168.10.7"; |
|||
|
|||
public static String userName = "kenpbtz"; |
|||
|
|||
public static String password = "66da74b2-f141-4b01-ae58-ac6ce4cfcc47"; |
|||
|
|||
/** |
|||
* 致远客户端 |
|||
* 文献:http://open.seeyon.com/book/ctp/restjie-kou/restjie-kou-java-ke-hu-duan.html
|
|||
* @return |
|||
*/ |
|||
public static CTPRestClient getRestClient() { |
|||
CTPServiceClientManager clientManager = CTPServiceClientManager.getInstance(restUrl); |
|||
CTPRestClient client = null; |
|||
try { |
|||
client = clientManager.getRestClient(); |
|||
//登录校验,成功返回true,失败返回false,此过程并会把验证通过获取的token保存在缓存中
|
|||
//再请求访问其他资源时会自动把token放入请求header中。
|
|||
client.authenticate(userName, password); |
|||
} catch (Exception e) { |
|||
log.error("致远客户端获取异常:{}",e.getMessage(),e); |
|||
} |
|||
return client; |
|||
} |
|||
|
|||
} |
@ -0,0 +1,16 @@ |
|||
package com.qs.serve.modules.tbs.common; |
|||
|
|||
/** |
|||
* @author YenHex |
|||
* @since 2022/11/23 |
|||
*/ |
|||
public interface TbsSeeYonConst { |
|||
|
|||
String COST_APPLY_FORM = "CostBill_Test"; |
|||
|
|||
String COST_APPLY_USER = "banzhang1"; |
|||
|
|||
String API_PROCESS_CREATE = "/process/create"; |
|||
String API_GET_FORM_ID = "/process/getFormId"; |
|||
|
|||
} |
Loading…
Reference in new issue