1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
| <?php
function queryUrl($url, $header, $postfields)
{
if (function_exists('curl_init') != 1)
throw new Exception("Please install curl plugin", 1); //请安装curl插件!
$curl = curl_init();
curl_setopt($curl, CURLOPT_URL, $url);
curl_setopt($curl, CURLOPT_HTTPHEADER, $header);
curl_setopt($curl, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($curl, CURLOPT_TIMEOUT, 5);
curl_setopt($curl, CURLOPT_POST, 1);
curl_setopt($curl, CURLOPT_POSTFIELDS, $postfields);
// curl_setopt($curl, CURLOPT_USERAGENT, 'Mozilla/5.0 (X11; Ubuntu; Linux x86_64; rv:68.0) Gecko/20100101 Firefox/68.0');
$result = curl_exec($curl);
curl_close($curl);
return $result;
}
// TODO
$app_access_token = '';
$header = array('Content-Type: application/json');
$fp = fopen('bmh_db', 'r');
while (!feof($fp)) {
$line = fgets($fp);
if ($line == false)
break;
$line = explode(' ', trim($line));
// 创建部门
$msg = array(
'id' => $line[0],
'name' => $line[1],
'parentid' => $line[2],
'order' => $line[3]
);
print $line[0];
echo "\n";
print(queryUrl("https://qyapi.weixin.qq.com/cgi-bin/department/create?access_token=$app_access_token", $header, json_encode($msg)));
echo "\n";
// 移动员工到部门
$order = 1000000;
for ($i = 4; $i < count($line); $i ++) {
echo ' ', $line[$i];
$order -= 100;
$msg2 = array(
'userid' => $line[$i],
'department' => array($line[0]),
'order' => array($order)
);
print(queryUrl("https://qyapi.weixin.qq.com/cgi-bin/user/update?access_token=$app_access_token", $header, json_encode($msg2)));
echo "\n";
}
}
|