chaosss 2022-11-04 13:36:30
Bmob加密请求
function onRequest(request, response, modules) {
var host = "https://api.example.com";
var url = host + request.query.path;
var timeStamp = Date.now();
var noncestr = "";
var secretKey = "应用密钥";
var safeToken = "API安全码";
var safeSign = "";
/*生成N位随机流水号*/
/*默认去掉了容易混淆的字符oOLl,9gq,Vv,Uu,I1*/
var n = 16;
var $chars = "ABCDEFGHJKMNPQRSTWXYZabcdefhijkmnprstwxyz2345678";
var maxPos = $chars.length;
for (i = 0; i < n; i++) {
noncestr += $chars.charAt(Math.floor(Math.random() * maxPos));
}
//获取crypto模块
var crypto = modules.oCrypto;
var md5 = crypto.createHash("md5");
safeSign = md5
.update(String(request.query.path + timeStamp + safeToken + noncestr))
.digest("hex");
//获取Http模块
var http = modules.oHttp;
var options = {
url: url,
headers: {
"X-Bmob-SDK-Type": "API",
"X-Bmob-Safe-Sign": safeSign,
"X-Bmob-Safe-Timestamp": timeStamp,
"X-Bmob-Noncestr-Key": noncestr,
"X-Bmob-Secret-Key": secretKey,
"Content-Type": "application/json"
}
};
//response.send(options);
//发起Get请求
http(options, function (error, res, body) {
response.send(body);
});
}