iOS APP 证书状态监控

苹果企业证书现在已经无法申请购买,企业大多数都在使用第三方签名,而第三方证书因为会给多个不同的APP签名,导致APP 签名经常性掉签,为了保证APP签名在失效后及时重签,所以写了这个脚本。

语言:Python
第三方平台:蒲公英

1、上传 .ipa 安装包到蒲公英平台
2、使用蒲公英平台的在线证书检测对安装包进行检测
3、对返回数据进行解析
4、判断签名状态进行钉钉提醒

代码:


import requests
import re
import time
import json


def certificate_inspection():
    """
    :return:
        APP名称:XXX
        状态:掉签
        证书名称: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 参数
          #多次验证登录态只需要 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状态:{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='请检查脚本登录状态!')


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()

你可能感兴趣的:(iOS APP 证书状态监控)