银联账单接口Ruby SDK
提供此版SDK,方便用户调用银联账单服务接口
安装
Add this line to your application's Gemfile:
gem 'unp_smart'
And then execute:
$ bundle
Or install it yourself as:
$ gem install unp_smart
配置
在项目下增加config/unp_smart.yml文件
development:
account: ''
secret_key: ''
server: 'https://data.unionpaysmart.com'
debug: true
verbose: false
raw_response: true
- account 账单服务账号
- secret_key 私钥
- server 账单服务地址
- debug 是否开始debug模式
- verbose 是否开始verbose模式
- raw_response 是否解析返回结果
使用
在项目中使用
UnpSmart.get path,params,&block
UnpSmart.post path,params,&block
支持 post or get,根据官方文档选择即可,接受两个参数
- 请求的接口 此接口可以从官方文档中得到
- 业务参数
如:
UnpSmart.get '/merchant/queryName',{mName: '巴黎春天'}
如果只关心返回成功结果,可以将配置参数raw_response设置为false,那么将返回两个值
- 第一个为接口是否请求成功,true or false
- 第二个为请求的内容,如果失败为失败信息
在终端中使用
为了方便用户使用或调试,还提供了命令行的工具,按如下方式执行
unpsmart [get/post] api_path key1 value1 key2 value2 [...]
前面的get或post可以省略,默认为get如
unpsmart get merchant/queryName mName 巴黎春天
参数按key value传递即可,如果使用终端并且当前目录没有config/unp_smart.yml文件,程序会尝试加载用户目录下的.unp_smart.yml,如果没有您可以新建一个
curl https://raw.githubusercontent.com/unpsmart/ruby-sdk/master/config/unp_smart.yml > ~/.unp_smart.yml
然后编辑这个文件即可
Contributing
- Fork it ( https://github.com/unpsmart/ruby-sdk/fork )
- Create your feature branch (
git checkout -b my-new-feature
) - Commit your changes (
git commit -am 'Add some feature'
) - Push to the branch (
git push origin my-new-feature
) - Create a new Pull Request