中宣部实名认证
先吐槽
這個文檔,絕對不是人看的,稀爛
然后給代碼吧,復制下面代碼就可以跑接口了
注意:
- 下面為正式環境代碼,測試環境下需要在請求鏈接后面拼接測試碼
- 測試環境下,只支持原文檔中提供的「預置數據」“某一一”等進行測試,不要用真實身份證和姓名測試
- 測試環境可以沒有content-Type,正式環境需要有
- 注意行為上報里面的參數,要匹配對應的測試接口
- 需要每個接口都測試到,才能跑正式環境
check接口
const urllib = require('urllib'); var crypto = require("crypto"); const request = require("request"); let SHA256 = require("crypto-js/sha256"); const fcmconfig = require("./config");ai = "xd_user_" + Date.now();console.log("請保留參數 ai: " + ai);//Requestvar contentType = 'application/json; charset=utf-8';var headers = {//'Content-Type': contentType,'appId': config.appid,'bizId': bid,'timestamps': Date.now()}var body = {idNum: idNum,name: name,ai: ai}var encbody = aesGcmEncrypt(JSON.stringify(body), config.key);var encbodystr = '{"data":"' + encbody + '"}';headers['sign'] = create_sign(headers, '', encbodystr, config.key);var reqData = {method: "POST",headers: headers,data: encbodystr}urllib.request("https://api.wlc.nppa.gov.cn/idcard/authentication/check", reqData,(err, data, response) => {console.log("返回數據:" + data.toString());});function aesGcmEncrypt(message, key) {console.log("請求參數:" + message);// AES 128 GCM Modelet iv = crypto.randomBytes(12);const cipher = crypto.createCipheriv('aes-128-gcm', Buffer.from(key, "hex"), iv);cipher.setAutoPadding(true);// encrypt the given textconst encrypted = Buffer.concat([cipher.update(message, 'utf8'), cipher.final()]);// extract the auth tagconst tag = cipher.getAuthTag();// generate outputreturn Buffer.concat([iv, encrypted, tag]).toString('base64'); }function sortObjectToString(data) {let sdic = Object.keys(data).sort();let str = '';for (let ki in sdic) {let k = sdic[ki];str += k + data[k];}return str; }function create_sign(headers, query, body, key) {let data = Object.assign(headers, query);return SHA256(key + sortObjectToString(data, true) + body).toString(); }需要其他接口的話,留言郵箱啊,我回復郵件,私聊無法發代碼文件
總結
- 上一篇: ESXI 6.7全面系统教程~esxi安
- 下一篇: 2023中国西部(西安)第六届城乡环卫新