Commit 92458d84 authored by 刘文胜's avatar 刘文胜

赠送积分改为调用 封装了rabbitmq的restful接口

parent 1c7c8602
......@@ -15,14 +15,43 @@ var ACTION_KEY = {
};
var mongoose = require('mongoose'),
moment = require('moment'),
then = require('thenjs');
then = require('thenjs'),
request = require('request'),
config = require('../../config/config'),
_ = require('lodash');
var ForumPVLog = mongoose.model('ForumPVLog'),
ForumUVLog = mongoose.model('ForumUVLog'),
ForumShareLog = mongoose.model('ForumShareLog'),
ForumThread = mongoose.model('ForumThread');
function paramSort(obj){
try{
var keys = _.map(obj,function(v,k){
return k;
}).sort();
return _.map(keys,function(n){
return (obj[n] || '').toString();
}).join('');
}catch(e){
console.log('参数排序失败',e);
}
}
function createSignature(str){
var signature=null;
try{
var Buffer = require("buffer").Buffer;
var buf = new Buffer(str);
var str = buf.toString("binary");
return require("crypto").createHash("md5").update(str).digest("hex");
}catch(e){
console.log('生成参数签名错误',e);
}
return signature;
}
exports.sendRequest = function(ent_code, mid, action, messageid, integral, exp) {
var obj = {
/*var obj = {
tag: 'member',
key: 'forum',
action: ACTION_KEY[action],
......@@ -36,6 +65,22 @@ exports.sendRequest = function(ent_code, mid, action, messageid, integral, exp)
if (err) {
console.error(err);
}
});*/
//使用 rabbitmq 提供的restful接口
var obj = {
action: ACTION_KEY[action],
mid: mid,
entCode: ent_code
};
//将参数排序
obj.signature=createSignature(paramSort(obj));//接口调用参数签名
request.post({
url: config.rest_api + '/v1.0/internal/taskcenter/integral/change',
json: obj
}, function(e, r, body) {
if (e) {
console.log(e)
}
});
};
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment