Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
wechaty
wechaty
提交
0a2a2b96
W
wechaty
项目概览
wechaty
/
wechaty
上一次同步 大约 3 年
通知
304
Star
10499
Fork
6
代码
文件
提交
分支
Tags
贡献者
分支图
Diff
Issue
152
列表
看板
标记
里程碑
合并请求
1
Wiki
0
Wiki
分析
仓库
DevOps
项目成员
Pages
W
wechaty
项目概览
项目概览
详情
发布
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
Issue
152
Issue
152
列表
看板
标记
里程碑
合并请求
1
合并请求
1
Pages
分析
分析
仓库分析
DevOps
Wiki
0
Wiki
成员
成员
收起侧边栏
关闭侧边栏
动态
分支图
创建新Issue
提交
Issue看板
体验新版 GitCode,发现更多精彩内容 >>
提交
0a2a2b96
编写于
5月 06, 2016
作者:
Huan (李卓桓)
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
half work... fighting
上级
632b1f42
变更
3
隐藏空白更改
内联
并排
Showing
3 changed file
with
81 addition
and
80 deletion
+81
-80
lib/puppet-web-browser.js
lib/puppet-web-browser.js
+1
-1
lib/puppet-web-injectio.js
lib/puppet-web-injectio.js
+78
-78
tests/puppet-web-browser-tests.js
tests/puppet-web-browser-tests.js
+2
-1
未找到文件。
lib/puppet-web-browser.js
浏览文件 @
0a2a2b96
...
...
@@ -57,7 +57,7 @@ class Browser {
})
.
then
(()
=>
{
console
.
error
(
'
injected injectio
'
)
return
this
.
execute
(
'
return Wechaty()
'
)
return
this
.
execute
(
'
return Wechaty
.init
()
'
)
})
.
then
(()
=>
{
console
.
error
(
'
injected Wechaty()
'
)
...
...
lib/puppet-web-injectio.js
浏览文件 @
0a2a2b96
/**
*
* Wechaty - Robot API/SDK Library for Personal WeChat(微信) Account
*
* Inject this js code to browser,
* in order to interactive with wechat web program.
*
* Licenst: MIT
* https://github.com/zixia/wechaty-lib
*
MMCgi.isLogin
loginScope.qrcodeUrl
loginScope.code:
0: 显示二维码
201: 扫描,未确认
200: 登录成功
408: 未确认
*/
*
* Wechaty - Wechat for Bot, and human who talk to bot.
*
* Inject this js code to browser,
* in order to interactive with wechat web program.
*
* Licenst: MIT
* https://github.com/zixia/wechaty-lib
*
MMCgi.isLogin
loginScope.qrcodeUrl
loginScope.code:
0: 显示二维码
201: 扫描,未确认
200: 登录成功
408: 未确认
*/
;(
function
(
port
)
{
port
=
port
||
8788
var
injector
=
angular
.
element
(
document
).
injector
()
var
zlog
=
createZlog
()
var
Wechaty
=
{
// get all we need from browser(angularjs)
// get all we need from
wx in
browser(angularjs)
glue
:
{
injector
:
angular
.
element
(
document
).
injector
()
injector
:
injector
,
rootScope
:
injector
.
get
(
"
$rootScope
"
)
,
http
:
injector
.
get
(
"
$http
"
)
,
chatFactory
:
injector
.
get
(
"
chatFactory
"
)
,
confFactory
:
injector
.
get
(
"
confFactory
"
)
,
loginScope
:
angular
.
element
(
"
.login_box
"
).
scope
()
}
// variables
,
var
{
socket
:
socket
}
// methods
,
func
{
,
init
:
init
,
send
:
send
,
zlog
:
zlog
,
log
:
log
,
log
:
function
(
msg
)
{
socket
&&
socket
.
emit
(
'
log
'
,
msg
)
}
,
ping
:
function
()
{
return
'
pong
'
}
,
getLoginStatusCode
:
function
()
{
return
loginScope
.
code
}
,
getLoginQrImgUrl
:
function
()
{
return
loginScope
.
qrcodeUrl
}
,
isLogined
:
function
()
{
return
200
===
loginScope
.
code
}
,
isReady
:
function
()
{
return
!!
(
angular
&&
angular
.
element
&&
angular
.
element
(
"
body
"
))
}
,
initSocket
:
initSocket
}
}
function
send
(
ToUserName
,
Content
)
{
var
m
=
chatFactory
.
createMessage
({
ToUserName
:
ToUserName
,
Content
:
Content
})
chatFactory
.
appendMessage
(
m
)
return
chatFactory
.
sendMessage
(
m
)
// glue funcs
,
getLoginStatusCode
:
function
()
{
return
loginScope
.
code
}
,
getLoginQrImgUrl
:
function
()
{
return
loginScope
.
qrcodeUrl
}
,
isLogined
:
function
()
{
return
200
===
loginScope
.
code
}
,
isReady
:
function
()
{
return
!!
(
angular
&&
angular
.
element
&&
angular
.
element
(
"
body
"
));
}
// variable
,
socket
:
null
// funcs
,
init
:
init
,
send
:
send
,
zlog
:
zlog
,
log
:
log
,
ping
:
ping
}
function
init
()
{
initZlog
()
zlog
(
'
wechaty port
'
+
port
)
initSocket
()
// save to socket
initSocket
()
hookUnload
()
hookMessage
()
zlog
(
'
Wechaty injected!. ;-D
'
)
}
angular
.
extend
(
Wechaty
,
{
})
function
initZlog
()
{
function
createZlog
()
{
var
enable
=
true
if
(
enable
)
{
if
(
!
console
.
memory
&&
console
.
time
)
{
// wechat debuger exist
...
...
@@ -95,47 +74,68 @@
}
else
{
window
.
zlog
=
function
()
{}
}
return
window
.
zlog
}
function
log
(
msg
)
{
Wechaty
.
socket
&&
Wechaty
.
socket
.
emit
(
'
log
'
,
msg
)
}
function
ping
()
{
return
'
pong
'
}
function
send
(
ToUserName
,
Content
)
{
var
c
=
Wechaty
.
glue
.
chatFactory
var
m
=
c
.
createMessage
({
ToUserName
:
ToUserName
,
Content
:
Content
})
c
.
appendMessage
(
m
)
return
c
.
sendMessage
(
m
)
}
function
hookMessage
()
{
var
rootScope
=
Wechaty
.
glue
.
rootScope
var
zlog
=
Wechaty
.
zlog
rootScope
.
$on
(
"
message:add:success
"
,
function
(
event
,
data
)
{
socket
.
emit
(
'
message
'
,
data
)
.
catch
(
function
(
e
)
{
zlog
(
'
socket.emit(message, data) fail:
'
);
zlog
(
e
)
})
Wechaty
.
socket
.
emit
(
'
message
'
,
data
)
.
catch
(
function
(
e
)
{
zlog
(
'
socket.emit(message, data) fail:
'
)
zlog
(
e
)
})
})
}
function
hookUnload
()
{
window
.
addEventListener
(
'
unload
'
,
function
(
e
)
{
socket
.
emit
(
'
unload
'
)
Wechaty
.
socket
.
emit
(
'
unload
'
)
})
}
function
initSocket
()
{
// Wechaty global variable: socket
Wechaty
.
socket
=
io
.
connect
(
'
https://127.0.0.1:
'
+
port
)
var
socket
=
Wechaty
.
socket
=
io
.
connect
(
'
https://127.0.0.1:
'
+
port
)
var
zlog
=
Wechaty
.
zlog
zlog
(
'
socket:
'
+
socket
)
Wechaty
.
socket
.
on
(
'
connect
'
,
function
()
{
socket
.
on
(
'
connect
'
,
function
()
{
zlog
(
'
on connect entried
'
)
rootScope
.
$on
(
"
message:add:success
"
,
function
(
event
,
data
)
{
Wechaty
.
glue
.
rootScope
.
$on
(
"
message:add:success
"
,
function
(
event
,
data
)
{
socket
.
emit
(
'
message
'
,
data
)
})
socket
.
on
(
'
disconnect
'
,
function
(
e
)
{
zlog
(
'
event: socket disconnect
'
)
// socket.emit('disconnect', e)
// for test & live check purpose: ping -> pong
socket
.
on
(
'
ping
'
,
function
(
e
)
{
Wechaty
.
zlog
(
'
received socket io event: ping. emit pong...
'
)
socket
.
emit
(
'
pong
'
,
'
pong
'
)
})
// Reconnect...
setTimeout
(
initSocket
,
1000
)
setTimeout
(
function
()
{
zlog
(
'
starting initSocket after disconnect
'
)
initSocket
()
},
1000
)
})
// for test & live check purpose: ping -> pong
socket
.
on
(
'
ping
'
,
function
(
e
)
{
zlog
(
'
received socket io event: ping. emit pong...
'
)
socket
.
emit
(
'
pong
'
,
'
pong
'
)
})
})
}
...
...
tests/puppet-web-browser-tests.js
浏览文件 @
0a2a2b96
...
...
@@ -3,7 +3,8 @@ const Browser = require('../lib/puppet-web-browser')
test
(
'
Browser class smoking tests
'
,
function
(
t
)
{
//t.plan(5)
const
b
=
new
Browser
()
const
PORT
=
58788
const
b
=
new
Browser
(
'
firefox
'
,
PORT
)
t
.
ok
(
b
,
'
Browser instance created
'
)
b
.
open
()
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录