Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
W
weixin_authorize
Overview
Overview
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
ikcrm_common
weixin_authorize
Commits
27e67364
Commit
27e67364
authored
Mar 19, 2014
by
lanrion
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
refactor custom.rb
parent
caa01769
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
63 additions
and
19 deletions
+63
-19
lib/weixin_authorize/api/custom.rb
+18
-16
spec/api/custom_spec.rb
+45
-3
No files found.
lib/weixin_authorize/api/custom.rb
View file @
27e67364
...
...
@@ -14,7 +14,7 @@ module WeixinAuthorize
# }
def
send_text_custom
(
to_user
,
content
)
message
=
default_options
(
to_user
).
merge
({
text:
{
content:
content
}})
http_post
(
custom_base_url
,
MultiJson
.
dump
(
message
)
)
http_post
(
custom_base_url
,
message
)
end
# 发送图片消息
...
...
@@ -27,8 +27,8 @@ module WeixinAuthorize
# }
# }
def
send_image_custom
(
to_user
,
media_id
)
message
=
default_options
(
to_user
).
merge
({
msgtype:
"image"
,
image:
{
media_id:
media_id
}})
http_post
(
custom_base_url
,
MultiJson
.
dump
(
message
)
)
message
=
default_options
(
to_user
,
"image"
).
merge
({
image:
{
media_id:
media_id
}})
http_post
(
custom_base_url
,
message
)
end
# 发送语音消息
...
...
@@ -41,8 +41,8 @@ module WeixinAuthorize
# }
# }
def
send_voice_custom
(
to_user
,
media_id
)
message
=
default_options
(
to_user
).
merge
({
msgtype:
"voice"
,
voice:
{
media_id:
media_id
}})
http_post
(
custom_base_url
,
MultiJson
.
dump
(
message
)
)
message
=
default_options
(
to_user
,
"voice"
).
merge
({
voice:
{
media_id:
media_id
}})
http_post
(
custom_base_url
,
message
)
end
# 发送视频消息
...
...
@@ -56,8 +56,8 @@ module WeixinAuthorize
# }
def
send_video_custom
(
to_user
,
media_id
,
options
=
{})
video_options
=
{
media_id:
media_id
}.
merge
(
options
)
message
=
default_options
(
to_user
).
merge
({
msgtype:
"video"
,
video:
video_options
})
http_post
(
custom_base_url
,
MultiJson
.
dump
(
message
)
)
message
=
default_options
(
to_user
,
"video"
).
merge
({
video:
video_options
})
http_post
(
custom_base_url
,
message
)
end
# 发送音乐消息
...
...
@@ -74,10 +74,12 @@ module WeixinAuthorize
# }
# }
def
send_music_custom
(
to_user
,
media_id
,
musicurl
,
hqmusicurl
,
options
=
{})
music_options
=
{
thumb_media_id:
media_id
,
musicurl:
musicurl
,
hqmusicurl:
hqmusicurl
}.
merge
(
options
)
message
=
default_options
(
to_user
).
merge
({
msgtype:
"music"
,
music:
music_options
})
http_post
(
custom_base_url
,
MultiJson
.
dump
(
message
))
music_options
=
{
thumb_media_id:
media_id
,
musicurl:
musicurl
,
hqmusicurl:
hqmusicurl
}.
merge
(
options
)
message
=
default_options
(
to_user
,
"music"
).
merge
({
music:
music_options
})
http_post
(
custom_base_url
,
message
)
end
# 发送图文消息
...
...
@@ -101,9 +103,9 @@ module WeixinAuthorize
# ]
# }
# }
def
send_news_custom
(
to_user
,
*
articles
)
message
=
default_options
(
to_user
).
merge
({
msgtype:
"news"
,
news:
{
articles:
articles
}})
http_post
(
custom_base_url
,
MultiJson
.
dump
(
message
)
)
def
send_news_custom
(
to_user
,
articles
=
[]
)
message
=
default_options
(
to_user
,
"news"
).
merge
({
news:
{
articles:
articles
}})
http_post
(
custom_base_url
,
message
)
end
private
...
...
@@ -113,8 +115,8 @@ module WeixinAuthorize
"/message/custom/send"
end
def
default_options
(
to_user
)
{
touser:
to_user
,
msgtype:
"text"
}
def
default_options
(
to_user
,
msgtype
=
"text"
)
{
touser:
to_user
,
msgtype:
msgtype
}
end
end
...
...
spec/api/custom_spec.rb
View file @
27e67364
require
"spec_helper"
describe
WeixinAuthorize
::
Api
::
Custom
do
it
"can send a text Custom message"
do
response
=
$client
.
send_text_custom
(
ENV
[
"OPENID"
],
"test send Custom Message"
)
puts
response
let
(
:text_message
)
do
"text Custom message"
end
it
"#send_text_custom"
do
response
=
$client
.
send_text_custom
(
ENV
[
"OPENID"
],
text_message
)
expect
(
response
[
"errcode"
]).
to
eq
(
0
)
end
it
"#send_news_custom"
do
articles
=
[{
"title"
=>
"Happy Day"
,
"description"
=>
"Is Really A Happy Day"
,
"url"
=>
"http://www.baidu.com"
,
"picurl"
=>
"http://www.baidu.com/img/bdlogo.gif"
},
{
"title"
=>
"Happy Day"
,
"description"
=>
"Is Really A Happy Day"
,
"url"
=>
"http://www.baidu.com"
,
"picurl"
=>
"http://www.baidu.com/img/bdlogo.gif"
}]
response
=
$client
.
send_news_custom
(
ENV
[
"OPENID"
],
articles
)
expect
(
response
[
"errcode"
]).
to
eq
(
0
)
end
it
"#send_image_custom"
do
pending
(
"The test must have a media_id"
)
this_should_not_get_executed
end
it
"#send_video_custom"
do
pending
(
"The test must have a media_id"
)
this_should_not_get_executed
end
it
"#send_music_custom"
do
pending
(
"The test must have a media_id"
)
this_should_not_get_executed
end
it
"#send_voice_custom"
do
pending
(
"The test must have a media_id"
)
this_should_not_get_executed
end
end
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment