forked from sskaje/weixin
-
Notifications
You must be signed in to change notification settings - Fork 0
/
cli.php
83 lines (58 loc) · 1.33 KB
/
cli.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
<?php
/**
* 命令行微信工具接口
* 直接不带参数执行可以看帮助
*
* @author sskaje
*/
require(__DIR__ . '/classes/weixin.inc.php');
# 启用Exception handler
spWxError::SetExceptionHandler();
if (!isset($argv[2])) {
usage();
}
$app_name = strtolower($argv[1]);
if (!preg_match('#^[a-z0-9]+$#i', $app_name)) {
usage();
}
$app_file = __DIR__ . '/app/' . $app_name . '.php';
if (!is_file($app_file)) {
throw new spWxException('微信应用文件不存在', 30001);
}
require($app_file);
$command = strtolower($argv[2]);
$app = spWeixin::App();
if ($command == 'menu_create') {
$menu_class = SPWX_MENU_CLASS;
$ret = $app->menu_create(new $menu_class());
var_dump($ret);
} else if ($command == 'menu_get') {
$ret = $app->menu_get();
var_dump($ret);
} else if ($command == 'menu_delete') {
$ret = $app->menu_delete();
var_dump($ret);
}
function usage($err = '')
{
$err = trim($err);
if ($err) {
echo <<<ERROR
Error:
{$err}
ERROR;
}
echo <<<USAGE
Weixin App CLI tools
Author: sskaje
Usage:
php cli.php APP_NAME COMMAND OPTIONS
App Name: ^[A-Za-z0-9]+\$
Commands:
menu_create create menu
menu_get get menu json
menu_delete delete menu
USAGE;
exit;
}
# EOF