Module: WxExt::Api::Qrcode

Extended by:
Qrcode
Included in:
Qrcode
Defined in:
lib/wx_ext/api/msg.rb

Overview

User api of weixin.

Author:

  • FuShengYang

Instance Method Summary collapse

Instance Method Details

#create_ticket(access_token, ticket_hash) ⇒ Hash

Create ticket via post.

Parameters:

  • access_token (Enumerable<String>)
  • ticket_hash (Hash)

Returns:

  • (Hash)

    Json based hash.



19
20
21
22
23
# File 'lib/wx_ext/api/msg.rb', line 19

def create_ticket(access_token, ticket_hash)
  url = 'https://api.weixin.qq.com/cgi-bin/qrcode/create'\
        "?access_token=#{access_token}"
  Helper.http_post(url, ticket_hash.to_json)
end

#get_qrcode_by_ticket(ticket) ⇒ Hash

Get the qrcode via ticket.

Parameters:

  • ticket (Enumerable<String>)

Returns:

  • (Hash)

    Json based hash.



29
30
31
32
33
# File 'lib/wx_ext/api/msg.rb', line 29

def get_qrcode_by_ticket(ticket)
  url = 'https://mp.weixin.qq.com/cgi-bin/showqrcode'\
        "?ticket=#{ticket}"
  Helper.http_get url
end

#long_url_2_short(access_token, action = 'long2short', long_url) ⇒ Hash

Long url to short url via post.

Parameters:

  • access_token (Enumerable<String>)
  • action (Enumerable<String>) (defaults to: 'long2short')
  • long_url (Enumerable<String>)

Returns:

  • (Hash)

    Json based hash.



41
42
43
44
45
# File 'lib/wx_ext/api/msg.rb', line 41

def long_url_2_short(access_token, action='long2short', long_url)
  url = 'https://api.weixin.qq.com/cgi-bin/shorturl'\
        "?access_token=#{access_token}"
  Helper.http_post(url, { action: action, long_url: long_url }.to_json)
end