Class: Wechat::Core::TinyLink

Inherits:
Object
  • Object
show all
Extended by:
Common
Defined in:
lib/wechat/core/tiny_link.rb

Overview

Tiny Link 是短链接的远程调用封装类。

Constant Summary

Constants included from Common

Common::ERROR_CODES, Common::LANGUAGE_ENGLISH, Common::LANGUAGE_SIMPLIFIED_CHINESE, Common::LANGUAGE_TRANDITIONAL_CHINESE

Class Method Summary collapse

Methods included from Common

assert_present!, get_json, post_json

Class Method Details

.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