Class: IAPServer::Order
- Inherits:
-
Object
- Object
- IAPServer::Order
- Defined in:
- lib/iap/order.rb
Instance Method Summary collapse
- #get_inputs(options, args) ⇒ Object
- #input(message) ⇒ Object
- #run(options, args) ⇒ Object
-
#validation_jwt(resp) ⇒ Object
验证jwt.
Instance Method Details
#get_inputs(options, args) ⇒ Object
17 18 19 20 21 |
# File 'lib/iap/order.rb', line 17 def get_inputs(, args) order_num = args.first || self.input('put order-num: ') return order_num end |
#input(message) ⇒ Object
23 24 25 26 |
# File 'lib/iap/order.rb', line 23 def input() print "#{}".red STDIN.gets.chomp.strip end |
#run(options, args) ⇒ Object
7 8 9 10 11 12 13 14 15 |
# File 'lib/iap/order.rb', line 7 def run(, args) # get the command line inputs and parse those into the vars we need... order_num = get_inputs(, args) raise "必须有订单号。".red if order_num.nil? || order_num.empty? req = IAPServer::StoreRequest.new resp = req.request("/inApps/v1/lookup/#{order_num}", IAPServer::JWTTools.generate) validation_jwt(resp) end |
#validation_jwt(resp) ⇒ Object
验证jwt
29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 |
# File 'lib/iap/order.rb', line 29 def validation_jwt(resp) puts 'Code = ' + resp.code ##请求状态码 puts 'Message = ' + resp. if resp.code == '200' body = JSON.parse(resp.body) status = body["status"] if !status.nil? && status == 0 jwt_list = body["signedTransactions"] jwt_token = jwt_list[0] if IAPServer::JWTTools.good_signature(jwt_token) payload = IAPServer::JWTTools.payload(jwt_token) puts "Payload:" + payload result = JSON.parse(payload) purchaseDate = result["purchaseDate"] puts "支付时间:#{Time.at(purchaseDate/1000)}" else puts "JWT 验证失败" end elsif status == 1 puts "status:#{status},查询失败。可能的原因:jwt签名正确,bundleid不一致" else puts "status:#{status},请排查错误原因" end end end |