随着网络游戏行业的发展,实名认证成为了确保青少年健康游戏的重要措施。本文将介绍网络游戏防沉迷实名认证接口的测试方法,分为8个测试用例,涵盖了实名认证接口、认证结果查询接口以及用户行为数据上报接口。以下是详细的测试步骤和代码示例。
首先正所谓授人以鱼就比授人以鱼竿强。所以上工具链接:网络游戏防沉迷实名认证接口测试
1. 测试用例概述
我们将对以下8个测试用例进行详细说明:
- testcase01: 认证接口测试
- testcase02: 认证接口测试
- testcase03: 认证接口测试
- testcase04: 认证结果查询接口测试
- testcase05: 认证结果查询接口测试
- testcase06: 认证结果查询接口测试
- testcase07: 游戏用户行为数据上报接口测试
- testcase08: 游戏用户行为数据上报接口测试
2. 测试接口定义
2.1 身份认证接口
接口路径: /test/authentication/check
请求方法: POST
请求参数:
ai
: 用户账号IDidentity
: 身份证号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. 结论
通过以上测试用例,我们可以验证网络游戏防沉迷实名认证接口的功能是否正常,包括身份认证、认证结果查询以及用户行为数据上报。确保这些接口能够正常工作对维护游戏环境的健康和合法性至关重要。如果有任何问题或错误,请根据返回的