Skip to content

renyijiu/alipay_mini

Repository files navigation

Gem Version Maintainability

English

AlipayMini

一个非官方的支付宝小程序相关的gem包。

由于官方未提供Ruby版本的服务端SDK,所以对于小程序开放的接口进行Ruby版本的封装。

安装

在Gemfile中添加下列命令:

gem 'alipay_mini', '~> 0.1.0'

执行下列命令:

$ bundle

或者通过命令行安装gem:

$ gem install alipay_mini

使用

Config配置

首先配置的初始选项

AlipayMini.configure do |c|
   c.private_key = "your own private key generate by alipay"
   c.public_key = "the alipay's public key"
   c.url = "the alipay api url"
   c.app_id = "your own app_id"
end

注意⚠️: public_key 为支付宝官方的公钥,不要填错了!!!

示例:

AlipayMini.configure do |c|
  c.private_key = "MIIEogIBAAKCAQEA0J12pYTGu5y6uWv06/vso4EZkmh9s51hbV4TiM9K99x4bz/mn8+6mRXCxooGvWqtU4xM7sYx+GE3EE4JX3Zxzzg7c/SUbzMC3GwIAO05U6R5dANBsBsl9GZ95EdPKKmxklM1Sa8IdeWNJkU9UJ9zXHHm35bzvVyfG3ava0Kp2pfKHskAfiqtOV5WEkwY3dAyqa2URHm182A0dUyCGXDeeTmbJ0VDXoAHdlNzhdHiH1hJtzSeJ9ouI6tY6lBcfII/ywvLF83a7GWUGFyBoV724xIBsBPc/bHCK2rlRdAqr7dyILHubetHtzs/6RT4OHjvnPTNbHemtWQrOXcVk4DpJQIDAQABAoIBAHEqKfVpzGBzibsR+/+TXm/nlVadhirMIdCxKsmZIWLJXy+CK3nftqpaaplGwJc56iIbRpR0QSEqozMeEemOF/i/2UhykZ6svk2R8NmH1gQwgY3UQmrknzcv7fTKVf+J5gCpUIvS/jTuPB5ZiwRUKsEoLIR3n2rGdqzwOgJmXDtuBpjqxfFDE2tS8hMx2xwBmN5xabUbAv897uci6Bw/J+p3C8xADMKOJvUqkoTz1V0zXJIJ0DA3yIo0SakZ8iGu5P8x1VPBccSO3LQIfX1xS7lsFk3lq1VED918/KKnJvwvF8moyKJEo4UgeKoDgJiYjMmIob2mj/bL+IJQR2vJN8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Jlowm9us8YgHranx+O1vR8olgVTdhjOub9QD/tK7ok1GWSw/dBFpcG9WTuKnPrklMIBxUllIONciH+7KGX+Yhs0zLTEPRufATAy1slIC8NhoBSxSB0PRsix4/gVCw4IAIzGPspdRPA0ZCeJPrjGvuBh9215lNpv0+ew6/a/x3db0ZIVDzLrzyQIDAQAB"
  c.app_id = "2015102700040153"
  c.url = "https://openapi.alipaydev.com/gateway.do"
end

API

# when grant_type is 'authorization_code', code is the auth_code
# when grant_type is 'refresh_token', code is the refresh_token
#
# @param grant_type String - 'authorization_code', 'refresh_token'
# @param code String - auth_code or refresh_token
#
# @return Array - [flag<Boolean>, res<Hash>] flag: request status, res: response hash
#
# Example:
#   AlipayMini.system_oauth_token('authorization_code', 'helloworld')
#

AlipayMini.system_oauth_token(grant_type, code)
# @param access_token String
#
# @return Array [flag<Boolean>, res<Hash>]
#
# Example:
#   AlipayMini.user_info_share("helloworld")
#

AlipayMini.user_info_share(access_token)

Response

# flag: request state, true is success, false means the request error
#
# Example:
#   AlipayMini.system_oauth_token('authorization_code', 'helloworld')
#
# Return:
#   [true,  {"access_token" => "12345", "alipay_user_id" => "12345", "expires_in" => 1296000, "re_expires_in" => 2592000, "refresh_token" => "12345", "user_id"=> "12345"}]
#   
#   [false, {"code" => "40002", "msg" => "Invalid Arguments", "sub_code" => "isv.code-invalid", "sub_msg" => "授权码code无效"}]]	
# 

进度

已完成

  1. 换取授权访问令牌(alipay.user.info.share)
  2. 支付宝会员授权信息查询接口(alipay.user.info.share)

如何贡献

  1. Fork it
  2. Create your feature branch (git checkout -b my-new-feature)
  3. Commit your changes (git commit -am 'Add some feature')
  4. Push to the branch (git push origin my-new-feature)
  5. Create new Pull Request

欢迎贡献相关代码或是提交你的使用反馈👏,另外请记得为你的代码编写测试。

Releases

No releases published

Packages

No packages published