mirror of
https://shylinux.com/x/icebergs
synced 2025-04-28 18:22:02 +08:00
opt lark
This commit is contained in:
parent
f6d6fabb1c
commit
7918ebc222
@ -272,7 +272,6 @@ func init() {
|
|||||||
m.Push(aaa.USERNICK, val[aaa.USERNICK])
|
m.Push(aaa.USERNICK, val[aaa.USERNICK])
|
||||||
m.PushImages(aaa.AVATAR, kit.Format(val[aaa.AVATAR]), kit.Select("60", "240", m.Option(mdb.FIELDS) == mdb.DETAIL))
|
m.PushImages(aaa.AVATAR, kit.Format(val[aaa.AVATAR]), kit.Select("60", "240", m.Option(mdb.FIELDS) == mdb.DETAIL))
|
||||||
})
|
})
|
||||||
|
|
||||||
})
|
})
|
||||||
m.PushAction(mdb.REMOVE)
|
m.PushAction(mdb.REMOVE)
|
||||||
}},
|
}},
|
||||||
|
@ -35,14 +35,16 @@ func init() {
|
|||||||
m.Cmdy(mdb.INSERT, m.Prefix(APP), "", mdb.HASH, arg)
|
m.Cmdy(mdb.INSERT, m.Prefix(APP), "", mdb.HASH, arg)
|
||||||
}},
|
}},
|
||||||
TOKEN: {Name: "token appid", Help: "令牌", Hand: func(m *ice.Message, arg ...string) {
|
TOKEN: {Name: "token appid", Help: "令牌", Hand: func(m *ice.Message, arg ...string) {
|
||||||
msg := m.Cmd(APP, m.Option(APPID))
|
m.Debug("what %v", m.Option(APPID))
|
||||||
|
msg := m.Cmd(APP, m.Option(APPID), ice.OptionFields(m.Conf(APP, kit.META_FIELD)))
|
||||||
if now := time.Now().Unix(); msg.Append(TOKEN) == "" || now > kit.Int64(msg.Append(EXPIRE)) {
|
if now := time.Now().Unix(); msg.Append(TOKEN) == "" || now > kit.Int64(msg.Append(EXPIRE)) {
|
||||||
sub := m.Cmd(web.SPIDE, LARK, web.SPIDE_POST, "/open-apis/auth/v3/tenant_access_token/internal/",
|
sub := m.Cmd(web.SPIDE, LARK, web.SPIDE_POST, "/open-apis/auth/v3/tenant_access_token/internal/",
|
||||||
APP_ID, msg.Append(APPID), "app_secret", msg.Append(APPMM))
|
APP_ID, msg.Append(APPID), "app_secret", msg.Append(APPMM))
|
||||||
|
|
||||||
m.Cmd(mdb.MODIFY, m.Prefix(APP), "", mdb.HASH, m.OptionSimple(APPID),
|
m.Cmd(mdb.MODIFY, m.Prefix(APP), "", mdb.HASH, m.OptionSimple(APPID),
|
||||||
TOKEN, sub.Append("tenant_access_token"), EXPIRE, now+kit.Int64(sub.Append(EXPIRE)))
|
TOKEN, sub.Append("tenant_access_token"), EXPIRE, now+kit.Int64(sub.Append(EXPIRE)))
|
||||||
msg.Append(TOKEN, sub.Append("tenant_access_token"))
|
m.Echo(sub.Append("tenant_access_token"))
|
||||||
|
return
|
||||||
}
|
}
|
||||||
m.Echo(msg.Append(TOKEN))
|
m.Echo(msg.Append(TOKEN))
|
||||||
}},
|
}},
|
||||||
|
@ -8,13 +8,8 @@ const DUTY = "duty"
|
|||||||
|
|
||||||
func init() {
|
func init() {
|
||||||
Index.Merge(&ice.Context{Commands: map[string]*ice.Command{
|
Index.Merge(&ice.Context{Commands: map[string]*ice.Command{
|
||||||
DUTY: {Name: "duty appid [title] text auto", Help: "通告", Hand: func(m *ice.Message, c *ice.Context, key string, arg ...string) {
|
DUTY: {Name: "duty [title] text auto", Help: "通告", Hand: func(m *ice.Message, c *ice.Context, key string, arg ...string) {
|
||||||
if len(arg) < 2 {
|
duty := m.Cmd(APP, m.Option(APP_ID)).Append(DUTY)
|
||||||
m.Cmdy(APP)
|
|
||||||
return
|
|
||||||
}
|
|
||||||
|
|
||||||
duty := m.Cmd(APP, arg[0]).Append(DUTY)
|
|
||||||
m.Cmdy(SEND, arg[0], duty, arg[1:])
|
m.Cmdy(SEND, arg[0], duty, arg[1:])
|
||||||
}},
|
}},
|
||||||
}})
|
}})
|
||||||
|
@ -12,7 +12,7 @@ const FORM = "form"
|
|||||||
func init() {
|
func init() {
|
||||||
Index.Merge(&ice.Context{Commands: map[string]*ice.Command{
|
Index.Merge(&ice.Context{Commands: map[string]*ice.Command{
|
||||||
FORM: {Name: "form [chat_id|open_id|user_id|email] target title text [confirm|value|url arg...]...", Help: "消息", Hand: func(m *ice.Message, c *ice.Context, key string, arg ...string) {
|
FORM: {Name: "form [chat_id|open_id|user_id|email] target title text [confirm|value|url arg...]...", Help: "消息", Hand: func(m *ice.Message, c *ice.Context, key string, arg ...string) {
|
||||||
var form = kit.Dict(CONTENT, kit.Dict())
|
var form = kit.Dict()
|
||||||
switch arg[0] {
|
switch arg[0] {
|
||||||
case CHAT_ID, OPEN_ID, USER_ID, aaa.EMAIL:
|
case CHAT_ID, OPEN_ID, USER_ID, aaa.EMAIL:
|
||||||
form[arg[0]], arg = arg[1], arg[2:]
|
form[arg[0]], arg = arg[1], arg[2:]
|
||||||
@ -47,11 +47,12 @@ func init() {
|
|||||||
case "url":
|
case "url":
|
||||||
button[arg[i+1]], i = arg[i+2], i+2
|
button[arg[i+1]], i = arg[i+2], i+2
|
||||||
default:
|
default:
|
||||||
button["value"], i = kit.Dict(
|
button["value"], i = map[string]interface{}{
|
||||||
ice.MSG_RIVER, m.Option(ice.MSG_RIVER),
|
ice.MSG_RIVER: m.Option(ice.MSG_RIVER),
|
||||||
ice.MSG_STORM, m.Option(ice.MSG_STORM),
|
ice.MSG_STORM: m.Option(ice.MSG_STORM),
|
||||||
arg[i+1], arg[i+2],
|
APP_ID: m.Option(APP_ID),
|
||||||
), i+2
|
arg[i+1]: arg[i+2],
|
||||||
|
}, i+2
|
||||||
}
|
}
|
||||||
kit.Value(button, "value.content", content)
|
kit.Value(button, "value.content", content)
|
||||||
kit.Value(button, "value.open_chat_id", m.Option(OPEN_CHAT_ID))
|
kit.Value(button, "value.open_chat_id", m.Option(OPEN_CHAT_ID))
|
||||||
|
@ -88,18 +88,15 @@ func init() {
|
|||||||
"card": {Name: "", Help: "", Hand: func(m *ice.Message, arg ...string) {
|
"card": {Name: "", Help: "", Hand: func(m *ice.Message, arg ...string) {
|
||||||
data := m.Optionv(ice.MSG_USERDATA)
|
data := m.Optionv(ice.MSG_USERDATA)
|
||||||
kit.Fetch(kit.Value(data, "action.value"), func(key string, value string) { m.Option(key, value) })
|
kit.Fetch(kit.Value(data, "action.value"), func(key string, value string) { m.Option(key, value) })
|
||||||
|
|
||||||
m.Cmdy(TALK, kit.Parse(nil, "", kit.Split(m.Option(kit.SSH_CMD))...))
|
m.Cmdy(TALK, kit.Parse(nil, "", kit.Split(m.Option(kit.SSH_CMD))...))
|
||||||
m.Cmd(SEND, m.Option(APP_ID), CHAT_ID, m.Option(OPEN_CHAT_ID),
|
m.Cmd(SEND, m.Option(APP_ID), CHAT_ID, m.Option(OPEN_CHAT_ID),
|
||||||
m.Option(wiki.TITLE)+" "+m.Option(kit.SSH_CMD), m.Result())
|
m.Option(wiki.TITLE)+" "+m.Option(kit.SSH_CMD), m.Result())
|
||||||
}},
|
}},
|
||||||
}, Hand: func(m *ice.Message, c *ice.Context, key string, arg ...string) {
|
}, Hand: func(m *ice.Message, c *ice.Context, key string, arg ...string) {
|
||||||
if m.Options(OPEN_CHAT_ID) {
|
if m.Options(OPEN_CHAT_ID) {
|
||||||
if m.Cmdy(TALK, strings.TrimSpace(m.Option("text_without_at_bot"))); len(m.Resultv()) > 0 {
|
m.Cmdy(TALK, strings.TrimSpace(m.Option("text_without_at_bot")))
|
||||||
m.Cmd(SEND, m.Option(APP_ID), m.Option(OPEN_CHAT_ID), m.Result())
|
|
||||||
}
|
|
||||||
} else {
|
} else {
|
||||||
m.Cmd(DUTY, m.Option(APP_ID), m.Option(kit.MDB_TYPE), kit.Formats(m.Optionv(ice.MSG_USERDATA)))
|
m.Cmdy(DUTY, m.Option(kit.MDB_TYPE), kit.Formats(m.Optionv(ice.MSG_USERDATA)))
|
||||||
}
|
}
|
||||||
}},
|
}},
|
||||||
}})
|
}})
|
||||||
|
@ -5,6 +5,7 @@ import (
|
|||||||
|
|
||||||
ice "github.com/shylinux/icebergs"
|
ice "github.com/shylinux/icebergs"
|
||||||
"github.com/shylinux/icebergs/base/aaa"
|
"github.com/shylinux/icebergs/base/aaa"
|
||||||
|
"github.com/shylinux/icebergs/base/web"
|
||||||
kit "github.com/shylinux/toolkits"
|
kit "github.com/shylinux/toolkits"
|
||||||
)
|
)
|
||||||
|
|
||||||
@ -16,14 +17,36 @@ func init() {
|
|||||||
cmds := kit.Split(strings.Join(arg, " "))
|
cmds := kit.Split(strings.Join(arg, " "))
|
||||||
if aaa.UserLogin(m, m.Option(OPEN_ID), ""); !m.Right(cmds) {
|
if aaa.UserLogin(m, m.Option(OPEN_ID), ""); !m.Right(cmds) {
|
||||||
if aaa.UserLogin(m, m.Option(OPEN_CHAT_ID), ""); !m.Right(cmds) {
|
if aaa.UserLogin(m, m.Option(OPEN_CHAT_ID), ""); !m.Right(cmds) {
|
||||||
m.Cmd(DUTY, m.Option(APP_ID), m.Option(OPEN_CHAT_ID), m.Option("text_without_at_bot"))
|
m.Cmd(DUTY, m.Option(OPEN_CHAT_ID), m.Option("text_without_at_bot"))
|
||||||
m.Cmd(HOME)
|
m.Cmd(HOME)
|
||||||
return // 没有权限
|
return // 没有权限
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// 执行命令
|
// 执行命令
|
||||||
m.Cmdy(cmds)
|
if m.Cmdy(cmds); len(m.Resultv()) > 0 {
|
||||||
|
m.Cmd(SEND, m.Option(APP_ID), m.Option(OPEN_CHAT_ID), m.Result())
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
val := []string{}
|
||||||
|
m.Table(func(index int, value map[string]string, head []string) {
|
||||||
|
for _, key := range head {
|
||||||
|
val = append(val, kit.Format("%s:\t%s", key, value[key]))
|
||||||
|
}
|
||||||
|
val = append(val, "\n")
|
||||||
|
})
|
||||||
|
|
||||||
|
_lark_post(m, m.Option(APP_ID), "/open-apis/message/v4/send/", web.SPIDE_DATA, kit.Formats(
|
||||||
|
kit.Dict("msg_type", "interactive", "chat_id", m.Option(OPEN_CHAT_ID), "card", kit.Dict(
|
||||||
|
"header", kit.Dict("title", kit.Dict("tag", "lark_md", "content", strings.Join(cmds, " "))),
|
||||||
|
"elements", []interface{}{kit.Dict("tag", "div", "fields", []interface{}{
|
||||||
|
kit.Dict("is_short", true, "text", kit.Dict(
|
||||||
|
"tag", "lark_md", "content", strings.Join(val, "\n"),
|
||||||
|
)),
|
||||||
|
})},
|
||||||
|
)),
|
||||||
|
))
|
||||||
}},
|
}},
|
||||||
}})
|
}})
|
||||||
}
|
}
|
||||||
|
@ -2,68 +2,20 @@ package mp
|
|||||||
|
|
||||||
import (
|
import (
|
||||||
ice "github.com/shylinux/icebergs"
|
ice "github.com/shylinux/icebergs"
|
||||||
"github.com/shylinux/icebergs/base/aaa"
|
|
||||||
"github.com/shylinux/icebergs/base/mdb"
|
|
||||||
"github.com/shylinux/icebergs/base/web"
|
"github.com/shylinux/icebergs/base/web"
|
||||||
"github.com/shylinux/icebergs/core/chat"
|
"github.com/shylinux/icebergs/core/chat"
|
||||||
kit "github.com/shylinux/toolkits"
|
|
||||||
)
|
)
|
||||||
|
|
||||||
const (
|
|
||||||
LOGIN = "login"
|
|
||||||
APPID = "appid"
|
|
||||||
APPMM = "appmm"
|
|
||||||
ACCESS = "access"
|
|
||||||
OPENID = "openid"
|
|
||||||
WEIXIN = "weixin"
|
|
||||||
)
|
|
||||||
const MP = "mp"
|
const MP = "mp"
|
||||||
|
|
||||||
var Index = &ice.Context{Name: MP, Help: "小程序",
|
var Index = &ice.Context{Name: MP, Help: "小程序",
|
||||||
Configs: map[string]*ice.Config{
|
|
||||||
LOGIN: {Name: LOGIN, Help: "认证", Value: kit.Data(
|
|
||||||
WEIXIN, "https://api.weixin.qq.com", APPID, "", APPMM, "",
|
|
||||||
)},
|
|
||||||
},
|
|
||||||
Commands: map[string]*ice.Command{
|
Commands: map[string]*ice.Command{
|
||||||
ice.CTX_INIT: {Hand: func(m *ice.Message, c *ice.Context, cmd string, arg ...string) {
|
ice.CTX_INIT: {Hand: func(m *ice.Message, c *ice.Context, cmd string, arg ...string) {
|
||||||
m.Load()
|
m.Load()
|
||||||
m.Cmd(web.SPIDE, mdb.CREATE, WEIXIN, m.Conf(LOGIN, kit.Keys(kit.MDB_META, WEIXIN)))
|
|
||||||
}},
|
}},
|
||||||
ice.CTX_EXIT: {Hand: func(m *ice.Message, c *ice.Context, cmd string, arg ...string) {
|
ice.CTX_EXIT: {Hand: func(m *ice.Message, c *ice.Context, cmd string, arg ...string) {
|
||||||
m.Save()
|
m.Save()
|
||||||
}},
|
}},
|
||||||
|
|
||||||
ACCESS: {Name: "access appid auto login", Help: "认证", Action: map[string]*ice.Action{
|
|
||||||
LOGIN: {Name: "login appid appmm", Help: "登录", Hand: func(m *ice.Message, arg ...string) {
|
|
||||||
m.Conf(LOGIN, kit.Keys(kit.MDB_META, APPID), m.Option(APPID))
|
|
||||||
m.Conf(LOGIN, kit.Keys(kit.MDB_META, APPMM), m.Option(APPMM))
|
|
||||||
}},
|
|
||||||
}, Hand: func(m *ice.Message, c *ice.Context, cmd string, arg ...string) {
|
|
||||||
m.Echo(m.Conf(LOGIN, kit.Keys(kit.MDB_META, APPID)))
|
|
||||||
}},
|
|
||||||
|
|
||||||
"/login/": {Name: "/login/", Help: "认证", Action: map[string]*ice.Action{
|
|
||||||
aaa.SESS: {Name: "sess code", Help: "会话", Hand: func(m *ice.Message, arg ...string) {
|
|
||||||
msg := m.Cmd(web.SPIDE, WEIXIN, web.SPIDE_GET, "/sns/jscode2session?grant_type=authorization_code", "js_code", m.Option("code"),
|
|
||||||
APPID, m.Conf(LOGIN, kit.Keys(kit.MDB_META, APPID)), "secret", m.Conf(LOGIN, kit.Keys(kit.MDB_META, APPMM)))
|
|
||||||
|
|
||||||
// 用户登录
|
|
||||||
m.Option(ice.MSG_USERZONE, MP)
|
|
||||||
m.Echo(aaa.SessCreate(msg, msg.Append(OPENID)))
|
|
||||||
}},
|
|
||||||
aaa.USER: {Name: "user", Help: "用户", Hand: func(m *ice.Message, arg ...string) {
|
|
||||||
m.Option(aaa.USERNAME, m.Option(ice.MSG_USERNAME))
|
|
||||||
m.Cmd(aaa.USER, mdb.MODIFY, aaa.USERZONE, MP, aaa.USERNICK, m.Option("nickName"),
|
|
||||||
aaa.AVATAR, m.Option("avatarUrl"), aaa.GENDER, kit.Select("女", "男", m.Option(aaa.GENDER) == "1"),
|
|
||||||
aaa.COUNTRY, m.Option(aaa.COUNTRY), aaa.LANGUAGE, m.Option(aaa.LANGUAGE),
|
|
||||||
aaa.CITY, m.Option(aaa.CITY), aaa.PROVINCE, m.Option(aaa.PROVINCE),
|
|
||||||
)
|
|
||||||
}},
|
|
||||||
chat.SCAN: {Name: "scan", Help: "扫码", Hand: func(m *ice.Message, arg ...string) {
|
|
||||||
m.Cmdy(chat.SCAN)
|
|
||||||
}},
|
|
||||||
}},
|
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -3,7 +3,6 @@ refer "" `
|
|||||||
官网 https://weixin.qq.com/
|
官网 https://weixin.qq.com/
|
||||||
后台 https://mp.weixin.qq.com/
|
后台 https://mp.weixin.qq.com/
|
||||||
文档 https://developers.weixin.qq.com/miniprogram/dev/api/
|
文档 https://developers.weixin.qq.com/miniprogram/dev/api/
|
||||||
源码 https://github.com/shylinux/icebergs/blob/master/misc/mp/mp.go
|
|
||||||
`
|
`
|
||||||
qrcode `https://mp.weixin.qq.com/a/~HkylKD4DZShrgSm5GuXWLQ~~`
|
qrcode `https://mp.weixin.qq.com/a/~HkylKD4DZShrgSm5GuXWLQ~~`
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user