网络游戏防沉迷实名认证-接口测试

随着网络游戏行业的发展,实名认证成为了确保青少年健康游戏的重要措施。本文将介绍网络游戏防沉迷实名认证接口的测试方法,分为8个测试用例,涵盖了实名认证接口、认证结果查询接口以及用户行为数据上报接口。以下是详细的测试步骤和代码示例。

首先正所谓授人以鱼就比授人以鱼竿强。所以上工具链接:网络游戏防沉迷实名认证接口测试

1. 测试用例概述

我们将对以下8个测试用例进行详细说明:

  1. testcase01: 认证接口测试
  2. testcase02: 认证接口测试
  3. testcase03: 认证接口测试
  4. testcase04: 认证结果查询接口测试
  5. testcase05: 认证结果查询接口测试
  6. testcase06: 认证结果查询接口测试
  7. testcase07: 游戏用户行为数据上报接口测试
  8. testcase08: 游戏用户行为数据上报接口测试
2. 测试接口定义
2.1 身份认证接口

接口路径: /test/authentication/check

请求方法: POST

请求参数:

  • ai: 用户账号ID
  • identity: 身份证号
  • name: 真实姓名

示例代码:

var getIdentityResult = function (testcode, ai, identity, name, cb) {
    let idJson = { 'ai': ai, 'name': name, 'idNum': identity };
    let postData = JSON.stringify(idJson);
    let encr = encrypt(postData);
    let encrData = JSON.stringify({ 'data': encr });
    let timestamps = Date.now();
    let signStr = signPreStr + timestamps + encrData;
    let sign = CryptoJS.SHA256(signStr).toString(CryptoJS.enc.Hex);

    fetch(`https://${host}${path}/${testcode}`, {
        method: 'POST',
        headers: {
            'Content-Type': 'application/json; charset=utf-8',
            'Content-Length': encrData.length.toString(),
            'appId': appId,
            'bizId': bizId,
            'timestamps': timestamps,
            'sign': sign
        },
        body: encrData
    }).then(response => response.json())
      .then(result => {
          if (result.errcode === 0 && result.data.result.status === 0) {
              cb && cb(null, idJson);
          } else {
              cb("认证失败");
          }
      })
      .catch(error => cb(error));
};
2.2 认证结果查询接口

接口路径: /test/authentication/query

请求方法: GET

请求参数:

  • ai: 用户账号ID

示例代码:

var queryAuthentication = function (testcode, ai, cb) {
    let getData = querystring.stringify({ 'ai': ai });
    let timestamps = Date.now();
    let signStr = secretKey + 'ai' + ai + 'appId' + appId + 'bizId' + bizId + 'timestamps' + timestamps;
    let sign = CryptoJS.SHA256(signStr).toString(CryptoJS.enc.Hex);

    fetch(`https://${host}${queryPath}/${testcode}?${getData}`, {
        method: 'GET',
        headers: {
            'appId': appId,
            'bizId': bizId,
            'timestamps': timestamps,
            'sign': sign
        }
    }).then(response => response.json())
      .then(result => {
          if (result.errcode === 0 && result.data.result.status === 0) {
              cb(null);
          } else {
              cb("查询失败");
          }
      })
      .catch(error => cb(error));
};
2.3 用户行为数据上报接口

接口路径: /test/collection/loginout

请求方法: POST

请求参数:

  • si: 游戏内部会话标识
  • bt: 行为类型
  • state: 用户状态
  • pi: 已通过实名认证用户的唯一标识(已认证用户必填)

示例代码:

var loginout = function (testcode, si, bt, state, pi, cb) {
    let idJson = {
        "no": 1,
        "si": si,
        "bt": bt,
        "ot": Math.floor(Date.now() / 1000),
        "ct": state === 1 ? 2 : 0,
        "pi": pi,
        "di": state === 1 ? "游客设备标识" : ''
    };
    let postData = JSON.stringify({ "collections": [idJson] });
    let encr = encrypt(postData);
    let encrData = JSON.stringify({ 'data': encr });
    let timestamps = Date.now();
    let signStr = signPreStr + timestamps + encrData;
    let sign = CryptoJS.SHA256(signStr).toString(CryptoJS.enc.Hex);

    fetch(`https://${host}${loginoutPath}/${testcode}`, {
        method: 'POST',
        headers: {
            'Content-Type': 'application/json; charset=utf-8',
            'Content-Length': encrData.length.toString(),
            'appId': appId,
            'bizId': bizId,
            'timestamps': timestamps,
            'sign': sign
        },
        body: encrData
    }).then(response => response.json())
      .then(result => {
          if (result.errcode === 0) {
              cb(null, 200);
          } else {
              cb("上报失败", 500);
          }
      })
      .catch(error => cb(error));
};
3. 测试用例实现

以下是每个测试用例的实现:


// test1
getIdentityResult("srkamM","100000000000000001", "110000190101010001", "某一一", function () {
    console.log("完成测试1")
})

getIdentityResult("bc42jo","200000000000000001", "110000190201010009", "某二一", function () {
    console.log("完成测试2")
})

getIdentityResult("gup2KZ","200000000000000001", "110000190201010009", "某二一1", function () {
    console.log("完成测试3")
})


queryAuthentication("8C5Nzt","100000000000000001", function () {
    console.log("testcase04-实名认证结果查询接口")
})

queryAuthentication("weeYVk","200000000000000001", function () {
    console.log("testcase05-实名认证结果查询接口")
})

queryAuthentication("7Ncjv5","300000000000000001", function () {
    console.log("testcase06-实名认证结果查询接口")
})

//游客用户行为数据上报
loginout("3xZHPa", "1hpfml09b57f3f8185f8cb5094ea3f26278efb", 0, 1, "1fffbjzos82bs9cnyj1dna7d6d29zg4esnh99u", function () {
    console.log("testcase07-游戏用户行为数据上报接口")
})
// 已认证
loginout("P6F2Eh","1hpfml09b57f3f8185f8cb5094ea3f26278efb",1,0,"1fffbjzos82bs9cnyj1dna7d6d29zg4esnh99u", function () {
    console.log("testcase087-游戏用户行为数据上报接口")
})
4. 结论

通过以上测试用例,我们可以验证网络游戏防沉迷实名认证接口的功能是否正常,包括身份认证、认证结果查询以及用户行为数据上报。确保这些接口能够正常工作对维护游戏环境的健康和合法性至关重要。如果有任何问题或错误,请根据返回的

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值