From 55a9a3666da76ac9f42d1ccc12568bb2c3ae7ff7 Mon Sep 17 00:00:00 2001 From: cyc Date: Thu, 14 Nov 2019 15:59:18 +0800 Subject: [PATCH] =?UTF-8?q?=E9=83=A8=E7=BD=B2=E9=92=89=E9=92=89=E6=8F=90?= =?UTF-8?q?=E4=BA=A4=E5=AE=A1=E6=89=B9?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../dingtools/controllers/index.php | 119 ++++++++++++++++++ .../dingtools/helpers/dingtools_helper.php | 49 ++++++++ 2 files changed, 168 insertions(+) create mode 100644 webht/third_party/dingtools/controllers/index.php create mode 100644 webht/third_party/dingtools/helpers/dingtools_helper.php diff --git a/webht/third_party/dingtools/controllers/index.php b/webht/third_party/dingtools/controllers/index.php new file mode 100644 index 00000000..91ce40ab --- /dev/null +++ b/webht/third_party/dingtools/controllers/index.php @@ -0,0 +1,119 @@ +load->helper('dingtools'); + $this->AppKey = 'dingjcbxgidah9uspeuc'; + $this->AppSecret = 'C4-8rUDK1u5Twpsw7U3yo42s_bbYxFIqzLMp2j7uI80Sa8D-OPbtSoCMgZxHxo2d'; + } + + public function index(){ + echo json_encode(array('https://data.chinahighlights.com/pic/logo/logo-132x104.png','https://data.chinahighlights.com/image/homepage/holding-panda.jpg')); + exit('前方高能!!!'); + } + + public function sendApproval(){ + header('Access-Control-Allow-Origin:*'); + header('Access-Control-Allow-Methods:POST, GET'); + header('Access-Control-Max-Age:0'); + header('Access-Control-Allow-Headers:x-requested-with, Content-Type'); + header('Access-Control-Allow-Credentials:true'); + //接收数据 + $img = $this->input->post('img'); + $money = $this->input->post('money'); + $postunionid = $this->input->post('postunionid'); + $approvers = $this->input->post('approvers'); + + if(empty($postunionid)){ + exit('参数错误'); + } + + //获取access_token + $access_url = 'https://oapi.dingtalk.com/gettoken?appkey='.$this->AppKey.'&appsecret='.$this->AppSecret; + $access_token = GetPost_http($access_url,'',''); + $access_token = json_decode($access_token)->access_token; + $url = 'https://oapi.dingtalk.com/topapi/processinstance/create?access_token='.$access_token; + + $originator_user_id = $this->getuserid($postunionid); + $dept_id = $this->getdeptid($originator_user_id); + $approversid = $this->getuserid($approvers); + + $postData = array(); + //表单code + $postData['process_code'] = 'PROC-9D90693F-DE34-423C-9B92-A19FFFC87577'; + //发起人id + $postData['originator_user_id'] = $originator_user_id; + //发起人部门id + $postData['dept_id'] = $dept_id; + //审批人id + $postData['approvers'] = $approversid; + $postData['form_component_values'] = array(); + $postData['form_component_values']['0']['name'] = '报账金额'; + $postData['form_component_values']['0']['value'] = $money; + $postData['form_component_values']['1']['name'] = '附件'; + $postData['form_component_values']['1']['value'] = json_decode($img); + + //print_r(json_encode($postData));die(); + $approoval = GetPost_http($url,json_encode($postData),'json'); + print_r($approoval); + } + + public function sendRefund(){ + //获取access_token + $access_url = 'https://oapi.dingtalk.com/gettoken?appkey='.$this->AppKey.'&appsecret='.$this->AppSecret; + $access_token = GetPost_http($access_url,'',''); + $access_token = json_decode($access_token)->access_token; + $url = 'https://oapi.dingtalk.com/topapi/processinstance/create?access_token='.$access_token; + + $postData = array(); + $postData['process_code'] = 'PROC-95F150AE-A2A9-4B99-B2D6-C26F62EC1E06'; + //发起人id + $postData['originator_user_id'] = '103218225237808971'; + //发起人部门id + $postData['dept_id'] = '111848239'; + //审批人id + $postData['approvers'] = '011702444537734182'; + $postData['form_component_values'] = array(); + $postData['form_component_values']['0']['name'] = '退款金额'; + $postData['form_component_values']['0']['value'] = 1000; + + $approoval = GetPost_http($url,json_encode($postData),'json'); + print_r($approoval); + } + + //获取用户id + function getuserid($unionid){ + if(empty($unionid)){ + exit('参数为空'); + }else{ + $access_url = 'https://oapi.dingtalk.com/gettoken?appkey='.$this->AppKey.'&appsecret='.$this->AppSecret; + $access_token = GetPost_http($access_url,'',''); + $access_token = json_decode($access_token)->access_token; + $listurl = 'https://oapi.dingtalk.com/user/getUseridByUnionid?access_token='.$access_token.'&unionid='.$unionid; + + $userlist = GetPost_http($listurl,'',''); + $userid = json_decode($userlist)->userid; + return $userid; + } + } + + //获取部门列表 + function getdeptid($userid){ + if(empty($userid)){ + exit('参数错误'); + }else{ + $access_url = 'https://oapi.dingtalk.com/gettoken?appkey='.$this->AppKey.'&appsecret='.$this->AppSecret; + $access_token = GetPost_http($access_url,'',''); + $access_token = json_decode($access_token)->access_token; + $detailurl = 'https://oapi.dingtalk.com/user/get?access_token='.$access_token.'&userid='.$userid; + + $userdetail = GetPost_http($detailurl,'',''); + $departid = json_decode($userdetail)->department; + return $departid['0']; + } + } +} \ No newline at end of file diff --git a/webht/third_party/dingtools/helpers/dingtools_helper.php b/webht/third_party/dingtools/helpers/dingtools_helper.php new file mode 100644 index 00000000..8eab66af --- /dev/null +++ b/webht/third_party/dingtools/helpers/dingtools_helper.php @@ -0,0 +1,49 @@ + \ No newline at end of file