Module: EasyWeixin

Extended by:
EasyWeixin
Included in:
EasyWeixin
Defined in:
lib/easy_weixin/auth.rb,
lib/easy_weixin.rb,
lib/easy_weixin/model.rb,
lib/easy_weixin/version.rb

Overview

接入认证

Defined Under Namespace

Classes: Auth, Item, Message, NewsReplyMessage, ReplyMessage, TextReplyMessage

Constant Summary collapse

VERSION =
"0.0.9"

Instance Method Summary collapse

Instance Method Details

#analysis_xml(request_xml) ⇒ Object



31
32
33
34
# File 'lib/easy_weixin.rb', line 31

def analysis_xml(request_xml)
  hash = MultiXml.parse(request_xml)['xml']
  source = OpenStruct.new(hash)
end

#get_weixin_access_token(appid, appsecret) ⇒ Object



36
37
38
39
# File 'lib/easy_weixin.rb', line 36

def get_weixin_access_token(appid, appsecret)
  url = "https://api.weixin.qq.com/cgi-bin/token?grant_type=client_credential&appid=#{appid}&secret=#{appsecret}"
  JSON.parse(open(url).read)["access_token"]
end

#news_msg(from, to, articles, articleCount = 1) ⇒ Object



19
20
21
22
23
24
25
26
27
28
29
# File 'lib/easy_weixin.rb', line 19

def news_msg(from, to, articles, articleCount=1)
  msg = NewsReplyMessage.new
  msg.ToUserName   = to
  msg.FromUserName = from
  unless articles.is_a?(Array)
    articles = [articles]
  end
  msg.Articles = articles
  msg.ArticleCount = articleCount
  msg.to_xml
end

#text_msg(from, to, content) ⇒ Object



11
12
13
14
15
16
17
# File 'lib/easy_weixin.rb', line 11

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