Class: WxOpendata::Service
- Inherits:
-
Object
- Object
- WxOpendata::Service
- Defined in:
- lib/wx_opendata/service.rb
Instance Attribute Summary collapse
-
#content_type ⇒ Object
Returns the value of attribute content_type.
Instance Method Summary collapse
-
#create_activity_id(token) ⇒ Object
创建被分享动态消息的 activity_id.
-
#create_wx_aqrcode(token, params = {}) ⇒ Object
获取小程序二维码,适用于需要的码数量较少的业务场景.
-
#get_wx_acode(token, params = {}) ⇒ Object
获取小程序码,适用于需要的码数量较少的业务场景.
-
#get_wx_acode_unlimit(token, params = {}) ⇒ Object
获取小程序码,适用于需要的码数量极多的业务场景。通过该接口生成的小程序码,永久有效,数量暂无限制。.
-
#img_sec_check ⇒ Object
校验一张图片是否含有违法违规内容.
-
#msg_sec_check(token, content) ⇒ Object
检查一段文本是否含有违法违规内容.
-
#send_template_message(token, params) ⇒ Object
发送模板消息.
-
#send_uniform_message ⇒ Object
下发小程序和公众号统一的服务消息.
Instance Attribute Details
#content_type ⇒ Object
Returns the value of attribute content_type.
8 9 10 |
# File 'lib/wx_opendata/service.rb', line 8 def content_type @content_type end |
Instance Method Details
#create_activity_id(token) ⇒ Object
创建被分享动态消息的 activity_id
48 49 50 51 52 53 |
# File 'lib/wx_opendata/service.rb', line 48 def create_activity_id(token) url = "cgi-bin/message/wxopen/activityid/create?access_token=#{token}" jsondata = get(url) raise ServiceNotAvailableError if jsondata['errcode'] != 0 jsondata['activity_id'] end |
#create_wx_aqrcode(token, params = {}) ⇒ Object
获取小程序二维码,适用于需要的码数量较少的业务场景
56 57 58 59 60 61 62 63 64 |
# File 'lib/wx_opendata/service.rb', line 56 def create_wx_aqrcode(token, params = {}) url = "cgi-bin/wxaapp/createwxaqrcode?access_token=#{token}" path = params[:path] || 'pages/index/main' width = params[:width] || 430 p = { path: path, width: width } data = post(url, p) raise InvalidCredentialError if data['errcode'] == 45029 tmpfile(data) end |
#get_wx_acode(token, params = {}) ⇒ Object
获取小程序码,适用于需要的码数量较少的业务场景
67 68 69 70 71 72 73 74 75 76 77 78 |
# File 'lib/wx_opendata/service.rb', line 67 def get_wx_acode(token, params = {}) url = "wxa/getwxacode?access_token=#{token}" path = params[:path] || 'pages/index/main' width = params[:width] || 430 auto_color = params[:auto_color] || false line_color = params[:line_color] || {"r": 0,"g": 0,"b": 0} is_hyaline = params[:is_hyaline] || true p = { path: path, width: width, auto_color: auto_color, line_color: line_color, is_hyaline: is_hyaline } data = post(url, p) raise InvalidCredentialError if data['errcode'] == 45029 tmpfile(data) end |
#get_wx_acode_unlimit(token, params = {}) ⇒ Object
获取小程序码,适用于需要的码数量极多的业务场景。通过该接口生成的小程序码,永久有效,数量暂无限制。
81 82 83 84 85 86 87 88 89 90 91 92 93 |
# File 'lib/wx_opendata/service.rb', line 81 def get_wx_acode_unlimit(token, params = {}) url = "wxa/getwxacodeunlimit?access_token=#{token}" scene = params[:scene] || 'api' page = params[:page] || 'pages/index/main' width = params[:width] || 430 auto_color = params[:auto_color] || false line_color = params[:line_color] || {"r": 0,"g": 0,"b": 0} is_hyaline = params[:is_hyaline] || true p = { scene: scene, page: page, width: width, auto_color: auto_color, line_color: line_color, is_hyaline: is_hyaline } data = post(url, p) raise InvalidCredentialError if data['errcode'] == 45009 || data['errcode'] == 41030 tmpfile(data) end |
#img_sec_check ⇒ Object
校验一张图片是否含有违法违规内容
44 45 |
# File 'lib/wx_opendata/service.rb', line 44 def img_sec_check end |
#msg_sec_check(token, content) ⇒ Object
检查一段文本是否含有违法违规内容
35 36 37 38 39 40 41 |
# File 'lib/wx_opendata/service.rb', line 35 def msg_sec_check(token, content) url = "wxa/msg_sec_check?access_token=#{token}" p = { content: content } jsondata = post(url, p) return true if jsondata['errcode'] == 0 return false if jsondata['errcode'] == 87014 end |
#send_template_message(token, params) ⇒ Object
发送模板消息
11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 |
# File 'lib/wx_opendata/service.rb', line 11 def (token, params) raise InvalidParametersError unless params[:touser] && params[:template_id] && params[:form_id] url = "cgi-bin/message/wxopen/template/send?access_token=#{token}" touser = params[:touser] template_id = params[:template_id] form_id = params[:form_id] page = params[:page] || 'pages/index/main' data = params[:data] || { keyword1: { value: 'Test Message Template' } } emphasis_keyword = params[:emphasis_keyword] || "" p = { touser: touser, template_id: template_id, form_id: form_id, page: page, data: data, emphasis_keyword: emphasis_keyword } jsondata = post(url, p) begin raise ErrCodeError, 'template_id不正确' if jsondata['errcode'] == 40037 raise ErrCodeError, 'form_id不正确,或者过期' if jsondata['errcode'] == 41028 raise ErrCodeError, 'form_id已被使用' if jsondata['errcode'] == 41029 raise ErrCodeError, 'page不正确' if jsondata['errcode'] == 41030 raise ErrCodeError, '接口调用超过限额(目前默认每个帐号日调用限额为100万)' if jsondata['errcode'] == 45009 jsondata['errcode'] == 0 rescue ErrCodeError => e p "#{e.class}: #{e.}" end end |
#send_uniform_message ⇒ Object
下发小程序和公众号统一的服务消息
96 97 |
# File 'lib/wx_opendata/service.rb', line 96 def end |