Skip to content

Commit

Permalink
Add wxa_msg_sec_check
Browse files Browse the repository at this point in the history
  • Loading branch information
Eric-Guo committed Sep 2, 2020
1 parent eaecdfb commit 46e8e13
Show file tree
Hide file tree
Showing 4 changed files with 22 additions and 1 deletion.
5 changes: 5 additions & 0 deletions bin/wechat
Original file line number Diff line number Diff line change
Expand Up @@ -225,6 +225,11 @@ class App < Thor
puts 'WXA Code File downloaded'
end

desc 'wxa_msg_sec_check [CONTENT]', '检查一段文本是否含有违法违规内容。'
def wxa_msg_sec_check(content)
puts wechat_api.wxa_msg_sec_check(content)
end

desc 'media_uploadnews [MPNEWS_YAML_PATH]', '上传图文消息素材'
def media_uploadnews(mpnews_yaml_path)
mpnew = YAML.load(File.read(mpnews_yaml_path))
Expand Down
2 changes: 1 addition & 1 deletion lib/wechat/api_base.rb
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ class ApiBase

API_BASE = 'https://api.weixin.qq.com/cgi-bin/'
MP_BASE = 'https://mp.weixin.qq.com/cgi-bin/'
WXA_BASE = 'https://api.weixin.qq.com/wxa/'
WXA_BASE = 'https://api.weixin.qq.com/wxa/'
OAUTH2_BASE = 'https://api.weixin.qq.com/sns/'
DATACUBE_BASE = 'https://api.weixin.qq.com/datacube/'
QYAPI_BASE = 'https://qyapi.weixin.qq.com/cgi-bin/'
Expand Down
4 changes: 4 additions & 0 deletions lib/wechat/concern/common.rb
Original file line number Diff line number Diff line change
Expand Up @@ -106,6 +106,10 @@ def wxa_create_qrcode(path, width = 430)
post 'wxaapp/createwxaqrcode', JSON.generate(path: path, width: width)
end

def wxa_msg_sec_check(content)
post 'msg_sec_check', JSON.generate(content: content), base: Wechat::Api::WXA_BASE
end

def menu
get 'menu/get'
end
Expand Down
12 changes: 12 additions & 0 deletions spec/lib/wechat/api_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -326,6 +326,18 @@
end
end

describe '#wxa_msg_sec_check' do
msg_sec_check_result = { errcode: 87014, errmsg: 'risky content' }

specify 'will post wxa_msg_sec_check with risky content' do
risky_content = '特3456书yuuo莞6543李zxcz蒜7782法fgnv级'
expect(subject.client).to receive(:post)
.with('msg_sec_check', JSON.generate(content: risky_content),
params: { access_token: 'access_token' }, base: Wechat::Api::WXA_BASE).and_return(msg_sec_check_result)
expect(subject.wxa_msg_sec_check(risky_content)).to eq msg_sec_check_result
end
end

describe '#menu' do
specify 'will get menu/get with access_token' do
menu_result = 'menu_result'
Expand Down

0 comments on commit 46e8e13

Please sign in to comment.