报告防伪系统 API文档 v 1.0

MiningLamp Blockchain Service




目录

API 1: 生成/获取二维码接口

API 2: 获取二维码对应链接接口

API 3: 报告提交/更新接口

API 4: 报告召回接口




API 1: 生成/获取二维码接口


简要描述

根据报告ID,获取对应的“封面二维码”,用户扫码后会跳转到对应的验证界面。

请求方式

 • POST

请求地址

 • 服务器:mlt.pub
 • 服务器(测试):192.168.2.128:8100(需连接机房VPN以访问)
 • URL:
  • /api/v1/generateqr/<report_id>
 • 注:<report_id> 需要替换成对应的报告ID

请求参数

参数名称 是否必选 数据类型 数据约束 描述 示例数据
user string N/A 用户名 test
passcode string N/A 密码 test

返回结果

 • 图片文件
 • Content-Type: image/png
 • headers示例:

    {
        'Content-Length': '12174', 
        'Content-Type': 'image/png', 
        'Last-Modified': 'Thu, 27 Feb 2020 06:32:44 GMT', 
        'Cache-Control': 
        'public, max-age=43200', 
        'Expires': 'Fri, 28 Feb 2020 20:03:57 GMT', 
        'ETag': '"1582785164.7559605-12174-3863353002"', 
        'Server': 'Werkzeug/0.14.1 Python/3.6.5', 
        'Date': 'Fri, 28 Feb 2020 08:03:57 GMT'
    }
        

示例代码


    def getqr(url, metadata, save_path):
        """
        """
        response = requests.post(url, data=metadata)

        if response.status_code == 200:
            print('Downloading QR Image ... ')
            with open(save_path, 'wb') as f:
                for chunk in response:
                    f.write(chunk)
            print('... QR Image Downloaded. ')
        
        # result = response.text
        result = response.headers

        return result

    if __name__ == '__main__':

        report_id = 'MZ1000987654'
        save_path = 'downloads/' + report_id + '.png'
        d = {}
        d['user'] = 'test'
        d['passcode'] = 'test'
        qr_url = 'http://192.168.2.128:8100/api/v1/generateqr' + '/' + report_id
        qr = getqr(qr_url, d, save_path)
        print(qr)
        



API 2: 获取二维码对应链接接口


简要描述

根据报告ID,获取(已生成的)二维码对应的链接地址(地址最后一部分即为短链接)。

请求方式

 • POST

请求地址

 • 服务器:mlt.pub
 • 服务器(测试):192.168.2.128:8100(需连接机房VPN以访问)
 • URL:
  • /api/v1/getqrlink/<report_id>
 • 注:<report_id> 需要替换成对应的报告ID

请求参数

参数名称 是否必选 数据类型 数据约束 描述 示例数据
user string N/A 用户名 test
passcode string N/A 密码 test

返回结果

 • URL(字符串)
 • Content-Type: text/html; charset=utf-8
 • 错误返回结果说明:
返回码 返回结果 含义说明
400 400 NO_USERNAME 未提供用户名
400 400 NO_PASSCODE 未提供密码
400 400 INVALID_USERNAME 用户名不正确
400 400 INVALID_PASSCODE 密码不正确
404 404 QR_LINK_NOT_FOUND 未找到对应二维码链接

示例代码


    def getqrlink(url, metadata):
        """
        """
        response = requests.post(url, data=metadata)

        result = response.text
        # result = response.headers

        return result
        
        # result = response.text
        result = response.headers

        return result

    if __name__ == '__main__':

        report_id = 'MZ1000987654'
        d['user'] = 'test'
        d['passcode'] = 'test'
        qr_url = 'http://192.168.2.128:8100/api/v1/getqrlink' + '/' + report_id
        link = getqrlink(qr_url, d)
        print(link)
        



API 3: 报告提交/更新接口


简要描述

根据报告ID,提交 / 更新 报告文件(封面添加过二维码,最终交付给客户的版本)以及其他报告基本信息。
报告的提交、更新使用了两个不同的接口,两个API用法相同,但场景不同,在后期权限分配上会考虑分别处理。
 •「提交」接口针对同一个ID只能使用一次,即成功上传后不能进行更新。
 •「更新」接口针对同一个ID可以重复调用,上传后发现报告文件有误、报告信息有误等可以进行更新。
当然,如果变更ID、初次上传,调用这两个接口的效果没有区别。

请求方式

 • POST

请求地址

 • 服务器:mlt.pub
 • 服务器(测试):192.168.2.128:8100(需连接机房VPN以访问)
 • URL:
  • 提交:/api/v1/commitreport/<report_id>
  • 更新:/api/v1/updatereport/<report_id>
 • 注:<report_id> 需要替换成对应的报告ID

请求参数

参数名称 是否必选 数据类型 数据约束 描述 示例数据
user string N/A 用户名 test
passcode string N/A 密码 test
title string 遵循OMI现有业务规范 报告标题 XXX报告
type string 遵循OMI现有业务规范 报告类型 监播报告
period string 遵循OMI现有业务规范 时间周期 2020.01.01 - 2020.01.31
geom string 遵循OMI现有业务规范 地理区域 中国大陆

请求文件

参数名称 是否必选 数据类型 数据约束 描述 示例数据
files binary N/A 所提交/更新报告的二进制文件 N/A

返回结果

 • Content-Type: text/html; charset=utf-8
 • 返回结果示例:
返回码 返回结果 含义说明
200 200 DATA_UPDATED 文件上传成功
501 501 DATA_ALREADY_EXIST 已经有同ID的文件存在(仅在调用「提交」API时会出现;考虑换用「更新」API)
400 400 NO_USERNAME 未提供用户名
400 400 NO_PASSCODE 未提供密码
400 400 INVALID_PASSCODE 密码不正确
400 400 METADATA_NOT_COMPLETE 报告信息不完整
400 400 NO_FILE_PROVIDED 没有添加文件

示例代码


    def commit_update(url, metadata, filename):
        """
        """
        multipart_data = {
                'file': (open(filepath, 'rb')),
                }
        response = requests.post(url, data=metadata, files=multipart_data)
        result = response.headers
        return result


    if __name__ == '__main__':

        report_id = 'MZ1000987654' 
        filepath = cwd + '/reports/' + 'MZ1000987654.pdf' # 确保你有这个文件
        d = {} # 新建字典,用于放入json形式的POST数据
        d['user'] = 'test' # 测试用户名
        d['passcode'] = 'test' # 测试密码
        d['id'] = report_id 
        d['title'] = 'XXX报告'
        d['type'] = '监播报告'
        d['period'] = '2020.01.01 - 2020.01.31'
        d['geom'] = '中国大陆'

        commit_url = 'http://192.168.2.128:8100/api/v1/commitreport' + '/' + report_id
        result = commit_update(commit_url, d, filepath)
        print(result)

        update_url = 'http://192.168.2.128:8100/api/v1/updatereport' + '/' + report_id
        result = commit_update(update_url, d, filepath)
        print(result)
        



API 4: 报告召回接口


简要描述

根据报告ID,召回 对应报告文件。
报告召回API的使用方式和报告提交/更新基本一致。无需再上传文件。

请求方式

 • POST

请求地址

 • 服务器:mlt.pub
 • 服务器(测试):192.168.2.128:8100(需连接机房VPN以访问)
 • URL:
  • /api/v1/recallreport/<report_id>
 • 注:<report_id> 需要替换成对应的报告ID

请求参数

参数名称 是否必选 数据类型 数据约束 描述 示例数据
user string N/A 用户名 test
passcode string N/A 密码 test
title string 遵循OMI现有业务规范 报告标题 XXX报告
type string 遵循OMI现有业务规范 报告类型 监播报告
period string 遵循OMI现有业务规范 时间周期 2020.01.01 - 2020.01.31
geom string 遵循OMI现有业务规范 地理区域 中国大陆

返回结果

 • Content-Type: text/html; charset=utf-8
 • 返回结果示例:
返回码 返回结果 含义说明
200 200 DATA_RECALLED 文件召回成功
501 501 DATA_NOT_EXIST 文件不存在(无需召回)
501 501 ALREADY_RECALLED 文件已被召回(本次召回操作被忽略)
400 400 NO_USERNAME 未提供用户名
400 400 NO_PASSCODE 未提供密码
400 400 INVALID_PASSCODE 密码不正确
400 400 METADATA_NOT_MATCHED 报告信息不匹配

示例代码


    def recall(url, metadata):
        """
        """
        response = requests.post(url, data=metadata)
        result = response.headers
        return result


    if __name__ == '__main__':

        report_id = 'MZ1000987654' 
        d = {} # 新建字典,用于放入json形式的POST数据
        d['user'] = 'test' # 测试用户名
        d['passcode'] = 'test' # 测试密码
        d['id'] = report_id 
        d['title'] = 'XXX报告'
        d['type'] = '监播报告'
        d['period'] = '2020.01.01 - 2020.01.31'
        d['geom'] = '中国大陆'

        recall_url = 'http://192.168.2.128:8100/api/v1/recallreport' + '/' + report_id
        result = recall(recall_url, d)
        print(result)
        





返回报告防伪系统首页










Author: Sen LEI
Copyright © 2020 MiningLamp Technology