|
@@ -17,6 +17,7 @@ import nckd.base.helper.CommonHelperUtils;
|
|
|
import okhttp3.*;
|
|
|
import javax.crypto.Cipher;
|
|
|
import java.io.IOException;
|
|
|
+import java.math.BigDecimal;
|
|
|
import java.security.KeyFactory;
|
|
|
import java.security.interfaces.RSAPrivateKey;
|
|
|
import java.security.spec.PKCS8EncodedKeySpec;
|
|
@@ -53,14 +54,6 @@ public class SRMHelperUtils {
|
|
|
String selectProperties = "id, billno, billstatus, nckd_srmbillno, nckd_srmurl";
|
|
|
DynamicObject billInfo = BusinessDataServiceHelper.loadSingle(billId, entityName, selectProperties);
|
|
|
|
|
|
- billInfo.set("billstatus", "A");
|
|
|
-
|
|
|
- SaveServiceHelper.update(new DynamicObject[]{billInfo});
|
|
|
-
|
|
|
-// if(true) {
|
|
|
-// return returnMap;
|
|
|
-// }
|
|
|
-
|
|
|
//退回
|
|
|
if("nckd_returnsrm".equals(operatorType)){
|
|
|
//判断单据状态是否等于暂存
|
|
@@ -87,16 +80,22 @@ public class SRMHelperUtils {
|
|
|
return returnMap;
|
|
|
}
|
|
|
|
|
|
- Map<String,String> doReturnMap = doSRMreturnDeal(srmBillNo);
|
|
|
+ Map<String,String> doReturnMap = writeReturnStatus(srmBillNo);
|
|
|
|
|
|
//退回成功后单点到srm
|
|
|
if (!"0".equals(doReturnMap.get("code"))) {//调接口异常
|
|
|
-// return doReturnMap;
|
|
|
+ return doReturnMap;
|
|
|
+ } else {//调接口成功后,获取单点登录链接
|
|
|
+ try {
|
|
|
+ billInfo.set("billstatus", "H");
|
|
|
+ SaveServiceHelper.update(new DynamicObject[]{billInfo});
|
|
|
+ } catch (Exception e){
|
|
|
+ returnMap.put("code", "1");
|
|
|
+ returnMap.put("msg", "单据(" + billInfo.getString("billno") + ")作废失败:" + e.getMessage());
|
|
|
|
|
|
- Map<String,String> ssomap = buildSSOUrl(srmurl);
|
|
|
+ return returnMap;
|
|
|
+ }
|
|
|
|
|
|
- return ssomap;
|
|
|
- } else {//调接口成功后,获取单点登录链接
|
|
|
Map<String,String> ssomap = buildSSOUrl(srmurl);
|
|
|
|
|
|
return ssomap;
|
|
@@ -114,7 +113,7 @@ public class SRMHelperUtils {
|
|
|
* @param srmBillNo
|
|
|
* @return
|
|
|
*/
|
|
|
- public static Map<String,String> doSRMreturnDeal(String srmBillNo) {
|
|
|
+ public static Map<String,String> writeReturnStatus(String srmBillNo) {
|
|
|
Map<String,String> returnMap = new HashMap<>();
|
|
|
//获取token
|
|
|
Map<String,String> tokenMap = getSRMToken();
|
|
@@ -224,6 +223,115 @@ public class SRMHelperUtils {
|
|
|
}
|
|
|
}
|
|
|
|
|
|
+ /**
|
|
|
+ * 同步付款信息至SRM
|
|
|
+ * @param srmBillNo
|
|
|
+ * @param paymentDate
|
|
|
+ * @param paymentAmount
|
|
|
+ * @return
|
|
|
+ */
|
|
|
+ public static Map<String,String> writeBackPayResulst(String srmBillNo, String paymentDate, BigDecimal paymentAmount) {
|
|
|
+ Map<String,String> returnMap = new HashMap<>();
|
|
|
+ //获取token
|
|
|
+ Map<String,String> tokenMap = getSRMToken();
|
|
|
+ if (!"0".equals(tokenMap.get("code"))) {//未获取到token
|
|
|
+ returnMap.put("code", "1");
|
|
|
+ returnMap.put("msg", tokenMap.get("msg"));
|
|
|
+
|
|
|
+ return returnMap;
|
|
|
+ }
|
|
|
+ String token = tokenMap.get("msg").toString();
|
|
|
+
|
|
|
+ Map<String, String> mapentity = CommonHelperUtils.getCommonParams("SRM");
|
|
|
+ if(mapentity == null ){
|
|
|
+ logger.info("SRMHelperUtils:nckd_entryentity is null");
|
|
|
+
|
|
|
+ returnMap.put("code", "1");
|
|
|
+ returnMap.put("msg", "未配置SRM系统对接参数!");
|
|
|
+ return returnMap;
|
|
|
+ }
|
|
|
+
|
|
|
+ String serverUrlApi = mapentity.get("apiserverurl");
|
|
|
+ String writePayResultApi = mapentity.get("apiwritepayresult");
|
|
|
+ String userName = mapentity.get("username");//用户名(srm提供)
|
|
|
+ String interfaceCode = mapentity.get("interfacecodewritebillstatus");//接口编码(srm提供,不同接口编码不同)
|
|
|
+ String externalSysCode = mapentity.get("externalsyscode");//外部系统(srm提供)
|
|
|
+ String applicationCode = mapentity.get("applicationcode");//应用(srm提供)
|
|
|
+ String applicationGroupCode = mapentity.get("applicationgroupcode");//应用组(srm提供)
|
|
|
+
|
|
|
+ if(StringUtils.isEmpty(serverUrlApi) || StringUtils.isEmpty(writePayResultApi) || StringUtils.isEmpty(userName)
|
|
|
+ || StringUtils.isEmpty(interfaceCode) ||StringUtils.isEmpty(externalSysCode)
|
|
|
+ || StringUtils.isEmpty(applicationCode) || StringUtils.isEmpty(applicationGroupCode)){
|
|
|
+ returnMap.put("code", "1");
|
|
|
+ returnMap.put("msg", "请检查是否配置SRM参数:服务地址、付款结果回写接口、用户名、接口编码、外部系统、应用编码、应用组");
|
|
|
+ return returnMap;
|
|
|
+ }
|
|
|
+
|
|
|
+ String url = serverUrlApi + writePayResultApi;
|
|
|
+ String timestamp = String.valueOf(System.currentTimeMillis());
|
|
|
+
|
|
|
+ JSONObject headerObj = new JSONObject();
|
|
|
+ headerObj.put("applicationCode", applicationCode);
|
|
|
+ headerObj.put("applicationGroupCode", applicationGroupCode);
|
|
|
+ headerObj.put("batchCount", "1");
|
|
|
+ headerObj.put("batchNum", timestamp);
|
|
|
+ headerObj.put("externalSystemCode", externalSysCode);
|
|
|
+ headerObj.put("interfaceCode", interfaceCode);
|
|
|
+ headerObj.put("userName", userName);
|
|
|
+
|
|
|
+ JSONArray bodyArr = new JSONArray();
|
|
|
+ JSONObject bodyObj = new JSONObject();
|
|
|
+
|
|
|
+ bodyObj.put("settleNum", srmBillNo);//SRM单据编号
|
|
|
+ bodyObj.put("paymentType", "PAYMENT");//PAYMENT 付款;PREPAYMENT 预付款
|
|
|
+ bodyObj.put("paymentDate", paymentDate);//付款日期
|
|
|
+ bodyObj.put("paymentAmount",paymentAmount);//付款金额
|
|
|
+
|
|
|
+ bodyArr.add(bodyObj);
|
|
|
+
|
|
|
+ JSONObject body=new JSONObject();
|
|
|
+ body.put("header", headerObj);
|
|
|
+ body.put("body", bodyArr);
|
|
|
+
|
|
|
+ Map<String, String> headerMap = new HashMap<>();
|
|
|
+ headerMap.put("Content-Type", "application/json");
|
|
|
+ headerMap.put("User-Agent", "apifox/1.0.0 (https://www.apifox.cn)");
|
|
|
+ headerMap.put("Authorization", "Bearer " + token);
|
|
|
+
|
|
|
+ try {
|
|
|
+ String response = KHttpClientUtils.postjson(url, headerMap, body.toJSONString());
|
|
|
+
|
|
|
+ if(StringUtils.isEmpty(response)){
|
|
|
+ returnMap.put("code", "1");
|
|
|
+ returnMap.put("msg", "回写付款状态失败, 返回为空");
|
|
|
+
|
|
|
+ return returnMap;
|
|
|
+ }
|
|
|
+
|
|
|
+ JSONObject resultJSON = JSONObject.parseObject(response);
|
|
|
+
|
|
|
+ if (resultJSON !=null && "SUCCESS".equals(resultJSON.get("responseStatus").toString())
|
|
|
+ &&"SUCCESS".equals(resultJSON.get("executeResult").toString())) {
|
|
|
+ returnMap.put("code","0");
|
|
|
+ } else{
|
|
|
+ returnMap.put("code","1");
|
|
|
+ returnMap.put("msg", "回写付款状态失败" + response);
|
|
|
+ }
|
|
|
+
|
|
|
+ return returnMap;
|
|
|
+ } catch(IOException e){
|
|
|
+ returnMap.put("code", "1");
|
|
|
+ returnMap.put("msg", "获取token失败, " + e.getMessage());
|
|
|
+
|
|
|
+ return returnMap;
|
|
|
+ } catch(Exception e){
|
|
|
+ returnMap.put("code", "1");
|
|
|
+ returnMap.put("msg", "获取token失败, " + e.getMessage());
|
|
|
+
|
|
|
+ return returnMap;
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
/**
|
|
|
* 构造单点url
|
|
|
* @param srmUrl
|
|
@@ -366,46 +474,4 @@ public class SRMHelperUtils {
|
|
|
return returnMap;
|
|
|
}
|
|
|
}
|
|
|
-
|
|
|
- /**
|
|
|
- * http post
|
|
|
- * @param url
|
|
|
- * @return
|
|
|
- * @throws IOException
|
|
|
- */
|
|
|
- public static String doHttpClientPost(String url) throws IOException{
|
|
|
- OkHttpClient client = new OkHttpClient().newBuilder()
|
|
|
-// .connectTimeout(timeout, TimeUnit.SECONDS)
|
|
|
-// .readTimeout(timeout, TimeUnit.SECONDS)
|
|
|
-// .writeTimeout(timeout, TimeUnit.SECONDS)
|
|
|
- .build();
|
|
|
- MediaType mediaType = MediaType.parse("text/plain");
|
|
|
- RequestBody body = RequestBody.create(mediaType, "");
|
|
|
- Request request = new Request.Builder().url(url).method("POST", body).addHeader("User-Agent", "apifox/1.0.0 (https://www.apifox.cn)").build();
|
|
|
- Response response = client.newCall(request).execute();
|
|
|
-
|
|
|
- if(response == null){
|
|
|
- return null;
|
|
|
- }
|
|
|
- return response.body().toString();
|
|
|
- }
|
|
|
-
|
|
|
- public static String doHttpClientPost(String url, String bodyString, String token) throws IOException{
|
|
|
-// int maxRentry=2;//请求重试次数(本次+ maxRentry),注意:BOS开发的jdk是1.6,我们本地测试用低版本的okhttp-3.2.0.jar和okio-1.9.0.jar,服务器还是用okhttp-3.12.13.jar和okio-1.15.0.jar
|
|
|
- OkHttpClient client = new OkHttpClient().newBuilder()
|
|
|
- .connectTimeout(timeout, TimeUnit.SECONDS)
|
|
|
- .readTimeout(timeout, TimeUnit.SECONDS)
|
|
|
- .writeTimeout(timeout, TimeUnit.SECONDS)
|
|
|
-// .addInterceptor(new HttpResponseConnectTimeout.OkhttpInterceptor(maxRentry)) //过滤器,设置最大重试次数
|
|
|
- .build();
|
|
|
- MediaType mediaType = MediaType.parse("application/json");
|
|
|
- RequestBody body = RequestBody.create(mediaType, bodyString);
|
|
|
- Request request = new Request.Builder().url(url).method("POST", body)
|
|
|
- .addHeader("User-Agent", "apifox/1.0.0 (https://www.apifox.cn)")
|
|
|
- .addHeader("Content-Type", "application/json")
|
|
|
- .addHeader("Authorization", "Bearer " + token).build();
|
|
|
-
|
|
|
- Response response = client.newCall(request).execute();
|
|
|
- return response.body().string();
|
|
|
- }
|
|
|
}
|