var qs = require('querystring');

//输入参数：id,name,portraitUri,deviceid，用于交换token
function process(req,res,db){
    var finish = false;
    var body = '';
    req.on('data', function (data) {
        body += data;
    });
    req.on('end', function () {
        var postBody = qs.parse(body);
        if (postBody.id == null || postBody.name == null || postBody.deviceid == null || postBody.portraitUri == null){
            res.writeHead(403,{'Content-Type': 'text/plain','Content-Length': "Missing parameter.".length});
            res.end("Missing parameter.");
            console.log("Missing parameter.");
            return;
        }
        authUser(postBody.id,postBody.name,postBody.portraitUri,postBody.deviceid,res,req);
    });
}

var conf = require("../conf.json");
var http = require('http');

function authUser(id,name,portrait,deviceid,res,req){
	// Build the post string from an object
	var post_data = qs.stringify({
		'userId' : id,
		'name': name,
		'portraitUri': portrait,
		'deviceId': deviceid
	});

	// An object of options to indicate where to post to
	var post_options = {
		host: conf.apiHost,
		port: conf.apiPort,
		path: '/reg.json',
		method: 'POST',
		headers: {
			'appKey': conf.appKey,
			'appSecret': conf.appSecret,
			'Content-Type': 'application/x-www-form-urlencoded',
			'Content-Length': Buffer.byteLength(post_data,'utf8')
		}
	};

	// Set up the request
	var post_req = http.request(post_options, function(response) {
        req.finish = true;
		response.setEncoding('utf8');
        var responseString = '';
        response.on('data',function(chunk){
            responseString += chunk;
        })
		response.on('end', function () {
			res.writeHead(response.statusCode, {'Content-Type': 'text/plain','Content-Length': Buffer.byteLength(responseString,'utf8')});
			res.end(responseString);
		});
	});

	post_req.on('error', function(e) {
        req.finish = true;
		console.log('problem with request: ' + e.message);
		res.writeHead(500,{'Content-Type': 'text/plain','Content-Length': e.message.length});
		res.end(e.message);
	});

	// post the data
	post_req.write(post_data);
	post_req.end();
}

exports.process = process;

@@ -347,37 +347,8 @@
 l %7C%7C
- postBody.deviceid == null %7C%7C
  pos
@@ -375,16 +375,16 @@
  null)%7B%0A
+
         
@@ -672,26 +672,8 @@
 Uri,
-postBody.deviceid,
 res,
@@ -793,17 +793,8 @@
 ait,
-deviceid,
 res,
@@ -934,32 +934,8 @@
 rait
-,%0A%09%09'deviceId': deviceid
 %0A%09%7D)
@@ -1071,11 +1071,21 @@
 : '/
-reg
+user/getToken
 .jso

Update auth.js