Skip to content

Commit

Permalink
init
Browse files Browse the repository at this point in the history
  • Loading branch information
liaoque committed Oct 8, 2019
0 parents commit 4f94405
Show file tree
Hide file tree
Showing 10 changed files with 673 additions and 0 deletions.
136 changes: 136 additions & 0 deletions addUUid.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,136 @@
require "spaceship"
require 'openssl'
require "mysql2"
require 'pathname'
require Pathname.new(File.dirname(__FILE__)).realpath.to_s + '/mysqlConfig'
require Pathname.new(File.dirname(__FILE__)).realpath.to_s + '/globalConfig'

#参考 https://github.com/fastlane/fastlane/blob/master/spaceship/docs/DeveloperPortal.md

apuid = ARGV[0].to_s;
username = ARGV[1].to_s;
password = ARGV[2].to_s;
uuid = ARGV[3].to_s;
bundleId = ARGV[4].to_s + '_' + apuid;


mobileprovision = '/sign.mobileprovision'

begin
# 绝对路径
cert_content = ARGV[2];
p12_path = GlobalConfig::ROOT_KEY + '/' + ARGV[3].to_s;

Spaceship::Portal.login(username, password)

#添加 bundleId
app = Spaceship::Portal.app.find(bundleId)
if !app
app = Spaceship::Portal.app.create!(bundle_id: bundleId, name: bundleId)
end

# 获取所有证书
certificates = Spaceship::Portal.certificate.all

if certificates.empty?
raise "证书为空"
end

# 连接mysql
client = Mysql2::Client.new(
:host => MysqlConfig::HOST, # 主机
:username => MysqlConfig::USER, # 用户名
:password => MysqlConfig::PASSWORD, # 密码
:database => MysqlConfig::DBNAME, # 数据库
:encoding => MysqlConfig::CHARSET # 编码
)

#如果uuid不存在则添加uuid
if !Spaceship::Portal.device.find_by_udid(uuid)
Spaceship::Portal.device.create!(name:uuid, udid: uuid)

#更新设备数量
deviceLength = Spaceship::Portal.device.all.length
client.query("update apple_developer set uuid_num = '#{deviceLength}' where apuid = '#{apuid}'")

end

adHocAll = Spaceship.provisioning_profile.ad_hoc.all
if adHocAll.empty?
#ad_hoc 不存在

#通过数据库 查询 证书id
results = client.query("SELECT certificate_id FROM apple_developer_cer where apuid = '#{apuid}' limit 1")
if !results.any?
raise "证书 不存在, 请先上传或者创建证书"
end


certificateObj = results.first

cert = Spaceship::Portal.certificate.production.find(certificateObj['certificate_id'])
if !cert
raise "证书#{certificateObj['id']} 不存在"
end


#创建 ad_hoc
profile = Spaceship::Portal.provisioning_profile.ad_hoc.create!(bundle_id: bundleId, certificate: cert, name: username)
end

devices = Spaceship.device.all
Spaceship.provisioning_profile.ad_hoc.all.each do |p|
# 根据cert 证书创建
#更新 ad_hoc
p.devices = devices
p.update!
end

# profile 写到对应的文件夹,以便更新
c_time = #{Time.now.strftime("%Y-%m-%d %H:%M:%S")}
Spaceship.provisioning_profile.ad_hoc.all.each do |p|
# 根据cert 证书创建

certificateId = p.certificates.first.id
mobileprovision = '/applesign/' + username + '/' + certificateId + mobileprovision
keyPath = GlobalConfig::ROOT_KEY + '/applesign/' + username + '/' + certificateId
system "mkdir -p #{keyPath}"
system "chmod 777 #{keyPath}"

# File.open(GlobalConfig::ROOT_KEY + mobileprovision,"a+") do |f|
# f.puts p.download
# end

File.write(GlobalConfig::ROOT_KEY + mobileprovision, p.download)

# 保存uuid
uUser = client.query("SELECT id FROM apple_developer_uuid WHERE uuid= '#{uuid}'")
if uUser.any?
client.query("update apple_developer_uuid set apuid = '#{apuid}' where uuid = '#{uuid}' ")
else
client.query("insert into apple_developer_uuid (apuid,uuid,c_time)values('#{apuid}', '#{uuid}', '#{c_time}')")
end

# 保存mobileprovision
# uUser = client.query("SELECT id FROM apple_developer_mobileprovision WHERE build_id= '#{bundleId}' and certificate_id = '#{certificateId}'")
mobileProvisionObj = client.query("SELECT id FROM apple_developer_mobileprovision WHERE certificate_id = '#{certificateId}'")

if mobileProvisionObj.any?
client.query("update apple_developer_mobileprovision set mobileprovision = '#{mobileprovision}' where certificate_id = '#{certificateId}' and build_id= '#{bundleId}'")
else
client.query("insert into apple_developer_mobileprovision (apuid, certificate_id, build_id, mobileprovision, c_time)values('#{apuid}', '#{certificateId}', '#{bundleId}', '#{mobileprovision}', '#{c_time}')")
end
end

rescue Exception => e
puts "Trace message: #{e}"
else
puts "Success message: uuid添加成功"
ensure
# 断开与服务器的连接
client.close if client
end




57 changes: 57 additions & 0 deletions checkLogin.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
require "spaceship"
require "mysql2"

require 'pathname'
require Pathname.new(File.dirname(__FILE__)).realpath.to_s + '/mysqlConfig'

username = ARGV[0]
pwd = ARGV[1]

begin

thr = Thread.new{ Spaceship::Portal.login(username, pwd) }



#定时检查
for i in 0..11
sleep 5

# 检查 线程是否在运行
case thr.status
when false
# 正常退出 更新数据库
client = Mysql2::Client.new(
:host => MysqlConfig::HOST, # 主机
:username => MysqlConfig::USER, # 用户名
:password => MysqlConfig::PASSWORD, # 密码
:database => MysqlConfig::DBNAME, # 数据库
:encoding => MysqlConfig::CHARSET # 编码
)

# client.query("update kxwweb.apple_dever set checked = 1 where user = #{username}")
break
when nil
raise "验证错误:退出"
break
else
puts Time.new
end
end

if thr.status
#强制结束线程
thr.exit
raise "验证手机号超时"
end
rescue Exception => e
puts "Trace message: #{e.message}"
else
puts "Success message: uuid添加成功"
ensure
# 断开与服务器的连接
client.close if client
end



13 changes: 13 additions & 0 deletions getCertificateId.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
#!/usr/bin/ruby
## -*- coding: UTF-8 -*-
# 运行方式 ruby getCertificateId.rb username password


require "spaceship"

username = ARGV[0];
password = ARGV[1];

Spaceship.login(username, password)
devices = Spaceship::Portal.certificate.production.all
puts devices
13 changes: 13 additions & 0 deletions globalConfig.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
module GlobalConfig

ROOT = '/'
ROOT_P12 = '/'
ROOT_KEY = '/'
ROOT_IMG_PATH = 'https://img.xxx.com'




end


9 changes: 9 additions & 0 deletions mysqlConfig.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
module MysqlConfig

HOST = ''
DBNAME = ''
USER = ''
PASSWORD = ''
CHARSET = ''

end
61 changes: 61 additions & 0 deletions readme.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,61 @@
### 超级签解决方案
#### 该解决方案不支持手机验证码自动验证,所以使用带有短信验证码的开发者帐号时, 先执行 `checkLogin.rb 开发者帐号 开发者密码` 手动填写一次验证码, 下次就不需要在输入了

##### 文件说明
> addUUid.rb 增加设备号, 增加 Bundle id 生成 设备授权文件 mobileprovision
> checkLogin.rb 检查苹果帐号 是否可以正常登录
> getCertificateId.rb 获取苹果账号下的 描述文件
> globalConfig.rb 路径相关的基本配置
> MysqlConfig.rb 相关mysql配置
> saveCert.rb 根据p12 文件,生成相对应的 私钥和证书
> signIpa.rb 重新签名 ipa包
> signMobileConfig.rb 签名 mobileconfig 用来获取用户设备码

##### 执行步骤
1. 执行 checkLogin
2. 保存 saveCert p12
3. 添加 addUUid 且更新 profile
4. 签名 signIpa

##### 注意
1. certificate_pem key_pem 所使用的的p12文件 必须和 mobileprovision的cer签名文件一致, 否则重新签名后也无法使用
2. 最好是由脚本创建这样就不会有以上这个问题
3. 如果需手动上传p12, 需要保证 两者一致,如果有误 请手动把 certificate_id 调整正确
4. getCertificateId.rb 该脚本可查看 certificate_id


##### 环境安装
> 服务器系统版本 centos 7.2
```shell
wget https://cache.ruby-lang.org/pub/ruby/2.6/ruby-2.6.4.tar.gz
tar -zxvf ruby-2.6.4.tar.gz
cd ruby-2.6.4
./configure --prefix=/usr/local/ruby-2.6.4
make && make install

ln -s /usr/local/ruby-2.6.4/bin/ruby /usr/bin/ruby
ln -s /usr/local/ruby-2.6.4/bin/gem /usr/bin/gem

gem install fastlane
gem install pry
gem install spaceship
gem install pry-coolline
gem install rails
gem install dbi
gem install mysql2
gem install dbd-mysql

yum install zip

python 2.7的环境, 不能是3.0的环境
pip install isign 不能使用这个安装
请使用
git clone https://github.com/apperian/isign
sh version.sh
python setup.py build
python setup.py install

```
更详细的请看: https://blog.csdn.net/LiaoQuesg/article/details/101219984

Loading

0 comments on commit 4f94405

Please sign in to comment.