农产品溯源场景

本文以大米溯源场景为示例,介绍存证与溯源服务的操作流程。

场景描述

如下描述了基于多方任务协同服务溯源场景的整个流程。 某个业务管理方开通多方任务协同服务之后,基于已开通的业务链创建了溯源协同模型,在溯源协同模型下创建了大米种植、大米加工和大米销售3个阶段。 再分别创建3个业务使用方,授予对应访问权限。每个业务使用方在已授权的阶段上对数据进行上链、读取操作。

步骤一:创建协同模型和阶段

  1. 业务管理方查看已开通的多方任务协业务链列表。

    API名称:ListMultiPartyCollaborationChain

    请求示例:

    ListMultiPartyCollaborationChainRequest request = new ListMultiPartyCollaborationChainRequest();
    request.setApiVersion("1.0.0");
    request.setNum(1);
    request.setSize(10);
    ListMultiPartyCollaborationChainResponse response = client.getAcsResponse(request);

    响应结果:多方任务协同业务链列表。

    {
        "num":1,
        "pageData":[
            {
                "bizChainId":"316464428168****",
                "name":"多方业务协同-业务链",
                "remark":"多方业务协同-业务链",
                "roleType":"ADMIN"
            }
        ],
        "size":10,
        "total":1
    }

  2. 业务管理方在步骤1返回的某条业务链上,创建协同模型。

    API名称:CreateMPCoSPhaseGroup

    请求示例:

    CreateMPCoSPhaseGroupRequest request = new CreateMPCoSPhaseGroupRequest();
    request.setApiVersion("1.0.0");
    request.setBizChainId("123498756487****");
    request.setName("协同模型xx");
    request.setRemark("备注");
    CreateMPCoSPhaseGroupResponse response = client.getAcsResponse(request);

    响应结果:创建完成的协同模型标识。

    requestId:90EDB054-BB13-47C9-AB7E-AFD0202D174B
    request success.
    0717524726439206

  3. 业务管理方在步骤2返回的协同模型上,创建多个阶段。每次可成功创建一个阶段,如果需要多个阶段创建,可重复多次调用API进行创建,并设置不同的阶段名称。如下过程演示创建三个不同的阶段,名称分别为:大米种植,大米加工,大米销售。

    API名称:CreateMPCoSPhase

    请求示例:

    CreateMPCoSPhaseRequest request = new CreateMPCoSPhaseRequest();
    request.setApiVersion("1.0.0");
    request.setBizChainId("123498756487****");
    request.setPhaseGroupId("288396756487****");
    request.setName("阶段xx");
    request.setRemark("备注");
    CreateMPCoSPhaseResponse response = client.getAcsResponse(request);

    响应结果:创建完成的阶段标识。

    大米种植

    requestId:D9F8AF1E-2699-4168-BC9F-FD6F63788578
    request success.
    2955458916203196

    大米加工

    requestId:9051EF36-9568-481A-8056-5D351B09F754
    request success.
    4522658648649195

    大米销售

    requestId:3078B87B-92AE-47D4-8C66-56E5D0E5CB3A
    request success.
    3901520305380189
  4. 业务管理方基于之前创建成功的协同模型,可查看已创建完成的阶段列表信息。

    API名称:ListMPCoSPhase

    请求示例:

    ListMPCoSPhaseGroupRequest request = new ListMPCoSPhaseGroupRequest();
    request.setApiVersion("1.0.0");
    request.setBizChainId("123498756487****");
    request.setNum(1);
    request.setSize(10);
    ListMPCoSPhaseGroupResponse response = client.getAcsResponse(request);

    响应结果:已创建完成的阶段列表。

    {
        "num": 1,
        "pageData": [
            {
                "accessPermission": 3,
                "name": "大米种植",
                "phaseId": "295545891620****",
                "remark": "大米种植"
            },
            {
                "accessPermission": 3,
                "name": "大米加工",
                "phaseId": "452265864864****",
                "remark": "大米加工"
            },
            {
                "accessPermission": 3,
                "name": "大米销售",
                "phaseId": "390152030538****",
                "remark": "大米销售"
            }
        ],
        "size": 10,
        "total": 3
    }

步骤二:添加成员和授权

  1. 管理方根据使用方提供的阿里云RAM用户UID,依次添加3个成员(大米生产方,大米加工方,大米销售方)。

    API名称:CreateMember

    请求示例:

    CreateMemberRequest request = new CreateMemberRequest();
    request.setApiVersion("1.0.0");
    request.setBizChainId("123498756487****");
    request.setMemberName("memberxx");
    request.setMemberUid("1234987564xxx");
    request.setMemberContact("联系人");
    request.setMemberPhone("联系电话");
    request.setRemark("备注");
    CreateMemberResponse response = client.getAcsResponse(request);

    响应结果:添加成功的成员标识。

    requestId:16044812-5C23-4E37-A64C-9F0E6FD4BDD8
    request success.
    4032294883597145
    requestId:23A1B861-3455-4C2E-B8D8-B9B899411C1D
    request success.
    2556518694597136
    requestId:3F266706-7B17-4CA0-BAC0-3F724147CAA1
    request success.
    1682410962801590

  2. 管理方可查看在该业务链上已添加成功的成员列表。

    API名称:ListMember

    请求示例:

    ListMemberRequest request = new ListMemberRequest();
    request.setApiVersion("1.0.0");
    request.setNum(1);
    request.setSize(10);
    request.setBizChainId("123498756487****");
    ListMemberResponse response = client.getAcsResponse(request);

    响应结果:已添加成功的成员标识列表。

    {
        "num":1,
        "pageData":[
            {
                "memberContact":"联系人",
                "memberId":"403229488359****",
                "memberName":"大米生产方",
                "memberPhone":"00000000000",
                "memberUid":"22946550804317****",
                "remark":"大米生产方",
                "status":"UNLOCK"
            },
            {
                "memberContact":"联系人",
                "memberId":"255651869459****",
                "memberName":"大米加工方",
                "memberPhone":"00000000000",
                "memberUid":"21799530804317****",
                "remark":"大米加工方",
                "status":"UNLOCK"
            },
            {
                "memberContact":"联系人",
                "memberId":"168241096280****",
                "memberName":"大米销售方",
                "memberPhone":"00000000000",
                "memberUid":"29906280810250****",
                "remark":"大米销售方",
                "status":"UNLOCK"
            }
        ],
        "size":10,
        "total":3
    }
  3. 管理方为添加的3个成员分别授予不同的阶段数据写入权限。

    API名称: UpdateMPCoSAuthorizedInfo

    请求示例:

    UpdateMPCoSAuthorizedInfoRequest request = new UpdateMPCoSAuthorizedInfoRequest();
    request.setApiVersion("1.0.0");
    request.setBizChainId("123498756487****");
    request.setPhaseGroupId("288396756487****");
    request.setMemberId("2575849238377****");
    
    List<String> phaseIdList = new LinkedList<>();
    phaseIdList.add("6854938438377****");
    request.setAuthorizedPhaseList(phaseIdList);
    
    UpdateMPCoSAuthorizedInfoResponse response = client.getAcsResponse(request);

    响应结果:无。

    标准制定方授权:

    requestId:4AD5D2DB-B458-4892-A974-DBB49B60AE0D
    request success.

    应用开发方授权:

    requestId:ECA51B76-191E-4829-8A81-86E948B45C9A
    request success.

    评测检测方授权:

    requestId:E591713A-FC4C-4122-8774-81A1375522B7
    request success.

  4. 管理方在授权完成之后,可查看每个成员的已授权阶段权限。

    API名称:DescribeMPCoSAuthorizedInfo

    请求示例:

    DescribeMPCoSAuthorizedInfoRequest request = new DescribeMPCoSAuthorizedInfoRequest();
    request.setApiVersion("1.0.0");
    request.setBizChainId("123498756487****");
    request.setPhaseGroupId("288396756487****");
    request.setMemberId("2575849238377****");
    DescribeMPCoSAuthorizedInfoResponse response = client.getAcsResponse(request);

    大米生产方权限列表:

    {
        "authorizedPhaseList":[
            {
                "phaseId":"585009241984****",
                "phaseName":"大米生产"
            }
        ],
        "unAuthorizedPhaseList":[
            {
                "phaseId":"993693114164****",
                "phaseName":"大米加工"
            },
            {
                "phaseId":"224431989774****",
                "phaseName":"大米销售"
            }
        ]
    }

    大米加工方权限列表:

    {
        "authorizedPhaseList":[
            {
                "phaseId":"993693114164****",
                "phaseName":"大米加工"
            }
        ],
        "unAuthorizedPhaseList":[
            {
                "phaseId":"585009241984****",
                "phaseName":"大米生产"
            },
            {
                "phaseId":"224431989774****",
                "phaseName":"大米销售"
            }
        ]
    }

    大米销售方权限列表:

    {
        "authorizedPhaseList":[
            {
                "phaseId":"224431989774****",
                "phaseName":"大米销售"
            }
        ],
        "unAuthorizedPhaseList":[
            {
                "phaseId":"585009241984****",
                "phaseName":"大米生产"
            },
            {
                "phaseId":"993693114164****",
                "phaseName":"大米加工"
            }
        ]
    }

步骤三: 成员协同数据上链

  1. 大米生产方在大米生产-阶段进行数据上链操作。

    API名称:UploadMPCoSPhaseTextInfo

    请求示例:

    UploadMPCoSPhaseTextInfoRequest request = new UploadMPCoSPhaseTextInfoRequest();
    request.setApiVersion("1.0.0");
    request.setBizChainId("123498756487****");
    request.setPhaseGroupId("288396756487****");
    request.setPhaseId("685947802937****");
    request.setDataKey("0000000000000000000000000000000000000000000000000000000000000001");
    request.setDataSeq("0000000000000000000000000000000000000000000000000000000000000001");
    request.setPhaseData("Phase-Data");
    // 设置依赖的数据
    List<RelatedData> relatedDataList = new LinkedList<>();
    RelatedData relatedData = new RelatedData();
    relatedData.setRelatedPhaseId("685944782937****");
    relatedData.setRelatedDataKey("0000000000000000000000000000000000000000000000000000000000000002");
    relatedData.setRelatedDataSeq("0000000000000000000000000000000000000000000000000000000000000001");
    relatedData.setRelatedPhaseData("Phase-Data");
    relatedDataList.add(relatedData);
    request.setRelatedDataList(relatedDataList);
    
    UploadMPCoSPhaseTextInfoResponse response = client.getAcsResponse(request);
    dataKey:   A000000000000000000000000000000000000000000000000000000000000001
    dataSeq:   0000000000000000000000000000000000000000000000000000000000000001
    phaseData: {"大米生产编号" : "37423894238947239472****"}

  2. 大米加工方在大米加工-阶段进行数据上链操作。

    API名称:UploadMPCoSPhaseTextInfo

    dataKey:   B000000000000000000000000000000000000000000000000000000000000001
    dataSeq:   0000000000000000000000000000000000000000000000000000000000000001
    phaseData: {"大米加工编号" : "97E6FBCE8A9DA6DC97E6FBCE8A9DA6DC97E6FBCE8A9DA6DC97E6FBCE********"}
    
    依赖数据:
    dataKey:   A000000000000000000000000000000000000000000000000000000000000001
    dataSeq:   0000000000000000000000000000000000000000000000000000000000000001
    phaseData: {"大米生产编号" : "37423894238947239472****"}

  3. 大米销售方在大米销售-阶段进行数据上链操作。

    API名称:UploadMPCoSPhaseTextInfo

    评测结果-上链数据:
    dataKey:   C000000000000000000000000000000000000000000000000000000000000001
    dataSeq:   0000000000000000000000000000000000000000000000000000000000000001
    phaseData: {"大米销售编号" : "39766baf2885ef042da75236454a****"}
    
    依赖数据:
    dataKey:   B000000000000000000000000000000000000000000000000000000000000001
    dataSeq:   0000000000000000000000000000000000000000000000000000000000000001
    phaseData: {"大米加工编号" : "97E6FBCE8A9DA6DC97E6FBCE8A9DA6DC97E6FBCE8A9DA6DC97E6FBCE********"}

步骤四:查询成员协同数据

参与到多方任务协同业务链的各个成员,数据上链成功之后,对该业务链上的数据有共享的读访问权限,可读取访问之前上链成功的数据。

API名称:DescribeMPCoSPhaseInfo

请求示例:

DescribeMPCoSPhaseInfoRequest request = new DescribeMPCoSPhaseInfoRequest();
request.setApiVersion("1.0.0");
request.setBizChainId("123498756487****");
request.setPhaseGroupId("288396756487****");
request.setPhaseId("685947802937****");
request.setDataKey("0000000000000000000000000000000000000000000000000000000000000001");
request.setDataSeq("0000000000000000000000000000000000000000000000000000000000000001");
DescribeMPCoSPhaseInfoResponse response = client.getAcsResponse(request);

读取大米生产-上链数据

{
    "blockHash":"3713c2b108691ecae4ff6e3b3ccd4f0226bd5ce38895df11a478f3e9c843****",
    "blockNumber":605364,
    "dataHash":"384bd33ea1748466f9f92688a127c35f2103d373a74180d27f243b7929f9****",
    "dataValue":"{\"大米生产\" : \"37423894238947239472****\"}",
    "iotId":"",
    "previousHash":"c4f2fce024d36f8417a6aee63d901313aee0115438a8c3c01f12d1a4d035****",
    "productKey":"",
    "relatedDataList":[],
    "timestamp":1608105171000,
    "transactionHash":"ad43b2f03dcb3bc72a3ff4eff5766056c1210b641e369e8173fb95cb7b74****"
}

读取大米加工-上链数据

{
    "blockHash":"a24a9e6a980890d50fc2c87097f83a2894c86e32ff90220d198e00dee5da****",
    "blockNumber":605365,
    "dataHash":"18d1922071fcc44da21e51763f9b7670b2c6336f54a0288f306776c977a8****",
    "dataValue":"{\"大米加工\" : \"97E6FBCE8A9DA6DC97E6FBCE8A9DA6DC97E6FBCE8A9DA6DC97E6FBCE8A9D****\"}",
    "iotId":"",
    "previousHash":"3713c2b108691ecae4ff6e3b3ccd4f0226bd5ce38895df11a478f3e9c843****",
    "productKey":"",
    "relatedDataList":[
    {
            "relatedDataKey":"0002_z1E9FBwCfdc9ICk6_5E9A_A000000000000000000000000000000000000000000000000000000000000001",
            "relatedDataSeq":"0000000000000000000000000000000000000000000000000000000000000001",
            "relatedPhaseDataHash":"0daf9fd452361b5d5bf53bc027224b3896f3953fdf4313a0bd73ab6954fe****",
            "relatedPhaseId":"585009241984****",
            "relatedPhaseName":"大米生产"
        }
  ],
    "timestamp":1608105227000,
    "transactionHash":"2d3e52745fc2903c113d0612d179a4bcdf8db8da5115c86d8dc6dd53f6a1****"
}

读取大米销售-上链数据

{
    "blockHash":"323c9e9509277b387416e6c32f61fd202391272ae8345c4085092a293f2e****",
    "blockNumber":605368,
    "dataHash":"a06eff24fb2419abb72c065859f1535c490733566679155743e0d00025f1****",
    "dataValue":"{\"大米销售编号\" : \"39766baf2885ef042da75236454a****\"}",
    "iotId":"",
    "previousHash":"afcf24a0611e2cc0a3a175ef7c029fd11f58aef4c35088f1967ef62a700d****",
    "productKey":"",
    "relatedDataList":[
        {
            "relatedDataKey":"0002_z1E9FBwCfdc9ICk6_A050_B000000000000000000000000000000000000000000000000000000000000001",
            "relatedDataSeq":"0000000000000000000000000000000000000000000000000000000000000001",
            "relatedPhaseDataHash":"ec84ef245f7bb3cc83bec6976d8fce936a7a352fc79d097c49d321d41fac****",
            "relatedPhaseId":"993693114164****",
            "relatedPhaseName":"大米加工"
        }
    ],
    "timestamp":1608105548000,
    "transactionHash":"2ffbac9ad742eb5b7a29baae9836e574edd55f5d5bd377a5dd8a58cf6713****"
}