Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add new api & Compatible with WeCom #317

Merged
merged 1 commit into from
Jul 28, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions lib/wechat/concern/common.rb
Original file line number Diff line number Diff line change
Expand Up @@ -88,6 +88,11 @@ def message_mass_get(msg_id)
post 'message/mass/get', JSON.generate(msg_id: msg_id)
end

def wxa_get_user_phone_number(code)
# https://developers.weixin.qq.com/miniprogram/dev/OpenApiDoc/user-info/phone-number/getPhoneNumber.html
post 'business/getuserphonenumber', JSON.generate(code: code), base: Wechat::Api::WXA_BASE
end

def wxa_get_wxacode(path, width = 430)
post 'getwxacode', JSON.generate(path: path, width: width), base: Wechat::Api::WXA_BASE
end
Expand Down
5 changes: 5 additions & 0 deletions lib/wechat/corp_api.rb
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,11 @@ def initialize(appid, secret, token_file, agentid, network_setting, jsapi_ticket
@qcloud = nil
end

def get_externalcontact(external_userid, cursor = nil)
# https://developer.work.weixin.qq.com/document/path/92114
get 'externalcontact/get', params: { external_userid: external_userid, cursor: cursor }
end

def agent_list
get 'agent/list'
end
Expand Down
3 changes: 3 additions & 0 deletions lib/wechat/helpers.rb
Original file line number Diff line number Diff line change
Expand Up @@ -27,8 +27,11 @@ def wechat_config_js(config_options = {})
page_url = page_url.split('#').first
js_hash = api.jsapi_ticket.signature(page_url)

# Field `beta` please check https://developer.work.weixin.qq.com/document/path/90514#%E6%AD%A5%E9%AA%A4%E4%BA%8C%EF%BC%9A%E9%80%9A%E8%BF%87config%E6%8E%A5%E5%8F%A3%E6%B3%A8%E5%85%A5%E6%9D%83%E9%99%90%E9%AA%8C%E8%AF%81%E9%85%8D%E7%BD%AE

config_js = <<~WECHAT_CONFIG_JS
wx.config({
beta: #{config_options[:beta]},
debug: #{config_options[:debug]},
appId: "#{app_id}",
timestamp: "#{js_hash[:timestamp]}",
Expand Down
25 changes: 25 additions & 0 deletions spec/lib/wechat/api_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -939,4 +939,29 @@
expect(subject.translatecontent('xxxxxxxx')).to eq response_result
end
end

describe '#wxa_get_user_phone_number' do
specify 'will post code with access_token to get user phone number' do
response_result = {
errcode: 0,
errmsg: 'ok',
phone_info: {
phoneNumber: '',
purePhoneNumber: '',
countryCode: '',
watermark: {
timestamp: 0,
appid: ''
}
}
}
expect(subject.client).to receive(:post)
.with('business/getuserphonenumber', JSON.generate(code: 'xxxxxxxx'),
hash_including(params: { access_token: 'access_token', }, base: Wechat::Api::WXA_BASE))
.and_return(response_result)
expect(subject.wxa_get_user_phone_number('xxxxxxxx')).to eq response_result
end

end

end
18 changes: 18 additions & 0 deletions spec/lib/wechat/corp_api_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -577,4 +577,22 @@
end
end

describe '#get_externalcontact' do
specify 'use get method and params external_userid and cursor to externalcontact data' do
externalcontact_data = {
errcode: 0,
errmsg: 'ok',
external_contact: {}
}

expect(subject.client).to receive(:get)
.with('externalcontact/get',
hash_including(params: { access_token: 'access_token',
external_userid: 'external_userid',
cursor: 'xxx',
})).and_return(externalcontact_data)
expect(subject.get_externalcontact('external_userid','xxx')).to eq externalcontact_data
end
end

end