我使用Stripe和sinatra以及支持json的ruby脚本在iOS上为信用卡收费。这种充电方式适用于iphone6模拟器,但不适用于运行9.3.5的iPad迷你设备。
htpp://192.168.1.11
但它还是会出错。我甚至试过
http://192.168.1.11:4567
//original baseURL for the app
enum Constants {
...
static let baseURLString = "http://localhost:4567"
...
}
iPhone6模拟器
iPad mini 9.3.5版
platform :ios, '9.0'
target 'RWPuppies' do
use_frameworks!
pod 'Alamofire', '~> 4.5'
pod 'AlamofireImage', '~> 3.3'
pod 'Stripe'
pod 'Cards'
end
Ruby脚本
#1
require 'sinatra'
require 'stripe'
require 'json'
#2
Stripe.api_key = 'YOUR_TEST_SECRET_KEY'
#3
get '/' do
status 200
return "RWPuppies back end has been set up correctly"
end
#4
post '/charge' do
#5
payload = params
if request.content_type.include? 'application/json' and params.empty?
payload = indifferent_params(JSON.parse(request.body.read))
end
begin
#6
charge = Stripe::Charge.create(
:amount => payload[:amount],
:currency => payload[:currency],
:source => payload[:token],
:description => payload[:description]
)
#7
rescue Stripe::StripeError => e
status 402
return "Error creating charge: #{e.message}"
end
#8
status 200
return "Charge successfully created"
end
解决了的:
-
打开我的项目信息列表并添加了一个名为NSAppTransportSecurity的密钥作为字典。添加了一个名为NSAllowsArbitraryLoads的子键作为Boolean,并将其值设置为YES
How do I load an HTTP URL with App Transport Security enabled in iOS 9?
-
将baseURLString设置为
-
从终端运行脚本
ruby web.rb -o 0.0.0.0
Cannot access local Sinatra server from another computer on same network