[IOS 推送] 迅速生成APNS证书,省去敲代码的时间

http://www.cocoachina.com/bbs/read.php?tid=136667&keyword=APNS


首先是手动的部分:
1.从Apple下了开发和上线的密钥后, 导出保存到XX文件夹.
2. 开发的密钥命名为cert_dev.p12, 上线的密钥命名为cert.p12.
3. 个人开发密钥导出命名为key.p12.

然后
4. 命令行进入XX的上级菜单.
5. sudo ./apns.sh XX YY (其中YY为你想要的生成证书的前缀 比如foo.pem和foo_dev.pem)

Done

接下来要研究一下如何用命令行导出APNS密钥.


apns.sh

?
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
#!/usr/bin/expect -f
#########################################
# batch rename                          #
# Input  :    $1 folder  #
#                  eg:XX          #
# Input  :    $2 prefix       #
#                  eg:YY  #
 
#########################################
set path [lindex $argv 0]
set prefx [lindex $argv 1]
 
spawn sh ./ck.sh $path "cert.p12" "key.p12" ${prefx}.pem
expect "Enter PEM pass phrase:"
send "12345\n"
expect "Verifying - Enter PEM pass phrase:"
send "12345\n"
expect eof
 
spawn sh ./ck.sh $path "cert_dev.p12" "key.p12" ${prefx}_dev.pem
expect "Enter PEM pass phrase:"
send "12345\n"
expect "Verifying - Enter PEM pass phrase:"
send "12345\n"
expect eof
exit


ck.sh

?
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
#!/bin/bash
#########################################
# batch rename                          #
# Input  :    $1 folder  #
#                  eg: XX          #
# Input  :    $2 cert.p12       #
#                  eg:cert.p12  #
# Input  :    $3 key.p12       #
#                  eg:key.p12  #
#########################################
 
cd $1
 
cert=$2
key=$3
o_pem=$4
 
o_cert=$cert ".pem"
 
o_key=$key ".pem"
 
if [ ! -f $cert ]; then
     echo "Cant find cert.p12"
     exit
fi
 
if [ ! -f $key ]; then
     echo "Cant find key.p12"
     exit
fi
 
if [ ! $o_pem ]; then
     echo "Please enter the name for output key"
     exit ;
fi
 
openssl pkcs12 -clcerts -nokeys -out $o_cert - in $cert -passin pass:
echo "1"
openssl pkcs12 -nocerts -out $o_key - in $key -passin pass:
echo "2"
openssl rsa - in $o_key -out $o_key -passin pass:12345
echo "3"
cat $o_cert $o_key > $o_pe rm
rm -f $o_ce rm
rm -f $o_k ls
ls $o_p cd
cd exit xit



你可能感兴趣的:([IOS 推送] 迅速生成APNS证书,省去敲代码的时间)