package com.changhong.epc.rely.api.tool; import com.changhong.epc.constter.base.BaseConst; import com.changhong.epc.constter.system.prop.ChangHongProperties; import com.changhong.epc.rely.api.bean.Process; import com.iemsoft.framework.cloud.core.thread.ThreadData; import com.iemsoft.framework.cloud.core.tools.JSONTool; import com.iemsoft.framework.cloud.core.tools.ObjectUtil; import com.iemsoft.framework.cloud.core.tools.SpringUtil; import org.springframework.stereotype.Service; import org.springframework.ui.ModelMap; import javax.servlet.http.HttpServletRequest; import java.text.SimpleDateFormat; import java.util.*; @Service public class WorkflowTool implements BaseConst { /** * 加工解析接收的参数 * 还需要修改 * 还需要修改 */ private HttpServletRequest request; //请求参数 public static Map getParam(Map data){ ChangHongProperties changHongProperties = SpringUtil.getBean(ChangHongProperties.class); Map param = new TreeMap<>(data); param.put("id", changHongProperties.getProcessAccessId() + new SimpleDateFormat("yyyyMMdd").format(new Date()) + String.format("%09d", new Random().nextInt(999999999))); param.put("sign", countSign(param)); return param; } public Process getProcess(Map jsonObject){ Map param = new TreeMap<>(); Map loginParam = new TreeMap<>(); Map data = new TreeMap<>(); param.put("data", JSONTool.toJson(jsonObject)); loginParam.put("loginSecurity",getLogInSecurity()); data.putAll(param); data.putAll(loginParam); Process pro = new Process(); if(jsonObject.get("tenantID") !=null){ pro.setTenantID(Objects.toString(jsonObject.get("tenantID").toString(),null)); } pro.setFlowmap(getParam(data)); pro.setChackmap(getParam( new ModelMap("loginSecurity", getCheckLogInSecurity()) .addAttribute("data", JSONTool.toJson(jsonObject)))); return pro; } public String getLogInSecurity(){ ChangHongProperties changHongProperties = SpringUtil.getBean(ChangHongProperties.class); String token = ThreadData.get(TOKEN); String openId = ThreadData.get(OPEN_ID); String tenantId = ThreadData.get(TENANT_ID); String companyId = Objects.toString(ThreadData.get(COMPANY_ID),""); return "{\"serviceId\":\"" + changHongProperties.getProcessServiceId() + (ObjectUtil.empty(token) ? "" : "\",\"token\":\"" + token) + "\",\"tenantId\":\"" + tenantId + "\",\"openId\":\"" + openId + "\",\"companyId\":\"" + companyId + "\"}"; } public String getCheckLogInSecurity(){ ChangHongProperties changHongProperties = SpringUtil.getBean(ChangHongProperties.class); String openId = ThreadData.get(OPEN_ID); return "{\"serviceId\":\"" + changHongProperties.getProcessServiceId() // + (ObjectUtil.empty(token) ? "" : "\",\"token\":\"" + token) + "\",\"accessId\":\"" + changHongProperties.getProcessAccessId() + "\",\"openId\":\"" + openId + "\",\"appKey\":\"" + changHongProperties.getProcessAppKey() + "\"}"; } //取出Sign public static String countSign(Map param) { ChangHongProperties changHongProperties = SpringUtil.getBean(ChangHongProperties.class); StringBuilder sb = new StringBuilder(); for (Map.Entry map : param.entrySet()) { /* 拼接条件 */ sb.append(map.getKey()) .append('=') .append(map.getValue()) .append('&'); } sb.append("key=").append(changHongProperties.getProcessSecurityKey()); return MD5.GetMD5Code(sb.toString().replaceAll(" ","")); } public HttpServletRequest getRequest() { return request; } public void setRequest(HttpServletRequest request) { this.request = request; } }