PHP code example of ywn / wecomapi

1. Go to this page and download the library: Download ywn/wecomapi library. Choose the download type require.

2. Extract the ZIP file and open the index.php.

3. Add this code to the index.php.
    
        
<?php
require_once('vendor/autoload.php');

/* Start to develop here. Best regards https://php-download.com/ */

    

ywn / wecomapi example snippets


    return [
       'qywx'=>['corpid'=>'','agentId'=>'','secret'=>'']
    ];
    

       use Phalapi\API;
       use WeWorkApi\CorpAPI;
       use WeWorkApi\Utils\ParameterError;
       class Qywx extends API{
       public function Sendmsg(){
           $config = DI()->config->get("app.qywx");
           try {
               $api = new CorpAPI($config['corpid'], $config['secret']);
           } catch (ParameterError $e) {
               echo $e->getMessage() . "\n";
           }
           $user = $api->UserGet("userid");
           var_dump($user);
           //
           $user->mobile = "1219887219873";
           $api->UserUpdate($user); 
       }
   }
    

//se WeWorkApi\CorpAPI;
// 实例化 API 类
$api = new CorpAPI($corpId='ww55ca070cb9b7eb22', $secret='ktmzrVIlUH0UW63zi7-JyzsgTL9NfwUhHde6or6zwQY');

try { 
    // 创建 User
    $user = new User();
    {
        $user->userid = "userid";
        $user->name = "name";
        $user->mobile = "131488888888";
        $user->email = "[email protected]";
        $user->department = array(1); 
    } 
    $api->UserCreate($user);

    // 获取User
    $user = $api->UserGet("userid");

    // 删除User
    $api->UserDelete("userid"); 
} catch {
    echo $e->getMessage() . "\n";
    $api->UserDelete("userid");
}