mirror of
https://shylinux.com/x/icebergs
synced 2025-04-27 17:58:29 +08:00
opt wx
This commit is contained in:
parent
cc449ecc1c
commit
7b92e41750
@ -59,9 +59,7 @@ func init() {
|
||||
}},
|
||||
}, mdb.ZoneAction()), Hand: func(m *ice.Message, c *ice.Context, cmd string, arg ...string) {
|
||||
m.Fields(len(arg), m.Config(kit.MDB_FIELD), "time,id,res")
|
||||
if mdb.ZoneSelect(m, arg...); len(arg) == 0 {
|
||||
m.PushAction(mdb.REMOVE)
|
||||
}
|
||||
mdb.ZoneSelect(m, arg...)
|
||||
}},
|
||||
}})
|
||||
}
|
||||
|
@ -188,6 +188,7 @@ func ZoneSelect(m *ice.Message, arg ...string) *ice.Message {
|
||||
m.Fields(len(arg), kit.Fields(kit.MDB_TIME, m.Config(kit.MDB_SHORT), kit.MDB_COUNT), m.Config(kit.MDB_FIELD))
|
||||
if m.Cmdy(SELECT, m.PrefixKey(), "", ZONE, arg); kit.Select("", arg, 0) == "" {
|
||||
m.Sort(m.Config(kit.MDB_SHORT))
|
||||
m.PushAction(REMOVE)
|
||||
}
|
||||
return m
|
||||
}
|
||||
|
@ -74,9 +74,7 @@ func init() {
|
||||
}
|
||||
})
|
||||
|
||||
if len(arg) == 0 {
|
||||
m.PushAction(mdb.REMOVE)
|
||||
} else {
|
||||
if len(arg) > 0 {
|
||||
m.StatusTimeCountTotal(_tail_count(m, arg[0]))
|
||||
}
|
||||
}},
|
||||
|
@ -24,6 +24,9 @@ func init() {
|
||||
mdb.CREATE: {Name: "create type=text name=hi text:textarea=hi", Help: "添加"},
|
||||
}, mdb.HashAction()), Hand: func(m *ice.Message, c *ice.Context, cmd string, arg ...string) {
|
||||
if mdb.HashSelect(m, arg...); len(arg) > 0 {
|
||||
if m.Append(kit.MDB_TYPE) == "image" {
|
||||
m.PushImages("image", m.Append(kit.MDB_TEXT))
|
||||
}
|
||||
m.PushScript(ssh.SCRIPT, m.Append(kit.MDB_TEXT))
|
||||
m.PushQRCode(cli.QRCODE, m.Append(kit.MDB_TEXT))
|
||||
}
|
||||
|
@ -88,9 +88,7 @@ func init() {
|
||||
_task_modify(m, STATUS, FINISH)
|
||||
}},
|
||||
}, mdb.ZoneAction(), ctx.CmdAction()), Hand: func(m *ice.Message, c *ice.Context, cmd string, arg ...string) {
|
||||
if mdb.ZoneSelect(m, arg...); len(arg) == 0 {
|
||||
m.PushAction(mdb.REMOVE)
|
||||
} else {
|
||||
if mdb.ZoneSelect(m, arg...); len(arg) > 0 {
|
||||
status := map[string]int{}
|
||||
m.Table(func(index int, value map[string]string, head []string) {
|
||||
m.PushButton(_task_action(m, value[STATUS]))
|
||||
|
14
meta.go
14
meta.go
@ -13,6 +13,20 @@ func (m *Message) Set(key string, arg ...string) *Message {
|
||||
case MSG_DETAIL, MSG_RESULT:
|
||||
delete(m.meta, key)
|
||||
case MSG_OPTION, MSG_APPEND:
|
||||
if m.FieldsIsDetail() {
|
||||
if len(arg) > 0 {
|
||||
for i := 0; i < len(m.meta[kit.MDB_KEY]); i++ {
|
||||
if m.meta[kit.MDB_KEY][i] == arg[0] {
|
||||
m.meta[kit.MDB_KEY][i] = ""
|
||||
m.meta[kit.MDB_VALUE][i] = ""
|
||||
}
|
||||
}
|
||||
return m
|
||||
}
|
||||
delete(m.meta, kit.MDB_KEY)
|
||||
delete(m.meta, kit.MDB_VALUE)
|
||||
return m
|
||||
}
|
||||
if len(arg) > 0 {
|
||||
if delete(m.meta, arg[0]); len(arg) == 1 {
|
||||
return m
|
||||
|
@ -37,7 +37,6 @@ func init() {
|
||||
}, mdb.ZoneAction()), Hand: func(m *ice.Message, c *ice.Context, cmd string, arg ...string) {
|
||||
if mdb.ZoneSelect(m, arg...); len(arg) == 0 {
|
||||
m.Action(mdb.CREATE, mdb.EXPORT, mdb.IMPORT)
|
||||
m.PushAction(mdb.REMOVE)
|
||||
} else {
|
||||
m.PushAction(cli.SYSTEM)
|
||||
m.StatusTimeCount()
|
||||
|
@ -20,7 +20,6 @@ func init() {
|
||||
}, mdb.ZoneAction()), Hand: func(m *ice.Message, c *ice.Context, cmd string, arg ...string) {
|
||||
if mdb.ZoneSelect(m, arg...); len(arg) == 0 {
|
||||
m.Action(mdb.CREATE, mdb.EXPORT, mdb.IMPORT)
|
||||
m.PushAction(mdb.REMOVE)
|
||||
} else {
|
||||
m.PushAction(code.INNER)
|
||||
}
|
||||
|
@ -46,9 +46,7 @@ func init() {
|
||||
})
|
||||
}},
|
||||
}, mdb.ZoneAction()), Hand: func(m *ice.Message, c *ice.Context, cmd string, arg ...string) {
|
||||
if mdb.ZoneSelect(m, arg...); len(arg) == 0 {
|
||||
m.PushAction(mdb.REMOVE)
|
||||
}
|
||||
mdb.ZoneSelect(m, arg...)
|
||||
}},
|
||||
}})
|
||||
}
|
||||
|
@ -33,9 +33,7 @@ func init() {
|
||||
})
|
||||
}},
|
||||
}, mdb.ZoneAction()), Hand: func(m *ice.Message, c *ice.Context, cmd string, arg ...string) {
|
||||
if mdb.ZoneSelect(m, arg...); len(arg) == 0 {
|
||||
m.PushAction(mdb.REMOVE)
|
||||
}
|
||||
mdb.ZoneSelect(m, arg...)
|
||||
}},
|
||||
}})
|
||||
}
|
||||
|
@ -22,13 +22,12 @@ func init() {
|
||||
Index.Merge(&ice.Context{Configs: map[string]*ice.Config{
|
||||
LOGIN: {Name: LOGIN, Help: "认证", Value: kit.Data(
|
||||
tcp.SERVER, "https://api.weixin.qq.com",
|
||||
APPID, "", APPMM, "", "tokens", "",
|
||||
)},
|
||||
}, Commands: map[string]*ice.Command{
|
||||
ice.CTX_INIT: {Hand: func(m *ice.Message, c *ice.Context, cmd string, arg ...string) {
|
||||
m.Cmd(web.SPIDE, mdb.CREATE, MP, m.Conf(LOGIN, kit.Keym(tcp.SERVER)))
|
||||
}},
|
||||
"/login/": {Name: "/login/", Help: "认证", Action: map[string]*ice.Action{
|
||||
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) {
|
||||
msg := m.Cmd(web.SPIDE, MP, web.SPIDE_GET, "/sns/jscode2session?grant_type=authorization_code",
|
||||
"js_code", m.Option(kit.MDB_CODE), APPID, m.Config(APPID), "secret", m.Config(APPMM))
|
||||
@ -49,7 +48,7 @@ func init() {
|
||||
m.Cmdy(chat.SCAN, arg)
|
||||
}},
|
||||
}},
|
||||
LOGIN: {Name: "login appid auto login", Help: "认证", Action: map[string]*ice.Action{
|
||||
LOGIN: {Name: "login appid auto create", Help: "认证", Action: map[string]*ice.Action{
|
||||
mdb.CREATE: {Name: "create appid appmm", Help: "登录", Hand: func(m *ice.Message, arg ...string) {
|
||||
m.Config(APPID, m.Option(APPID))
|
||||
m.Config(APPMM, m.Option(APPMM))
|
||||
@ -57,6 +56,5 @@ func init() {
|
||||
}, Hand: func(m *ice.Message, c *ice.Context, cmd string, arg ...string) {
|
||||
m.Echo(m.Config(APPID))
|
||||
}},
|
||||
},
|
||||
})
|
||||
}})
|
||||
}
|
||||
|
@ -7,16 +7,17 @@ refer `
|
||||
qrcode `https://mp.weixin.qq.com/a/~HkylKD4DZShrgSm5GuXWLQ~~`
|
||||
|
||||
chapter "应用"
|
||||
field scan web.chat.scan
|
||||
field files web.chat.files
|
||||
field paste web.chat.paste
|
||||
field location web.chat.location
|
||||
field "认证" web.chat.mp.login
|
||||
|
||||
field "扫码" web.chat.scan
|
||||
field "复制" web.chat.paste
|
||||
field "文件" web.chat.files
|
||||
field "位置" web.chat.location
|
||||
|
||||
chapter "权限"
|
||||
field access web.chat.mp.access
|
||||
field share web.share
|
||||
field sess aaa.sess
|
||||
field user aaa.user
|
||||
field "共享" web.share
|
||||
field "会话" aaa.sess
|
||||
field "用户" aaa.user
|
||||
|
||||
chapter "项目"
|
||||
field "icebergs" web.code.git.trend args `icebergs`
|
||||
|
@ -42,7 +42,6 @@ func init() {
|
||||
}, mdb.ZoneAction()), Hand: func(m *ice.Message, c *ice.Context, cmd string, arg ...string) {
|
||||
if mdb.ZoneSelect(m, arg...); len(arg) == 0 {
|
||||
m.Action(mdb.CREATE, mdb.EXPORT, mdb.IMPORT)
|
||||
m.PushAction(mdb.REMOVE)
|
||||
} else {
|
||||
m.PushAction(code.INNER)
|
||||
m.StatusTimeCount()
|
||||
|
@ -56,7 +56,6 @@ func init() {
|
||||
m.Option(ice.CACHE_LIMIT, "-1")
|
||||
if mdb.ZoneSelect(m, arg...); len(arg) == 0 {
|
||||
m.Action("listTags", mdb.CREATE, mdb.EXPORT, mdb.IMPORT)
|
||||
m.PushAction(mdb.REMOVE)
|
||||
} else {
|
||||
if m.IsCliUA() {
|
||||
if m.Length() == 0 {
|
||||
|
@ -2,10 +2,10 @@ package wx
|
||||
|
||||
import (
|
||||
"crypto/sha1"
|
||||
"strings"
|
||||
"time"
|
||||
|
||||
ice "shylinux.com/x/icebergs"
|
||||
"shylinux.com/x/icebergs/base/ctx"
|
||||
"shylinux.com/x/icebergs/base/mdb"
|
||||
"shylinux.com/x/icebergs/base/ssh"
|
||||
"shylinux.com/x/icebergs/base/tcp"
|
||||
@ -14,27 +14,40 @@ import (
|
||||
)
|
||||
|
||||
func _wx_sign(m *ice.Message, nonce, stamp string) string {
|
||||
return kit.Format(sha1.Sum([]byte(kit.Join(kit.Sort([]string{
|
||||
return kit.Format(sha1.Sum([]byte(kit.Join(kit.Sort(kit.Simple(
|
||||
kit.Format("jsapi_ticket=%s", m.Cmdx(ACCESS, TICKET)),
|
||||
kit.Format("url=%s", m.Option(ice.MSG_USERWEB)),
|
||||
kit.Format("timestamp=%s", stamp),
|
||||
kit.Format("noncestr=%s", nonce),
|
||||
}), "&"))))
|
||||
)), "&"))))
|
||||
}
|
||||
|
||||
func _wx_config(m *ice.Message, nonce string) {
|
||||
m.Option(APPID, m.Config(APPID))
|
||||
m.Option(ssh.SCRIPT, m.Config(ssh.SCRIPT))
|
||||
m.Option("signature", _wx_sign(m, m.Option("noncestr", nonce), m.Option("timestamp", kit.Format(time.Now().Unix()))))
|
||||
}
|
||||
func _wx_check(m *ice.Message) {
|
||||
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) {
|
||||
return // 验证失败
|
||||
}
|
||||
if m.Option("echostr") != "" {
|
||||
m.RenderResult(m.Option("echostr"))
|
||||
return // 绑定验证
|
||||
}
|
||||
m.Echo(ice.TRUE)
|
||||
}
|
||||
|
||||
const (
|
||||
APPID = "appid"
|
||||
APPMM = "appmm"
|
||||
TOKEN = "token"
|
||||
EXPIRE = "expire"
|
||||
TICKET = "ticket"
|
||||
TOKENS = "tokens"
|
||||
EXPIRES = "expires"
|
||||
TICKET = "ticket"
|
||||
EXPIRE = "expire"
|
||||
CONFIG = "config"
|
||||
CHECK = "check"
|
||||
)
|
||||
const (
|
||||
ERRCODE = "errcode"
|
||||
@ -45,49 +58,51 @@ const ACCESS = "access"
|
||||
func init() {
|
||||
Index.Merge(&ice.Context{Configs: map[string]*ice.Config{
|
||||
ACCESS: {Name: ACCESS, Help: "认证", Value: kit.Data(
|
||||
ssh.SCRIPT, "/plugin/local/chat/wx.js",
|
||||
tcp.SERVER, "https://api.weixin.qq.com",
|
||||
APPID, "", APPMM, "", "tokens", "",
|
||||
tcp.SERVER, "https://api.weixin.qq.com", ssh.SCRIPT, "/plugin/local/chat/wx.js",
|
||||
)},
|
||||
}, Commands: map[string]*ice.Command{
|
||||
ice.CTX_INIT: {Hand: func(m *ice.Message, c *ice.Context, cmd string, arg ...string) {
|
||||
m.Cmd(web.SPIDE, mdb.CREATE, WX, m.Conf(ACCESS, kit.Keym(tcp.SERVER)))
|
||||
}},
|
||||
ACCESS: {Name: "access appid auto ticket token login", Help: "认证", Action: map[string]*ice.Action{
|
||||
ACCESS: {Name: "access appid auto config ticket tokens login", Help: "认证", Action: ice.MergeAction(map[string]*ice.Action{
|
||||
ice.CTX_INIT: {Hand: func(m *ice.Message, arg ...string) {
|
||||
m.Cmd(web.SPIDE, mdb.CREATE, WX, m.Config(tcp.SERVER))
|
||||
}},
|
||||
LOGIN: {Name: "login appid appmm token", Help: "登录", Hand: func(m *ice.Message, arg ...string) {
|
||||
m.Config(APPID, m.Option(APPID))
|
||||
m.Config(APPMM, m.Option(APPMM))
|
||||
m.Config("tokens", m.Option(TOKEN))
|
||||
m.Config(TOKEN, m.Option(TOKEN))
|
||||
}},
|
||||
TOKEN: {Name: "token", Help: "令牌", Hand: func(m *ice.Message, arg ...string) {
|
||||
if now := time.Now().Unix(); m.Config(TOKEN) == "" || now > kit.Int64(m.Config(EXPIRE)) {
|
||||
|
||||
TOKENS: {Name: "tokens", Help: "令牌", Hand: func(m *ice.Message, arg ...string) {
|
||||
if now := time.Now().Unix(); m.Config(TOKENS) == "" || now > kit.Int64(m.Config(EXPIRES)) {
|
||||
msg := m.Cmd(web.SPIDE, WX, web.SPIDE_GET, "/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)) {
|
||||
return
|
||||
}
|
||||
|
||||
m.Config(EXPIRE, now+kit.Int64(msg.Append("expires_in")))
|
||||
m.Config(TOKEN, msg.Append("access_token"))
|
||||
m.Config(EXPIRES, now+kit.Int64(msg.Append("expires_in")))
|
||||
m.Config(TOKENS, msg.Append("access_token"))
|
||||
}
|
||||
m.Echo(m.Config(TOKEN))
|
||||
m.Echo(m.Config(TOKENS))
|
||||
}},
|
||||
TICKET: {Name: "ticket", Help: "票据", Hand: func(m *ice.Message, arg ...string) {
|
||||
if now := time.Now().Unix(); m.Conf(TICKET) == "" || now > kit.Int64(m.Config(EXPIRES)) {
|
||||
msg := m.Cmd(web.SPIDE, WX, web.SPIDE_GET, "/cgi-bin/ticket/getticket?type=jsapi", "access_token", m.Cmdx(ACCESS, TOKEN))
|
||||
if now := time.Now().Unix(); m.Config(TICKET) == "" || now > kit.Int64(m.Config(EXPIRE)) {
|
||||
msg := m.Cmd(web.SPIDE, WX, web.SPIDE_GET, "/cgi-bin/ticket/getticket?type=jsapi", "access_token", m.Cmdx(ACCESS, TOKENS))
|
||||
if m.Warn(msg.Append(ERRCODE) != "0", msg.Append(ERRCODE), msg.Append(ERRMSG)) {
|
||||
return
|
||||
}
|
||||
|
||||
m.Config(EXPIRES, now+kit.Int64(msg.Append("expires_in")))
|
||||
m.Config(EXPIRE, now+kit.Int64(msg.Append("expires_in")))
|
||||
m.Config(TICKET, msg.Append(TICKET))
|
||||
}
|
||||
m.Echo(m.Config(TICKET))
|
||||
}},
|
||||
ctx.CONFIG: {Name: "config", Help: "配置", Hand: func(m *ice.Message, arg ...string) {
|
||||
_wx_config(m, "some")
|
||||
CONFIG: {Name: "config", Help: "配置", Hand: func(m *ice.Message, arg ...string) {
|
||||
_wx_config(m, m.Config(APPID))
|
||||
}},
|
||||
}, Hand: func(m *ice.Message, c *ice.Context, cmd string, arg ...string) {
|
||||
CHECK: {Name: "check", Help: "检验", Hand: func(m *ice.Message, arg ...string) {
|
||||
_wx_check(m)
|
||||
}},
|
||||
}, mdb.HashAction()), Hand: func(m *ice.Message, c *ice.Context, cmd string, arg ...string) {
|
||||
m.Echo(m.Config(APPID))
|
||||
}},
|
||||
}})
|
||||
|
@ -13,11 +13,10 @@ func init() {
|
||||
}, Commands: map[string]*ice.Command{
|
||||
EVENT: {Name: "event", Help: "事件", Action: map[string]*ice.Action{
|
||||
"subscribe": {Name: "subscribe", Help: "订阅", Hand: func(m *ice.Message, arg ...string) {
|
||||
_wx_action(m.Cmdy(MENU, "home"))
|
||||
m.Cmdy(MENU, "home")
|
||||
}},
|
||||
"unsubscribe": {Name: "unsubscribe", Help: "取关", Hand: func(m *ice.Message, arg ...string) {
|
||||
}},
|
||||
}, Hand: func(m *ice.Message, c *ice.Context, cmd string, arg ...string) {
|
||||
}},
|
||||
}})
|
||||
}
|
||||
|
@ -13,13 +13,14 @@ func init() {
|
||||
Index.Merge(&ice.Context{Configs: map[string]*ice.Config{
|
||||
FAVOR: {Name: "favor", Help: "收藏", Value: kit.Data(
|
||||
kit.MDB_SHORT, kit.MDB_TEXT, kit.MDB_FIELD, "time,type,name,text",
|
||||
kit.MDB_LINK, "https://open.weixin.qq.com/qr/code",
|
||||
)},
|
||||
}, Commands: map[string]*ice.Command{
|
||||
FAVOR: {Name: "favor text auto create", Help: "收藏", Action: ice.MergeAction(map[string]*ice.Action{
|
||||
FAVOR: {Name: "favor text:text auto create", Help: "收藏", Action: ice.MergeAction(map[string]*ice.Action{
|
||||
mdb.CREATE: {Name: "create type name text", Help: "添加"},
|
||||
}, mdb.HashAction()), Hand: func(m *ice.Message, c *ice.Context, cmd string, arg ...string) {
|
||||
mdb.HashSelect(m, arg...).Table(func(index int, value map[string]string, head []string) {
|
||||
m.PushQRCode(kit.MDB_SCAN, kit.MergeURL("https://open.weixin.qq.com/qr/code", aaa.USERNAME, value[kit.MDB_TEXT]))
|
||||
m.PushQRCode(kit.MDB_SCAN, kit.MergeURL(m.Config(kit.MDB_LINK), aaa.USERNAME, value[kit.MDB_TEXT]))
|
||||
})
|
||||
}},
|
||||
}})
|
||||
|
@ -1,27 +1,17 @@
|
||||
package wx
|
||||
|
||||
import (
|
||||
"crypto/sha1"
|
||||
"bytes"
|
||||
"encoding/xml"
|
||||
"strings"
|
||||
"io/ioutil"
|
||||
|
||||
ice "shylinux.com/x/icebergs"
|
||||
"shylinux.com/x/icebergs/base/aaa"
|
||||
"shylinux.com/x/icebergs/base/mdb"
|
||||
"shylinux.com/x/icebergs/core/chat"
|
||||
kit "shylinux.com/x/toolkits"
|
||||
)
|
||||
|
||||
func _wx_check(m *ice.Message) bool {
|
||||
check := kit.Sort([]string{m.Conf(ACCESS, "meta.tokens"), 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) {
|
||||
return false // 验证失败
|
||||
}
|
||||
if m.Option("echostr") != "" {
|
||||
m.RenderResult(m.Option("echostr"))
|
||||
return false // 绑定验证
|
||||
}
|
||||
return true
|
||||
}
|
||||
func _wx_parse(m *ice.Message) {
|
||||
data := struct {
|
||||
FromUserName string
|
||||
@ -31,9 +21,22 @@ func _wx_parse(m *ice.Message) {
|
||||
Event string
|
||||
MsgType string
|
||||
Content string
|
||||
|
||||
Location_X float64
|
||||
Location_Y float64
|
||||
Scale string
|
||||
Label string
|
||||
|
||||
Title string
|
||||
Description string
|
||||
Url string
|
||||
|
||||
PicUrl string
|
||||
}{}
|
||||
xml.NewDecoder(m.R.Body).Decode(&data)
|
||||
m.Debug("data: %#v", data)
|
||||
buf, _ := ioutil.ReadAll(m.R.Body)
|
||||
m.Debug("buf: %+v", string(buf))
|
||||
xml.NewDecoder(bytes.NewBuffer(buf)).Decode(&data)
|
||||
m.Debug("data: %+v", data)
|
||||
|
||||
m.Option("FromUserName", data.FromUserName)
|
||||
m.Option("ToUserName", data.ToUserName)
|
||||
@ -43,11 +46,17 @@ func _wx_parse(m *ice.Message) {
|
||||
m.Option("Event", data.Event)
|
||||
m.Option("MsgType", data.MsgType)
|
||||
m.Option("Content", data.Content)
|
||||
}
|
||||
func _wx_reply(m *ice.Message, tmpl string) {
|
||||
if res, err := kit.Render(m.Config(kit.MDB_TEMPLATE), m); err == nil {
|
||||
m.Set(ice.MSG_RESULT).RenderResult(string(res))
|
||||
}
|
||||
|
||||
m.Option("LocationX", kit.Int(data.Location_X*100000))
|
||||
m.Option("LocationY", kit.Int(data.Location_Y*100000))
|
||||
m.Option("Scale", data.Scale)
|
||||
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"
|
||||
@ -57,7 +66,7 @@ func init() {
|
||||
LOGIN: {Name: LOGIN, Help: "登录", Value: kit.Data()},
|
||||
}, Commands: map[string]*ice.Command{
|
||||
"/login/": {Name: "/login/", Help: "认证", Hand: func(m *ice.Message, c *ice.Context, cmd string, arg ...string) {
|
||||
if !_wx_check(m) {
|
||||
if m.Cmdx(ACCESS, CHECK) == "" {
|
||||
return // 验签失败
|
||||
}
|
||||
|
||||
@ -72,12 +81,22 @@ func init() {
|
||||
case EVENT: // 事件
|
||||
m.Cmdy(EVENT, m.Option("Event"))
|
||||
|
||||
case chat.LOCATION: // 打卡
|
||||
m.Cmdy(chat.LOCATION, mdb.CREATE, kit.MDB_TYPE, "", kit.MDB_NAME, m.Option("Label"), kit.MDB_TEXT, m.Option("Label"),
|
||||
"latitude", m.Option("LocationX"), "longitude", m.Option("LocationY"), "scale", m.Option("Scale"),
|
||||
)
|
||||
case kit.MDB_LINK: // 打卡
|
||||
m.Cmdy(chat.SCAN, mdb.CREATE, kit.MDB_TYPE, kit.MDB_LINK, kit.MDB_NAME, m.Option("Title"), kit.MDB_TEXT, m.Option("URL"))
|
||||
|
||||
case "image": // 文本
|
||||
m.Cmdy(chat.SCAN, mdb.CREATE, kit.MDB_TYPE, kit.MDB_IMAGE, kit.MDB_NAME, m.Option("Title"), kit.MDB_TEXT, m.Option("URL"))
|
||||
|
||||
case TEXT: // 文本
|
||||
cmds := kit.Split(m.Option("Content"))
|
||||
if !m.Right(cmds) {
|
||||
cmds = []string{MENU, mdb.CREATE}
|
||||
if cmds := kit.Split(m.Option("Content")); m.Right(cmds) {
|
||||
m.Cmdy(TEXT, cmds)
|
||||
break
|
||||
}
|
||||
m.Cmdy(TEXT, cmds)
|
||||
m.Cmdy(MENU, "home")
|
||||
}
|
||||
}},
|
||||
}})
|
||||
|
@ -50,10 +50,10 @@ func init() {
|
||||
)},
|
||||
}, Commands: map[string]*ice.Command{
|
||||
MENU: {Name: "menu zone id auto insert", Help: "菜单", Action: ice.MergeAction(map[string]*ice.Action{
|
||||
mdb.INSERT: {Name: "insert zone=home title=hi refer=hello image=", Help: "添加"},
|
||||
mdb.INSERT: {Name: "insert zone=home title=hi refer=hello image", Help: "添加"},
|
||||
}, mdb.ZoneAction()), Hand: func(m *ice.Message, c *ice.Context, cmd string, arg ...string) {
|
||||
if mdb.ZoneSelect(m, arg...); len(arg) == 0 {
|
||||
m.PushAction(mdb.REMOVE)
|
||||
if mdb.ZoneSelect(m, arg...); len(arg) > 0 {
|
||||
_wx_action(m)
|
||||
}
|
||||
}},
|
||||
}})
|
||||
|
@ -6,6 +6,12 @@ import (
|
||||
kit "shylinux.com/x/toolkits"
|
||||
)
|
||||
|
||||
func _wx_reply(m *ice.Message, tmpl string) {
|
||||
if res, err := kit.Render(m.Config(kit.MDB_TEMPLATE), m); err == nil {
|
||||
m.Set(ice.MSG_RESULT).RenderResult(string(res))
|
||||
}
|
||||
}
|
||||
|
||||
const TEXT = "text"
|
||||
|
||||
func init() {
|
||||
@ -14,18 +20,16 @@ func init() {
|
||||
}, Commands: map[string]*ice.Command{
|
||||
TEXT: {Name: "text", Help: "文本", Action: map[string]*ice.Action{
|
||||
MENU: {Name: "menu name", Help: "菜单", Hand: func(m *ice.Message, arg ...string) {
|
||||
_wx_action(m.Cmdy(MENU, kit.Select("home", m.Option(kit.MDB_NAME))))
|
||||
m.Cmdy(MENU, kit.Select("home", m.Option(kit.MDB_NAME)))
|
||||
}},
|
||||
}, Hand: func(m *ice.Message, c *ice.Context, cmd string, arg ...string) {
|
||||
// 执行命令
|
||||
if m.Cmdy(arg); len(m.Appendv(ice.MSG_APPEND)) == 0 && len(m.Result()) == 0 {
|
||||
m.Cmdy(cli.SYSTEM, arg)
|
||||
if m.Cmdy(arg); m.Length() == 0 && (m.Result() == "" || m.Result(1) == ice.ErrNotFound) {
|
||||
m.Set(ice.MSG_RESULT)
|
||||
m.Cmdy(cli.SYSTEM, arg) // 系统命令
|
||||
}
|
||||
if len(m.Result()) == 0 {
|
||||
if m.Result() == "" {
|
||||
m.Table()
|
||||
}
|
||||
|
||||
// 返回结果
|
||||
_wx_reply(m, m.CommandKey())
|
||||
}},
|
||||
}})
|
||||
|
@ -9,7 +9,6 @@ qrcode `http://weixin.qq.com/r/_B1-Z7TEXOkjrfAE90jq`
|
||||
|
||||
chapter "应用"
|
||||
field "访问" web.chat.wx.access
|
||||
field "收藏" web.chat.wx.login
|
||||
field "收藏" web.chat.wx.favor
|
||||
field "菜单" web.chat.wx.menu
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user