Created
August 29, 2019 01:56
-
-
Save SiZapPaaiGwat/8d7fff987db936ce6da0342930b6835d to your computer and use it in GitHub Desktop.
parse ios udid in safari from mobileconfig file using express as a middleware
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
const parseString = require('xml2js').parseString | |
const _ = require('lodash') | |
/** | |
* 通过 safari 浏览器获取 iOS 的 udid | |
* POST 过来的是二进制,不是标准的 xml | |
* https://www.exchen.net/%E9%80%9A%E8%BF%87-safari-%E6%B5%8F%E8%A7%88%E5%99%A8%E8%8E%B7%E5%8F%96-udid.html | |
*/ | |
function parser (req, res, next) { | |
if (req.method !== 'POST' || req.get('content-type') !== 'application/pkcs7-signature') { | |
next() | |
return | |
} | |
const tag = 'dict' | |
let data = '' | |
req.setEncoding('utf8') | |
req.on('data', function (chunk) { | |
data += chunk | |
}) | |
req.on('end', function () { | |
let xmlStr = data.slice(data.indexOf(`<${tag}>`), data.indexOf(`</${tag}>`)) + `</${tag}>` | |
parseString(xmlStr, function (err, result) { | |
if (err) { | |
next(err) | |
} else { | |
req.body = _.zipObject(result[tag].key, result[tag].string) | |
next() | |
} | |
}) | |
}) | |
} | |
module.exports = parser | |
/* | |
<dict> | |
<key>IMEI</key> | |
<string>35 382108 864314 5</string> | |
<key>PRODUCT</key> | |
<string>iPhone9,2</string> | |
<key>UDID</key> | |
<string>9636243e9bb07fe57b27ab252b424a1cfc9d0595</string> | |
<key>VERSION</key> | |
<string>16E227</string> | |
</dict> | |
*/ |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment