Przeglądaj źródła

拍照调整及url跳转调整

wangqiang 8 miesięcy temu
rodzic
commit
a7c9fb9075

+ 58 - 5
jeeplus-modules/jeeplus-flowable/src/main/java/com/jeeplus/flowable/controller/FlowableTaskController.java

@@ -50,6 +50,7 @@ import org.flowable.engine.runtime.ProcessInstance;
 import org.flowable.task.api.Task;
 import org.flowable.task.api.TaskQuery;
 import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.beans.factory.annotation.Value;
 import org.springframework.cloud.openfeign.SpringQueryMap;
 import org.springframework.http.ResponseEntity;
 import org.springframework.scheduling.annotation.Scheduled;
@@ -57,6 +58,7 @@ import org.springframework.web.bind.annotation.*;
 
 import javax.annotation.Resource;
 import javax.servlet.http.HttpServletRequest;
+import java.io.UnsupportedEncodingException;
 import java.text.SimpleDateFormat;
 import java.util.*;
 import java.util.concurrent.*;
@@ -105,6 +107,9 @@ public class FlowableTaskController {
     @Autowired
     private RedisUtils redisUtils;
 
+    @Value("${wechat.projecturl}")
+    private String projectUrl;
+
     @GetMapping("todo")
     public ResponseEntity todoListData(Page<ProcessVo> page, Flow flow, String type) throws Exception {
 //        page = flowTaskService.todoList ( page, flow, type );
@@ -404,7 +409,7 @@ public class FlowableTaskController {
      * 启动流程
      */
     @PostMapping("start")
-    public ResponseEntity start(@RequestBody Flow flow) {
+    public ResponseEntity start(@RequestBody Flow flow) throws UnsupportedEncodingException {
         String procInsId = flowTaskService.startProcess(flow.getProcDefKey(), flow.getBusinessTable(), flow.getBusinessId(), flow.getTitle(), flow.getRecordType(), flow.getProcDefId(), flow.getDays());
 
         //指定下一步处理人
@@ -622,7 +627,7 @@ public class FlowableTaskController {
      * @param flow
      */
     @PostMapping("audit")
-    public ResponseEntity auditTask(HttpServletRequest request, Flow flow) {
+    public ResponseEntity auditTask(HttpServletRequest request, Flow flow) throws UnsupportedEncodingException {
         Map<String, Object> vars = Maps.newHashMap();
         Map<String, String[]> map = request.getParameterMap();
         for (Map.Entry<String, String[]> entry : map.entrySet()) {
@@ -650,7 +655,7 @@ public class FlowableTaskController {
     }
 
     // 向审核人发送 公众号通知
-    public void sendMsgToOpenIds(String procInsId){
+    public void sendMsgToOpenIds(String procInsId) throws UnsupportedEncodingException {
 
         TaskQuery todoTaskQuery = taskService.createTaskQuery()
                 .active()
@@ -664,7 +669,6 @@ public class FlowableTaskController {
         for (int i = 0; i < list.size(); i++) {
             List<String> users = flowTaskService.getTaskAuditUsers(list.get(i).getId());
             // 根据得到的审核人id,查询出对应的openId
-
             for (String user : users) {
                 if (allUsersStringBuilder.length() > 0) {
                     allUsersStringBuilder.append(","); // 添加逗号作为分隔符
@@ -677,8 +681,57 @@ public class FlowableTaskController {
             String[] openIdArray = openIds.split(",");
             List<String> openIdsList = Arrays.asList(openIdArray);
 
-            SendMessageUtil.sendMessage(list.get(i), openIdsList);
+            Flow flow = new Flow();
+            String procDefId = list.get(i).getProcessDefinitionId();
+            String taskDefKey = list.get(i).getTaskDefinitionKey();
+//            String procInsIdFromTask = list.get(i).getProcessInstanceId();
+            String procDefKey = SpringUtil.getBean(RepositoryService.class).createProcessDefinitionQuery()
+                    .processDefinitionId(procDefId)
+                    .singleResult()
+                    .getKey();
+
+            flow.setProcDefId(procDefId);
+            flow.setTaskDefKey(taskDefKey);
+            flow.setProcInsId(procInsId);
+            flow.setProcDefKey(procDefKey);
+            flow = getFlowInfo(flow);
+
+            SendMessageUtil.sendMessage(list.get(i), openIdsList, flow, projectUrl);
+        }
+    }
+
+    public Flow getFlowInfo(Flow flow){
+        // 获取流程XML上的表单KEY
+        String formKey = flowTaskService.getFormKey(flow.getProcDefId(), flow.getTaskDefKey());
+
+        NodeSetting typeNode = nodeSettingService.queryByKey(flow.getProcDefKey(), flow.getTaskDefKey(), "formType");
+        NodeSetting ReadOnlyNode = nodeSettingService.queryByKey(flow.getProcDefKey(), flow.getTaskDefKey(), "formReadOnly");
+        String formType = "1";
+        boolean formReadOnly = false;
+        if (typeNode != null) {
+            formType = typeNode.getValue();
+            formReadOnly = "true".equals(ReadOnlyNode.getValue());
+        } else {
+            if (StringUtils.isBlank(formKey)) {
+                formType = "1";
+            } else if (formKey.indexOf("/") >= 0) {
+                formType = "2";
+            }
+        }
+
+        // 获取流程实例对象
+        if (flow.getProcInsId() != null) {
+            if (flowTaskService.getProcIns(flow.getProcInsId()) != null) {
+                flow.setProcIns(flowTaskService.getProcIns(flow.getProcInsId()));
+            } else {
+                flow.setFinishedProcIns(flowTaskService.getFinishedProcIns(flow.getProcInsId()));
+            }
         }
+
+        flow.setFormUrl(formKey);
+        flow.setFormReadOnly(formReadOnly);
+        flow.setFormType(formType);
+        return flow;
     }
 
     /**

+ 8 - 1
jeeplus-modules/jeeplus-flowable/src/main/java/com/jeeplus/weChat/controller/ProxyController.java

@@ -1,6 +1,7 @@
 package com.jeeplus.weChat.controller;
 
 import com.alibaba.fastjson.JSONObject;
+import com.jeeplus.weChat.domain.SignatureInfo;
 import com.jeeplus.weChat.domain.WXTransportTemplate;
 import com.jeeplus.weChat.service.WxSendService;
 import com.jeeplus.weChat.util.HttpUtils;
@@ -66,6 +67,12 @@ public class ProxyController {
         String token = HttpUtils.dogetToken();
         return token;
     }
+    // 根据微信的access_token获取签名
+    @GetMapping("/app/getSignature")
+    public SignatureInfo getSignature(){
+        SignatureInfo signature = HttpUtils.dogetSignature();
+        return signature;
+    }
 
     @PostMapping("/app/sendTemplate")
     public String sendTranTemplate( @RequestBody WXTransportTemplate resource) throws IOException {
@@ -86,5 +93,5 @@ public class ProxyController {
 
 
 //    这是测试号在微信开发者工具里面的 地址
-//    https://open.weixin.qq.com/connect/oauth2/authorize?appid=wxa79f618dcaf992f7&redirect_uri=http%3A%2F%2Fk2e6ew.natappfree.cc%2Fh5%2F&response_type=code&scope=snsapi_userinfo&state=STATE#wechat_redirect
+//    https://open.weixin.qq.com/connect/oauth2/authorize?appid=wxa79f618dcaf992f7&redirect_uri=http%3A%2F%2Fgfnu5c.natappfree.cc%2Fh5%2F&response_type=code&scope=snsapi_userinfo&state=STATE#wechat_redirect
 }

+ 4 - 1
jeeplus-modules/jeeplus-flowable/src/main/java/com/jeeplus/weChat/controller/WeChatController.java

@@ -36,10 +36,13 @@ public class WeChatController {
     public void sendMsgTest(HttpServletRequest request, HttpServletResponse response) throws IOException {
         // 微信加密签名.
         String signature = request.getParameter("signature");
+        System.out.println("微信加密签名-》  " + signature);
         // 时间戳.
         String timestamp = request.getParameter("timestamp");
+        System.out.println("微信加密签名时间戳-》  " + timestamp);
         // 随机数.
         String nonce = request.getParameter("nonce");
+        System.out.println("微信加密签名随机数-》  " + nonce);
         // 随机字符串.
         String echostr = request.getParameter("echostr");
         // 请求校验,若校验成功则原样返回echostr,表示接入成功,否则接入失败.
@@ -73,7 +76,7 @@ public class WeChatController {
      * 微信授权登录
      */
     @GetMapping( value = "/authorize")
-    public String authorize(@RequestParam(value = "returnUrl", defaultValue = "http://k2e6ew.natappfree.cc/") String returnUrl) throws UnsupportedEncodingException {
+    public String authorize(@RequestParam(value = "returnUrl", defaultValue = "http://gfnu5c.natappfree.cc/") String returnUrl) throws UnsupportedEncodingException {
         log.info("【微信网页授权】进来了,参数={}", returnUrl);
         System.out.println("进来了:" + returnUrl);
         //1. 配置

+ 21 - 0
jeeplus-modules/jeeplus-flowable/src/main/java/com/jeeplus/weChat/domain/SignatureInfo.java

@@ -0,0 +1,21 @@
+package com.jeeplus.weChat.domain;
+
+import lombok.Data;
+
+/**
+ * 签名相关参数
+ * @author 王强
+ * @version 1.0
+ * @date 2024-08-21 16:45
+ */
+@Data
+public class SignatureInfo {
+
+    // 随机字符串
+    private String nonceStr;
+    // 时间戳
+    private String timestamp;
+    // 签名
+    private String signature;
+
+}

+ 2 - 0
jeeplus-modules/jeeplus-flowable/src/main/java/com/jeeplus/weChat/domain/TranTemplate.java

@@ -18,4 +18,6 @@ public class TranTemplate {
     String template_id;
     //接收人ID
     String touser;
+
+    String url;
 }

+ 2 - 0
jeeplus-modules/jeeplus-flowable/src/main/java/com/jeeplus/weChat/domain/WXTransportTemplate.java

@@ -26,4 +26,6 @@ public class WXTransportTemplate {
     private String processInitiator; //流程发起人
 
     private String createTime; //创建时间
+
+    private String url;
 }

+ 3 - 0
jeeplus-modules/jeeplus-flowable/src/main/java/com/jeeplus/weChat/service/WxSendService.java

@@ -38,6 +38,7 @@ public class WxSendService {
         TranTemplate tranTemplate = new TranTemplate();
         //设置接收司机微信ID
         tranTemplate.setTouser(resource.getOpenid());
+        tranTemplate.setUrl("https://www.baidu.com/");
         //设置模板ID
         tranTemplate.setTemplate_id("3b5rKQ1nTjvML1Xyj0OSMV0CnMNt7WjdzPksAHhvhRI");
         //给模板的内容赋值
@@ -72,6 +73,8 @@ public class WxSendService {
 
         tranTemplate.setTouser(resource.getOpenid());
 
+        tranTemplate.setUrl(resource.getUrl());
+
         //设置模板ID
         tranTemplate.setTemplate_id("ehTUuyDFL7f2RApsMXLsJEPlCgt82aTj2vtmO2l9Cso");
         //给模板的内容赋值

+ 90 - 0
jeeplus-modules/jeeplus-flowable/src/main/java/com/jeeplus/weChat/util/HttpUtils.java

@@ -2,17 +2,24 @@ package com.jeeplus.weChat.util;
 
 import com.alibaba.fastjson.JSONObject;
 import com.jeeplus.weChat.config.WechatAccountConfig;
+import com.jeeplus.weChat.domain.SignatureInfo;
 import lombok.extern.slf4j.Slf4j;
 import org.apache.http.HttpEntity;
+import org.apache.http.HttpResponse;
 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.HttpClients;
 import org.apache.http.util.EntityUtils;
 import org.flowable.ui.common.service.exception.BadRequestException;
+import java.security.MessageDigest;
 
+import java.util.UUID;
+import java.util.Formatter;
 import java.io.IOException;
+import java.util.HashMap;
 import java.util.Map;
 import java.util.Timer;
 
@@ -24,6 +31,9 @@ import java.util.Timer;
 @Slf4j
 public class HttpUtils {
 
+    // 获取jsapi_ticket的URL
+    private static final String TICKET_URL = "https://api.weixin.qq.com/cgi-bin/ticket/getticket?access_token=ACCESS_TOKEN&type=jsapi";
+
     public static String access_token;
     public static String requestPost(String url,String jsonParam){
 
@@ -110,5 +120,85 @@ public class HttpUtils {
 
     }
 
+    // 获取jsapi_ticket
+    public static String dogetJsapiTicket(String accessToken) {
+        String result = null;
+        try (CloseableHttpClient client = HttpClients.createDefault()) {
+            String url = TICKET_URL.replace("ACCESS_TOKEN", accessToken);
+            HttpGet httpGet = new HttpGet(url);
+            HttpResponse response = client.execute(httpGet);
+            HttpEntity entity = response.getEntity();
+            if (entity != null) {
+                String responseStr = EntityUtils.toString(entity, "UTF-8");
+                // 解析出jsapi_ticket
+                Map<String, Object> responseMap = parseJson(responseStr);
+                result = (String) responseMap.get("ticket");
+            }
+        } catch (Exception e) {
+            e.printStackTrace();
+        }
+        return result;
+    }
+
+    // 生成签名
+    public static String generateSignature(String jsapiTicket, String nonceStr, String timestamp, String url) {
+        String signature = "";
+        String string1;
+        try {
+            string1 = "jsapi_ticket=" + jsapiTicket +
+                    "&noncestr=" + nonceStr +
+                    "&timestamp=" + timestamp +
+                    "&url=" + url;
+
+            MessageDigest crypt = MessageDigest.getInstance("SHA-1");
+            crypt.reset();
+            crypt.update(string1.getBytes("UTF-8"));
+            signature = byteToHex(crypt.digest());
+        } catch (Exception e) {
+            e.printStackTrace();
+        }
+        return signature;
+    }
+
+    public static SignatureInfo dogetSignature() {
+        String accessToken = dogetToken();
+        String jsapiTicket = dogetJsapiTicket(accessToken);
+
+        String nonceStr = UUID.randomUUID().toString(); // 生成随机字符串
+        String timestamp = Long.toString(System.currentTimeMillis() / 1000); // 生成时间戳
+        String url = "http://gfnu5c.natappfree.cc/h5/"; // 调用接口的页面URL
+
+        String signature = generateSignature(jsapiTicket, nonceStr, timestamp, url);
+
+        SignatureInfo signatureInfo = new SignatureInfo();
+        signatureInfo.setNonceStr(nonceStr);
+        signatureInfo.setTimestamp(timestamp);
+        signatureInfo.setSignature(signature);
+        // 如果需要将这些参数返回给前端,可以将它们封装成对象或JSON
+        System.out.println("nonceStr: " + nonceStr);
+        System.out.println("timestamp: " + timestamp);
+        System.out.println("signature: " + signature);
+
+        return signatureInfo; // 返回生成的签名
+    }
+
+    // 解析JSON字符串为Map
+    private static Map<String, Object> parseJson(String jsonStr) {
+        // 这里你可以使用任何一种JSON解析库,如Gson、Jackson等
+        Map<String, Object> map = new HashMap<>();
+        // ... 实现解析逻辑
+        return map;
+    }
+
+    // 字节转为16进制
+    private static String byteToHex(final byte[] hash) {
+        Formatter formatter = new Formatter();
+        for (byte b : hash) {
+            formatter.format("%02x", b);
+        }
+        String result = formatter.toString();
+        formatter.close();
+        return result;
+    }
 }
 

Plik diff jest za duży
+ 50 - 1
jeeplus-modules/jeeplus-flowable/src/main/java/com/jeeplus/weChat/util/SendMessageUtil.java