Module: Weixin

Extended by:
Weixin
Included in:
Weixin
Defined in:
lib/rack-weixin.rb,
lib/weixin/menu.rb,
lib/weixin/model.rb,
lib/weixin/version.rb,
lib/weixin/middleware.rb

Defined Under Namespace

Classes: Item, LocationMessage, Menu, Message, Middleware, Music, MusicReplyMessage, NewsReplyMessage, ReplyMessage, TextReplyMessage, VideoMessage, VoiceMessage

Constant Summary collapse

TextMessage =

<xml>

<ToUserName><![CDATA[toUser]]></ToUserName>
<FromUserName><![CDATA[fromUser]]></FromUserName> 
<CreateTime>1348831860</CreateTime>
<MsgType><![CDATA[text]]></MsgType>
<Content><![CDATA[this is a test]]></Content>
<MsgId>1234567890123456</MsgId>

</xml>

Class.new(Message)
ImageMessage =

<xml>

<ToUserName><![CDATA[toUser]]></ToUserName>
<FromUserName><![CDATA[fromUser]]></FromUserName>
<CreateTime>1348831860</CreateTime>
<MsgType><![CDATA[image]]></MsgType>
<PicUrl><![CDATA[this is a url]]></PicUrl>
<MsgId>1234567890123456</MsgId>

</xml>

Class.new(Message)
LinkMessage =

<xml>

<ToUserName><![CDATA[toUser]]></ToUserName>
<FromUserName><![CDATA[fromUser]]></FromUserName>
<CreateTime>1351776360</CreateTime>
<MsgType><![CDATA[link]]></MsgType>
<Title><![CDATA[公众平台官网链接]]></Title>
<Description><![CDATA[公众平台官网链接]]></Description>
<Url><![CDATA[url]]></Url>
<MsgId>1234567890123456</MsgId>

</xml>

Class.new(Message)
EventMessage =

<xml>

<ToUserName><![CDATA[toUser]]></ToUserName>
<FromUserName><![CDATA[FromUser]]></FromUserName>
<CreateTime>123456789</CreateTime>
<MsgType><![CDATA[event]]></MsgType>
<Event><![CDATA[EVENT]]></Event>
<EventKey><![CDATA[EVENTKEY]]></EventKey>

</xml>

Class.new(Message)
VERSION =
"0.0.4.2"

Instance Method Summary collapse

Instance Method Details

#item(title, desc, pic_url, link_url) ⇒ Object



20
21
22
23
24
25
26
27
# File 'lib/rack-weixin.rb', line 20

def item(title, desc, pic_url, link_url)
  item = Item.new
  item.Title = title
  item.Description = desc
  item.PicUrl = pic_url
  item.Url    = link_url
  item
end

#music(title, desc, music_url, hq_music_url) ⇒ Object



11
12
13
14
15
16
17
18
# File 'lib/rack-weixin.rb', line 11

def music(title, desc, music_url, hq_music_url)
  item = Music.new
  item.Title = title
  item.Description = desc
  item.MusicUrl    = music_url
  item.HQMusicUrl  = hq_music_url
  item
end

#music_msg(from, to, music) ⇒ Object



37
38
39
40
41
42
43
# File 'lib/rack-weixin.rb', line 37

def music_msg(from, to, music)
  msg = MusicReplyMessage.new
  msg.ToUserName   = to
  msg.FromUserName = from
  msg.Music = music
  msg.to_xml
end

#news_msg(from, to, items) ⇒ Object



45
46
47
48
49
50
51
52
# File 'lib/rack-weixin.rb', line 45

def news_msg(from, to, items)
  msg = NewsReplyMessage.new
  msg.ToUserName   = to
  msg.FromUserName = from
  msg.Articles     = items
  msg.ArticleCount = items.count
  msg.to_xml
end

#text_msg(from, to, content) ⇒ Object



29
30
31
32
33
34
35
# File 'lib/rack-weixin.rb', line 29

def text_msg(from, to, content)
  msg = TextReplyMessage.new
  msg.ToUserName   = to
  msg.FromUserName = from
  msg.Content = content
  msg.to_xml
end