1
0
forked from x/icebergs
This commit is contained in:
IT 老营长 @云轩领航-创始人 2022-12-15 22:04:21 +08:00
parent 0274061161
commit 16618a388f
22 changed files with 152 additions and 312 deletions

View File

@ -24,7 +24,8 @@ type server struct {
func (s server) Search(m *ice.Message, arg ...string) { func (s server) Search(m *ice.Message, arg ...string) {
if arg[0] == mdb.FOREACH && arg[1] == "" { if arg[0] == mdb.FOREACH && arg[1] == "" {
s.List(m.Spawn(kit.Dict(ice.MSG_FIELDS, "time,port,status,pid,cmd,dir"))).Tables(func(value ice.Maps) { s.Code.List(m.Spawn(kit.Dict(ice.MSG_FIELDS, "time,port,status,pid,cmd,dir")), "")
m.Tables(func(value ice.Maps) {
m.PushSearch(mdb.TYPE, value[cli.STATUS], mdb.NAME, value[nfs.PATH], mdb.TEXT, value[mdb.LINK]) m.PushSearch(mdb.TYPE, value[cli.STATUS], mdb.NAME, value[nfs.PATH], mdb.TEXT, value[mdb.LINK])
}) })
} }

View File

@ -1,12 +1,12 @@
package java package java
import ( import (
"path"
"strings" "strings"
"shylinux.com/x/ice" "shylinux.com/x/ice"
"shylinux.com/x/icebergs/base/cli" "shylinux.com/x/icebergs/base/cli"
"shylinux.com/x/icebergs/base/mdb" "shylinux.com/x/icebergs/base/mdb"
"shylinux.com/x/icebergs/base/nfs"
kit "shylinux.com/x/toolkits" kit "shylinux.com/x/toolkits"
) )

View File

@ -22,30 +22,20 @@ const APP = "app"
func init() { func init() {
Index.MergeCommands(ice.Commands{ Index.MergeCommands(ice.Commands{
APP: {Name: "app appid auto token login", Help: "应用", Actions: ice.MergeActions(ice.Actions{ APP: {Name: "app appid auto token login", Help: "应用", Actions: ice.MergeActions(ice.Actions{
ice.CTX_INIT: {Hand: func(m *ice.Message, arg ...string) { ice.CTX_INIT: {Hand: func(m *ice.Message, arg ...string) { m.Cmd(web.SPIDE, mdb.CREATE, LARK, m.Config(tcp.SERVER)) }},
m.Cmd(web.SPIDE, mdb.CREATE, LARK, m.Config(tcp.SERVER)) LOGIN: {Name: "login appid* appmm* duty", Help: "登录", Hand: func(m *ice.Message, arg ...string) {
mdb.HashCreate(m, m.OptionSimple(APPID, APPMM, DUTY))
}}, }},
LOGIN: {Name: "login appid appmm duty", Help: "登录", Hand: func(m *ice.Message, arg ...string) { TOKEN: {Name: "token appid*", Help: "令牌", Hand: func(m *ice.Message, arg ...string) {
m.Cmdy(mdb.INSERT, m.PrefixKey(), "", mdb.HASH, m.OptionSimple(APPID, APPMM, DUTY))
}},
TOKEN: {Name: "token appid", Help: "令牌", Hand: func(m *ice.Message, arg ...string) {
msg := m.Cmd(APP, m.Option(APPID)) msg := m.Cmd(APP, m.Option(APPID))
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)) {
res := m.Cmd(web.SPIDE, LARK, "/open-apis/auth/v3/tenant_access_token/internal/", res := m.Cmd(web.SPIDE, LARK, "/open-apis/auth/v3/tenant_access_token/internal/", APP_ID, msg.AppendSimple(APPID), "app_secret", msg.Append(APPMM))
APP_ID, msg.Append(APPID), "app_secret", msg.Append(APPMM)) mdb.HashModify(m, m.OptionSimple(APPID), TOKEN, res.Append("tenant_access_token"), EXPIRE, now+kit.Int64(res.Append(EXPIRE)))
m.Cmd(mdb.MODIFY, m.PrefixKey(), "", mdb.HASH, m.OptionSimple(APPID),
TOKEN, res.Append("tenant_access_token"), EXPIRE, now+kit.Int64(res.Append(EXPIRE)))
m.Echo(res.Append("tenant_access_token")) m.Echo(res.Append("tenant_access_token"))
return } else {
}
m.Echo(msg.Append(TOKEN)) m.Echo(msg.Append(TOKEN))
}
}}, }},
}, mdb.HashAction( }, mdb.HashAction(mdb.SHORT, APPID, mdb.FIELD, "time,appid,duty,token,expire", tcp.SERVER, "https://open.feishu.cn/"))},
mdb.SHORT, APPID, mdb.FIELD, "time,appid,duty,token,expire",
tcp.SERVER, "https://open.feishu.cn/",
)), Hand: func(m *ice.Message, arg ...string) {
mdb.HashSelect(m, arg...)
}},
}) })
} }

View File

@ -9,7 +9,6 @@ import (
func _company_list(m *ice.Message, appid string) { func _company_list(m *ice.Message, appid string) {
_, data := _lark_get(m, appid, "/open-apis/contact/v1/scope/get/") _, data := _lark_get(m, appid, "/open-apis/contact/v1/scope/get/")
kit.Fetch(kit.Value(data, "data.authed_departments"), func(index int, ship_id string) { kit.Fetch(kit.Value(data, "data.authed_departments"), func(index int, ship_id string) {
_, data := _lark_get(m, appid, "/open-apis/contact/v1/department/detail/batch_get", "department_ids", ship_id) _, data := _lark_get(m, appid, "/open-apis/contact/v1/department/detail/batch_get", "department_ids", ship_id)
kit.Fetch(kit.Value(data, "data.department_infos"), func(index int, value ice.Map) { kit.Fetch(kit.Value(data, "data.department_infos"), func(index int, value ice.Map) {
@ -22,9 +21,7 @@ func _company_list(m *ice.Message, appid string) {
m.Sort(mdb.NAME) m.Sort(mdb.NAME)
} }
func _company_members(m *ice.Message, appid string, ship_id string) { func _company_members(m *ice.Message, appid string, ship_id string) {
_, data := _lark_get(m, appid, "/open-apis/contact/v1/department/user/list", _, data := _lark_get(m, appid, "/open-apis/contact/v1/department/user/list", "department_id", ship_id, "page_size", "100", "fetch_child", ice.TRUE)
"department_id", ship_id, "page_size", "100", "fetch_child", ice.TRUE)
kit.Fetch(kit.Value(data, "data.user_list"), func(index int, value ice.Map) { kit.Fetch(kit.Value(data, "data.user_list"), func(index int, value ice.Map) {
msg := m.Cmd(EMPLOYEE, appid, value[OPEN_ID]) msg := m.Cmd(EMPLOYEE, appid, value[OPEN_ID])
m.PushImages(aaa.AVATAR, msg.Append("avatar_72")) m.PushImages(aaa.AVATAR, msg.Append("avatar_72"))
@ -41,22 +38,13 @@ const COMPANY = "company"
func init() { func init() {
Index.MergeCommands(ice.Commands{ Index.MergeCommands(ice.Commands{
COMPANY: {Name: "company appid ship_id open_id text auto", Help: "组织", Hand: func(m *ice.Message, arg ...string) { COMPANY: {Name: "company appid ship_id open_id text auto", Help: "组织", Hand: func(m *ice.Message, arg ...string) {
switch len(arg) { kit.Switch(len(arg),
case 0: // 应用列表 0, func() { m.Cmdy(APP) },
m.Cmdy(APP) 1, func() { _company_list(m, arg[0]) },
2, func() { _company_members(m, arg[0], arg[1]) },
case 1: // 组织列表 3, func() { m.Cmdy(EMPLOYEE, arg[0], arg[2]) },
_company_list(m, arg[0]) func() { m.Cmdy(SEND, arg[0], OPEN_ID, arg[2], arg[3:]) },
)
case 2: // 员工列表
_company_members(m, arg[0], arg[1])
case 3: // 员工详情
m.Cmdy(EMPLOYEE, arg[0], arg[2])
default: // 员工通知
m.Cmdy(SEND, arg[0], OPEN_ID, arg[2], arg[3:])
}
}}, }},
}) })
} }

View File

@ -4,25 +4,21 @@ import (
"strings" "strings"
ice "shylinux.com/x/icebergs" ice "shylinux.com/x/icebergs"
"shylinux.com/x/icebergs/base/mdb"
kit "shylinux.com/x/toolkits" kit "shylinux.com/x/toolkits"
) )
func _employee_info(m *ice.Message, appid string, arg ...string) { func _employee_info(m *ice.Message, appid string, arg ...string) {
for _, id := range arg { kit.For(arg, func(id string) {
_, data := _lark_get(m, appid, "/open-apis/contact/v1/user/batch_get", "open_ids", id) _, data := _lark_get(m, appid, "/open-apis/contact/v1/user/batch_get", "open_ids", id)
kit.Fetch(kit.Value(data, "data.user_infos"), func(index int, value ice.Map) { kit.For(kit.Value(data, "data.user_infos"), func(value ice.Map) { m.PushDetail(value) })
m.Push(mdb.DETAIL, value)
}) })
} }
}
func _employee_openid(m *ice.Message, appid string, arg ...string) { func _employee_openid(m *ice.Message, appid string, arg ...string) {
us := []string{} args := []string{}
for i := 0; i < len(arg); i++ { for i := 0; i < len(arg); i++ {
us = append(us, kit.Select("mobiles", "emails", strings.Contains(arg[i], "@")), arg[i]) args = append(args, kit.Select("mobiles", "emails", strings.Contains(arg[i], "@")), arg[i])
} }
_lark_get(m, appid, "/open-apis/user/v1/batch_get_id", args)
_lark_get(m, appid, "/open-apis/user/v1/batch_get_id", us)
for i := 0; i < len(arg); i++ { for i := 0; i < len(arg); i++ {
m.Echo(m.Append(kit.Keys("data.mobile_users", arg[i], "0.open_id"))) m.Echo(m.Append(kit.Keys("data.mobile_users", arg[i], "0.open_id")))
} }
@ -35,8 +31,7 @@ func init() {
EMPLOYEE: {Name: "employee appid open_id|mobile|email auto", Help: "员工", Hand: func(m *ice.Message, arg ...string) { EMPLOYEE: {Name: "employee appid open_id|mobile|email auto", Help: "员工", Hand: func(m *ice.Message, arg ...string) {
if len(arg) < 2 { if len(arg) < 2 {
return return
} } else if strings.HasPrefix(arg[1], "ou_") {
if strings.HasPrefix(arg[1], "ou_") {
_employee_info(m, arg[0], arg[1:]...) _employee_info(m, arg[0], arg[1:]...)
} else { } else {
_employee_openid(m, arg[0], arg[1:]...) _employee_openid(m, arg[0], arg[1:]...)

View File

@ -19,22 +19,18 @@ const EVENT = "event"
func init() { func init() {
Index.MergeCommands(ice.Commands{ Index.MergeCommands(ice.Commands{
EVENT: {Name: "event", Help: "事件", Actions: ice.Actions{ EVENT: {Name: "event", Help: "事件", Actions: ice.Actions{
P2P_CHAT_CREATE: {Name: "", Help: "", Hand: func(m *ice.Message, arg ...string) { P2P_CHAT_CREATE: {Hand: func(m *ice.Message, arg ...string) {
if m.Option(OPEN_CHAT_ID) != "" { if m.Option(OPEN_CHAT_ID) != "" {
m.Cmdy(SEND, m.Option(APP_ID), m.Option(OPEN_CHAT_ID), m.Conf(APP, kit.Keym(nfs.TEMPLATE, m.Option(mdb.TYPE)))) m.Cmdy(SEND, m.Option(APP_ID), m.Option(OPEN_CHAT_ID), m.Conf(APP, kit.Keym(nfs.TEMPLATE, m.Option(mdb.TYPE))))
} }
}}, }},
MESSAGE_READ: {Name: "", Help: "", Hand: func(m *ice.Message, arg ...string) { MESSAGE_READ: {Hand: func(m *ice.Message, arg ...string) {}},
}}, CHAT_DISBAND: {Hand: func(m *ice.Message, arg ...string) {}},
CHAT_DISBAND: {Name: "", Help: "", Hand: func(m *ice.Message, arg ...string) { ADD_BOT: {Hand: func(m *ice.Message, arg ...string) {
}},
ADD_BOT: {Name: "", Help: "", Hand: func(m *ice.Message, arg ...string) {
if m.Option(OPEN_CHAT_ID) != "" { if m.Option(OPEN_CHAT_ID) != "" {
m.Cmdy(SEND, m.Option(APP_ID), m.Option(OPEN_CHAT_ID), m.Conf(APP, kit.Keym(nfs.TEMPLATE, m.Option(mdb.TYPE)))) m.Cmdy(SEND, m.Option(APP_ID), m.Option(OPEN_CHAT_ID), m.Conf(APP, kit.Keym(nfs.TEMPLATE, m.Option(mdb.TYPE))))
} }
}}, }},
}, Hand: func(m *ice.Message, arg ...string) { }, Hand: func(m *ice.Message, arg ...string) { m.Cmdy(MSG, m.Option(MSG_TYPE)) }},
m.Cmdy(MSG, m.Option(MSG_TYPE))
}},
}) })
} }

View File

@ -9,7 +9,7 @@ import (
func _group_list(m *ice.Message, appid string) { func _group_list(m *ice.Message, appid string) {
_, data := _lark_get(m, appid, "/open-apis/chat/v4/list") _, data := _lark_get(m, appid, "/open-apis/chat/v4/list")
kit.Fetch(kit.Value(data, "data.groups"), func(index int, value ice.Map) { kit.For(kit.Value(data, "data.groups"), func(index int, value ice.Map) {
m.Push(CHAT_ID, value[CHAT_ID]) m.Push(CHAT_ID, value[CHAT_ID])
m.PushImages(aaa.AVATAR, kit.Format(value[aaa.AVATAR])) m.PushImages(aaa.AVATAR, kit.Format(value[aaa.AVATAR]))
m.Push(mdb.NAME, value[mdb.NAME]) m.Push(mdb.NAME, value[mdb.NAME])
@ -20,7 +20,7 @@ func _group_list(m *ice.Message, appid string) {
} }
func _group_members(m *ice.Message, appid string, chat_id string) { func _group_members(m *ice.Message, appid string, chat_id string) {
_, data := _lark_get(m, appid, "/open-apis/chat/v4/info", "chat_id", chat_id) _, data := _lark_get(m, appid, "/open-apis/chat/v4/info", "chat_id", chat_id)
kit.Fetch(kit.Value(data, "data.members"), func(index int, value ice.Map) { kit.For(kit.Value(data, "data.members"), func(index int, value ice.Map) {
msg := m.Cmd(EMPLOYEE, appid, value[OPEN_ID]) msg := m.Cmd(EMPLOYEE, appid, value[OPEN_ID])
m.PushImages(aaa.AVATAR, msg.Append("avatar_72")) m.PushImages(aaa.AVATAR, msg.Append("avatar_72"))
m.Push(aaa.GENDER, kit.Select("女", "男", msg.Append(aaa.GENDER) == "1")) m.Push(aaa.GENDER, kit.Select("女", "男", msg.Append(aaa.GENDER) == "1"))
@ -36,22 +36,13 @@ const GROUP = "group"
func init() { func init() {
Index.MergeCommands(ice.Commands{ Index.MergeCommands(ice.Commands{
GROUP: {Name: "group appid chat_id open_id text auto", Help: "群组", Hand: func(m *ice.Message, arg ...string) { GROUP: {Name: "group appid chat_id open_id text auto", Help: "群组", Hand: func(m *ice.Message, arg ...string) {
switch len(arg) { kit.Switch(len(arg),
case 0: // 应用列表 0, func() { m.Cmdy(APP) },
m.Cmdy(APP) 1, func() { _group_list(m, arg[0]) },
2, func() { _group_members(m, arg[0], arg[1]) },
case 1: // 群组列表 3, func() { m.Cmdy(EMPLOYEE, arg[0], arg[2]) },
_group_list(m, arg[0]) func() { m.Cmdy(SEND, arg[0], OPEN_ID, arg[2], arg[3:]) },
)
case 2: // 组员列表
_group_members(m, arg[0], arg[1])
case 3: // 组员详情
m.Cmdy(EMPLOYEE, arg[0], arg[2])
default: // 组员通知
m.Cmdy(SEND, arg[0], OPEN_ID, arg[2], arg[3:])
}
}}, }},
}) })
} }

View File

@ -14,22 +14,18 @@ func init() {
Index.MergeCommands(ice.Commands{ Index.MergeCommands(ice.Commands{
HOME: {Name: "home river storm title content", Help: "首页", Hand: func(m *ice.Message, arg ...string) { HOME: {Name: "home river storm title content", Help: "首页", Hand: func(m *ice.Message, arg ...string) {
name := kit.Select(m.Option(ice.MSG_USERNAME), m.Option(ice.MSG_USERNICK)) name := kit.Select(m.Option(ice.MSG_USERNAME), m.Option(ice.MSG_USERNICK))
if len(name) > 10 { kit.If(len(name) > 10, func() { name = name[:10] })
name = name[:10]
}
name += "的" + kit.Select("应用列表", arg, 2) name += "的" + kit.Select("应用列表", arg, 2)
text, link, list := kit.Select("", arg, 3), kit.MergeURL2(m.Conf(web.SHARE, kit.Keym(web.DOMAIN)), "/chat/lark/sso"), []string{}
text, link, list := kit.Select("", arg, 3), kit.MergeURL2(m.Conf(web.SHARE, kit.Keym("domain")), "/chat/lark/sso"), []string{}
if len(arg) == 0 { if len(arg) == 0 {
m.Cmd("web.chat./river", func(val ice.Maps) { m.Cmd("web.chat./river", func(val ice.Maps) {
m.Cmd("web.chat./river", val[mdb.HASH], chat.STORM, func(value ice.Maps) { m.Cmd("web.chat./river", val[mdb.HASH], chat.STORM, func(value ice.Maps) {
list = append(list, kit.Keys(val[mdb.NAME], value[mdb.NAME]), list = append(list, kit.Keys(val[mdb.NAME], value[mdb.NAME]),
ice.CMD, kit.Format([]string{HOME, val[mdb.HASH], value[mdb.HASH], val[mdb.NAME] + "." + value[mdb.NAME]})) ice.CMD, kit.Format([]string{HOME, val[mdb.HASH], value[mdb.HASH], val[mdb.NAME] + ice.PT + value[mdb.NAME]}))
}) })
}) })
} else { } else {
m.Option(ice.MSG_RIVER, arg[0]) m.Options(ice.MSG_RIVER, arg[0], ice.MSG_STORM, arg[1])
m.Option(ice.MSG_STORM, arg[1])
link = kit.MergeURL(link, chat.RIVER, arg[0], chat.STORM, arg[1]) link = kit.MergeURL(link, chat.RIVER, arg[0], chat.STORM, arg[1])
m.Cmd("web.chat./river", arg[0], chat.STORM, arg[1], func(value ice.Maps) { m.Cmd("web.chat./river", arg[0], chat.STORM, arg[1], func(value ice.Maps) {
list = append(list, value[ice.CMD], ice.CMD, kit.Keys(value[ice.CTX], value[ice.CMD])) list = append(list, value[ice.CMD], ice.CMD, kit.Keys(value[ice.CTX], value[ice.CMD]))

View File

@ -82,16 +82,12 @@ func init() {
} }
}}, }},
MSG: {Name: "msg", Help: "聊天消息", Actions: ice.Actions{ MSG: {Name: "msg", Help: "聊天消息", Actions: ice.Actions{
"location": {Name: "", Help: "", Hand: func(m *ice.Message, arg ...string) { "location": {Hand: func(m *ice.Message, arg ...string) {}},
}}, "image": {Hand: func(m *ice.Message, arg ...string) {}},
"image": {Name: "", Help: "", Hand: func(m *ice.Message, arg ...string) { "card": {Hand: func(m *ice.Message, arg ...string) {
}}, kit.For(kit.Value(m.Optionv(ice.MSG_USERDATA), "action.value"), func(k string, v string) { m.Option(k, v) })
"card": {Name: "", Help: "", Hand: func(m *ice.Message, arg ...string) {
data := m.Optionv(ice.MSG_USERDATA)
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(ice.CMD))...)) m.Cmdy(TALK, kit.Parse(nil, "", kit.Split(m.Option(ice.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)+ice.SP+m.Option(ice.CMD), m.Result())
m.Option(wiki.TITLE)+" "+m.Option(ice.CMD), m.Result())
}}, }},
}, Hand: func(m *ice.Message, arg ...string) { }, Hand: func(m *ice.Message, arg ...string) {
if m.Option(OPEN_CHAT_ID) == "" { if m.Option(OPEN_CHAT_ID) == "" {

View File

@ -14,12 +14,11 @@ func init() {
Index.MergeCommands(ice.Commands{ Index.MergeCommands(ice.Commands{
RAND: {Name: "rand", Help: "随机", Hand: func(m *ice.Message, arg ...string) { RAND: {Name: "rand", Help: "随机", Hand: func(m *ice.Message, arg ...string) {
msg := m.Cmd(GROUP, m.Option(APP_ID), EMPLOYEE, m.Option(OPEN_CHAT_ID)) msg := m.Cmd(GROUP, m.Option(APP_ID), EMPLOYEE, m.Option(OPEN_CHAT_ID))
list := msg.Appendv(mdb.NAME) if list := msg.Appendv(mdb.NAME); strings.Contains(m.Option(CONTENT), "誰") {
if strings.Contains(m.Option(CONTENT), "誰") {
m.Echo(strings.Replace(m.Option(CONTENT), "誰", list[rand.Intn(len(list))], 1)) m.Echo(strings.Replace(m.Option(CONTENT), "誰", list[rand.Intn(len(list))], 1))
return } else {
}
m.Echo(list[rand.Intn(len(list))]) m.Echo(list[rand.Intn(len(list))])
}
}}, }},
}) })
} }

View File

@ -33,7 +33,6 @@ func _send_text(m *ice.Message, form ice.Map, arg ...string) bool {
line = append(line, ice.Map{"tag": "text", "text": v + " "}) line = append(line, ice.Map{"tag": "text", "text": v + " "})
} }
content = append(content, line) content = append(content, line)
kit.Value(form, "msg_type", "post") kit.Value(form, "msg_type", "post")
kit.Value(form, "content.post", ice.Map{ kit.Value(form, "content.post", ice.Map{
"zh_cn": ice.Map{"title": arg[0], CONTENT: content}, "zh_cn": ice.Map{"title": arg[0], CONTENT: content},
@ -58,11 +57,9 @@ func init() {
default: default:
form[CHAT_ID], arg = arg[0], arg[1:] form[CHAT_ID], arg = arg[0], arg[1:]
} }
if _send_text(m, form, arg...) { if _send_text(m, form, arg...) {
msg := _lark_post(m, appid, "/open-apis/message/v4/send/", web.SPIDE_DATA, kit.Format(form)) msg := _lark_post(m, appid, "/open-apis/message/v4/send/", web.SPIDE_DATA, kit.Format(form))
m.Push(mdb.TIME, m.Time()) m.Push(mdb.TIME, m.Time()).Push("message_id", msg.Append("data.message_id"))
m.Push("message_id", msg.Append("data.message_id"))
} }
}}, }},
}) })

View File

@ -13,40 +13,25 @@ const SSO = "sso"
func init() { func init() {
Index.MergeCommands(ice.Commands{ Index.MergeCommands(ice.Commands{
"/sso": {Name: "/sso", Help: "网页", Hand: func(m *ice.Message, arg ...string) { web.P(SSO): {Hand: func(m *ice.Message, arg ...string) {
if m.Option(ice.MSG_USERNAME) != "" { // 默认主页 if m.Option(ice.MSG_USERNAME) != "" {
web.RenderIndex(m, ice.VOLCANOS) web.RenderIndex(m, ice.VOLCANOS)
return return
} }
appid := m.Cmd(APP).Append(APPID) appid := m.Cmd(APP).Append(APPID)
home := web.MergeURL2(m, "/chat/lark/sso") home := web.MergeURL2(m, "/chat/lark/sso")
if m.Option(cli.CODE) == "" { // 登录页面 if m.Option(cli.CODE) == "" {
if back := m.R.Header.Get("Referer"); back != "" {
home = kit.MergeURL(home, cli.BACK, back)
}
m.RenderRedirect(kit.MergeURL2(m.Cmd(web.SPIDE, LARK).Append("client.url"), "/open-apis/authen/v1/index"), m.RenderRedirect(kit.MergeURL2(m.Cmd(web.SPIDE, LARK).Append("client.url"), "/open-apis/authen/v1/index"),
"redirect_uri", home, APP_ID, m.Cmd(APP).Append(APPID)) "redirect_uri", kit.MergeURL(home, cli.BACK, m.R.Header.Get("Referer")), APP_ID, appid)
return return
} }
msg := m.Cmd(web.SPIDE, LARK, "/open-apis/authen/v1/access_token", "grant_type", "authorization_code", msg := m.Cmd(web.SPIDE, LARK, "/open-apis/authen/v1/access_token", "grant_type", "authorization_code",
cli.CODE, m.Option(cli.CODE), "app_access_token", m.Cmdx(APP, TOKEN, appid)) cli.CODE, m.Option(cli.CODE), "app_access_token", m.Cmdx(APP, TOKEN, appid))
msg = m.Cmd(EMPLOYEE, appid, m.Option(aaa.USERNAME, msg.Append("data.open_id")))
// 更新用户 m.Cmd(aaa.USER, mdb.CREATE, m.Option(aaa.USERNAME), "", msg.Append(mdb.NAME), LARK, kit.Select(aaa.VOID, aaa.TECH, msg.Append("is_tenant_manager") == ice.TRUE))
m.Option(aaa.USERNAME, msg.Append("data.open_id")) m.Cmd(aaa.USER, mdb.MODIFY, aaa.AVATAR, msg.Append("avatar_url"), aaa.GENDER, kit.Select("女", "男", msg.Append(aaa.GENDER) == "1"),
msg = m.Cmd(EMPLOYEE, appid, m.Option(aaa.USERNAME)) msg.AppendSimple(aaa.MOBILE, aaa.EMAIL, aaa.CITY, aaa.COUNTRY))
userrole := kit.Select(aaa.VOID, aaa.TECH, msg.Append("is_tenant_manager") == ice.TRUE) m.RenderRedirect(kit.MergeURL(kit.Select(home, m.Option(cli.BACK)), ice.MSG_SESSID, aaa.SessCreate(m, m.Option(aaa.USERNAME))))
m.Cmd(aaa.USER, mdb.CREATE, m.Option(aaa.USERNAME), "", userrole)
m.Cmd(aaa.USER, mdb.MODIFY, aaa.USERROLE, userrole,
aaa.USERNICK, msg.Append(mdb.NAME), aaa.USERZONE, LARK,
aaa.AVATAR, msg.Append("avatar_url"), aaa.GENDER, kit.Select("女", "男", msg.Append(aaa.GENDER) == "1"),
msg.AppendSimple(aaa.MOBILE, aaa.EMAIL, aaa.CITY, aaa.COUNTRY),
)
// 创建会话
// web.RenderCookie(m, aaa.SessCreate(m, m.Option(aaa.USERNAME)), web.CookieName(m.Option(cli.BACK)))
m.RenderRedirect(kit.MergeURL(kit.Select(home, m.Option(cli.BACK)), "sessid", aaa.SessCreate(m, m.Option(aaa.USERNAME))))
}}, }},
}) })
} }

View File

@ -20,37 +20,28 @@ func init() {
if aaa.UserLogin(m, m.Option(OPEN_CHAT_ID), ""); !aaa.Right(m, cmds) { if aaa.UserLogin(m, m.Option(OPEN_CHAT_ID), ""); !aaa.Right(m, cmds) {
m.Cmd(DUTY, 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
} }
} }
// 执行命令
if m.Cmdy(cmds); m.Result() != "" && m.Result(1) != ice.ErrNotFound { if m.Cmdy(cmds); m.Result() != "" && m.Result(1) != ice.ErrNotFound {
m.Cmd(SEND, m.Option(APP_ID), m.Option(OPEN_CHAT_ID), m.Result()) m.Cmd(SEND, m.Option(APP_ID), m.Option(OPEN_CHAT_ID), m.Result())
return return
} } else if m.Length() == 0 {
if m.Length() == 0 {
m.Set(ice.MSG_RESULT) m.Set(ice.MSG_RESULT)
m.Cmdy(cli.SYSTEM, cmds) m.Cmdy(cli.SYSTEM, cmds)
m.Cmd(SEND, m.Option(APP_ID), m.Option(OPEN_CHAT_ID), m.Result()) m.Cmd(SEND, m.Option(APP_ID), m.Option(OPEN_CHAT_ID), m.Result())
return return
} }
val := []string{} val := []string{}
m.Table(func(index int, value ice.Maps, head []string) { m.Table(func(index int, value ice.Maps, head []string) {
for _, key := range head { kit.For(head, func(k string) { val = append(val, kit.Format("%s:\t%s", k, value[k])) })
val = append(val, kit.Format("%s:\t%s", key, value[key])) val = append(val, ice.NL)
}
val = append(val, "\n")
}) })
_lark_post(m, m.Option(APP_ID), "/open-apis/message/v4/send/", web.SPIDE_DATA, kit.Formats( _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( 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, " "))), "header", kit.Dict("title", kit.Dict("tag", "lark_md", "content", strings.Join(cmds, " "))),
"elements", []ice.Any{kit.Dict("tag", "div", "fields", []ice.Any{ "elements", []ice.Any{kit.Dict("tag", "div", "fields", []ice.Any{
kit.Dict("is_short", true, "text", kit.Dict( kit.Dict("is_short", true, "text", kit.Dict("tag", "lark_md", "content", strings.Join(val, ice.NL))),
"tag", "lark_md", "content", strings.Join(val, "\n"),
)),
})}, })},
)), )),
)) ))

View File

@ -12,7 +12,6 @@ import (
"shylinux.com/x/icebergs/base/mdb" "shylinux.com/x/icebergs/base/mdb"
"shylinux.com/x/icebergs/base/tcp" "shylinux.com/x/icebergs/base/tcp"
"shylinux.com/x/icebergs/base/web" "shylinux.com/x/icebergs/base/web"
"shylinux.com/x/icebergs/core/chat"
kit "shylinux.com/x/toolkits" kit "shylinux.com/x/toolkits"
) )
@ -32,65 +31,43 @@ const (
const LOGIN = "login" const LOGIN = "login"
func init() { func init() {
Index.Merge(&ice.Context{Configs: ice.Configs{ Index.MergeCommands(ice.Commands{
LOGIN: {Name: LOGIN, Help: "认证", Value: kit.Data(tcp.SERVER, "https://api.weixin.qq.com")}, web.PP(LOGIN): {Actions: ice.MergeActions(ice.Actions{
}, Commands: ice.Commands{ ice.CTX_INIT: {Hand: func(m *ice.Message, arg ...string) { m.Cmd(web.SPIDE, mdb.CREATE, MP, m.Config(tcp.SERVER)) }},
"/login/": {Name: "/login/", Help: "认证", Actions: ice.Actions{
ice.CTX_INIT: {Hand: func(m *ice.Message, arg ...string) {
m.Cmd(web.SPIDE, mdb.CREATE, MP, m.Config(tcp.SERVER))
}},
aaa.SESS: {Name: "sess code", Help: "会话", Hand: func(m *ice.Message, arg ...string) { aaa.SESS: {Name: "sess code", Help: "会话", Hand: func(m *ice.Message, arg ...string) {
msg := m.Cmd(web.SPIDE, MP, http.MethodGet, "/sns/jscode2session?grant_type=authorization_code", msg := m.Cmd(web.SPIDE, MP, http.MethodGet, "/sns/jscode2session?grant_type=authorization_code", "js_code", m.Option(cli.CODE), APPID, m.Config(APPID), "secret", m.Config(APPMM))
"js_code", m.Option(cli.CODE), APPID, m.Config(APPID), "secret", m.Config(APPMM))
// 用户登录
m.Option(ice.MSG_USERZONE, MP) m.Option(ice.MSG_USERZONE, MP)
m.Echo(aaa.SessCreate(msg, msg.Append(OPENID))) m.Echo(aaa.SessCreate(msg, msg.Append(OPENID)))
}}, }},
aaa.USER: {Name: "user", Help: "用户", Hand: func(m *ice.Message, arg ...string) { aaa.USER: {Help: "用户", Hand: func(m *ice.Message, arg ...string) {
m.Option(aaa.USERNAME, m.Option(ice.MSG_USERNAME)) if m.Cmd(aaa.USER, m.Option(aaa.USERNAME, m.Option(ice.MSG_USERNAME))).Length() == 0 {
if m.Cmd(aaa.USER, m.Option(aaa.USERNAME)).Length() == 0 {
m.Cmd(aaa.USER, mdb.CREATE, m.OptionSimple(aaa.USERNAME)) m.Cmd(aaa.USER, mdb.CREATE, m.OptionSimple(aaa.USERNAME))
} }
m.Cmd(aaa.USER, mdb.MODIFY, m.Cmd(aaa.USER, mdb.MODIFY, aaa.USERNICK, m.Option("nickName"), aaa.USERZONE, MP,
aaa.USERNICK, m.Option("nickName"), aaa.USERZONE, MP,
aaa.AVATAR, m.Option("avatarUrl"), aaa.GENDER, kit.Select("女", "男", m.Option(aaa.GENDER) == "1"), aaa.AVATAR, m.Option("avatarUrl"), aaa.GENDER, kit.Select("女", "男", m.Option(aaa.GENDER) == "1"),
m.OptionSimple(aaa.CITY, aaa.COUNTRY, aaa.LANGUAGE, aaa.PROVINCE), m.OptionSimple(aaa.CITY, aaa.COUNTRY, aaa.LANGUAGE, aaa.PROVINCE),
) )
}}, }},
"scan": {Name: "scan", Help: "扫码", Hand: func(m *ice.Message, arg ...string) { }, ctx.ConfAction(tcp.SERVER, "https://api.weixin.qq.com"), aaa.WhiteAction(aaa.SESS, aaa.USER))},
if m.Option(chat.GRANT) != "" {
m.Cmdy(chat.HEADER, chat.GRANT, web.SPACE, m.Option(chat.GRANT))
return
}
m.Cmdy("scan", arg)
}},
}},
LOGIN: {Name: "login appid auto qrcode tokens create", Help: "认证", Actions: ice.Actions{ LOGIN: {Name: "login appid auto qrcode tokens create", Help: "认证", Actions: ice.Actions{
mdb.CREATE: {Name: "create appid appmm", Help: "登录", Hand: func(m *ice.Message, arg ...string) { mdb.CREATE: {Name: "create appid appmm", Help: "登录", Hand: func(m *ice.Message, arg ...string) {
ctx.ConfigFromOption(m, APPID, APPMM) ctx.ConfigFromOption(m, APPID, APPMM)
}}, }},
TOKENS: {Name: "tokens", Help: "令牌", Hand: func(m *ice.Message, arg ...string) { TOKENS: {Help: "令牌", Hand: func(m *ice.Message, arg ...string) {
if now := time.Now().Unix(); m.Config(TOKENS) == "" || now > kit.Int64(m.Config(EXPIRES)) { if now := time.Now().Unix(); m.Config(TOKENS) == "" || now > kit.Int64(m.Config(EXPIRES)) {
msg := m.Cmd(web.SPIDE, MP, http.MethodGet, "/cgi-bin/token?grant_type=client_credential", msg := m.Cmd(web.SPIDE, MP, http.MethodGet, "/cgi-bin/token?grant_type=client_credential", APPID, m.Config(APPID), "secret", m.Config(APPMM))
APPID, m.Config(APPID), "secret", m.Config(APPMM))
if m.Warn(msg.Append(ERRCODE) != "", msg.Append(ERRCODE), msg.Append(ERRMSG)) { if m.Warn(msg.Append(ERRCODE) != "", msg.Append(ERRCODE), msg.Append(ERRMSG)) {
return return
} }
m.Config(EXPIRES, now+kit.Int64(msg.Append("expires_in"))) m.Config(EXPIRES, now+kit.Int64(msg.Append("expires_in")))
m.Config(TOKENS, msg.Append("access_token")) m.Config(TOKENS, msg.Append("access_token"))
} }
m.Echo(m.Config(TOKENS)) m.Echo(m.Config(TOKENS)).Status(EXPIRES, time.Unix(kit.Int64(m.Config(EXPIRES)), 0).Format(ice.MOD_TIME))
}}, }},
QRCODE: {Name: "qrcode path scene", Help: "扫码", Hand: func(m *ice.Message, arg ...string) { QRCODE: {Name: "qrcode path scene", Help: "扫码", Hand: func(m *ice.Message, arg ...string) {
msg := m.Cmd(web.SPIDE, MP, http.MethodPost, "/wxa/getwxacodeunlimit?access_token="+m.Cmdx(LOGIN, TOKENS), msg := m.Cmd(web.SPIDE, MP, http.MethodPost, "/wxa/getwxacodeunlimit?access_token="+m.Cmdx(LOGIN, TOKENS), m.OptionSimple("path,scene"))
m.OptionSimple("path,scene")) m.Echo(kit.Format(`<img src="data:image/png;base64,%s" title='%s'>`, base64.StdEncoding.EncodeToString([]byte(msg.Result())), "some")).ProcessInner()
m.Echo(kit.Format(`<img src="data:image/png;base64,%s" title='%s'>`, base64.StdEncoding.EncodeToString([]byte(msg.Result())), "some"))
m.ProcessInner()
}}, }},
}, Hand: func(m *ice.Message, arg ...string) { }, Hand: func(m *ice.Message, arg ...string) { m.Echo(m.Config(APPID)) }},
m.Echo(m.Config(APPID)) })
}},
}})
} }

View File

@ -8,10 +8,6 @@ qrcode `https://mp.weixin.qq.com/a/~HkylKD4DZShrgSm5GuXWLQ~~`
chapter "应用" chapter "应用"
field "认证" web.chat.mp.login field "认证" web.chat.mp.login
field "扫码" web.chat.scan
field "复制" web.chat.paste
field "文件" web.chat.files
field "位置" web.chat.location field "位置" web.chat.location
chapter "权限" chapter "权限"
@ -23,4 +19,3 @@ chapter "项目"
field "源代码" web.code.inner args `usr/icebergs/ misc/mp/login.go` field "源代码" web.code.inner args `usr/icebergs/ misc/mp/login.go`
field "趋势图" web.code.git.trend args `icebergs` field "趋势图" web.code.git.trend args `icebergs`
field "架构图" web.code.git.spide args `icebergs` field "架构图" web.code.git.spide args `icebergs`

View File

@ -18,29 +18,22 @@ import (
) )
func _wx_sign(m *ice.Message, nonce, stamp string) string { func _wx_sign(m *ice.Message, nonce, stamp string) string {
text := kit.Join(kit.Sort(kit.Simple( return kit.Format(sha1.Sum([]byte(kit.Join(kit.Sort(kit.Simple(
kit.Format("jsapi_ticket=%s", m.Cmdx(ACCESS, TICKET)), kit.Format("jsapi_ticket=%s", m.Cmdx(ACCESS, TICKET)),
kit.Format("url=%s", m.Option(ice.MSG_USERWEB)), kit.Format("url=%s", m.Option(ice.MSG_USERWEB)),
kit.Format("timestamp=%s", stamp), kit.Format("timestamp=%s", stamp),
kit.Format("noncestr=%s", nonce), kit.Format("noncestr=%s", nonce),
)), "&") )), "&"))))
return kit.Format(sha1.Sum([]byte(text)))
} }
func _wx_config(m *ice.Message, nonce string) { func _wx_config(m *ice.Message, nonce string) {
m.Option(APPID, m.Config(APPID))
m.Option(nfs.SCRIPT, m.Config(nfs.SCRIPT))
m.Option("signature", _wx_sign(m, m.Option("noncestr", nonce), m.Option("timestamp", kit.Format(time.Now().Unix())))) m.Option("signature", _wx_sign(m, m.Option("noncestr", nonce), m.Option("timestamp", kit.Format(time.Now().Unix()))))
m.OptionFromConfig(APPID, nfs.SCRIPT)
} }
func _wx_check(m *ice.Message) { func _wx_check(m *ice.Message) {
check := kit.Sort([]string{m.Config(TOKEN), m.Option("timestamp"), m.Option("nonce")}) check := kit.Sort([]string{m.Config(TOKEN), m.Option("timestamp"), m.Option("nonce")})
if sig := kit.Format(sha1.Sum([]byte(strings.Join(check, "")))); m.Warn(sig != m.Option("signature"), ice.ErrNotRight, check) { if sig := kit.Format(sha1.Sum([]byte(strings.Join(check, "")))); !m.Warn(sig != m.Option("signature"), ice.ErrNotRight, check) {
return // 验证失败 kit.If(m.Option("echostr") != "", func() { m.RenderResult(m.Option("echostr")) }, func() { m.Echo(ice.TRUE) })
} }
if m.Option("echostr") != "" {
m.RenderResult(m.Option("echostr"))
return // 绑定验证
}
m.Echo(ice.TRUE)
} }
const ( const (
@ -62,7 +55,7 @@ const ACCESS = "access"
func init() { func init() {
Index.MergeCommands(ice.Commands{ Index.MergeCommands(ice.Commands{
ACCESS: {Name: "access appid auto config ticket tokens login", Help: "认证", Actions: ice.MergeActions(ice.Actions{ ACCESS: {Name: "access appid auto ticket tokens login", Help: "认证", Actions: ice.MergeActions(ice.Actions{
ice.CTX_INIT: {Hand: func(m *ice.Message, arg ...string) { ice.CTX_INIT: {Hand: func(m *ice.Message, arg ...string) {
m.Cmd(web.SPIDE, mdb.CREATE, WX, m.Config(tcp.SERVER)) m.Cmd(web.SPIDE, mdb.CREATE, WX, m.Config(tcp.SERVER))
gdb.Watch(m, chat.HEADER_AGENT, m.PrefixKey()) gdb.Watch(m, chat.HEADER_AGENT, m.PrefixKey())
@ -75,7 +68,7 @@ func init() {
LOGIN: {Name: "login appid appmm token", Help: "登录", Hand: func(m *ice.Message, arg ...string) { LOGIN: {Name: "login appid appmm token", Help: "登录", Hand: func(m *ice.Message, arg ...string) {
ctx.ConfigFromOption(m, APPID, APPMM, TOKEN) ctx.ConfigFromOption(m, APPID, APPMM, TOKEN)
}}, }},
TOKENS: {Name: "tokens", Help: "令牌", Hand: func(m *ice.Message, arg ...string) { TOKENS: {Help: "令牌", Hand: func(m *ice.Message, arg ...string) {
if now := time.Now().Unix(); m.Config(TOKENS) == "" || now > kit.Int64(m.Config(EXPIRES)) { if now := time.Now().Unix(); m.Config(TOKENS) == "" || now > kit.Int64(m.Config(EXPIRES)) {
msg := m.Cmd(web.SPIDE, WX, http.MethodGet, "/cgi-bin/token?grant_type=client_credential", APPID, m.Config(APPID), "secret", m.Config(APPMM)) msg := m.Cmd(web.SPIDE, WX, http.MethodGet, "/cgi-bin/token?grant_type=client_credential", APPID, m.Config(APPID), "secret", m.Config(APPMM))
if m.Warn(msg.Append(ERRCODE) != "", msg.Append(ERRCODE), msg.Append(ERRMSG)) { if m.Warn(msg.Append(ERRCODE) != "", msg.Append(ERRCODE), msg.Append(ERRMSG)) {
@ -84,9 +77,9 @@ func init() {
m.Config(EXPIRES, now+kit.Int64(msg.Append("expires_in"))) m.Config(EXPIRES, now+kit.Int64(msg.Append("expires_in")))
m.Config(TOKENS, msg.Append("access_token")) m.Config(TOKENS, msg.Append("access_token"))
} }
m.Echo(m.Config(TOKENS)) m.Echo(m.Config(TOKENS)).Status(EXPIRES, time.Unix(kit.Int64(m.Config(EXPIRES)), 0).Format(ice.MOD_TIME))
}}, }},
TICKET: {Name: "ticket", Help: "票据", Hand: func(m *ice.Message, arg ...string) { TICKET: {Help: "票据", Hand: func(m *ice.Message, arg ...string) {
if now := time.Now().Unix(); m.Config(TICKET) == "" || now > kit.Int64(m.Config(EXPIRE)) { if now := time.Now().Unix(); m.Config(TICKET) == "" || now > kit.Int64(m.Config(EXPIRE)) {
msg := m.Cmd(web.SPIDE, WX, http.MethodGet, "/cgi-bin/ticket/getticket?type=jsapi", "access_token", m.Cmdx("", TOKENS)) msg := m.Cmd(web.SPIDE, WX, http.MethodGet, "/cgi-bin/ticket/getticket?type=jsapi", "access_token", m.Cmdx("", TOKENS))
if m.Warn(msg.Append(ERRCODE) != "0", msg.Append(ERRCODE), msg.Append(ERRMSG)) { if m.Warn(msg.Append(ERRCODE) != "0", msg.Append(ERRCODE), msg.Append(ERRMSG)) {
@ -95,14 +88,10 @@ func init() {
m.Config(EXPIRE, now+kit.Int64(msg.Append("expires_in"))) m.Config(EXPIRE, now+kit.Int64(msg.Append("expires_in")))
m.Config(TICKET, msg.Append(TICKET)) m.Config(TICKET, msg.Append(TICKET))
} }
m.Echo(m.Config(TICKET)) m.Echo(m.Config(TICKET)).Status(EXPIRE, time.Unix(kit.Int64(m.Config(EXPIRE)), 0).Format(ice.MOD_TIME))
}},
CONFIG: {Name: "config", Help: "配置", Hand: func(m *ice.Message, arg ...string) {
_wx_config(m, m.Config(APPID))
}},
CHECK: {Name: "check", Help: "检验", Hand: func(m *ice.Message, arg ...string) {
_wx_check(m)
}}, }},
CONFIG: {Hand: func(m *ice.Message, arg ...string) { _wx_config(m, m.Config(APPID)) }},
CHECK: {Hand: func(m *ice.Message, arg ...string) { _wx_check(m) }},
}, mdb.HashAction(tcp.SERVER, "https://api.weixin.qq.com", nfs.SCRIPT, "/plugin/local/chat/wx.js")), Hand: func(m *ice.Message, arg ...string) { }, mdb.HashAction(tcp.SERVER, "https://api.weixin.qq.com", nfs.SCRIPT, "/plugin/local/chat/wx.js")), Hand: func(m *ice.Message, arg ...string) {
m.Echo(m.Config(APPID)) m.Echo(m.Config(APPID))
}}, }},

View File

@ -9,11 +9,8 @@ const EVENT = "event"
func init() { func init() {
Index.MergeCommands(ice.Commands{ Index.MergeCommands(ice.Commands{
EVENT: {Name: "event", Help: "事件", Actions: ice.Actions{ EVENT: {Name: "event", Help: "事件", Actions: ice.Actions{
"subscribe": {Name: "subscribe", Help: "订阅", Hand: func(m *ice.Message, arg ...string) { "subscribe": {Help: "订阅", Hand: func(m *ice.Message, arg ...string) { m.Cmdy(MENU, "home") }},
m.Cmdy(MENU, "home") "unsubscribe": {Help: "取关", Hand: func(m *ice.Message, arg ...string) {}},
}},
"unsubscribe": {Name: "unsubscribe", Help: "取关", Hand: func(m *ice.Message, arg ...string) {
}},
}}, }},
}) })
} }

View File

@ -10,18 +10,13 @@ import (
const FAVOR = "favor" const FAVOR = "favor"
func init() { func init() {
Index.Merge(&ice.Context{Configs: ice.Configs{ Index.MergeCommands(ice.Commands{
FAVOR: {Name: "favor", Help: "收藏", Value: kit.Data( FAVOR: {Name: "favor text:text auto create", Help: "收藏", Actions: mdb.HashAction(
mdb.SHORT, mdb.TEXT, mdb.FIELD, "time,type,name,text", mdb.SHORT, mdb.TEXT, mdb.FIELD, "time,type,name,text", mdb.LINK, "https://open.weixin.qq.com/qr/code",
mdb.LINK, "https://open.weixin.qq.com/qr/code", ), Hand: func(m *ice.Message, arg ...string) {
)},
}, Commands: ice.Commands{
FAVOR: {Name: "favor text:text auto create", Help: "收藏", Actions: ice.MergeActions(ice.Actions{
mdb.CREATE: {Name: "create type name text", Help: "添加"},
}, mdb.HashAction()), Hand: func(m *ice.Message, arg ...string) {
mdb.HashSelect(m, arg...).Tables(func(value ice.Maps) { mdb.HashSelect(m, arg...).Tables(func(value ice.Maps) {
m.PushQRCode(mdb.SCAN, kit.MergeURL(m.Config(mdb.LINK), aaa.USERNAME, value[mdb.TEXT])) m.PushQRCode(mdb.SCAN, kit.MergeURL(m.Config(mdb.LINK), aaa.USERNAME, value[mdb.TEXT]))
}) })
}}, }},
}}) })
} }

View File

@ -8,6 +8,7 @@ import (
ice "shylinux.com/x/icebergs" ice "shylinux.com/x/icebergs"
"shylinux.com/x/icebergs/base/aaa" "shylinux.com/x/icebergs/base/aaa"
"shylinux.com/x/icebergs/base/mdb" "shylinux.com/x/icebergs/base/mdb"
"shylinux.com/x/icebergs/base/web"
"shylinux.com/x/icebergs/core/chat" "shylinux.com/x/icebergs/core/chat"
"shylinux.com/x/icebergs/core/wiki" "shylinux.com/x/icebergs/core/wiki"
kit "shylinux.com/x/toolkits" kit "shylinux.com/x/toolkits"
@ -18,92 +19,73 @@ func _wx_parse(m *ice.Message) {
FromUserName string FromUserName string
ToUserName string ToUserName string
CreateTime int64 CreateTime int64
MsgType string
MsgId int64 MsgId int64
Event string Event string
MsgType string
Content string Content string
Title string
Description string
Url string
PicUrl string
Location_X float64 Location_X float64
Location_Y float64 Location_Y float64
Scale string Scale string
Label string Label string
Title string
Description string
Url string
PicUrl string
}{} }{}
defer m.R.Body.Close() defer m.R.Body.Close()
buf, _ := ioutil.ReadAll(m.R.Body) buf, _ := ioutil.ReadAll(m.R.Body)
m.Debug("buf: %+v", string(buf)) m.Debug("buf: %+v", string(buf))
xml.NewDecoder(bytes.NewBuffer(buf)).Decode(&data) xml.NewDecoder(bytes.NewBuffer(buf)).Decode(&data)
m.Debug("data: %+v", data) m.Debug("data: %+v", data)
m.Option("FromUserName", data.FromUserName) m.Option("FromUserName", data.FromUserName)
m.Option("ToUserName", data.ToUserName) m.Option("ToUserName", data.ToUserName)
m.Option("CreateTime", data.CreateTime) m.Option("CreateTime", data.CreateTime)
m.Option("MsgId", data.MsgId) m.Option("MsgId", data.MsgId)
m.Option("Event", data.Event) m.Option("Event", data.Event)
m.Option("MsgType", data.MsgType) m.Option("MsgType", data.MsgType)
m.Option("Content", data.Content) m.Option("Content", data.Content)
m.Option("Title", data.Title)
m.Option("Description", data.Description)
m.Option("URL", data.Url)
m.Option("URL", data.PicUrl)
m.Option("LocationX", kit.Int(data.Location_X*100000)) m.Option("LocationX", kit.Int(data.Location_X*100000))
m.Option("LocationY", kit.Int(data.Location_Y*100000)) m.Option("LocationY", kit.Int(data.Location_Y*100000))
m.Option("Scale", data.Scale) m.Option("Scale", data.Scale)
m.Option("Label", data.Label) m.Option("Label", data.Label)
m.Option("Title", data.Title)
m.Option("Description", data.Description)
m.Option("URL", data.Url)
m.Option("URL", data.PicUrl)
} }
const LOGIN = "login" const LOGIN = "login"
func init() { func init() {
Index.MergeCommands(ice.Commands{ Index.MergeCommands(ice.Commands{
"/login/": {Name: "/login/", Help: "认证", Hand: func(m *ice.Message, arg ...string) { web.PP(LOGIN): {Actions: aaa.WhiteAction(), Hand: func(m *ice.Message, arg ...string) {
if m.Cmdx(ACCESS, CHECK) == "" { if m.Cmdx(ACCESS, CHECK) == "" {
return // 验签失败 return
} }
// 解析数据
_wx_parse(m) _wx_parse(m)
// 用户登录
m.Option(ice.MSG_USERZONE, WX) m.Option(ice.MSG_USERZONE, WX)
aaa.UserLogin(m, m.Append("FromUserName"), "") aaa.SessAuth(m, kit.Dict(aaa.USERNAME, m.Option("FromUserName"), aaa.USERROLE, aaa.UserRole(m, m.Option("FromUserName"))))
switch m.Option("MsgType") { switch m.Option("MsgType") {
case EVENT: // 事件 case EVENT:
m.Cmdy(EVENT, m.Option("Event")) m.Cmdy(EVENT, m.Option("Event"))
case TEXT:
case chat.LOCATION: // 打卡 if cmds := kit.Split(m.Option("Content")); aaa.Right(m, cmds) {
m.Cmdy(TEXT, cmds)
} else {
m.Cmdy(MENU, "home")
}
case mdb.LINK:
m.Cmdy(chat.FAVOR, mdb.CREATE, mdb.TYPE, mdb.LINK, mdb.NAME, m.Option("Title"), mdb.TEXT, m.Option("URL"))
case wiki.IMAGE:
m.Cmdy(chat.FAVOR, mdb.CREATE, mdb.TYPE, wiki.IMAGE, mdb.NAME, m.Option("Title"), mdb.TEXT, m.Option("URL"))
case chat.LOCATION:
m.Cmdy(chat.LOCATION, mdb.CREATE, mdb.TYPE, "", mdb.NAME, m.Option("Label"), mdb.TEXT, m.Option("Label"), m.Cmdy(chat.LOCATION, mdb.CREATE, mdb.TYPE, "", mdb.NAME, m.Option("Label"), mdb.TEXT, m.Option("Label"),
"latitude", m.Option("LocationX"), "longitude", m.Option("LocationY"), "scale", m.Option("Scale"), "latitude", m.Option("LocationX"), "longitude", m.Option("LocationY"), "scale", m.Option("Scale"),
) )
case mdb.LINK: // 打卡
m.Cmdy("scan", mdb.CREATE, mdb.TYPE, mdb.LINK, mdb.NAME, m.Option("Title"), mdb.TEXT, m.Option("URL"))
case "image": // 文本
m.Cmdy("scan", mdb.CREATE, mdb.TYPE, wiki.IMAGE, mdb.NAME, m.Option("Title"), mdb.TEXT, m.Option("URL"))
case TEXT: // 文本
if cmds := kit.Split(m.Option("Content")); aaa.Right(m, cmds) {
m.Cmdy(TEXT, cmds)
break
}
m.Cmdy(MENU, "home")
} }
}}, }},
LOGIN: {Name: "login", Help: "登录", Actions: ice.Actions{ LOGIN: {Name: "login", Help: "登录", Actions: ice.Actions{
mdb.CREATE: {Name: "create appid appmm token", Help: "创建", Hand: func(m *ice.Message, arg ...string) { mdb.CREATE: {Name: "create appid appmm token", Hand: func(m *ice.Message, arg ...string) { m.Cmd(ACCESS, LOGIN, arg) }},
m.Cmd(ACCESS, LOGIN, arg)
}},
}}, }},
}) })
} }

View File

@ -8,23 +8,17 @@ import (
kit "shylinux.com/x/toolkits" kit "shylinux.com/x/toolkits"
) )
func _wx_action(m *ice.Message) { func _wx_action(m *ice.Message) (count int) {
m.SetResult().RenderResult() m.SetResult().RenderResult()
m.Echo(`<xml> m.Echo(`<xml>
<FromUserName><![CDATA[%s]]></FromUserName> <FromUserName><![CDATA[%s]]></FromUserName>
<ToUserName><![CDATA[%s]]></ToUserName> <ToUserName><![CDATA[%s]]></ToUserName>
<CreateTime>%s</CreateTime> <CreateTime>%s</CreateTime>
<MsgType><![CDATA[%s]]></MsgType> <MsgType><![CDATA[%s]]></MsgType>
`, m.Option("ToUserName"), m.Option("FromUserName"), m.Option("CreateTime"), "news") `, m.Option("ToUserName"), m.Option("FromUserName"), m.Option("CreateTime"), "news")
count := 0
m.Tables(func(value ice.Maps) { count++ }) m.Tables(func(value ice.Maps) { count++ })
m.Echo(`<ArticleCount>%d</ArticleCount>`, count) m.Echo(`<ArticleCount>%d</ArticleCount>`, count).Echo(`<Articles>`)
share := m.Cmdx(web.SHARE, mdb.CREATE, mdb.TYPE, web.LOGIN) share := m.Cmdx(web.SHARE, mdb.CREATE, mdb.TYPE, web.LOGIN)
m.Echo(`<Articles>`)
m.Tables(func(value ice.Maps) { m.Tables(func(value ice.Maps) {
m.Echo(`<item> m.Echo(`<item>
<Title><![CDATA[%s]]></Title> <Title><![CDATA[%s]]></Title>
@ -32,13 +26,10 @@ func _wx_action(m *ice.Message) {
<PicUrl><![CDATA[%s]]></PicUrl> <PicUrl><![CDATA[%s]]></PicUrl>
<Url><![CDATA[%s]]></Url> <Url><![CDATA[%s]]></Url>
</item> </item>
`, value[wiki.TITLE], value[wiki.SPARK], value[wiki.IMAGE], `, value[wiki.TITLE], value[wiki.SPARK], value[wiki.IMAGE], kit.MergeURL2(kit.Format(value[wiki.REFER]), "/share/"+share))
kit.MergeURL(kit.Format(value[wiki.REFER]), web.SHARE, share)) }).Echo(`</Articles>`).Echo(`</xml>`)
})
m.Echo(`</Articles>`)
m.Echo(`</xml>`)
m.Debug("echo: %v", m.Result()) m.Debug("echo: %v", m.Result())
return
} }
const MENU = "menu" const MENU = "menu"
@ -46,8 +37,8 @@ const MENU = "menu"
func init() { func init() {
Index.MergeCommands(ice.Commands{ Index.MergeCommands(ice.Commands{
MENU: {Name: "menu zone id auto insert", Help: "菜单", Actions: ice.MergeActions(ice.Actions{ MENU: {Name: "menu zone id auto insert", Help: "菜单", Actions: ice.MergeActions(ice.Actions{
mdb.INSERT: {Name: "insert zone=home title=hi refer=hello image", Help: "添加"}, mdb.INSERT: {Name: "insert zone=home title=hi refer=hello image"},
}, mdb.ZoneAction(mdb.SHORT, mdb.ZONE, mdb.FIELD, "time,id,title,refer,image")), Hand: func(m *ice.Message, arg ...string) { }, mdb.ZoneAction(mdb.FIELD, "time,id,title,refer,image")), Hand: func(m *ice.Message, arg ...string) {
if mdb.ZoneSelect(m, arg...); len(arg) > 0 { if mdb.ZoneSelect(m, arg...); len(arg) > 0 {
_wx_action(m) _wx_action(m)
} }

View File

@ -3,6 +3,7 @@ package wx
import ( import (
ice "shylinux.com/x/icebergs" ice "shylinux.com/x/icebergs"
"shylinux.com/x/icebergs/base/cli" "shylinux.com/x/icebergs/base/cli"
"shylinux.com/x/icebergs/base/ctx"
"shylinux.com/x/icebergs/base/mdb" "shylinux.com/x/icebergs/base/mdb"
"shylinux.com/x/icebergs/base/nfs" "shylinux.com/x/icebergs/base/nfs"
kit "shylinux.com/x/toolkits" kit "shylinux.com/x/toolkits"
@ -17,23 +18,17 @@ func _wx_reply(m *ice.Message, tmpl string) {
const TEXT = "text" const TEXT = "text"
func init() { func init() {
Index.Merge(&ice.Context{Configs: ice.Configs{ Index.MergeCommands(ice.Commands{
TEXT: {Name: TEXT, Help: "文本", Value: kit.Data(nfs.TEMPLATE, text)}, TEXT: {Name: "text", Help: "文本", Actions: ice.MergeActions(ice.Actions{
}, Commands: ice.Commands{ MENU: {Name: "menu name=home", Hand: func(m *ice.Message, arg ...string) { m.Cmdy(MENU, m.Option(mdb.NAME)) }},
TEXT: {Name: "text", Help: "文本", Actions: ice.Actions{ }, ctx.ConfAction(nfs.TEMPLATE, text)), Hand: func(m *ice.Message, arg ...string) {
MENU: {Name: "menu name", Help: "菜单", Hand: func(m *ice.Message, arg ...string) { if m.Cmdy(arg); m.IsErrNotFound() {
m.Cmdy(MENU, kit.Select("home", m.Option(mdb.NAME))) m.SetResult().Cmdy(cli.SYSTEM, arg)
}},
}, Hand: func(m *ice.Message, arg ...string) {
if m.Cmdy(arg); m.Length() == 0 && (m.Result() == "" || m.IsErrNotFound()) {
m.SetResult().Cmdy(cli.SYSTEM, arg) // 系统命令
}
if m.Result() == "" {
m.Table()
} }
kit.If(m.Result() == "", func() { m.Table() })
_wx_reply(m, m.CommandKey()) _wx_reply(m, m.CommandKey())
}}, }},
}}) })
} }
var text = `<xml> var text = `<xml>

View File

@ -4,17 +4,12 @@ refer `
后台 https://mp.weixin.qq.com/ 后台 https://mp.weixin.qq.com/
文档 https://developers.weixin.qq.com/doc/offiaccount/Getting_Started/Overview.html 文档 https://developers.weixin.qq.com/doc/offiaccount/Getting_Started/Overview.html
` `
qrcode `http://weixin.qq.com/r/_B1-Z7TEXOkjrfAE90jq` qrcode `http://weixin.qq.com/r/_B1-Z7TEXOkjrfAE90jq`
chapter "应用" chapter "应用"
field "访问" web.chat.wx.access field "访问" web.chat.wx.access
field "收藏" web.chat.wx.favor field "收藏" web.chat.wx.favor
field "菜单" web.chat.wx.menu field "菜单" web.chat.wx.menu
field "扫码" web.chat.scan
field "复制" web.chat.paste
field "文件" web.chat.files
field "位置" web.chat.location field "位置" web.chat.location
chapter "权限" chapter "权限"
@ -29,4 +24,3 @@ chapter "项目"
field "源代码" web.code.inner args `usr/icebergs/ misc/wx/login.go` field "源代码" web.code.inner args `usr/icebergs/ misc/wx/login.go`
field "趋势图" web.code.git.trend args `icebergs` field "趋势图" web.code.git.trend args `icebergs`
field "架构图" web.code.git.spide args `icebergs` field "架构图" web.code.git.spide args `icebergs`