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
307bdf68
Commit
307bdf68
authored
Mar 16, 2014
by
lanrion
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
added custom apis
parent
9e9716f5
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
133 additions
and
0 deletions
+133
-0
lib/weixin_authorize.rb
+1
-0
lib/weixin_authorize/api/custom.rb
+123
-0
lib/weixin_authorize/client.rb
+1
-0
spec/api/custom_spec.rb
+8
-0
No files found.
lib/weixin_authorize.rb
View file @
307bdf68
...
...
@@ -2,6 +2,7 @@ require "rest-client"
require
"weixin_authorize/version"
require
"weixin_authorize/api/user"
require
"weixin_authorize/api/menu"
require
"weixin_authorize/api/custom"
require
"weixin_authorize/client"
module
WeixinAuthorize
...
...
lib/weixin_authorize/api/custom.rb
0 → 100644
View file @
307bdf68
# encoding: utf-8
module
WeixinAuthorize
module
Api
module
Custom
# 发送文本消息
# {
# "touser":"OPENID",
# "msgtype":"text",
# "text":
# {
# "content":"Hello World"
# }
# }
def
send_text_custom
(
to_user
,
content
)
message
=
default_options
(
to_user
).
merge
({
text:
{
content:
content
}})
JSON
.
parse
(
RestClient
.
post
(
custom_base_url
,
MultiJson
.
dump
(
message
)))
end
# 发送图片消息
# {
# "touser":"OPENID",
# "msgtype":"image",
# "image":
# {
# "media_id":"MEDIA_ID"
# }
# }
def
sent_image_custom
(
to_user
,
media_id
)
message
=
default_options
(
to_user
).
merge
({
msgtype:
image
,
image:
{
media_id:
media_id
}})
JSON
.
parse
(
RestClient
.
post
(
custom_base_url
,
MultiJson
.
dump
(
message
)))
end
# 发送语音消息
# {
# "touser":"OPENID",
# "msgtype":"voice",
# "voice":
# {
# "media_id":"MEDIA_ID"
# }
# }
def
sent_voice_custom
(
to_user
,
media_id
)
message
=
default_options
(
to_user
).
merge
({
msgtype:
voice
,
voice:
{
media_id:
media_id
}})
JSON
.
parse
(
RestClient
.
post
(
custom_base_url
,
MultiJson
.
dump
(
message
)))
end
# 发送视频消息
# {
# "touser":"OPENID",
# "msgtype":"video",
# "video":
# {
# "media_id":"MEDIA_ID"
# }
# }
def
sent_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
})
JSON
.
parse
(
RestClient
.
post
(
custom_base_url
,
MultiJson
.
dump
(
message
)))
end
# 发送音乐消息
# {
# "touser":"OPENID",
# "msgtype":"music",
# "music":
# {
# "title":"MUSIC_TITLE",
# "description":"MUSIC_DESCRIPTION",
# "musicurl":"MUSIC_URL",
# "hqmusicurl":"HQ_MUSIC_URL",
# "thumb_media_id":"THUMB_MEDIA_ID"
# }
# }
def
sent_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
})
JSON
.
parse
(
RestClient
.
post
(
custom_base_url
,
MultiJson
.
dump
(
message
)))
end
# 发送图文消息
# {
# "touser":"OPENID",
# "msgtype":"news",
# "news":{
# "articles": [
# {
# "title":"Happy Day",
# "description":"Is Really A Happy Day",
# "url":"URL",
# "picurl":"PIC_URL"
# },
# {
# "title":"Happy Day",
# "description":"Is Really A Happy Day",
# "url":"URL",
# "picurl":"PIC_URL"
# }
# ]
# }
# }
def
send_news_custom
(
to_user
,
*
articles
)
message
=
default_options
(
to_user
).
merge
({
msgtype:
"news"
,
news:
{
articles:
articles
}})
JSON
.
parse
(
RestClient
.
post
(
custom_base_url
,
MultiJson
.
dump
(
message
)))
end
private
# https://api.weixin.qq.com/cgi-bin/message/custom/send?access_token=ACCESS_TOKEN
def
custom_base_url
"
#{
endpoint
}
/message/custom/send?
#{
access_token_param
}
"
end
def
default_options
(
to_user
)
{
touser:
to_user
,
msgtype:
"text"
}
end
end
end
end
lib/weixin_authorize/client.rb
View file @
307bdf68
...
...
@@ -6,6 +6,7 @@ module WeixinAuthorize
attr_accessor
:app_id
,
:app_secret
,
:expired_at
# Time.now + expires_in
include
Api
::
User
include
Api
::
Menu
include
Api
::
Custom
attr_accessor
:access_token
...
...
spec/api/custom_spec.rb
0 → 100644
View file @
307bdf68
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
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