PHP enterprise wechat obtains employee userid and clock in information


Enterprise wechat can obtain the employee information under the Department through the Department list, so as to obtain the employee’s userid

//First obtain the required access_token

$access_token = json_decode ($this – > Getwork ($url =’ Corpid = Corpid of enterprise number & corpsecret = corpsecret of enterprise number), true);

/ / after access_token is obtained, it will be placed in the cache, and the gettoken interface cannot be called frequently, otherwise it will be blocked by frequency. The validity period of access_token is 2 hours

  public function getWork($url){
    $curl = curl_init();
    curl_setopt($curl, CURLOPT_URL, $url);
    curl_setopt($curl, CURLOPT_SSL_VERIFYPEER, FALSE);
    curl_setopt($curl, CURLOPT_SSL_VERIFYHOST, FALSE);
    curl_setopt($curl, CURLOPT_RETURNTRANSFER, 1);
    //curl_setopt($ch, CURLOPT_HTTPHEADER, $headers );
    $output = curl_exec($curl);
    return $output;


//After access_token is obtained, you can get the Department list under the current enterprise

  $department = $this->getWork($url=’’.Cache::get(‘access_token’));

//Get employee information under the Department (userid)

  $simplelist = json_decode($this->getWork($url=’’.Cache::get(‘access_token’).’&department_id=18′),true);

//After obtaining the userid of the employee, you can query the clock in record of the current employee

$stardate = date (‘y-m-01 ‘); / / the first day of the current month
$enddate = date (‘y-m-d ‘); / / current month
    $url = ‘’.Cache::get(‘access_token’);
    $post[‘starttime’]= strtotime($starDate);
    $post[‘endtime’]= strtotime($endDate);
$post [‘useridlist ‘] = $simplelist [‘userlist’] [‘userid ‘]; / / / employee’s userid
    $res = $this->request_post($url,json_encode($post));