コード例 #1
0
ファイル: app_helper.py プロジェクト: 292887172/open
def denied_app(app_id, remark):
    """
    拒绝app, 审核不通过
    :param app_id:
    :param remark:
    :return:
    """
    try:
        if not remark:
            return False
        update_line = App.objects.filter(app_id=int(app_id)).update(
            check_status=_convention.APP_CHECK_FAILED,
            check_remarks=remark,
            app_update_date=datetime.datetime.utcnow())
        if update_line > 0:
            app = App.objects.get(app_id=int(app_id))
            message_content = '"' + app.app_name + '"' + DENIED_APP
            save_user_message(app.developer_id, message_content, USER_TYPE,
                              app.developer_id, app.app_appid)
            return True
        else:
            return False
    except Exception as e:
        logging.getLogger("").error(e)
        return False
コード例 #2
0
ファイル: app_helper.py プロジェクト: 292887172/open
def update_app_info(app_id, app_name, app_model, app_describe, app_site,
                    app_logo, app_command, app_group, app_factory_uid):
    """
    更新应用基础信息
    :param app_id:
    :param app_name:
    :param app_category:
    :param app_model:
    :param app_describe:
    :param app_site:
    :param app_logo:
    :param app_command:
    :param app_device_type:
    :param app_group:
    :param app_factory_uid:
    :return:
    """
    try:
        params = dict(
            app_name=app_name,
            app_describe=app_describe,
            app_site=app_site,
            app_model=app_model,
            app_command=app_command,
            app_update_date=datetime.datetime.utcnow(),
            app_group=app_group,
            app_factory_uid=app_factory_uid,
        )
        if app_logo:
            params["app_logo"] = app_logo
        update_line = App.objects.filter(app_id=int(app_id)).update(**params)
        if update_line > 0:
            app = App.objects.get(app_id=int(app_id))
            message_content = '"' + app.app_name + '"' + UPDATE_APP
            save_user_message(app.developer_id, message_content, USER_TYPE,
                              app.developer_id, app.app_appid)
            try:
                delete_app_access_token(app.app_appid)
            except Exception as e:
                logging.getLogger('').info('删除appaccess_token出错' + str(e))
            return True
        else:
            return False
    except Exception as e:
        logging.getLogger("").error(e)
        return False
コード例 #3
0
ファイル: app_helper.py プロジェクト: 292887172/open
def del_app(app_id):
    """
    删除应用(移除到历史应用表)
    :param app_id: 应用编号
    :return:
    """
    try:
        app = App.objects.get(app_id=int(app_id))
        new_app_history = AppHistory(app_id=app.app_id,
                                     developer=app.developer,
                                     app_name=app.app_name,
                                     app_describe=app.app_describe,
                                     app_logo=app.app_logo,
                                     app_action=app.app_action,
                                     check_status=app.check_status,
                                     check_remarks=app.check_remarks,
                                     app_appid=app.app_appid,
                                     app_appsecret=app.app_appsecret,
                                     app_is_forbid=app.app_is_forbid,
                                     app_brand=app.app_brand,
                                     app_category=app.app_category,
                                     app_model=app.app_model,
                                     app_level=app.app_level,
                                     app_group=app.app_group,
                                     app_push_url=app.app_push_url,
                                     app_push_token=app.app_push_token,
                                     app_device_type=app.app_device_type,
                                     app_protocol_type=app.app_protocol_type,
                                     app_create_date=app.app_create_date,
                                     app_update_date=app.app_update_date)
        new_app_history.save()
        app.delete()
        message_content = '"' + app.app_name + '"' + DEL_APP

        save_user_message(app.developer_id, message_content, USER_TYPE,
                          app.developer_id, app.app_app_id)
        # 删除应用, 同步到 RESTFul API
        delete_api_app(app.app_appid)
        return True
    except Exception as e:
        logging.getLogger("").error(e)
        return False
コード例 #4
0
ファイル: app_helper.py プロジェクト: 292887172/open
def release_app(app_id):
    """
    申请发布应用
    :param app_id:
    :return:
    """
    try:
        update_line = App.objects.filter(app_id=int(app_id)).update(
            check_status=_convention.APP_CHECKING,
            app_update_date=datetime.datetime.utcnow())
        if update_line > 0:
            app = App.objects.get(app_id=int(app_id))
            message_content = '"' + app.app_name + '"' + RELEASE_APP
            save_user_message(app.developer_id, message_content, USER_TYPE,
                              app.developer_id, app.app_app_id)
            return True
        else:
            return False
    except Exception as e:
        logging.getLogger("").error(e)
        return False
コード例 #5
0
ファイル: app_helper.py プロジェクト: 292887172/open
def pass_app(app_id):
    """
    通过app, 审核通过
    :param app_id:
    :return:
    """
    try:
        update_line = App.objects.filter(app_id=int(app_id)).update(
            check_status=_convention.APP_CHECKED,
            app_update_date=datetime.datetime.utcnow())
        if update_line > 0:
            # APP审核通过, 同步到 RESTFul API
            app = App.objects.get(app_id=int(app_id))
            message_content = '"' + app.app_name + '"' + PASS_APP
            save_user_message(app.developer_id, message_content, USER_TYPE,
                              app.developer_id, app.app_appid)
            create_release_api_app(app.app_appid)
            return True
        else:
            return False
    except Exception as e:
        logging.getLogger("").error(e)
        return False
コード例 #6
0
ファイル: app_helper.py プロジェクト: 292887172/open
def cancel_release_app(app_id):
    """
    取消发布应用
    :param app_id:
    :return:
    """
    try:
        update_line = App.objects.filter(app_id=int(app_id)).update(
            check_status=_convention.APP_UN_CHECK,
            app_update_date=datetime.datetime.utcnow())
        if update_line > 0:
            # 应用下架, 同步到 RESTFul API
            app = App.objects.get(app_id=int(app_id))
            message_content = '"' + app.app_name + '"' + CANCEL_RELEASE_APP
            save_user_message(app.developer_id, message_content, USER_TYPE,
                              app.developer_id, app.app_app_id)
            delete_release_api_app(app.app_appid)
            return True
        else:
            return False
    except Exception as e:
        logging.getLogger("").error(e)
        return False
コード例 #7
0
ファイル: app_helper.py プロジェクト: 292887172/open
def reset_app_secret(app_id):
    """
    重置应用的AppSecret
    :param app_id:
    :return:
    """
    try:
        app = App.objects.get(app_id=int(app_id))
        new_app_secret = gen_app_app_secret()
        update_line = App.objects.filter(app_id=int(app_id)).update(
            app_appsecret=new_app_secret,
            app_update_date=datetime.datetime.utcnow())
        if update_line > 0:
            # 同步到 RESTFul API
            message_content = '"' + app.app_name + '"' + RESET_APP_SECRET
            save_user_message(app.developer_id, message_content, USER_TYPE,
                              app.developer_id, app.app_appid)
            reset_api_app_secret(app.app_appid, new_app_secret)
            return new_app_secret
        else:
            return ""
    except Exception as e:
        logging.getLogger("").error(e)
        return ""
コード例 #8
0
ファイル: app_helper.py プロジェクト: 292887172/open
def update_app_config(app_id, app_push_url, app_push_token):
    """
    更新应用配置信息
    :param app_id:
    :param app_push_url:
    :param app_push_token:
    :return:
    """
    try:
        update_line = App.objects.filter(app_id=int(app_id)).update(
            app_push_url=app_push_url,
            app_push_token=app_push_token,
            app_update_date=datetime.datetime.utcnow())
        if update_line > 0:
            app = App.objects.get(app_id=int(app_id))
            message_content = '"' + app.app_name + '"' + UPDATE_APP_CONFIG
            save_user_message(app.developer_id, message_content, USER_TYPE,
                              app.developer_id, app.app_appid)
            return True
        else:
            return False
    except Exception as e:
        logging.getLogger("").error(e)
        return False
コード例 #9
0
ファイル: app_helper.py プロジェクト: 292887172/open
def create_app(developer_id,
               app_name,
               app_model,
               app_category,
               app_category_detail,
               app_command,
               device_conf,
               app_factory_id,
               app_group,
               app_logo,
               app_product_fast,
               check_status=0,
               app_category_detail2=1):
    """
    创建应用
    :param developer_id: 开发者编号
    :param app_name: 应用名称
    :param app_model: 型号
    :param app_category: 分类
    :param app_category_detail: 详细分类
    :param app_category_detail2: 屏幕尺寸
    :param app_command: 指令类型
    :param device_conf: 产品默认功能配置
    :param app_factory_id: app品牌id
    :param app_group: 设备类型
    :param check_status: 产品审核状态
    :param app_product_fast: 是否快速创建
    :return:
    """
    try:
        developer = Developer.objects.get(developer_id=developer_id)
        try:
            g = Group.objects.get(create_user=str(developer_id).split("_")[1],
                                  relate_project=0)
            group_id = g.group_id
        except Exception as e:
            group_id = 0
            pass
        while True:
            try:
                app_app_id = gen_app_app_id()
                app_app_secret = gen_app_app_secret()
                try:
                    device_conf = json.dumps(device_conf)
                except Exception as e:
                    pass

                app = App(developer=developer,
                          app_name=app_name,
                          app_appid=app_app_id,
                          app_appsecret=app_app_secret,
                          app_model=app_model,
                          app_command=app_command,
                          app_category=app_category,
                          app_device_type=app_category_detail,
                          device_conf=device_conf,
                          app_config_path='',
                          package_name='',
                          app_screen_size=app_category_detail2,
                          app_factory_uid=app_factory_id,
                          app_group=app_group,
                          app_logo=app_logo,
                          app_create_source=app_product_fast,
                          check_status=check_status,
                          group_id=group_id,
                          app_device_config_version=int(2),
                          app_create_date=datetime.datetime.utcnow(),
                          app_update_date=datetime.datetime.utcnow())
                app.save()

                Message.objects.create(message_content='生成标准屏端工程软件',
                                       device_key=app_app_id[-8:],
                                       message_sender=app.developer_id,
                                       message_target=app.developer_id,
                                       is_read=0,
                                       create_date=datetime.datetime.utcnow(),
                                       update_date=datetime.datetime.utcnow())
                Message.objects.create(message_content='生成标准工程文件',
                                       device_key=app_app_id[-8:],
                                       message_sender=app.developer_id,
                                       message_target=app.developer_id,
                                       is_read=0,
                                       create_date=datetime.datetime.utcnow(),
                                       update_date=datetime.datetime.utcnow())
                Message.objects.create(message_content='生成标准控制协议',
                                       device_key=app_app_id[-8:],
                                       message_sender=app.developer_id,
                                       message_target=app.developer_id,
                                       is_read=0,
                                       create_date=datetime.datetime.utcnow(),
                                       update_date=datetime.datetime.utcnow())
                message_content = '"' + app_name + '"' + CREATE_APP
                save_user_message(developer_id, message_content, USER_TYPE,
                                  developer_id, app_app_id)
                # 创建默认标准协议 DefaultProtocol().DEFAULT_DATA_ZDY
                update_protocol(app_app_id[-8:],
                                json.dumps(DefaultProtocol().DEFAULT_DATA_ZDY),
                                0, app.developer_id)
                break
            except Exception as e:
                del e
        # 同步到 RESTFul API
        create_sandbox_api_app(app_app_id, app_app_secret)
        return app.app_id
    except Exception as e:
        logging.getLogger("").error(e)
        return ""