diff --git a/src/main/java/com/chinaunicom/mall/ebtp/extend/wps/service/impl/WpsServiceImpl.java b/src/main/java/com/chinaunicom/mall/ebtp/extend/wps/service/impl/WpsServiceImpl.java index 58a8dc5..9dc7a66 100644 --- a/src/main/java/com/chinaunicom/mall/ebtp/extend/wps/service/impl/WpsServiceImpl.java +++ b/src/main/java/com/chinaunicom/mall/ebtp/extend/wps/service/impl/WpsServiceImpl.java @@ -37,6 +37,8 @@ import java.io.*; import java.math.BigInteger; import java.net.HttpURLConnection; import java.net.URL; +import java.net.URLDecoder; +import java.net.URLEncoder; import java.security.MessageDigest; import java.security.NoSuchAlgorithmException; import java.text.SimpleDateFormat; @@ -74,6 +76,12 @@ public class WpsServiceImpl implements WpsService { private String wpsAppId; @Value("${mconfig.wps.appKey}") private String wpsAppKey; + @Value("${mconfig.wps.bss.appTokenUrl}") + private String bssAppTokenUrl; + @Value("${mconfig.wps.bss.previewUrl}") + private String bssPreviewUrl; + @Value("${mconfig.wps.bss.editUrl}") + private String bssEditUrl; @Value("${mconfig.wps.url.appTokenUrl}") private String wpsAppTokenUrl; @Value("${mconfig.wps.url.previewUrl}") @@ -95,25 +103,37 @@ public class WpsServiceImpl implements WpsService { public WpsResultVo getWpsUrl(WpsClientInVo in){ WpsResultVo re =new WpsResultVo(); String tokenValue =getWpsAppToken(); - CrypBean bean=new CrypBean(); + WpsVO bean=new WpsVO(); + StringBuffer uri=new StringBuffer(); if("read".equals(in.getPermission())){ - bean.setUrl(wpsPreviewUrl); + bean.setBssUrl(bssPreviewUrl); + uri.append(wpsPreviewUrl); } if("write".equals(in.getPermission())){ - bean.setUrl(wpsEditUrl); + bean.setBssUrl(bssEditUrl); + uri.append(wpsEditUrl); } - WpsExceptionEnum.FRAME_EXCEPTION_NO.customValidName("无法查询",StringUtils.isBlank(bean.getUrl())); - Map req=new HashMap<>(); + WpsExceptionEnum.FRAME_EXCEPTION_NO.customValidName("无法查询",StringUtils.isBlank(bean.getBssUrl())); + uri.append("?"); + Map req=new LinkedHashMap<>(); req.put("app_token",tokenValue); + uri.append("app_token="+encode(tokenValue)); req.put("file_id",in.getFileId()); + uri.append("&file_id="+encode(in.getFileId())); req.put("type","w"); + uri.append("&type=w"); req.put("scene_id",in.getId()); + uri.append("&scene_id="+encode(in.getId())); req.put("_w_third_user_id",cacheUserService.getCacheUser().getUserId()); + uri.append("&_w_third_user_id="+encode(cacheUserService.getCacheUser().getUserId())); req.put("_w_third_user_name",cacheUserService.getCacheUser().getFullName()); + uri.append("&_w_third_user_name="+encode(cacheUserService.getCacheUser().getFullName())); req.put("_w_third_file_name",in.getFileName()); + uri.append("&_w_third_file_name="+encode(in.getFileName())); bean.setObject(req); bean.setReqName("APPTOKEN_REQ"); bean.setContentJson(""); + bean.setWpsUri(uri.toString()); Map urlMap=this.callUniWpsInterfaceJson(bean); WpsExceptionEnum.IS_SUCCESS.customValid(urlMap==null); re.setAppToken(tokenValue); @@ -237,12 +257,14 @@ public class WpsServiceImpl implements WpsService { if(redisTemplate.opsForValue().get("wpsAppToken:"+bss_app_id)!=null){ return String.valueOf(redisTemplate.opsForValue().get("wpsAppToken:"+bss_app_id)); } - CrypBean bean=new CrypBean(); - bean.setUrl(wpsAppTokenUrl); - Map req=new HashMap<>(); + WpsVO bean=new WpsVO(); + bean.setBssUrl(bssAppTokenUrl); + //顺序与uri一致 所以用LinkedHashMap + Map req=new LinkedHashMap<>(); req.put("scope","file_preview,file_edit,file_format_control"); req.put("app_id",wpsAppId); bean.setObject(req); + bean.setWpsUri(wpsAppTokenUrl+"?scope="+encode(req.get("scope"))+"&app_id="+encode(req.get("app_id"))); bean.setReqName("APPTOKEN_REQ"); bean.setContentJson(""); Map tokenMap=this.callUniWpsInterfaceJson(bean); @@ -257,9 +279,9 @@ public class WpsServiceImpl implements WpsService { * @return */ @OperationLogDetail(businessModule = EbtpLogBusinessModule.OTHER,operationType = EbtpLogType.SELECT,detail = "沃文档-调用天擎接口") - public Map callUniWpsInterfaceJson(CrypBean bean) { + public Map callUniWpsInterfaceJson(WpsVO bean) { log.info("沃文档-天擎接口------callUniInterface:---入参-----" + JSON.toJSONString(bean)); - log.info("请求路径:" +bss_app_url+ bean.getUrl()); + log.info("请求路径:" +bss_app_url+ bean.getBssUrl()); String json = ""; String str = ""; try { @@ -271,12 +293,12 @@ public class WpsServiceImpl implements WpsService { json = getUniBss(bean.getReqName(), map); String nlptDate=getGmtDate(); String contentType = "application/json;charset=utf-8"; - String nlptAuth="WPS-3:"+wpsAppId+":"+sha1Encode(wpsAppKey+contentMd5+bean.getUrl()+contentType+nlptDate); + String nlptAuth="WPS-3:"+wpsAppId+":"+sha1Encode(wpsAppKey+contentMd5+bean.getWpsUri()+contentType+nlptDate); log.warn("沃文档请求头--------- nlpt-Date="+nlptDate); log.warn("沃文档请求头--------- nlpt-X-Auth="+nlptAuth); log.warn("沃文档请求头--------- nlpt-Content-Md5="+contentMd5); - str = this.uniBssWpsHttpPost(bss_app_url+bean.getUrl(), json,nlptDate,nlptAuth,contentMd5,contentType); - operationLogService.addOperationLog("沃文档天擎接口调用信息,请求地址:"+bean.getUrl()+",参数:"+json+",返回信息:"+str,true, EbtpLogBusinessModule.OTHER, EbtpLogType.INSERT); + str = this.uniBssWpsHttpPost(bss_app_url+bean.getBssUrl(), json,nlptDate,nlptAuth,contentMd5,contentType); + operationLogService.addOperationLog("沃文档天擎接口调用信息,请求地址:"+bean.getBssUrl()+",参数:"+json+",返回信息:"+str,true, EbtpLogBusinessModule.OTHER, EbtpLogType.INSERT); Map callMap = (Map)JSON.parse(str); log.info("天擎接口--沃文档接口--返回数据callMap:"+ JSONObject.toJSONString(callMap)); Object head = callMap.get("UNI_BSS_HEAD"); @@ -308,7 +330,7 @@ public class WpsServiceImpl implements WpsService { } } catch (Exception e) { log.error("沃文档--天擎接口返回参数!~-----------------{}",ExceptionUtil.stacktraceToString(e)); - operationLogService.addOperationLog("沃文档天擎接口调用信息失败,请求地址{}"+bean.getUrl()+",参数{}"+json+",返回信息{}"+str,false, EbtpLogBusinessModule.PAY_PUSH, EbtpLogType.INSERT); + operationLogService.addOperationLog("沃文档天擎接口调用信息失败,请求地址{}"+bean.getBssUrl()+",参数{}"+json+",返回信息{}"+str,false, EbtpLogBusinessModule.PAY_PUSH, EbtpLogType.INSERT); } log.info("---沃文档--天擎接口返回参数-----"+str); return null; @@ -436,8 +458,21 @@ public class WpsServiceImpl implements WpsService { return sb.toString(); } - public static void main(String[] args) { - System.out.println(String.valueOf(null)); + public String encode(String in){ + try { + return URLEncoder.encode(in,"utf-8"); + } catch (UnsupportedEncodingException e) { + log.warn(ExceptionUtil.stacktraceToString(e)); + } + return null; + } + + public static void main(String[] args) throws UnsupportedEncodingException { + String str = URLEncoder.encode("file_preview,file_edit,file_format_control","utf-8"); + System.out.println(str); +//解码 + String str1=URLDecoder.decode(str, "UTF-8"); + System.out.println(str1); } } diff --git a/src/main/java/com/chinaunicom/mall/ebtp/extend/wps/vo/WpsVO.java b/src/main/java/com/chinaunicom/mall/ebtp/extend/wps/vo/WpsVO.java new file mode 100644 index 0000000..5e16707 --- /dev/null +++ b/src/main/java/com/chinaunicom/mall/ebtp/extend/wps/vo/WpsVO.java @@ -0,0 +1,51 @@ +package com.chinaunicom.mall.ebtp.extend.wps.vo; + +import io.swagger.annotations.ApiModelProperty; +import lombok.Data; + +/** +* 实体类 CrypConfigure-区块链参数配置表 +* +* @author yss +*/ +@Data +public class WpsVO { + /** + * 能力req名称 + * BIDDING_PUBLISH_REQ 发标 + */ + @ApiModelProperty(value = "能力req名称") + public String reqName; + /** + * 天擎接口地址 + */ + @ApiModelProperty(value = "天擎接口地址") + public String bssUrl; + /** + * 沃文档-uri及query参数 + */ + @ApiModelProperty(value = "签名") + public String wpsUri; + /** + * 待签名参数 Map + */ + @ApiModelProperty(value = "待签名参数") + public Object object; + /** + * 中信支付使用ClientId + */ + @ApiModelProperty(value = "clientId") + public String clientId; + /** + * 中信支付使用OperationCode + */ + @ApiModelProperty(value = "operationCode") + public String operationCode; + + /** + * 沃文档 content的json串 + */ + @ApiModelProperty(value = "签名") + public String contentJson; + +}