Method: Wechat::Core::TinyLink.create

Defined in:
lib/wechat/core/tiny_link.rb

.create(access_token, link) ⇒ Object

长链接转短链接接口mp.weixin.qq.com/wiki/10/165c9b15eddcfbd8699ac12b0bd89ae6.html

Response if success:

"errcode":   0,
"errmsg":    "ok",
"short_url": "http:\/\/w.url.cn\/s\/AvCo6Ih"

Response if failure:

"errcode": 40013,
"errmsg":  "invalid appid"



25
26
27
28
29
30
31
32
33
34
35
# File 'lib/wechat/core/tiny_link.rb', line 25

def self.create(access_token, link)

  assert_present! :access_token, access_token
  assert_present! :link,         link

  post_json "https://api.weixin.qq.com/cgi-bin/shorturl?access_token=#{access_token}", body:
    {
      action:   'long2short',
      long_url: link
    }
end