蘋果企業(yè)證書現在已經無法申請購買,企業(yè)大多數都在使用第三方簽名,而第三方證書因為會給多個不同的APP簽名,導致APP 簽名經常性掉簽,為了保證APP簽名在失效后及時重簽,所以寫了這個腳本。
語言:Python
第三方平臺:蒲公英
1、上傳 .ipa 安裝包到蒲公英平臺
2、使用蒲公英平臺的在線證書檢測對安裝包進行檢測
3、對返回數據進行解析
4、判斷簽名狀態(tài)進行釘釘提醒
代碼:
import requests
import re
import time
import json
def certificate_inspection():
"""
:return:
APP名稱:XXX
狀態(tài):掉簽
證書名稱:Wondors Information Co., LTD1.
證書過期時間:( 113 天后過期 )
時間:2020-11-05 15:38:14
"""
url = "https://www.pgyer.com/tools/certificate"
headers = {
"Cookie": "pgyx2_session=XXXXXX"
#登錄蒲公英平臺網頁端在request header 中獲取 Cookie中的 pgyx2_session 參數
#多次驗證登錄態(tài)只需要 pgyx2_session,網頁退出后也不回影響pgyx2_session 使用
}
data = {
# url 為蒲公英平臺下載短連接 如 https://www.pgyer.com/RFpA 可在應該概述頁面獲取
"url": "RFpA",
'password': ""
}
response = requests.post(url=url, data=data, headers=headers)
try:
res = response.json()
except Exception as e:
pass
else:
if '掉簽' in res['extra']['status']:
ding_message(
text='APP名稱:{3}\n狀態(tài):{0}\n證書名稱:{1}\n證書過期時間:{2}\n時間:{4}\n下載驗證:https://download.xxx.com/'.format(
re.findall(".*>(.*)<.*", res['extra']['status'])[0],
res['extra']['name'],
re.findall(".*>(.*)<.*", res['extra']['certExpiredSpan'])[0].strip(),
res['extra']['appName'],
time.strftime("%Y-%m-%d %H:%M:%S", time.localtime(), )))
elif '登錄' in res['extra']['status']:
ding_message(text='請檢查腳本登錄狀態(tài)!')
def ding_message(text):
# 釘釘機器人
webhook = "https://oapi.dingtalk.com/robot/send?access_token=XXXXXXXXXXX"
header = {
"Content-Type": "application/json",
"Charset": "UTF-8"
}
message = {
"msgtype": "text",
"text": {
"content": text
},
"at": {"isAtAll": True}}
message_json = json.dumps(message)
requests.post(url=webhook, data=message_json, headers=header)
certificate_inspection()