相关接口代码
<?php
/*
* Copyright (C) 2017 All rights reserved.
*
* @File UserTest.php
* @Brief
* @Author 毛子
* @Version 1.0
* @Date 2017-12-26
* @Remark cms框架合并企业微信接口demo
*/
namespace app\api\controller;
use think\Config;
class Test extends Common{
protected $mem_mod;
protected $api;
protected $api_app;
protected $config;
public function _initialize(){
parent::_initialize();
#企业微信配置文件
$this->config = Config::get('wechat');
#企业微信接口demo 不用管token
\think\Loader::import('Wechat.api.src.CorpAPI',EXTEND_PATH,'.class.php');
$this->api = new \CorpAPI($this->config['CORP_ID'], $this->config['CONTACT_SYNC_SECRET']);
$this->api_app = new \CorpAPI($this->config['CORP_ID'], $this->config['APP_SECRET']);
}
#获取部门成员
public function getDepartmem(){
#部门id
$depart_id = 1;
$members = $this->api->UserSimpleList($depart_id, 1);
$members = mz_Object2Array($members);
return mz_apisuc('成功', $members);
}
#获取部门列表
public function getDepartlist() {
$depart_list = $departmentList = $this->api->DepartmentList();
$depart_list = mz_Object2Array($depart_list);
return mz_apisuc('成功', $depart_list);
}
#发送消息
public function sendMessage() {
$agentId = $this->config['APP_ID'];
try {
//
$message = new \Message();
{
$message->sendToAll = false;
$message->touser = array("MaoJianYu");
$message->toparty = array(1);
$message->totag = array();
$message->agentid = $agentId;
$message->safe = 0;
$message->messageContent = new \NewsMessageContent(
array(
new \NewsArticle(
$title = "Got you !",
$description = "Who's this cute guy testing me ?",
$url = "https://work.weixin.qq.com/wework_admin/ww_mt/agenda",
$picurl = "https://p.qpic.cn/pic_wework/167386225/f9ffc8f0a34f301580daaf05f225723ff571679f07e69f91/0", $btntxt = "btntxt"
),
)
);
}
$invalidUserIdList = null;
$invalidPartyIdList = null;
$invalidTagIdList = null;
$this->api_app->MessageSend($message, $invalidUserIdList, $invalidPartyIdList, $invalidTagIdList);
} catch (Exception $e) {
echo $e->getMessage() . "\n";
}
}
#新增成员
public function addUser() {
$user = new \User(); {
$user->userid = "userid";
$user->name = "name";
$user->mobile = "131488888888";
$user->email = "sbzhu@ipp.cas.cn";
$user->department = array(1);
$ExtattrList = new \ExtattrList();
$ExtattrList->attrs = array(new \ExtattrItem("s_a_2", "aaa"), new \ExtattrItem("s_a_3", "bbb"));
$user->extattr = $ExtattrList;
}
$this->api->UserCreate($user);
}
#删除成员
public function deleteUser() {
$this->api->UserDelete("userid");
}
}
网友评论