forked from open-dingtalk/corp_demo_php
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcallback.php
executable file
·86 lines (79 loc) · 2.48 KB
/
callback.php
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
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
<?php
require_once(__DIR__ . "/config.php");
require_once(__DIR__ . "/util/Log.php");
require_once(__DIR__ . "/util/Cache.php");
require_once(__DIR__ . "/crypto/DingtalkCrypt.php");
$signature = $_GET["signature"];
$timeStamp = $_GET["timestamp"];
$nonce = $_GET["nonce"];
$postdata = file_get_contents("php://input");
$postList = json_decode($postdata,true);
$encrypt = $postList['encrypt'];
$msg = "";
/**
* TOKEN, ENCODING_AES_KEY, CORPID配置在config文件中
*/
try {
$crypt = new DingtalkCrypt(TOKEN, ENCODING_AES_KEY, CORPID);
$errCode = $crypt->DecryptMsg($signature, $timeStamp, $nonce, $encrypt, $msg);
} catch (Exception $e) {
Log::e("DecryptMsg Exception".$e->getMessage());
print $e->getMessage();
exit();
}
$eventMsg = json_decode($msg);
$eventType = $eventMsg->EventType;
switch ($eventType){
case "user_add_org":
//通讯录用户增加 do something
Log::i("【callback】:user_add_org_action");
break;
case "user_modify_org":
//通讯录用户更改 do something
Log::i("【callback】:user_modify_org_action");
break;
case "user_leave_org":
//通讯录用户离职 do something
Log::i("【callback】:user_leave_org_action");
break;
case "org_admin_add":
//通讯录用户被设为管理员 do something
Log::i("【callback】:org_admin_add_action");
break;
case "org_admin_remove":
//通讯录用户被取消设置管理员 do something
Log::i("【callback】:org_admin_remove_action");
break;
case "org_dept_create":
//通讯录企业部门创建 do something
Log::i("【callback】:org_dept_create_action");
break;
case "org_dept_modify":
//通讯录企业部门修改 do something
Log::i("【callback】:org_dept_modify_action");
break;
case "org_dept_remove":
//通讯录企业部门删除 do something
Log::i("【callback】:org_dept_remove_action");
break;
case "org_remove":
//企业被解散 do something
Log::i("【callback】:org_remove_action");
break;
case "check_url"://do something
default : //do something
break;
}
/**对返回信息进行加密**/
$res = "success";
$encryptMsg = "";
$errCode = $crypt->EncryptMsg($res, $timeStamp, $nonce, $encryptMsg);
if ($errCode == 0)
{
echo $encryptMsg;
Log::i("【callback】:RESPONSE: " . $encryptMsg);
}
else
{
Log::e("RESPONSE ERR: " . $errCode);
}