-
Notifications
You must be signed in to change notification settings - Fork 6
/
iapTool.rb
162 lines (110 loc) · 2.88 KB
/
iapTool.rb
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
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
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
require 'spaceship'
require 'csv'
Spaceship::Tunes.login("")
app = Spaceship::Application.find("")
# 批量修改被打回的商品
def modify_iap_demo(app = nil, filePath, str)
#解析csv得到内购商品
p_array = parase_csv_file(filePath)
for mode in p_array do
puts "正在修改商品 #{mode}"
purch = app.in_app_purchases.find(mode["id"])
e = purch.edit
e.versions = {
'zh-CN': {
name: mode["name"],
description: mode["describe"] + str
}
}
e.save!
puts "修改成功"
end
end
# 批量创建商品
def create_iap(app = nil, iapMode)
iapType = get_correct_iapType(iapMode["type"])
tier = get_correct_price(iapMode["price"])
product_name = iapMode["name"]
product_id = iapMode["id"]
description = iapMode["describe"]
puts "正在上传商品 #{iapMode}"
app.in_app_purchases.create!(
type: iapType,
versions: {
'zh-CN': {
name: product_name,
description: description
}
},
reference_name: product_name,
product_id: product_id,
cleared_for_sale: true,
review_notes: " ",
review_screenshot: "",
pricing_intervals:
[
{
country: "WW",
begin_date: nil,
end_date: nil,
tier: tier
}
]
)
puts "上传成功"
end
# 获取到对应的商品类型
def get_correct_iapType(type)
if type == "消耗品"
return Spaceship::Tunes::IAPType::CONSUMABLE
elsif type == "非消耗品"
return Spaceship::Tunes::IAPType::NON_CONSUMABLE
elsif type == "非自动续订"
return Spaceship::Tunes::IAPType::NON_RENEW_SUBSCRIPTION
elsif type == "自动续订"
return Spaceship::Tunes::IAPType::RECURRING
end
end
# 获取到对应的商品价格登记
def get_correct_price(price)
# 分割字符串 去除价格中所带的tier
tier = price.gsub("Tier", "")
return tier.strip
end
# 解析 csv 文件,返回 商品信息 数组
def parase_csv_file(filePath)
#数组用于存放解析过后的商品对象
m_array = []
#按行读取csv文件,并存放到数组中
CSV.foreach(filePath, headers:true) do |row|
#hash 对象,用于存放每一个商品的信息
m_map = Hash.new
# 获取所需数据
m_productName = row[1]
m_productID = row[2]
m_type = row[3]
m_price = row[4]
m_describe = row[5]
# key-value 设置
m_map["name"] = m_productName
m_map["id"] = m_productID
m_map["type"] = m_type
m_map["price"] = m_price
m_map["describe"] = m_describe
m_array << m_map
end
return m_array
end
# 开始创建ipa商品
def create_iap_demo(app = nil, filePath)
#解析csv得到内购商品
p_array = parase_csv_file(filePath)
#遍历创建商品
mode = Hash.new
for mode in p_array do
create_iap(app, mode)
end
end
# 执行
create_iap_demo(app, '')
modify_iap_demo(app, '', '。')