我正在尝试打印一个应用了 sha256 哈希值的 int,但仅在服务器日志中获取 [object Object]。
关于如何打印/查看对象有什么想法吗?
Meteor.methods({
twilioTest:function () {
console.log("Twilio Test Called!");
// Get time for 2fa code
var d = new Date();
var seconds = d.getTime() / 1000;
seconds = parseInt(seconds);
// Get large random int
var largeInt = Math.floor(Math.random() * (999999999 - 99999999999999999) + 99999999999999999);
console.log("seconds value: " + seconds);
console.log("largeInt value: " + largeInt);
// Combine the values
var combined = seconds + largeInt;
console.log("combined value: " + combined);
// Hash the value
combined = Meteor.call('generateHash',combined);
console.log("combined value HASHED: " + combined);
},
generateHash: function(val){
check(val, Match.Any);
var hash = 0;
var crypto = Npm.require('crypto');
var key = 'abc123';
hash = crypto.createHmac('sha256', key);
return hash;
}
});
最佳答案
Meteor.call() 不会按照您期望的方式返回值;你需要检查回调。使用这样的东西:
Meteor.call('generateHash', function(error, hash) {
if (error) {
console.log(error);
} else {
console.log(hash);
}
});
关于javascript - 打印出哈希值?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/34625162/