18 changed files with 1077 additions and 29 deletions
@ -0,0 +1,369 @@ |
|||||
|
package com.zdxt.enforcementcode.common.util; |
||||
|
|
||||
|
import com.alibaba.fastjson.JSON; |
||||
|
import com.alibaba.fastjson.JSONObject; |
||||
|
import org.apache.commons.codec.binary.Base64; |
||||
|
import org.apache.commons.lang3.StringUtils; |
||||
|
import org.apache.http.HttpEntity; |
||||
|
import org.apache.http.NameValuePair; |
||||
|
import org.apache.http.client.config.RequestConfig; |
||||
|
import org.apache.http.client.entity.UrlEncodedFormEntity; |
||||
|
import org.apache.http.client.methods.CloseableHttpResponse; |
||||
|
import org.apache.http.client.methods.HttpPost; |
||||
|
import org.apache.http.config.Registry; |
||||
|
import org.apache.http.config.RegistryBuilder; |
||||
|
import org.apache.http.conn.socket.ConnectionSocketFactory; |
||||
|
import org.apache.http.conn.socket.PlainConnectionSocketFactory; |
||||
|
import org.apache.http.conn.ssl.SSLConnectionSocketFactory; |
||||
|
import org.apache.http.impl.client.CloseableHttpClient; |
||||
|
import org.apache.http.impl.client.HttpClients; |
||||
|
import org.apache.http.impl.conn.PoolingHttpClientConnectionManager; |
||||
|
import org.apache.http.message.BasicNameValuePair; |
||||
|
import org.apache.http.util.EntityUtils; |
||||
|
import org.slf4j.Logger; |
||||
|
import org.slf4j.LoggerFactory; |
||||
|
import org.springframework.stereotype.Component; |
||||
|
|
||||
|
import javax.crypto.*; |
||||
|
import javax.crypto.spec.GCMParameterSpec; |
||||
|
import javax.crypto.spec.SecretKeySpec; |
||||
|
import javax.net.ssl.SSLContext; |
||||
|
import javax.net.ssl.TrustManager; |
||||
|
import java.io.*; |
||||
|
import java.net.ConnectException; |
||||
|
import java.net.HttpURLConnection; |
||||
|
import java.net.URL; |
||||
|
import java.security.InvalidAlgorithmParameterException; |
||||
|
import java.security.InvalidKeyException; |
||||
|
import java.security.NoSuchAlgorithmException; |
||||
|
import java.security.SecureRandom; |
||||
|
import java.util.ArrayList; |
||||
|
import java.util.List; |
||||
|
import java.util.Map; |
||||
|
|
||||
|
/** |
||||
|
* 民生诉求氢气 |
||||
|
*/ |
||||
|
@Component |
||||
|
public class ServiceInvocation { |
||||
|
private static final Logger log = LoggerFactory.getLogger(ServiceInvocation.class); |
||||
|
/** |
||||
|
* 密钥生成【核心网关】 |
||||
|
* |
||||
|
* @param appKey 授权码 |
||||
|
* @param appId 请求者标识 |
||||
|
* @param rtime 请求时间戳 |
||||
|
* @return 加密后的sign |
||||
|
*/ |
||||
|
public static String gatewaySignEncode(String appId, String appKey, String rtime) throws Exception { |
||||
|
String inputString = appId + rtime; |
||||
|
return encode(appKey, inputString); |
||||
|
} |
||||
|
|
||||
|
/** |
||||
|
* 应用公钥appKey进行HMAC-SHA256计算并进行base64转码产生签名 |
||||
|
* |
||||
|
* @param appKey |
||||
|
* @param inputStr |
||||
|
* @return |
||||
|
* @throws NoSuchAlgorithmException |
||||
|
* @throws UnsupportedEncodingException |
||||
|
* @throws InvalidKeyException |
||||
|
*/ |
||||
|
private static String encode(String appKey, String inputStr) throws NoSuchAlgorithmException, UnsupportedEncodingException, InvalidKeyException { |
||||
|
String sign; |
||||
|
Mac hmacSha256 = Mac.getInstance("HmacSHA256"); |
||||
|
byte[] keyBytes = appKey.getBytes("UTF-8"); |
||||
|
hmacSha256.init(new SecretKeySpec(keyBytes, 0, keyBytes.length, "HmacSHA256")); |
||||
|
byte[] hmacSha256Bytes = hmacSha256.doFinal(inputStr.getBytes("UTF-8")); |
||||
|
sign = new String(Base64.encodeBase64(hmacSha256Bytes), "UTF-8"); |
||||
|
return sign; |
||||
|
} |
||||
|
|
||||
|
/** |
||||
|
* 解密 解密过程: 1.构造密钥生成器 2.根据ecnodeRules规则初始化密钥生成器 3.产生密钥 4.创建和初始化密码器 |
||||
|
* 5.将加密后的字符串反纺成byte[]数组 6.将加密内容解密 |
||||
|
*/ |
||||
|
public static String gatewayAesDecode(String encryptPass, String base64Content) { |
||||
|
byte[] content = cn.hutool.core.codec.Base64.decode(base64Content); |
||||
|
if (content.length < 28) { |
||||
|
throw new IllegalArgumentException(); |
||||
|
} else { |
||||
|
GCMParameterSpec params = new GCMParameterSpec(128, content, 0, 12); |
||||
|
|
||||
|
try { |
||||
|
Cipher cipher = Cipher.getInstance("AES/GCM/PKCS5Padding"); |
||||
|
cipher.init(2, getSecretKey(encryptPass), params); |
||||
|
byte[] decryptData = cipher.doFinal(content, 12, content.length - 12); |
||||
|
return new String(decryptData); |
||||
|
} catch (NoSuchAlgorithmException | NoSuchPaddingException | InvalidAlgorithmParameterException | IllegalBlockSizeException | BadPaddingException | InvalidKeyException var6) { |
||||
|
log.error("解密失败:{}", var6.getMessage()); |
||||
|
return null; |
||||
|
} |
||||
|
} |
||||
|
} |
||||
|
|
||||
|
private static SecretKeySpec getSecretKey(String encryptPass) throws NoSuchAlgorithmException { |
||||
|
KeyGenerator kg = KeyGenerator.getInstance("AES"); |
||||
|
SecureRandom secureRandom = SecureRandom.getInstance("SHA1PRNG"); |
||||
|
secureRandom.setSeed(encryptPass.getBytes()); |
||||
|
kg.init(128, secureRandom); |
||||
|
SecretKey secretKey = kg.generateKey(); |
||||
|
return new SecretKeySpec(secretKey.getEncoded(), "AES"); |
||||
|
} |
||||
|
|
||||
|
/** |
||||
|
* http请求过程 |
||||
|
* |
||||
|
* @param requestUrl 请求的url,在服务调用过程中url为获取token的url(格式为ip:port/auth/token)或者是服务调用的url |
||||
|
* @param requestMethod 获取token时,请求方法为POST;调用服务是请求方法依据服务注册时定义。 |
||||
|
* @param appIdorSecretKey 获取token时该参数为appId;抵用服务时该参数为SecretKey |
||||
|
* @param currTime 该参数为当前时间 |
||||
|
* @param sign 该参数为head参数gateway_sig,由秘钥生成方法gatewaySignEncode生成。 |
||||
|
* @return |
||||
|
*/ |
||||
|
public static JSONObject httpRequest(String requestUrl, String requestMethod, String reqBody, String appIdorSecretKey, |
||||
|
String currTime, String sign) throws Exception { |
||||
|
JSONObject jsonObject; |
||||
|
StringBuffer buffer = new StringBuffer(); |
||||
|
InputStream inputStream = null; |
||||
|
try { |
||||
|
System.setProperty("http.agent", "Chrome"); |
||||
|
URL url = new URL(requestUrl); |
||||
|
HttpURLConnection httpUrlConnection = (HttpURLConnection) url.openConnection(); |
||||
|
httpUrlConnection.setRequestMethod(requestMethod); |
||||
|
httpUrlConnection.setDoOutput(true); |
||||
|
httpUrlConnection.setDoInput(true); |
||||
|
httpUrlConnection.setRequestProperty("gateway_appid", appIdorSecretKey); |
||||
|
httpUrlConnection.setRequestProperty("gateway_rtime", currTime); |
||||
|
httpUrlConnection.setRequestProperty("gateway_sig", sign); |
||||
|
if ("POST".equalsIgnoreCase(requestMethod) && StringUtils.isNotBlank(reqBody)) { |
||||
|
httpUrlConnection.setRequestProperty("Content-Type", "application/json"); |
||||
|
httpUrlConnection.setRequestProperty("Accept", "application/json"); |
||||
|
OutputStream os = httpUrlConnection.getOutputStream(); |
||||
|
OutputStreamWriter osw = new OutputStreamWriter(os, "UTF-8"); |
||||
|
osw.write(reqBody); |
||||
|
osw.flush(); |
||||
|
osw.close(); |
||||
|
} |
||||
|
httpUrlConnection.connect(); |
||||
|
inputStream = httpUrlConnection.getInputStream(); |
||||
|
InputStreamReader inputStreamReader = new InputStreamReader(inputStream, "UTF-8"); |
||||
|
BufferedReader bufferReader = new BufferedReader(inputStreamReader); |
||||
|
String str; |
||||
|
while ((str = bufferReader.readLine()) != null) { |
||||
|
buffer.append(str); |
||||
|
} |
||||
|
String buffer2str = buffer.toString(); |
||||
|
jsonObject = JSONObject.parseObject(buffer2str); |
||||
|
bufferReader.close(); |
||||
|
inputStreamReader.close(); |
||||
|
inputStream.close(); |
||||
|
inputStream = null; |
||||
|
httpUrlConnection.disconnect(); |
||||
|
} catch (ConnectException ce) { |
||||
|
log.error("Server connect time out!",ce); |
||||
|
System.out.println("Server connect time out!"); |
||||
|
throw new ConnectException(); |
||||
|
} catch (IOException ioe) { |
||||
|
log.error("ioexception request error",ioe); |
||||
|
throw new IOException(); |
||||
|
} catch (Exception e) { |
||||
|
log.error("http request error!",e); |
||||
|
throw e; |
||||
|
} finally { |
||||
|
try { |
||||
|
if (inputStream != null) { |
||||
|
inputStream.close(); |
||||
|
} |
||||
|
} catch (IOException ioe) { |
||||
|
ioe.printStackTrace(); |
||||
|
} |
||||
|
} |
||||
|
return jsonObject; |
||||
|
} |
||||
|
public static JSONObject httpRequestForInterface(String requestUrl, String requestMethod, String reqBody, String appIdorSecretKey, |
||||
|
String currTime, String sign) throws Exception { |
||||
|
JSONObject jsonObject=new JSONObject(); |
||||
|
StringBuffer buffer = new StringBuffer(); |
||||
|
InputStream inputStream = null; |
||||
|
try { |
||||
|
System.setProperty("http.agent", "Chrome"); |
||||
|
URL url = new URL(requestUrl); |
||||
|
HttpURLConnection httpUrlConnection = (HttpURLConnection) url.openConnection(); |
||||
|
httpUrlConnection.setRequestMethod(requestMethod); |
||||
|
httpUrlConnection.setDoOutput(true); |
||||
|
httpUrlConnection.setDoInput(true); |
||||
|
httpUrlConnection.setRequestProperty("gateway_appid", appIdorSecretKey); |
||||
|
httpUrlConnection.setRequestProperty("gateway_rtime", currTime); |
||||
|
httpUrlConnection.setRequestProperty("gateway_sig", sign); |
||||
|
if ("POST".equalsIgnoreCase(requestMethod) && StringUtils.isNotBlank(reqBody)) { |
||||
|
httpUrlConnection.setRequestProperty("Content-Type", "application/json"); |
||||
|
httpUrlConnection.setRequestProperty("Accept", "application/json"); |
||||
|
OutputStream os = httpUrlConnection.getOutputStream(); |
||||
|
OutputStreamWriter osw = new OutputStreamWriter(os, "UTF-8"); |
||||
|
osw.write(reqBody); |
||||
|
osw.flush(); |
||||
|
osw.close(); |
||||
|
} |
||||
|
httpUrlConnection.connect(); |
||||
|
inputStream = httpUrlConnection.getInputStream(); |
||||
|
InputStreamReader inputStreamReader = new InputStreamReader(inputStream, "UTF-8"); |
||||
|
BufferedReader bufferReader = new BufferedReader(inputStreamReader); |
||||
|
String str; |
||||
|
while ((str = bufferReader.readLine()) != null) { |
||||
|
buffer.append(str); |
||||
|
} |
||||
|
String buffer2str = buffer.toString(); |
||||
|
|
||||
|
jsonObject.put("code",httpUrlConnection.getResponseCode()); |
||||
|
jsonObject.put("result",buffer2str); |
||||
|
bufferReader.close(); |
||||
|
inputStreamReader.close(); |
||||
|
inputStream.close(); |
||||
|
inputStream = null; |
||||
|
httpUrlConnection.disconnect(); |
||||
|
} catch (ConnectException ce) { |
||||
|
log.error("Server connect time out!",ce); |
||||
|
throw new ConnectException(); |
||||
|
} catch (IOException ioe) { |
||||
|
log.error("ioexception request error",ioe); |
||||
|
throw new IOException(); |
||||
|
} catch (Exception e) { |
||||
|
log.error("http request error!",e); |
||||
|
throw e; |
||||
|
} finally { |
||||
|
try { |
||||
|
if (inputStream != null) { |
||||
|
inputStream.close(); |
||||
|
} |
||||
|
} catch (IOException ioe) { |
||||
|
ioe.printStackTrace(); |
||||
|
} |
||||
|
} |
||||
|
return jsonObject; |
||||
|
} |
||||
|
public static String httpRequestForInterface2Form(String requestUrl, String requestMethod, String reqBody, String appIdorSecretKey, |
||||
|
String currTime, String sign) throws Exception { |
||||
|
CloseableHttpResponse response=null; |
||||
|
InputStream inputStream = null; |
||||
|
try { |
||||
|
System.setProperty("http.agent", "Chrome"); |
||||
|
|
||||
|
HttpPost post = new HttpPost(requestUrl); |
||||
|
post.setHeader("gateway_appid", appIdorSecretKey); |
||||
|
post.setHeader("gateway_rtime", currTime); |
||||
|
post.setHeader("gateway_sig", sign); |
||||
|
Map<String, String> param = JSON.parseObject(reqBody,Map.class); |
||||
|
List<NameValuePair> paramList = new ArrayList<>(); |
||||
|
for(String key : param.keySet()){ |
||||
|
NameValuePair pair = new BasicNameValuePair(key,param.get(key)); |
||||
|
paramList.add(pair); |
||||
|
} |
||||
|
|
||||
|
SSLContext sc = SSLContext.getInstance("SSL"); |
||||
|
sc.init(null, new TrustManager[] { new HttpUtil.TrustAnyTrustManager() }, new SecureRandom()); |
||||
|
Registry<ConnectionSocketFactory> registry = RegistryBuilder.<ConnectionSocketFactory>create() |
||||
|
.register("http", PlainConnectionSocketFactory.INSTANCE) |
||||
|
.register("https",new SSLConnectionSocketFactory(sc)) |
||||
|
.build(); |
||||
|
PoolingHttpClientConnectionManager manager = new PoolingHttpClientConnectionManager(registry); |
||||
|
CloseableHttpClient httpClient = HttpClients.custom().setConnectionManager(manager).build(); |
||||
|
HttpEntity entity = new UrlEncodedFormEntity(paramList,"utf-8"); |
||||
|
post.setEntity(entity); |
||||
|
RequestConfig config = RequestConfig.custom(). |
||||
|
setConnectTimeout(3000). |
||||
|
setSocketTimeout(3000). |
||||
|
build(); |
||||
|
post.setConfig(config); |
||||
|
response = httpClient.execute(post); |
||||
|
} catch (ConnectException ce) { |
||||
|
log.error("Server connect time out!",ce); |
||||
|
throw new ConnectException(); |
||||
|
} catch (IOException ioe) { |
||||
|
log.error("ioexception request error",ioe); |
||||
|
throw new IOException(); |
||||
|
} catch (Exception e) { |
||||
|
log.error("http request error!",e); |
||||
|
throw e; |
||||
|
} finally { |
||||
|
try { |
||||
|
if (inputStream != null) { |
||||
|
inputStream.close(); |
||||
|
} |
||||
|
} catch (IOException ioe) { |
||||
|
ioe.printStackTrace(); |
||||
|
} |
||||
|
} |
||||
|
return EntityUtils.toString(response.getEntity(),"utf-8"); |
||||
|
} |
||||
|
|
||||
|
private static void test(String id, String code,String invokingServiceRequestMethod, String invokingServiceUrl,String reqBodyForUrl) throws Exception { |
||||
|
// 参数设定
|
||||
|
String appId = id; |
||||
|
String appKey = code; |
||||
|
String currTime = System.currentTimeMillis() + ""; |
||||
|
//服务聚合获取tokenUrl
|
||||
|
String generateTokenUrl = "http://10.132.108.3/mssqApi/auth/token"; |
||||
|
// 服务调用的请求方法
|
||||
|
// 1.获取本地签名
|
||||
|
String tokenSign = gatewaySignEncode(appId, appKey, currTime); |
||||
|
// 2.调用获取token接口
|
||||
|
JSONObject jsonObject = httpRequest(generateTokenUrl, "POST", "", appId, currTime, tokenSign); |
||||
|
JSONObject jsonObjectBody = JSONObject.parseObject(jsonObject.getString("body")); |
||||
|
if (jsonObjectBody != null) { |
||||
|
String accessToken = jsonObjectBody.getString("access_token"); |
||||
|
// 3.在获得服务调用秘钥access_token后,根据自己的appKey使用AES解密算法对返回值进行解密,最终获取签名密钥secretKey
|
||||
|
String secretKey = gatewayAesDecode(appKey, accessToken); |
||||
|
// 4.获取本地签名
|
||||
|
String sign = gatewaySignEncode(appId, secretKey, currTime); |
||||
|
//4.调用服务接口
|
||||
|
JSONObject serviceJsonData = httpRequestForInterface(invokingServiceUrl, invokingServiceRequestMethod, reqBodyForUrl, appId, currTime, sign); |
||||
|
String codeValue = serviceJsonData.getString("code"); |
||||
|
if (codeValue.equals("200")) { |
||||
|
log.info("请求url:{},响应成功!",invokingServiceUrl); |
||||
|
} else { |
||||
|
log.error("请求url:{},响应失败!",invokingServiceUrl); |
||||
|
} |
||||
|
} else { |
||||
|
} |
||||
|
} |
||||
|
|
||||
|
public static void main(String[] args) throws Exception { |
||||
|
// 参数设定
|
||||
|
String appId = "67a83c8a136346cd98f844359902a23c"; |
||||
|
String appKey = "NjdhODNjOGExMzYzNDZjZDk4Zjg0NDM1OTkwMmEyM2M6TXNzcTIwMjQ="; |
||||
|
/*String appId = "ea5acb3cceb24365b415e9affa560d49"; |
||||
|
String appKey = "ZWE1YWNiM2NjZWIyNDM2NWI0MTVlOWFmZmE1NjBkNDk6eDEyMzQ1Ng==";*/ |
||||
|
|
||||
|
String currTime = String.valueOf(System.currentTimeMillis()); |
||||
|
//服务聚合获取tokenUrl
|
||||
|
String generateTokenUrl = "http://10.132.108.3/mssqApi/auth/token"; |
||||
|
String invokingServiceUrl="http://10.132.108.3/mssqApi/auth/token"; |
||||
|
String invokingServiceRequestMethod="POST"; |
||||
|
// 服务调用的请求方法
|
||||
|
// 1.获取本地签名
|
||||
|
String tokenSign = gatewaySignEncode(appId, appKey, currTime); |
||||
|
// 2.调用获取token接口
|
||||
|
JSONObject jsonObject = httpRequest(generateTokenUrl, "POST", "", appId, currTime, tokenSign); |
||||
|
JSONObject jsonObjectBody = JSONObject.parseObject(jsonObject.getString("body")); |
||||
|
System.out.println(jsonObject); |
||||
|
if (jsonObjectBody != null) { |
||||
|
String accessToken = jsonObjectBody.getString("access_token"); |
||||
|
// 3.在获得服务调用秘钥access_token后,根据自己的appKey使用AES解密算法对返回值进行解密,最终获取签名密钥secretKey
|
||||
|
String secretKey = gatewayAesDecode(appKey, accessToken); |
||||
|
// 4.获取本地签名
|
||||
|
String sign = gatewaySignEncode(appId, secretKey, currTime); |
||||
|
// //4.调用服务接口
|
||||
|
JSONObject serviceJsonData = httpRequestForInterface(invokingServiceUrl, invokingServiceRequestMethod, "", appId, currTime, sign); |
||||
|
// String codeValue = serviceJsonData.getString("code");
|
||||
|
// if (codeValue.equals("200")) {
|
||||
|
// log.info("请求url:{},响应成功!",invokingServiceUrl);
|
||||
|
// } else {
|
||||
|
// log.error("请求url:{},响应失败!",invokingServiceUrl);
|
||||
|
// }
|
||||
|
} else {} |
||||
|
// test(appId,appKey,"post","","");
|
||||
|
} |
||||
|
|
||||
|
} |
||||
@ -0,0 +1,17 @@ |
|||||
|
package com.zdxt.enforcementcode.domain.bo; |
||||
|
|
||||
|
import lombok.Data; |
||||
|
|
||||
|
|
||||
|
@Data |
||||
|
public class FileDataBo { |
||||
|
/** |
||||
|
* 附件名称 |
||||
|
*/ |
||||
|
private String fileName; |
||||
|
/** |
||||
|
* 附件数据流,需要转成Base64编码格式 |
||||
|
*/ |
||||
|
private String fileBytes; |
||||
|
|
||||
|
} |
||||
@ -0,0 +1,165 @@ |
|||||
|
package com.zdxt.enforcementcode.domain.bo; |
||||
|
|
||||
|
import lombok.Data; |
||||
|
|
||||
|
import java.util.List; |
||||
|
|
||||
|
/** |
||||
|
* 民生诉求工单Bo |
||||
|
*/ |
||||
|
@Data |
||||
|
public class MssqAddOrderBo extends MssqBaseDomainBo { |
||||
|
|
||||
|
/** |
||||
|
* 诉求标题 |
||||
|
*/ |
||||
|
private String requestTopic; |
||||
|
/** |
||||
|
* 诉求内容 |
||||
|
*/ |
||||
|
private String requestContent; |
||||
|
|
||||
|
/** |
||||
|
* 联系人姓名 |
||||
|
*/ |
||||
|
private String contactName; |
||||
|
|
||||
|
/** |
||||
|
* 联系人电话 |
||||
|
*/ |
||||
|
private String contactTel; |
||||
|
|
||||
|
/** |
||||
|
* 证件类型:字典参数类型:zjlx |
||||
|
*/ |
||||
|
private Integer certType; |
||||
|
|
||||
|
/** |
||||
|
* 证件号码 |
||||
|
*/ |
||||
|
private String certCode; |
||||
|
|
||||
|
/** |
||||
|
* 联系地址 |
||||
|
*/ |
||||
|
private String contactAddress; |
||||
|
/** |
||||
|
* 事发地址 |
||||
|
*/ |
||||
|
private String requestArea; |
||||
|
|
||||
|
/** |
||||
|
* 事发详细地址X坐标 |
||||
|
*/ |
||||
|
private String addressX; |
||||
|
|
||||
|
/** |
||||
|
* 事发详细地址Y坐标 |
||||
|
*/ |
||||
|
private String addressY; |
||||
|
/** |
||||
|
* 来源渠道:字典参数类型:sqly |
||||
|
*/ |
||||
|
private Integer requestFrom; |
||||
|
|
||||
|
/** |
||||
|
* 公开意向 y—公开 n—不公开 |
||||
|
*/ |
||||
|
private String pubIntent; |
||||
|
|
||||
|
/** |
||||
|
* 工单类型:字典参数类型:sqlx |
||||
|
*/ |
||||
|
private Integer orderType; |
||||
|
|
||||
|
/** |
||||
|
* 是否党员: 1: 是; 0: 否 |
||||
|
*/ |
||||
|
private Integer isParty; |
||||
|
/** |
||||
|
* 第三方系统工单id |
||||
|
*/ |
||||
|
private String extendId; |
||||
|
|
||||
|
/** |
||||
|
* 事发地址所属区 |
||||
|
*/ |
||||
|
private String area; |
||||
|
|
||||
|
/** |
||||
|
* 事发地址所属街道 |
||||
|
*/ |
||||
|
private String street; |
||||
|
|
||||
|
/** |
||||
|
* 是否保密: 1: 是; 0: 否 |
||||
|
*/ |
||||
|
private Integer isSecrecy; |
||||
|
/** |
||||
|
* 事项编码 |
||||
|
*/ |
||||
|
private String actCode; |
||||
|
|
||||
|
/** |
||||
|
* 诉求分类(个人/商事主体): 1: 个人; 2: 商事主体 |
||||
|
*/ |
||||
|
private Integer formUserNature; |
||||
|
/** |
||||
|
* 涉事主体 |
||||
|
*/ |
||||
|
private String thingSubject; |
||||
|
|
||||
|
/** |
||||
|
* 涉事主体地址(如:**区**街道**) |
||||
|
*/ |
||||
|
private String subjectAddress; |
||||
|
|
||||
|
/** |
||||
|
* 上传附件数据集 |
||||
|
*/ |
||||
|
private List<FileDataBo> fileDatas; |
||||
|
|
||||
|
|
||||
|
/** 工单编码 */ |
||||
|
private String proWoCode; |
||||
|
/** 工单编码,可以传递多个,最多20个 */ |
||||
|
private List<String> proWoCodes; |
||||
|
/** 开始时间 YYYY-MM-DD HH24:MI:SS */ |
||||
|
private String startTime; |
||||
|
/** 结束时间 YYYY-MM-DD HH24:MI:SS */ |
||||
|
private String endTime; |
||||
|
|
||||
|
private String appId; |
||||
|
private String sign; |
||||
|
private String timestamp; |
||||
|
/** 评价渠道 */ |
||||
|
private String pf; |
||||
|
/** 回调网址 */ |
||||
|
private String backUrl; |
||||
|
/** 评价业务,诉求工单代码值4 */ |
||||
|
private String assessServiceType; |
||||
|
/** 业务主键(诉求工单编号) */ |
||||
|
private String assessServiceCode; |
||||
|
/** 评价对象名称(诉求工单事项名称,若无则传诉求工单标题) */ |
||||
|
private String assessObjectName; |
||||
|
/** 评价对象编码(诉求工单事项编号,若无则传诉求工单编号) */ |
||||
|
private String assessObjectCode; |
||||
|
/** 部门编码(处理部门编码,区平台可以用区编码,编码需要保持与通过工作门户下发的一致) */ |
||||
|
private String deptCode; |
||||
|
/** 评价人名称 */ |
||||
|
private String evaluatorName; |
||||
|
/** 评价人联系号码 */ |
||||
|
private String evaluatorPapersPhone; |
||||
|
/** 附件地址 */ |
||||
|
private List<String> uploadPaths; |
||||
|
private String uploadPath; |
||||
|
|
||||
|
/** |
||||
|
* 获取工单流程信息-工单编码参数 |
||||
|
*/ |
||||
|
private String orderCode; |
||||
|
|
||||
|
|
||||
|
} |
||||
|
|
||||
|
|
||||
@ -0,0 +1,34 @@ |
|||||
|
package com.zdxt.enforcementcode.domain.bo; |
||||
|
|
||||
|
import lombok.Data; |
||||
|
|
||||
|
@Data |
||||
|
public class MssqBaseDomainBo { |
||||
|
|
||||
|
/** |
||||
|
* 认证token |
||||
|
*/ |
||||
|
private String accessToken; |
||||
|
/** |
||||
|
* 分配的appId |
||||
|
*/ |
||||
|
private String appid; |
||||
|
/** |
||||
|
* 请求头携带的appId |
||||
|
*/ |
||||
|
private String gatewayAppId; |
||||
|
/** |
||||
|
* 请求头携带的签名 |
||||
|
*/ |
||||
|
private String gatewaySig; |
||||
|
|
||||
|
/** |
||||
|
* 请求方式 |
||||
|
*/ |
||||
|
private String invokingServiceRequestMethod; |
||||
|
/** |
||||
|
* 请求头携带的当前时间的时间戳 |
||||
|
*/ |
||||
|
private String gatewayRtime; |
||||
|
|
||||
|
} |
||||
@ -0,0 +1,72 @@ |
|||||
|
package com.zdxt.enforcementcode.domain.bo; |
||||
|
|
||||
|
|
||||
|
import lombok.Data; |
||||
|
|
||||
|
@Data |
||||
|
public class MssqOrderFlowBo { |
||||
|
|
||||
|
/** |
||||
|
* 审批部门 |
||||
|
*/ |
||||
|
private String appOrgName; |
||||
|
|
||||
|
/** |
||||
|
* 审批人名称 |
||||
|
*/ |
||||
|
private String approveUserName; |
||||
|
|
||||
|
/** |
||||
|
* 审批时间 |
||||
|
*/ |
||||
|
private String approveTime; |
||||
|
|
||||
|
/** |
||||
|
* 审批意见 |
||||
|
*/ |
||||
|
private String approveContent; |
||||
|
/** |
||||
|
* 操作类型名 |
||||
|
*/ |
||||
|
private String operName; |
||||
|
|
||||
|
/** |
||||
|
* 状态 |
||||
|
*/ |
||||
|
private Integer state; |
||||
|
|
||||
|
/** |
||||
|
* 文件 |
||||
|
*/ |
||||
|
private String appOrgShortname; |
||||
|
|
||||
|
|
||||
|
class AppFiles { |
||||
|
/** |
||||
|
* 文件名称 |
||||
|
*/ |
||||
|
private String fileName; |
||||
|
/** |
||||
|
* 文件地址 |
||||
|
*/ |
||||
|
private String fileUrl; |
||||
|
|
||||
|
public String getFileName() { |
||||
|
return fileName; |
||||
|
} |
||||
|
|
||||
|
public void setFileName(String fileName) { |
||||
|
this.fileName = fileName; |
||||
|
} |
||||
|
|
||||
|
public String getFileUrl() { |
||||
|
return fileUrl; |
||||
|
} |
||||
|
|
||||
|
public void setFileUrl(String fileUrl) { |
||||
|
this.fileUrl = fileUrl; |
||||
|
} |
||||
|
|
||||
|
} |
||||
|
} |
||||
|
|
||||
@ -0,0 +1,62 @@ |
|||||
|
package com.zdxt.enforcementcode.service; |
||||
|
|
||||
|
import com.zdxt.enforcementcode.domain.bo.MssqAddOrderBo; |
||||
|
import com.zdxt.enforcementcode.domain.bo.MssqBaseDomainBo; |
||||
|
|
||||
|
/** |
||||
|
* 民生诉求接口实现类 |
||||
|
*/ |
||||
|
public interface IMssqApiService { |
||||
|
|
||||
|
/** |
||||
|
* 添加民生诉求工单 |
||||
|
* @param mssqAddOrder |
||||
|
* @return |
||||
|
*/ |
||||
|
String addMssqOrder(MssqAddOrderBo mssqAddOrder) throws Exception; |
||||
|
|
||||
|
/** |
||||
|
* 获取token |
||||
|
* @return |
||||
|
* @throws Exception |
||||
|
*/ |
||||
|
MssqBaseDomainBo getMssqToken() throws Exception; |
||||
|
MssqBaseDomainBo getMssqHcpToken() throws Exception; |
||||
|
|
||||
|
/** |
||||
|
* 诉求工单评价页面 |
||||
|
* @param mssqAddOrder |
||||
|
* @return |
||||
|
* @throws Exception |
||||
|
*/ |
||||
|
String mssqAppraise(MssqAddOrderBo mssqAddOrder) throws Exception; |
||||
|
|
||||
|
/** |
||||
|
* 查询办结信息 |
||||
|
* @param mssqAddOrder |
||||
|
* @return |
||||
|
* @throws Exception |
||||
|
*/ |
||||
|
String mssqQueryEndInfo(MssqAddOrderBo mssqAddOrder); |
||||
|
|
||||
|
/** |
||||
|
* 查询工单满意度 |
||||
|
* @param mssqAddOrder |
||||
|
* @return |
||||
|
* @throws Exception |
||||
|
*/ |
||||
|
String mssqQuerySatisfy(MssqAddOrderBo mssqAddOrder) throws Exception; |
||||
|
|
||||
|
/** |
||||
|
* 文件下载 |
||||
|
* @param mssqAddOrder |
||||
|
* @return |
||||
|
* @throws Exception |
||||
|
*/ |
||||
|
String mssqDownFile(MssqAddOrderBo mssqAddOrder) throws Exception; |
||||
|
|
||||
|
String queryMssq(MssqAddOrderBo mssqAddOrder, String url); |
||||
|
|
||||
|
|
||||
|
|
||||
|
} |
||||
@ -0,0 +1,226 @@ |
|||||
|
package com.zdxt.enforcementcode.service.impl; |
||||
|
|
||||
|
import com.alibaba.fastjson.JSONObject; |
||||
|
|
||||
|
import com.zdxt.enforcementcode.common.util.ServiceInvocation; |
||||
|
import com.zdxt.enforcementcode.domain.bo.MssqAddOrderBo; |
||||
|
import com.zdxt.enforcementcode.domain.bo.MssqBaseDomainBo; |
||||
|
import com.zdxt.enforcementcode.service.IMssqApiService; |
||||
|
import org.slf4j.Logger; |
||||
|
import org.slf4j.LoggerFactory; |
||||
|
import org.springframework.beans.factory.annotation.Value; |
||||
|
import org.springframework.stereotype.Service; |
||||
|
|
||||
|
import static com.zdxt.enforcementcode.common.util.ServiceInvocation.gatewaySignEncode; |
||||
|
import static com.zdxt.enforcementcode.common.util.ServiceInvocation.httpRequest; |
||||
|
|
||||
|
|
||||
|
@Service |
||||
|
public class MssqApiServiceImpl implements IMssqApiService { |
||||
|
|
||||
|
|
||||
|
private static final Logger log = LoggerFactory.getLogger(MssqApiServiceImpl.class); |
||||
|
|
||||
|
@Value("${mssq.apiUrl}") |
||||
|
private String mssqUrl; |
||||
|
|
||||
|
@Value("${mssq.appId}") |
||||
|
private String appId; |
||||
|
|
||||
|
@Value("${mssq.appKey}") |
||||
|
private String appKey; |
||||
|
|
||||
|
@Value("${mssq.hcpappid}") |
||||
|
private String hcpAppId; |
||||
|
|
||||
|
@Value("${mssq.hcpsign}") |
||||
|
private String hcpSign; |
||||
|
|
||||
|
@Value("${mssq.hcptimestamp}") |
||||
|
private String hcpTimestamp; |
||||
|
|
||||
|
@Override |
||||
|
public String addMssqOrder(MssqAddOrderBo mssqAddOrder) throws Exception { |
||||
|
MssqBaseDomainBo mssqToken = this.getMssqToken(); |
||||
|
mssqAddOrder.setAccessToken(mssqToken.getAccessToken()); |
||||
|
//appId
|
||||
|
mssqAddOrder.setAppid(appId); |
||||
|
//签名
|
||||
|
mssqAddOrder.setGatewaySig(mssqToken.getGatewaySig()); |
||||
|
//请求时间戳
|
||||
|
mssqAddOrder.setGatewayRtime(mssqToken.getGatewayRtime()); |
||||
|
//请求类型
|
||||
|
mssqAddOrder.setInvokingServiceRequestMethod("POST"); |
||||
|
String s = JSONObject.toJSONString(mssqAddOrder); |
||||
|
log.info("民生诉求token:{}",JSONObject.toJSONString(mssqToken)); |
||||
|
log.info("民生诉求工单新增,上传参数:{}",s); |
||||
|
JSONObject serviceJsonData = ServiceInvocation.httpRequestForInterface(mssqUrl + "/api/API_YX/handlerProcess/channelAddOrder", |
||||
|
mssqAddOrder.getInvokingServiceRequestMethod(), s, appId, mssqToken.getGatewayRtime(), mssqToken.getGatewaySig()); |
||||
|
String jsonRes = serviceJsonData.getString("result"); |
||||
|
return jsonRes; |
||||
|
} |
||||
|
|
||||
|
@Override |
||||
|
public MssqBaseDomainBo getMssqToken() throws Exception { |
||||
|
MssqBaseDomainBo mssqBaseDomain = new MssqBaseDomainBo(); |
||||
|
String currTime = String.valueOf(System.currentTimeMillis()); |
||||
|
String invokingServiceRequestMethod="POST"; |
||||
|
// 服务调用的请求方法
|
||||
|
// 1.获取本地签名
|
||||
|
String tokenSign = gatewaySignEncode(appId, appKey, currTime); |
||||
|
// 2.调用获取token接口
|
||||
|
JSONObject jsonObject = httpRequest(mssqUrl + "/auth/token", "POST", "", appId, currTime, tokenSign); |
||||
|
log.info("民生诉求获取auth:{}",jsonObject.toJSONString()); |
||||
|
JSONObject jsonObjectBody = JSONObject.parseObject(jsonObject.getString("body")); |
||||
|
// log.info("民生诉求获取token接口:{}",jsonObject);
|
||||
|
if (jsonObjectBody != null) { |
||||
|
String accessToken = jsonObjectBody.getString("access_token"); |
||||
|
log.info("民生诉求获取token:{}",accessToken); |
||||
|
// 3.在获得服务调用秘钥access_token后,根据自己的appKey使用AES解密算法对返回值进行解密,最终获取签名密钥secretKey
|
||||
|
String secretKey = ServiceInvocation.gatewayAesDecode(appKey, accessToken); |
||||
|
log.info("民生诉求获取secretKey:{}",secretKey); |
||||
|
// 4.获取本地签名
|
||||
|
String sign = gatewaySignEncode(appId, secretKey, currTime); |
||||
|
mssqBaseDomain.setAccessToken(accessToken); |
||||
|
log.info("民生诉求获取sign:{}",sign); |
||||
|
//签名
|
||||
|
mssqBaseDomain.setGatewaySig(sign); |
||||
|
} |
||||
|
//当前时间戳
|
||||
|
mssqBaseDomain.setGatewayRtime(currTime); |
||||
|
|
||||
|
return mssqBaseDomain; |
||||
|
} |
||||
|
|
||||
|
@Override |
||||
|
public String mssqAppraise(MssqAddOrderBo mssqAddOrder) throws Exception { |
||||
|
MssqBaseDomainBo mssqToken = this.getMssqToken(); |
||||
|
mssqAddOrder.setAccessToken(mssqToken.getAccessToken()); |
||||
|
//appId
|
||||
|
mssqAddOrder.setAppId(hcpAppId); |
||||
|
mssqAddOrder.setSign(hcpSign); |
||||
|
mssqAddOrder.setTimestamp(hcpTimestamp); |
||||
|
//签名
|
||||
|
mssqAddOrder.setGatewaySig(mssqToken.getGatewaySig()); |
||||
|
//请求时间戳
|
||||
|
mssqAddOrder.setGatewayRtime(mssqToken.getGatewayRtime()); |
||||
|
//请求类型
|
||||
|
mssqAddOrder.setInvokingServiceRequestMethod("POST"); |
||||
|
|
||||
|
/** 评价渠道 */ |
||||
|
mssqAddOrder.setPf("2"); |
||||
|
/** 评价业务,诉求工单代码值4 */ |
||||
|
mssqAddOrder.setAssessServiceType("4"); |
||||
|
/** 回调网址 */ |
||||
|
// mssqAddOrder.setBackUrl("http://jdm.szssfj.cn/enterprise");
|
||||
|
/** 业务主键(诉求工单编号) */ |
||||
|
// mssqAddOrder.setAssessServiceCode("082407081009143119701");
|
||||
|
/** 评价对象名称(诉求工单事项名称,若无则传诉求工单标题) */ |
||||
|
// mssqAddOrder.setAssessObjectName("测试工单");
|
||||
|
/** 评价对象编码(诉求工单事项编号,若无则传诉求工单编号) */ |
||||
|
// mssqAddOrder.setAssessObjectCode("082407081009143119701");
|
||||
|
/** 部门编码(处理部门编码,区平台可以用区编码,编码需要保持与通过工作门户下发的一致) */ |
||||
|
// mssqAddOrder.setDeptCode("151615");
|
||||
|
/** 评价人名称 */ |
||||
|
// mssqAddOrder.setEvaluatorName("测试");
|
||||
|
/** 评价人联系号码 */ |
||||
|
// mssqAddOrder.setEvaluatorPapersPhone("18528845598");
|
||||
|
|
||||
|
|
||||
|
String s = JSONObject.toJSONString(mssqAddOrder); |
||||
|
log.info("民生诉求token:{}",JSONObject.toJSONString(mssqToken)); |
||||
|
log.info("民生诉求查询工单状态,上传参数:{}",s); |
||||
|
String serviceJsonData = ServiceInvocation.httpRequestForInterface2Form(mssqUrl + "/api/hcp-api/comprehensive/comprehensiveView", |
||||
|
mssqAddOrder.getInvokingServiceRequestMethod(), s, appId, mssqToken.getGatewayRtime(), mssqToken.getGatewaySig()); |
||||
|
// String jsonRes = serviceJsonData.getString("result");
|
||||
|
JSONObject jsonObj = JSONObject.parseObject(serviceJsonData); |
||||
|
JSONObject jsonData = jsonObj.getJSONObject("data"); |
||||
|
String url = null; |
||||
|
try { |
||||
|
url = jsonData.getString("url"); |
||||
|
} catch (Exception e){ e.printStackTrace(); } |
||||
|
return url; |
||||
|
} |
||||
|
|
||||
|
@Override |
||||
|
public String mssqQueryEndInfo(MssqAddOrderBo mssqAddOrder) { |
||||
|
mssqAddOrder.setAppid(appId); |
||||
|
return this.queryMssq(mssqAddOrder, "/api/API_YX/proProcess/queryEndInfo"); |
||||
|
} |
||||
|
|
||||
|
@Override |
||||
|
public String mssqQuerySatisfy(MssqAddOrderBo mssqAddOrder) throws Exception { |
||||
|
mssqAddOrder.setAppid(appId); |
||||
|
return this.queryMssq(mssqAddOrder, "/api/API_YX/proProcess/querySatisfy"); |
||||
|
} |
||||
|
|
||||
|
@Override |
||||
|
public String mssqDownFile(MssqAddOrderBo mssqAddOrder) throws Exception { |
||||
|
mssqAddOrder.setAppid(appId); |
||||
|
return this.queryMssq(mssqAddOrder, "/api/API_YX/fast/downFile"); |
||||
|
} |
||||
|
|
||||
|
@Override |
||||
|
public String queryMssq(MssqAddOrderBo mssqAddOrder, String url) { |
||||
|
MssqBaseDomainBo mssqToken = null; |
||||
|
try { |
||||
|
mssqToken = this.getMssqToken(); |
||||
|
} catch (Exception e) { |
||||
|
e.printStackTrace(); |
||||
|
} |
||||
|
mssqAddOrder.setAccessToken(mssqToken.getAccessToken()); |
||||
|
//appId
|
||||
|
mssqAddOrder.setAppid(appId); |
||||
|
//签名
|
||||
|
mssqAddOrder.setGatewaySig(mssqToken.getGatewaySig()); |
||||
|
//请求时间戳
|
||||
|
mssqAddOrder.setGatewayRtime(mssqToken.getGatewayRtime()); |
||||
|
//请求类型
|
||||
|
mssqAddOrder.setInvokingServiceRequestMethod("POST"); |
||||
|
String s = JSONObject.toJSONString(mssqAddOrder); |
||||
|
log.info("民生诉求token:{}",JSONObject.toJSONString(mssqToken)); |
||||
|
log.info("民生诉求查询工单状态,上传参数:{}",s); |
||||
|
JSONObject serviceJsonData = null; |
||||
|
try { |
||||
|
serviceJsonData = ServiceInvocation.httpRequestForInterface(mssqUrl + url, |
||||
|
mssqAddOrder.getInvokingServiceRequestMethod(), s, appId, mssqToken.getGatewayRtime(), mssqToken.getGatewaySig()); |
||||
|
} catch (Exception e) { |
||||
|
e.printStackTrace(); |
||||
|
} |
||||
|
log.info("民生诉求查询结果:{}",serviceJsonData.toJSONString()); |
||||
|
String jsonRes = serviceJsonData.getString("result"); |
||||
|
return jsonRes; |
||||
|
} |
||||
|
|
||||
|
@Override |
||||
|
public MssqBaseDomainBo getMssqHcpToken() throws Exception { |
||||
|
MssqBaseDomainBo mssqBaseDomain = new MssqBaseDomainBo(); |
||||
|
String currTime = String.valueOf(System.currentTimeMillis()); |
||||
|
String invokingServiceRequestMethod="POST"; |
||||
|
// 服务调用的请求方法
|
||||
|
// 1.获取本地签名
|
||||
|
String tokenSign = gatewaySignEncode(appId, appKey, currTime); |
||||
|
// 2.调用获取token接口
|
||||
|
JSONObject jsonObject = httpRequest(mssqUrl + "/auth/token", "POST", "", hcpAppId, hcpTimestamp, hcpSign); |
||||
|
log.info("民生诉求获取auth:{}",jsonObject.toJSONString()); |
||||
|
JSONObject jsonObjectBody = JSONObject.parseObject(jsonObject.getString("body")); |
||||
|
// log.info("民生诉求获取token接口:{}",jsonObject);
|
||||
|
if (jsonObjectBody != null) { |
||||
|
String accessToken = jsonObjectBody.getString("access_token"); |
||||
|
log.info("民生诉求获取token:{}",accessToken); |
||||
|
// 3.在获得服务调用秘钥access_token后,根据自己的appKey使用AES解密算法对返回值进行解密,最终获取签名密钥secretKey
|
||||
|
String secretKey = ServiceInvocation.gatewayAesDecode(appKey, accessToken); |
||||
|
log.info("民生诉求获取secretKey:{}",secretKey); |
||||
|
// 4.获取本地签名
|
||||
|
String sign = gatewaySignEncode(appId, secretKey, currTime); |
||||
|
mssqBaseDomain.setAccessToken(accessToken); |
||||
|
log.info("民生诉求获取sign:{}",sign); |
||||
|
//签名
|
||||
|
mssqBaseDomain.setGatewaySig(sign); |
||||
|
} |
||||
|
//当前时间戳
|
||||
|
mssqBaseDomain.setGatewayRtime(currTime); |
||||
|
|
||||
|
return mssqBaseDomain; |
||||
|
} |
||||
|
} |
||||
Loading…
Reference in new issue