diff --git a/base/cli/cli.go b/base/cli/cli.go index 352cf5d2..a90309d8 100644 --- a/base/cli/cli.go +++ b/base/cli/cli.go @@ -18,6 +18,7 @@ var Index = &ice.Context{Name: "cli", Help: "命令模块", Configs: map[string]*ice.Config{ ice.CLI_RUNTIME: {Name: "runtime", Help: "运行环境", Value: kit.Dict()}, ice.CLI_SYSTEM: {Name: "system", Help: "系统命令", Value: kit.Data()}, + "python": {Name: "python", Help: "系统命令", Value: kit.Data("python", "python", "pip", "pip")}, }, Commands: map[string]*ice.Command{ ice.ICE_INIT: {Hand: func(m *ice.Message, c *ice.Context, cmd string, arg ...string) { @@ -109,6 +110,17 @@ var Index = &ice.Context{Name: "cli", Help: "命令模块", m.Echo(out.String()) } }}, + "python": {Name: "python", Help: "运行环境", Hand: func(m *ice.Message, c *ice.Context, cmd string, arg ...string) { + prefix := []string{ice.CLI_SYSTEM, m.Conf("python", "meta.python")} + switch arg[0] { + case "qrcode": + m.Cmdy(prefix, "-c", fmt.Sprintf(`import pyqrcode; print(pyqrcode.create("%s").terminal(quiet_zone=1))`, arg[1])) + case "install": + m.Cmdy(prefix[:1], m.Conf("python", "meta.pip"), "install", arg[1:]) + default: + m.Cmdy(prefix, arg) + } + }}, }, } diff --git a/core/wiki/template.go b/core/wiki/template.go index 5802160b..f1c8c52a 100644 --- a/core/wiki/template.go +++ b/core/wiki/template.go @@ -1,10 +1,10 @@ package wiki var title = `<{{.Option "level"}} class="story" data-type="{{.Option "type"}}" data-name="{{.Option "prefix"}}" data-text="{{.Option "text"}}">{{.Option "prefix"}}{{.Option "content"}}` -var brief = `

{{.Option "text"}}

` +var brief = `

{{.Option "text"}}

` var refer = `` +{{range $index, $value := .Optionv "list"}}
  • {{index $value 0}}: {{index $value 1}}
  • {{end}}` var spark = `

    {{.}}

    ` var shell = `
    $ {{.Option "input"}} diff --git a/core/wiki/wiki.go b/core/wiki/wiki.go index 95e39c09..16d8def6 100644 --- a/core/wiki/wiki.go +++ b/core/wiki/wiki.go @@ -9,7 +9,6 @@ import ( "bytes" "fmt" - "html" "path" "strings" ) @@ -113,8 +112,8 @@ var Index = &ice.Context{Name: "wiki", Help: "文档中心", output = m.Cmdx("cli.system", "sh", "-c", strings.Join(arg, " ")) } - m.Option("input", html.EscapeString(input)) - m.Option("output", html.EscapeString(output)) + m.Option("input", input) + m.Option("output", output) m.Render(m.Conf("spark", ice.Meta("template")), m.Option("name")) m.Render(m.Conf("shell", ice.Meta("template"))) }}, @@ -130,14 +129,14 @@ var Index = &ice.Context{Name: "wiki", Help: "文档中心", m.Option("type", "refer") m.Option("name", arg[0]) m.Option("text", arg[1]) - list := []interface{}{} + list := [][]string{} for _, v := range kit.Split(arg[1], "\n") { list = append(list, kit.Split(v, " ")) } m.Optionv("list", list) - m.Render(m.Conf("order", ice.Meta("template"))) + m.Render(m.Conf("refer", ice.Meta("template"))) }}, - "brief": {Name: "brief text", Help: "摘要", Hand: func(m *ice.Message, c *ice.Context, cmd string, arg ...string) { + "brief": {Name: "brief name text", Help: "摘要", Hand: func(m *ice.Message, c *ice.Context, cmd string, arg ...string) { m.Option("type", "brief") m.Option("name", arg[0]) m.Option("text", arg[1]) diff --git a/misc/wx/wx.go b/misc/wx/wx.go new file mode 100644 index 00000000..14414348 --- /dev/null +++ b/misc/wx/wx.go @@ -0,0 +1,56 @@ +package wx + +import ( + "github.com/shylinux/icebergs" + "github.com/shylinux/icebergs/base/cli" + "github.com/shylinux/toolkits" + "regexp" +) + +var Index = &ice.Context{Name: "wx", Help: "wx", + Caches: map[string]*ice.Cache{}, + Configs: map[string]*ice.Config{ + "login": {Name: "login", Help: "认证", Value: kit.Data("wechat", "https://login.weixin.qq.com")}, + }, + Commands: map[string]*ice.Command{ + ice.ICE_INIT: {Hand: func(m *ice.Message, c *ice.Context, cmd string, arg ...string) { + m.Cmd(ice.WEB_SPIDE, "add", "wechat", m.Conf("login", "meta.wechat")) + }}, + ice.ICE_EXIT: {Hand: func(m *ice.Message, c *ice.Context, cmd string, arg ...string) {}}, + + "login": {Name: "login", Help: "认证", Hand: func(m *ice.Message, c *ice.Context, cmd string, arg ...string) { + what := m.Cmdx(ice.WEB_SPIDE, "wechat", "raw", "GET", "/jslogin", "appid", "wx782c26e4c19acffb", "fun", "new") + // what := `window.QRLogin.code = 200; window.QRLogin.uuid = "gZUohppbCw==";` + reg, _ := regexp.Compile(`window.QRLogin.code = (\d+); window.QRLogin.uuid = "(\S+?)";`) + if list := reg.FindStringSubmatch(what); list[1] == "200" { + m.Richs(ice.WEB_SPIDE, nil, "wechat", func(key string, value map[string]interface{}) { + if qrcode := kit.Format("%s/l/%s", kit.Value(value, "client.url"), list[2]); m.R == nil { + m.Cmdy("cli.python", "qrcode", qrcode) + } else { + m.Push("_output", "qrcode").Echo(qrcode) + } + + m.Gos(m, func(m *ice.Message) { + reg, _ := regexp.Compile(`window.code=(\d+)`) + for i := 0; i < 1000; i++ { + what := m.Cmdx(ice.WEB_SPIDE, "wechat", "raw", "GET", "/cgi-bin/mmwebwx-bin/login", "loginicon", "true", "uuid", list[2], "tip", "1", "r", kit.Int(m.Time("stamp"))/1579, "_", m.Time("stamp")) + // window.code=200; window.redirect_uri="https://wx2.qq.com/cgi-bin/mmwebwx-bin/webwxnewloginpage?ticket=A7_l6ng7wSjNbs7-qD3ArIRJ@qrticket_0&uuid=Ia1-kbZ0wA==&lang=zh_CN&scan=1579005657"; + if list := reg.FindStringSubmatch(what); list[1] == "200" { + reg, _ := regexp.Compile(`window.redirect_uri="(\S+)";`) + if list := reg.FindStringSubmatch(what); len(list) > 1 { + what := m.Cmdx(ice.WEB_SPIDE, "wechat", "raw", "GET", list[1]) + m.Info("what %s", what) + break + } + } + m.Info("wait scan %v", list) + m.Sleep("1s") + } + }) + }) + } + }}, + }, +} + +func init() { cli.Index.Register(Index, nil) } diff --git a/misc/wx/wx.md b/misc/wx/wx.md new file mode 100644 index 00000000..6e1bb64b --- /dev/null +++ b/misc/wx/wx.md @@ -0,0 +1 @@ +# {{title "wx"}} diff --git a/miss/src/main.go b/miss/src/main.go index c6aeb888..4e7b3bb2 100644 --- a/miss/src/main.go +++ b/miss/src/main.go @@ -7,6 +7,7 @@ import ( _ "github.com/shylinux/icebergs/misc" _ "github.com/shylinux/icebergs/misc/mp" + _ "github.com/shylinux/icebergs/misc/wx" ) func main() { diff --git a/template.sh b/template.sh index 7b6a1453..abe9752e 100755 --- a/template.sh +++ b/template.sh @@ -104,6 +104,9 @@ build() { tutor() { mkdir $1 + [ -f "$1/$1.md" ] || cat >> "$1/$1.md" <> "$1/$1.go" <