cqp il y a 1 semaine
Parent
commit
d9b4eca283
1 fichiers modifiés avec 17 ajouts et 66 suppressions
  1. 17 66
      app/Http/Controllers/Api/DingTalkController.php

+ 17 - 66
app/Http/Controllers/Api/DingTalkController.php

@@ -89,12 +89,29 @@ class DingTalkController extends BaseController
                         $processInstanceId = $event['processInstanceId'] ?? null;
                         $result = $event['result'] ?? null;
                         Log::info('审批实例变更', compact('processInstanceId','result'));
+
+                        // 捕捉最后一个节点审核通过
+                        if ($result === 'agree') {
+                            // TODO: 执行你的业务逻辑,比如更新数据库、触发后续操作
+                            Log::info("最后一个节点审核通过,审批完成", compact('processInstanceId'));
+                        }elseif ($result === 'oppose' || $result === 'terminate') {
+                            Log::info("审批流程被驳回或终止", compact('processInstanceId','result'));
+                        }
+
                         break;
                     case 'bpms_task_change':
                         $processInstanceId = $event['processInstanceId'] ?? null;
                         $taskId = $event['taskId'] ?? null;
                         $result = $event['result'] ?? null;
+                        $approverUserId = $event['staffId'] ?? null;
+
                         Log::info('审批任务变更', compact('processInstanceId','taskId','result'));
+
+                        // 捕获节点被驳回
+                        if ($result === 'oppose') {
+                            Log::info("节点被驳回", compact('processInstanceId','taskId','approverUserId'));
+                            // TODO: 执行你的业务逻辑,比如通知申请人、更新状态
+                        }
                         break;
                 }
             }
@@ -107,71 +124,5 @@ class DingTalkController extends BaseController
             Log::error('钉钉回调解密异常', ['msg' => $e->getMessage()]);
             return response()->json(['errcode'=>1, 'errmsg'=>'解密失败']);
         }
-
-        return;
-
-        $crypt = new DingTalkCrypto($token, $aesKey);
-
-        // 1. 获取钉钉传来的参数
-        $msgSignature = $request->get('msg_signature'); // 注意
-        $signature = $request->get('signature');
-        $timestamp = $request->get('timestamp');
-        $nonce     = $request->get('nonce');
-        $encrypt   = $request->input('encrypt');
-
-        // 2. 解密
-        $event = $crypt->decryptMsg($msgSignature, $timestamp, $nonce, $encrypt);
-        if ($event === false) {
-            Log::error('钉钉解密失败', compact('msgSignature','timestamp','nonce','encrypt'));
-            return response()->json([
-                'errcode' => 40001,
-                'errmsg' => 'decrypt fail'
-            ]);
-        }
-
-        Log::info('钉钉解密后的事件数据', $event);
-
-        // 3. 验证 challenge
-        if (isset($event['EventType']) && $event['EventType'] === 'check_url') {
-            $encryptMsg = $crypt->encryptMsg($event['Random'], $timestamp, $nonce);
-            return response()->json([
-                "msg_signature" => $encryptMsg['msg_signature'],
-                "timeStamp"     => $timestamp,
-                "nonce"         => $nonce,
-                "encrypt"       => $encryptMsg['encrypt']
-            ]);
-        }
-
-        // 4. 处理事件
-        if (isset($event['EventType'])) {
-            switch ($event['EventType']) {
-                case 'bpms_instance_change': // 审批实例变更
-                    $processInstanceId = $event['processInstanceId'] ?? null;
-                    $result            = $event['result'] ?? null; // agree / oppose / terminate
-                    Log::info("审批实例变更事件", compact('processInstanceId', 'result'));
-                    // TODO: 在这里执行你的业务逻辑,例如更新数据库状态
-                    break;
-
-                case 'bpms_task_change': // 审批任务变更
-                    $processInstanceId = $event['processInstanceId'] ?? null;
-                    $taskId            = $event['taskId'] ?? null;
-                    $result            = $event['result'] ?? null; // agree / oppose
-                    Log::info("审批任务变更事件", compact('processInstanceId', 'taskId', 'result'));
-                    // TODO: 在这里执行你的业务逻辑,例如记录审批人操作
-                    break;
-
-                default:
-                    Log::warning("未处理的事件类型", ['EventType' => $event['EventType']]);
-            }
-        }
-
-        // 5. 返回 success(加密)
-        $resEncrypt = $crypt->encryptMsg('success', $timestamp, $nonce);
-        return response()->json([
-            "msg_signature" => $resEncrypt['msg_signature'],
-            "timeStamp"     => $timestamp,
-            "nonce"         => $nonce,
-            "encrypt"       => $resEncrypt['encrypt']
-        ]);
     }
 }