Php实现钉钉OA一级审批,二级审批

Php实现钉钉OA一级审批,二级审批
一级审批

 public function oaPush($user_id,$person,$data)
    {
        //测试数据,上线需要删除
        $user_id = '154502333155';//发起人
        $person = ['154502665555'];//审批人
        $len = count($person);
        $result = null;
        if($len>0){
            $approve_config = DingApproveConfig::where("type", 8)->first();
            $url = $approve_config->url;
            $rep['originatorUserId']    = $user_id;
            $rep['processCode']         = $approve_config->processCode;
            $type = $len>1?'AND':'NONE';
            $rep['approvers'][]         = ['actionType'=>$type,'userIds'=>$person];
            $rep['microappAgentId']     = env("DD_AGENT_ID");
            $rep['formComponentValues'] = $data;
            $result = $this->oaCurl($url,$rep);
        }
        return $result;
    }

一级审批

public function oaPush2l($user_id,$person,$data)
    {
        //测试数据,上线需要删除
        $user_id = '154502333155';//发起人
        $person = ['154502333155','013359400664'];//审批人
        $len = count($person);
        $result = null;
        if($len>0){
            // 审批人,按照顺序审批
            $arr = [];
            foreach ($person as $key => $value) {
                $level2 = [];
                $level2['actionType'] = "NONE";
                $level2['userIds'] = [$value];
                array_push($arr, $level2);
            }
            $approve_config = DingApproveConfig::where("type", 9)->first();
            $url = $approve_config->url;
            $rep['originatorUserId']    = $user_id;
            $rep['processCode']         = $approve_config->processCode;
            $rep['approvers']           = $arr;
            $rep['microappAgentId']     = env("DD_AGENT_ID");
            $rep['formComponentValues'] = $data;
            $result = $this->oaCurl($url,$rep);
        }
        return $result;
    }

区别在于参数: approvers

一级审批传入的是:

$type = $len>1?'AND':'NONE';
$rep['approvers'][]  = ['actionType'=>$type,'userIds'=>$person];
  'AND' 是两个人以审批,同时收到,然后同时通过才算通过。

二级审批传入的是

array:2 [
  0 => array:2 [
    "actionType" => "NONE"
    "userIds" => array:1 [
      0 => "154502335555"
    ]
  ]
  1 => array:2 [
    "actionType" => "NONE"
    "userIds" => array:1 [
      0 => "01335926400664"
    ]
  ]
]

 $rep['approvers'] = $arr;
public function oaCurl($url,$data)
    {
        $ding = new Dingd();
        $access_token = $ding->getDingdAccessToken(env('DD_APPKEY_COM'),env('DD_APPSECRET_COM'));
        $ch = curl_init();
        curl_setopt($ch, CURLOPT_URL, $url);
        curl_setopt($ch, CURLOPT_POST, 1);
        curl_setopt($ch, CURLOPT_POSTFIELDS, json_encode($data));
        curl_setopt($ch, CURLOPT_REFERER, '');
        curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, false);
        curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
        curl_setopt($ch, CURLOPT_FOLLOWLOCATION, 1);
        curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
        curl_setopt( $ch,CURLOPT_HTTPHEADER, array(
            'Content-Type: application/json',
            'x-acs-dingtalk-access-token:' . $access_token
        ));

        curl_setopt($ch, CURLOPT_TIMEOUT, 30);
        $result = curl_exec($ch);
        curl_close($ch);

        $result = mb_convert_encoding($result, 'UTF-8','UTF-8 ,GBK, GB2312, BIG5');
        return json_decode($result,true);
    }

钉钉回调处理
app\Jobs

public function handle()
    {
    
        // 钉钉审批事件
         $config = DingApproveConfig::where("type", 4)->first();
         $code= $config->processCode;
        if ($this->type == "bpms_task_change") {
            if (isset($this->res['result'])) {
                // 有result才有返回结果
 
                if($this->res['processCode']==$code){
                  //对数据库进行处理
                }
            }
        }

        if ($this->type == 'bpms_instance_change') {
            if (isset($this->res['result'])) {
                // 有result才有返回结果
                if ($this->res['processCode'] == $code) {
                  //对数据库进行处理
                }
            }
            if ($this->res['type'] === 'terminate') {
                // 审批撤回
                if ($this->res['processCode'] == $code) {
                  //对数据库进行处理
                }
            }
        }
    }
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值