Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions .eslintrc.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
module.exports = {
extends: 'guo',
rules: {
'valid-jsdoc': 'off',
}
};
27 changes: 15 additions & 12 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,29 +1,32 @@
{
"name": "tencentyoutuyun",
"version": "1.0.0",
"description": "node sdk for qcloud youtu",
"name": "youtusdk",
"version": "2.0.0",
"description": "腾讯优图开放平台第三方SDK",
"main": "index.js",
"scripts": {
"test": "echo \"Error: no test specified\" && exit 1"
"sample": "export DEBUG='YouTu:*' && node sample/sample.js",
"test": "echo \"Error: no test specified\" && exit 1",
"lint": "eslint tencentyoutuyun sample --fix"
},
"repository": {
"type": "git",
"url": "git+https://github.com/TencentYouTu/nodejs_sdk.git"
"url": "https://github.com/yourtion/node-youtu"
},
"keywords": [
"qcloud",
"youtu"
],
"author": "tencentyoutuyun",
"author": "YourtionGuo <yourtion@gmail.com>",
"license": "MIT",
"bugs": {
"url": "https://github.com/TencentYouTu/nodejs_sdk/issues"
"url": "https://github.com/yourtion/node-youtu/issues"
},
"homepage": "https://github.com/TencentYouTu/nodejs_sdk#readme",
"engines": [
"node >= 0.4.7"
],
"homepage": "https://github.com/yourtion/node-youtu#readme",
"dependencies": {
"iconv-lite": "^0.4.13"
"debug": "^2.2.0"
},
"devDependencies": {
"eslint": "^4.12.1",
"eslint-config-guo": "^0.6.0"
}
}
2 changes: 2 additions & 0 deletions run
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
export DEBUG=*
node sample/sample.js
61 changes: 47 additions & 14 deletions sample/sample.js
Original file line number Diff line number Diff line change
@@ -1,26 +1,59 @@
var tencentyoutuyun = require('..');
var conf = tencentyoutuyun.conf;
var youtu = tencentyoutuyun.youtu;
const tencentyoutuyun = require('..');
const conf = tencentyoutuyun.conf;
const youtu = tencentyoutuyun.youtu;

// 设置开发者和应用信息, 请填写你在开放平台
var appid = '****';
var secretId = '****';
var secretKey = '****';
var userid = '****';
const appid = '****';
const secretId = '****';
const secretKey = '****';
const userid = '****';

conf.setAppInfo(appid, secretId, secretKey, userid, 0)

conf.setAppInfo(appid, secretId, secretKey, userid, 0);

//youtu.imageporn('a1.jpg', function(data){
// 人脸检测 测试
// youtu.detectface('a.jpg', 0, function (data){
// console.log('detectface:' + JSON.stringify(data));
// });

// 人脸比对 测试
// youtu.facecompare('a.jpg', 'a.jpg', function(data){
// console.log("facecompare:" + JSON.stringify(data));
// });

// 人脸比对 测试
// youtu.fuzzydetect('a.jpg', function(data){
// console.log("fuzzydetect:" + JSON.stringify(data));
// })

// youtu.fooddetect('a.jpg', function(data){
// console.log("fooddetect:" + JSON.stringify(data));
// });

// youtu.imagetag('a.jpg', function(data){
// console.log("imagetag:" + JSON.stringify(data));
// });


// youtu.imageporn('a1.jpg', function(data){
// console.log("imagetag:" + JSON.stringify(data));
//});
// });

//youtu.idcardocr('a.jpg', 0, function(data){
// youtu.idcardocr('a.jpg', 0, function(data){
// console.log("idcardocr:" + JSON.stringify(data));
//});
// });

//youtu.namecardocr('a.jpg', false, function(data){
// youtu.namecardocr('a.jpg', false, function(data){
// console.log("namecardocr:" + JSON.stringify(data));
//});
// });

// 其他接口 类似
// 身份证OCR识别
// youtu.idcardocr('sfz3.jpg',0,function(data){
// console.log("fuzzydetect:" + JSON.stringify(data));
// })

// 身份证OCR识别
// youtu.namecardocr('mp2.jpg',true,function(data){
// console.log("fuzzydetect:" + JSON.stringify(data));
// })
49 changes: 24 additions & 25 deletions tencentyoutuyun/auth.js
Original file line number Diff line number Diff line change
@@ -1,42 +1,41 @@
var crypto = require('crypto');
var urlM = require('url');
var conf = require('./conf');
const crypto = require('crypto');
const conf = require('./conf');

exports.AUTH_PARAMS_ERROR = -1;
exports.AUTH_SECRET_ID_KEY_ERROR = -2;

exports.appSign = function(expired, userid) {
exports.appSign = function (expired, userid) {

var secretId = conf.SECRET_ID || '';
var secretKey = conf.SECRET_KEY || '';
var appid = conf.APPID || '';
const secretId = conf.SECRET_ID || '';
const secretKey = conf.SECRET_KEY || '';
const appid = conf.APPID || '';

var pexpired = expired || '';
var puserid = userid || conf.USERID;
const pexpired = expired || '';
const puserid = userid || conf.USERID;


if (!pexpired || !puserid ) {
return module.exports.AUTH_PARAMS_ERROR;
}
if (!pexpired || !puserid) {
return module.exports.AUTH_PARAMS_ERROR;
}

if ( !secretId || !secretKey ) {
return module.exports.AUTH_SECRET_ID_KEY_ERROR;
}
if (!secretId || !secretKey) {
return module.exports.AUTH_SECRET_ID_KEY_ERROR;
}

var now = parseInt(Date.now() / 1000);
var rdm = parseInt(Math.random() * Math.pow(2, 32));
const now = parseInt(Date.now() / 1000, 10);
const rdm = parseInt(Math.random() * Math.pow(2, 32), 10);

// the order of every key is not matter verify
var plainText = 'a=' + appid + '&k=' + secretId + '&e=' + pexpired + '&t=' + now + '&r=' + rdm + '&u=' + puserid;
// the order of every key is not matter verify
const plainText = 'a=' + appid + '&k=' + secretId + '&e=' + pexpired + '&t=' + now + '&r=' + rdm + '&u=' + puserid;

var data = new Buffer(plainText,'utf8');
const data = new Buffer(plainText, 'utf8');

var res = crypto.createHmac('sha1',secretKey).update(data).digest();
const res = crypto.createHmac('sha1', secretKey).update(data).digest();

var bin = Buffer.concat([res,data]);
const bin = Buffer.concat([ res, data ]);

var sign = bin.toString('base64');
const sign = bin.toString('base64');

return sign;
}
return sign;
};

52 changes: 24 additions & 28 deletions tencentyoutuyun/conf.js
Original file line number Diff line number Diff line change
@@ -1,40 +1,36 @@
var fs = require('fs');
var path = require('path');
var os = require('os');
const fs = require('fs');
const path = require('path');
const os = require('os');

// 请到 open.youtu.qq.com查看您对应的appid相关信息并填充
// 请统一 通过 setAppInfo 设置
// 请统一 通过 setAppInfo 设置

exports.APPID = '';
exports.SECRET_ID = '';
exports.SECRET_KEY = '';
exports.USERID = '';

var pkg = JSON.parse(fs.readFileSync(path.join(__dirname, '../', 'package.json')));
var ua = function() {
return 'QcloudNodejs/' + pkg.version + ' (' + os.type() + '; ' + os.platform() + '; ' + os.arch() + '; ) ';
}
const pkg = JSON.parse(fs.readFileSync(path.join(__dirname, '../', 'package.json')));
const ua = function () {
return 'YouTuSDK/' + pkg.version + ' (' + os.type() + '; ' + os.platform() + '; ' + os.arch() + '; ) ';
};

exports.USER_AGENT = ua;
exports.API_YOUTU_SERVER= 'api.youtu.qq.com';
exports.API_YOUTU_PORT= 80;
exports.getAgent = ua;
exports.API_YOUTU_SERVER = 'api.youtu.qq.com';
exports.API_YOUTU_PORT = 80;
exports.API_DOMAIN = 0;

// 初始化 应用信息
exports.setAppInfo = function(appid, secretId, secretKey, userid, domain) {
module.exports.APPID = appid;
module.exports.SECRET_ID = secretId;
module.exports.SECRET_KEY = secretKey;
module.exports.USERID = userid;
if(domain == 0)
{
exports.API_YOUTU_SERVER= 'api.youtu.qq.com';
}
else
{
exports.API_YOUTU_SERVER= 'youtu.api.qcloud.com';
}
exports.API_DOMAIN = domain;
}

// 初始化 应用信息
exports.setAppInfo = function (appid, secretId, secretKey, userid, domain) {
module.exports.APPID = appid;
module.exports.SECRET_ID = secretId;
module.exports.SECRET_KEY = secretKey;
module.exports.USERID = userid;
if(domain === 0) {
exports.API_YOUTU_SERVER = 'api.youtu.qq.com';
} else {
exports.API_YOUTU_SERVER = 'youtu.api.qcloud.com';
}
exports.API_DOMAIN = domain;
};

Loading