提交 fa57eaeb authored 作者: 王鹏飞's avatar 王鹏飞

chore: update

上级 0c468741
This source diff could not be displayed because it is too large. You can view the blob instead.
const fs = require('fs') const fs = require('fs')
const conf = require('../config') const conf = require('../config')
const com = require('@god/node-com') const com = require('@ezijing/node-com')
const Proxy = com.Proxy const Proxy = com.Proxy
const ckeditorUpload = (req, res) => { const ckeditorUpload = (req, res) => {
/* 文件上传 ckeditor4.5以上返回格式 */ /* 文件上传 ckeditor4.5以上返回格式 */
function sendHtml (url, msg) { function sendHtml(url, msg) {
res.json({ res.json({
'uploaded': url ? 1 : 0, uploaded: url ? 1 : 0,
'fileName': 'image', fileName: 'image',
'url': url, url: url,
'error': { error: {
'message': msg message: msg,
} },
}) })
} }
if (req.files.length) { if (req.files.length) {
if (!req.files[0].mimetype.startsWith('image')) { sendHtml('', '文件类型错误,请上传图片'); return } if (!req.files[0].mimetype.startsWith('image')) {
if (req.files[0].size > 10 * 1024 * 1024) { sendHtml('', '图片大小超限'); return } sendHtml('', '文件类型错误,请上传图片')
return
}
if (req.files[0].size > 10 * 1024 * 1024) {
sendHtml('', '图片大小超限')
return
}
req.files[0].fieldname = 'file' req.files[0].fieldname = 'file'
Proxy.reqHttps({ Proxy.reqHttps(
{
hostname: req.headers.reqhost, // 直接传 host,会被 kong的nginx接管,不能再调用,所以改为自定义host hostname: req.headers.reqhost, // 直接传 host,会被 kong的nginx接管,不能再调用,所以改为自定义host
path: '/api/lms/util/upload-file', path: '/api/lms/util/upload-file',
method: 'POST', method: 'POST',
...@@ -30,12 +37,13 @@ const ckeditorUpload = (req, res) => { ...@@ -30,12 +37,13 @@ const ckeditorUpload = (req, res) => {
query: req.query || {}, query: req.query || {},
files: req.files, files: req.files,
headers: { headers: {
'tenant': req.headers.tenant, tenant: req.headers.tenant,
'Cookie': req.headers.cookie || '', Cookie: req.headers.cookie || '',
'User-Agent': req.headers['user-agent'], 'User-Agent': req.headers['user-agent'],
'Content-Type': 'multipart/form-data' 'Content-Type': 'multipart/form-data',
} },
}, function (str, obj) { },
function (str, obj) {
try { try {
const _json = JSON.parse(str) const _json = JSON.parse(str)
if (_json.success) { if (_json.success) {
...@@ -46,10 +54,11 @@ const ckeditorUpload = (req, res) => { ...@@ -46,10 +54,11 @@ const ckeditorUpload = (req, res) => {
} catch (e) { } catch (e) {
sendHtml('', '上传错误,请重试1') sendHtml('', '上传错误,请重试1')
} }
}) }
)
} }
} }
module.exports = { module.exports = {
ckeditorUpload: ckeditorUpload ckeditorUpload: ckeditorUpload,
} }
...@@ -2,7 +2,7 @@ const fs = require('fs') ...@@ -2,7 +2,7 @@ const fs = require('fs')
// 自带模块 crypto // 自带模块 crypto
const crypto = require('crypto') const crypto = require('crypto')
const path = require('path') const path = require('path')
const com = require('@god/node-com') const com = require('@ezijing/node-com')
const Proxy = com.Proxy const Proxy = com.Proxy
const md5 = com.Tool.md5 const md5 = com.Tool.md5
...@@ -10,7 +10,7 @@ const md5 = com.Tool.md5 ...@@ -10,7 +10,7 @@ const md5 = com.Tool.md5
const appPro1 = { const appPro1 = {
AppId: '5111635045', AppId: '5111635045',
AppSecret: '0f35445117f738c9292c52ad8af94064' AppSecret: '0f35445117f738c9292c52ad8af94064',
} }
// 数据文件必须存 固定地点 // 数据文件必须存 固定地点
const appPro2 = { const appPro2 = {
...@@ -29,23 +29,22 @@ const appTest = { ...@@ -29,23 +29,22 @@ const appTest = {
// flowId: '9926fcd1956d41ab8e081c4480562f53' // flowId: '9926fcd1956d41ab8e081c4480562f53'
} }
let _accessToken = 'eyJ0eXAiOiJKV1QiLCJhbGciOiJIUzI1NiJ9.eyJnSWQiOiIzZWVkMDZkODE1MmQ0YzNlOGMwOGM2ZTQzNjA5ODViZCIsImFwcElkIjoiNTExMTYzNTA2OCIsIm9JZCI6IjhiYTNkMDY0ZDZjYTQ0MThhM2Q0YzNkNTI4MDVlOWJiIiwidGltZXN0YW1wIjoxNjA5NDMxOTg5NTQ4fQ.3F4izbojHlWj80zA4mUcgBZTWJn9IDzQsd-tHQw7cr8' let _accessToken =
'eyJ0eXAiOiJKV1QiLCJhbGciOiJIUzI1NiJ9.eyJnSWQiOiIzZWVkMDZkODE1MmQ0YzNlOGMwOGM2ZTQzNjA5ODViZCIsImFwcElkIjoiNTExMTYzNTA2OCIsIm9JZCI6IjhiYTNkMDY0ZDZjYTQ0MThhM2Q0YzNkNTI4MDVlOWJiIiwidGltZXN0YW1wIjoxNjA5NDMxOTg5NTQ4fQ.3F4izbojHlWj80zA4mUcgBZTWJn9IDzQsd-tHQw7cr8'
let _info = { let _info = {
domain_test: 'smlopenapi.esign.cn', domain_test: 'smlopenapi.esign.cn',
domain_pro: 'openapi.esign.cn' domain_pro: 'openapi.esign.cn',
} }
// const _app = appPro2 // const _app = appPro2
// const _domain = _info.domain_pro // const _domain = _info.domain_pro
const _app = appTest const _app = appTest
const _domain = _info.domain_test const _domain = _info.domain_test
const _getAccessToken = (req, res) => { const _getAccessToken = (req, res) => {
Proxy.reqHttps({ Proxy.reqHttps(
{
hostname: _domain, hostname: _domain,
path: '/v1/oauth2/access_token', path: '/v1/oauth2/access_token',
method: 'GET', method: 'GET',
...@@ -53,12 +52,13 @@ const _getAccessToken = (req, res) => { ...@@ -53,12 +52,13 @@ const _getAccessToken = (req, res) => {
query: { query: {
appId: _app.AppId, appId: _app.AppId,
secret: _app.AppSecret, secret: _app.AppSecret,
grantType: 'client_credentials' grantType: 'client_credentials',
}, },
headers: { headers: {
'Host': _domain Host: _domain,
} },
}, function (str, obj) { },
function (str, obj) {
let jsonErr = { code: 500, message: '_getAccessToken 接口 调用失败' } let jsonErr = { code: 500, message: '_getAccessToken 接口 调用失败' }
let _json = {} let _json = {}
try { try {
...@@ -74,12 +74,12 @@ const _getAccessToken = (req, res) => { ...@@ -74,12 +74,12 @@ const _getAccessToken = (req, res) => {
} }
_accessToken = _json.data.token _accessToken = _json.data.token
res.status(200).json(_json) res.status(200).json(_json)
}) }
)
} }
// 需要传一个 file - 暂时只支持单文件 // 需要传一个 file - 暂时只支持单文件
const _getUploadUrl = (req, res) => { const _getUploadUrl = (req, res) => {
// 暂时先指定 originalname,中文本地服务存在问题 // 暂时先指定 originalname,中文本地服务存在问题
req.files[0].originalname = req.body.name || req.files[0].originalname req.files[0].originalname = req.body.name || req.files[0].originalname
...@@ -94,7 +94,8 @@ const _getUploadUrl = (req, res) => { ...@@ -94,7 +94,8 @@ const _getUploadUrl = (req, res) => {
fs.renameSync(req.files[0].path, req.files[0].destination + req.files[0].originalname) fs.renameSync(req.files[0].path, req.files[0].destination + req.files[0].originalname)
req.files[0].path = req.files[0].destination + req.files[0].originalname req.files[0].path = req.files[0].destination + req.files[0].originalname
Proxy.reqHttps({ Proxy.reqHttps(
{
hostname: _domain, hostname: _domain,
path: '/v1/files/getUploadUrl', path: '/v1/files/getUploadUrl',
method: 'POST', method: 'POST',
...@@ -104,16 +105,17 @@ const _getUploadUrl = (req, res) => { ...@@ -104,16 +105,17 @@ const _getUploadUrl = (req, res) => {
contentType: 'application/octet-stream', contentType: 'application/octet-stream',
convert2Pdf: /pdf/gi.test(req.files[0].originalname), convert2Pdf: /pdf/gi.test(req.files[0].originalname),
fileName: req.files[0].originalname, // req.files[0].originalname 暂时存在一个问题,1.本地服务中文乱码 fileName: req.files[0].originalname, // req.files[0].originalname 暂时存在一个问题,1.本地服务中文乱码
fileSize: req.files[0].size fileSize: req.files[0].size,
}, },
query: {}, query: {},
headers: { headers: {
'Host': _domain, Host: _domain,
'Content-Type': 'application/json; charset=UTF-8', 'Content-Type': 'application/json; charset=UTF-8',
'X-Tsign-Open-Token': _accessToken, 'X-Tsign-Open-Token': _accessToken,
'X-Tsign-Open-App-Id': _app.AppId 'X-Tsign-Open-App-Id': _app.AppId,
} },
}, function (str, obj) { },
function (str, obj) {
let jsonErr = { code: 500, message: '_getUploadUrl 接口 第一步调用失败' } let jsonErr = { code: 500, message: '_getUploadUrl 接口 第一步调用失败' }
let _json = {} let _json = {}
try { try {
...@@ -136,14 +138,16 @@ const _getUploadUrl = (req, res) => { ...@@ -136,14 +138,16 @@ const _getUploadUrl = (req, res) => {
_app.fileId = fileId _app.fileId = fileId
res.status(200).json(_json) res.status(200).json(_json)
}) })
}) }
)
} }
// 通过 application/octet-stream 方式 上传 文件 // 通过 application/octet-stream 方式 上传 文件
const _uploadFileFromOctetStream = (uploadUrl, str_base64_md5, filePath, callback) => { const _uploadFileFromOctetStream = (uploadUrl, str_base64_md5, filePath, callback) => {
let buffer = fs.readFileSync(filePath) let buffer = fs.readFileSync(filePath)
console.log(uploadUrl) console.log(uploadUrl)
Proxy.reqHttps({ Proxy.reqHttps(
{
hostname: uploadUrl.replace(/http(s|):\/\//gi, '').replace(/\/.*$/gi, ''), hostname: uploadUrl.replace(/http(s|):\/\//gi, '').replace(/\/.*$/gi, ''),
path: uploadUrl.replace(/http(s|):\/\/[^\/]*?\//gi, '/'), path: uploadUrl.replace(/http(s|):\/\/[^\/]*?\//gi, '/'),
method: 'PUT', method: 'PUT',
...@@ -152,8 +156,9 @@ const _uploadFileFromOctetStream = (uploadUrl, str_base64_md5, filePath, callbac ...@@ -152,8 +156,9 @@ const _uploadFileFromOctetStream = (uploadUrl, str_base64_md5, filePath, callbac
headers: { headers: {
'content-md5': str_base64_md5, 'content-md5': str_base64_md5,
'content-type': 'application/octet-stream', 'content-type': 'application/octet-stream',
} },
}, function (str, obj) { },
function (str, obj) {
let jsonErr = { code: 500, message: '_getUploadUrl 接口 第二步 _uploadFileFromOctetStream 调用失败' } let jsonErr = { code: 500, message: '_getUploadUrl 接口 第二步 _uploadFileFromOctetStream 调用失败' }
let _json = {} let _json = {}
try { try {
...@@ -163,28 +168,32 @@ const _uploadFileFromOctetStream = (uploadUrl, str_base64_md5, filePath, callbac ...@@ -163,28 +168,32 @@ const _uploadFileFromOctetStream = (uploadUrl, str_base64_md5, filePath, callbac
_json = jsonErr _json = jsonErr
} }
callback(_json) callback(_json)
}) }
)
} }
// 根据 fileId 查询文件上传状态 // 根据 fileId 查询文件上传状态
const _getInfoToUploadFile = (req, res) => { const _getInfoToUploadFile = (req, res) => {
Proxy.reqHttps({ Proxy.reqHttps(
{
hostname: _domain, hostname: _domain,
path: '/v1/files/' + req.body.fileId, path: '/v1/files/' + req.body.fileId,
method: 'GET', method: 'GET',
data: {}, data: {},
query: {}, query: {},
headers: { headers: {
'Host': _domain, Host: _domain,
'Content-Type': 'application/json; charset=UTF-8', 'Content-Type': 'application/json; charset=UTF-8',
'X-Tsign-Open-Token': _accessToken, 'X-Tsign-Open-Token': _accessToken,
'X-Tsign-Open-App-Id': _app.AppId 'X-Tsign-Open-App-Id': _app.AppId,
} },
}, function (str, obj) { },
function (str, obj) {
console.log(str) console.log(str)
// callback(str) // callback(str)
res.status(200).json(JSON.parse(str)) res.status(200).json(JSON.parse(str))
}) }
)
} }
// 先调用创建用户 再一建发起签署,返回url // 先调用创建用户 再一建发起签署,返回url
...@@ -203,7 +212,8 @@ const getOneStepUrl = (req, res) => { ...@@ -203,7 +212,8 @@ const getOneStepUrl = (req, res) => {
} }
const _token = (req, res, callback) => { const _token = (req, res, callback) => {
// 获取token // 获取token
Proxy.reqHttps({ Proxy.reqHttps(
{
hostname: _domain, hostname: _domain,
path: '/v1/oauth2/access_token', path: '/v1/oauth2/access_token',
method: 'GET', method: 'GET',
...@@ -211,12 +221,13 @@ const _token = (req, res, callback) => { ...@@ -211,12 +221,13 @@ const _token = (req, res, callback) => {
query: { query: {
appId: _app.AppId, appId: _app.AppId,
secret: _app.AppSecret, secret: _app.AppSecret,
grantType: 'client_credentials' grantType: 'client_credentials',
}, },
headers: { headers: {
'Host': _domain Host: _domain,
} },
}, function (str, obj) { },
function (str, obj) {
let jsonErr = { code: 500, message: 'getOneStepUrl 接口 第一步 /v1/oauth2/access_token调用失败' } let jsonErr = { code: 500, message: 'getOneStepUrl 接口 第一步 /v1/oauth2/access_token调用失败' }
let _json = {} let _json = {}
try { try {
...@@ -233,30 +244,33 @@ const _token = (req, res, callback) => { ...@@ -233,30 +244,33 @@ const _token = (req, res, callback) => {
_accessToken = _json.data.token _accessToken = _json.data.token
callback && callback() callback && callback()
}) }
)
} }
const _createUser = (req, res, callback) => { const _createUser = (req, res, callback) => {
// 创建用户 // 创建用户
Proxy.reqHttps({ Proxy.reqHttps(
{
hostname: _domain, hostname: _domain,
path: '/v1/accounts/createByThirdPartyUserId', path: '/v1/accounts/createByThirdPartyUserId',
method: 'POST', method: 'POST',
data: { data: {
"email": req.body.email || "", email: req.body.email || '',
"idNumber": "", idNumber: '',
"idType": "", idType: '',
"mobile": req.body.mobile || "", mobile: req.body.mobile || '',
"name": req.body.name || "张彦新", name: req.body.name || '张彦新',
"thirdPartyUserId": req.body.uuid || "17601621100" thirdPartyUserId: req.body.uuid || '17601621100',
}, },
query: {}, query: {},
headers: { headers: {
'Host': _domain, Host: _domain,
'Content-Type': 'application/json; charset=UTF-8', 'Content-Type': 'application/json; charset=UTF-8',
'X-Tsign-Open-Token': _accessToken, 'X-Tsign-Open-Token': _accessToken,
'X-Tsign-Open-App-Id': _app.AppId 'X-Tsign-Open-App-Id': _app.AppId,
} },
}, function (str, obj) { },
function (str, obj) {
let jsonErr = { code: 500, message: 'getOneStepUrl 接口 第二步 /v1/accounts/createByThirdPartyUserId调用失败' } let jsonErr = { code: 500, message: 'getOneStepUrl 接口 第二步 /v1/accounts/createByThirdPartyUserId调用失败' }
let _json = {} let _json = {}
try { try {
...@@ -274,66 +288,75 @@ const _createUser = (req, res, callback) => { ...@@ -274,66 +288,75 @@ const _createUser = (req, res, callback) => {
// accountId 传入,防止高并发时,出现意外 // accountId 传入,防止高并发时,出现意外
callback && callback(_json.data.accountId) callback && callback(_json.data.accountId)
}) }
)
} }
const _signFlowId = (req, res, callback) => { const _signFlowId = (req, res, callback) => {
// 一建发起签署 // 一建发起签署
Proxy.reqHttps({ Proxy.reqHttps(
{
hostname: _domain, hostname: _domain,
path: '/api/v2/signflows/createFlowOneStep', path: '/api/v2/signflows/createFlowOneStep',
method: 'POST', method: 'POST',
data: { data: {
"attachments": [], attachments: [],
"copiers": [], copiers: [],
"docs":[{ docs: [
"fileId": _app.fileId, {
"fileName": "", fileId: _app.fileId,
"filePassword": "" fileName: '',
}], filePassword: '',
"flowInfo": { },
"autoArchive": true, ],
"autoInitiate": true, flowInfo: {
"businessScene": "Test 一键发起部署", autoArchive: true,
"flowConfigInfo": { autoInitiate: true,
"noticeDeveloperUrl": "", businessScene: 'Test 一键发起部署',
"noticeType": "", flowConfigInfo: {
"redirectUrl": "", noticeDeveloperUrl: '',
"signPlatform": "" noticeType: '',
}, redirectUrl: '',
"initiatorAccountId": "", signPlatform: '',
"initiatorAuthorizedAccountId": "", },
"remark": "" initiatorAccountId: '',
}, initiatorAuthorizedAccountId: '',
"signers": [{ remark: '',
"platformSign": false, },
"signerAccount": { signers: [
"authorizedAccountId": "", {
"signerAccountId": req.accountId platformSign: false,
}, signerAccount: {
"signfields": [{ authorizedAccountId: '',
"autoExecute": false, signerAccountId: req.accountId,
"fileId": _app.fileId, },
"signType": 0, signfields: [
"posBean": { {
"posPage": "" autoExecute: false,
}, fileId: _app.fileId,
"sealId": "", signType: 0,
"sealType": "0, 1", posBean: {
"signDateBean": { posPage: '',
"format": "" },
} sealId: '',
}], sealType: '0, 1',
"thirdOrderNo": "" signDateBean: {
}] format: '',
},
},
],
thirdOrderNo: '',
},
],
}, },
query: {}, query: {},
headers: { headers: {
'Host': _domain, Host: _domain,
'Content-Type': 'application/json; charset=UTF-8', 'Content-Type': 'application/json; charset=UTF-8',
'X-Tsign-Open-Token': _accessToken, 'X-Tsign-Open-Token': _accessToken,
'X-Tsign-Open-App-Id': _app.AppId 'X-Tsign-Open-App-Id': _app.AppId,
} },
}, function (str, obj) { },
function (str, obj) {
let jsonErr = { code: 500, message: 'getOneStepUrl 接口 第三步 /api/v2/signflows/createFlowOneStep调用失败' } let jsonErr = { code: 500, message: 'getOneStepUrl 接口 第三步 /api/v2/signflows/createFlowOneStep调用失败' }
let _json = {} let _json = {}
try { try {
...@@ -351,26 +374,29 @@ const _signFlowId = (req, res, callback) => { ...@@ -351,26 +374,29 @@ const _signFlowId = (req, res, callback) => {
// 每次生成的flowId不一致,防止高并发时出现意外 // 每次生成的flowId不一致,防止高并发时出现意外
callback && callback(_json.data.flowId) callback && callback(_json.data.flowId)
}) }
)
} }
const _getUrl = (req, res, callback) => { const _getUrl = (req, res, callback) => {
// 获取url // 获取url
Proxy.reqHttps({ Proxy.reqHttps(
{
hostname: _domain, hostname: _domain,
path: '/v1/signflows/' + req.flowId + '/executeUrl', path: '/v1/signflows/' + req.flowId + '/executeUrl',
method: 'GET', method: 'GET',
data: {}, data: {},
query: { query: {
flowId: req.flowId, flowId: req.flowId,
accountId: req.accountId accountId: req.accountId,
}, },
headers: { headers: {
'Host': _domain, Host: _domain,
'Content-Type': 'application/json; charset=UTF-8', 'Content-Type': 'application/json; charset=UTF-8',
'X-Tsign-Open-Token': _accessToken, 'X-Tsign-Open-Token': _accessToken,
'X-Tsign-Open-App-Id': _app.AppId 'X-Tsign-Open-App-Id': _app.AppId,
} },
}, function (str, obj) { },
function (str, obj) {
let jsonErr = { code: 500, message: 'getOneStepUrl 接口 第四步 /v1/signflows/{flowId}/executeUrl调用失败' } let jsonErr = { code: 500, message: 'getOneStepUrl 接口 第四步 /v1/signflows/{flowId}/executeUrl调用失败' }
let _json = {} let _json = {}
try { try {
...@@ -390,35 +416,38 @@ const _getUrl = (req, res, callback) => { ...@@ -390,35 +416,38 @@ const _getUrl = (req, res, callback) => {
_json.data.accountId = req.accountId _json.data.accountId = req.accountId
_json.data.fileId = _app.fileId _json.data.fileId = _app.fileId
callback && callback(_json) callback && callback(_json)
}) }
)
} }
// 获取签署后的文件 // 获取签署后的文件
const getAfterSignFile = (req, res) => { const getAfterSignFile = (req, res) => {
Proxy.reqHttps({ Proxy.reqHttps(
{
hostname: _domain, hostname: _domain,
path: '/v1/signflows/' + req.body.flowId + '/documents', path: '/v1/signflows/' + req.body.flowId + '/documents',
method: 'GET', method: 'GET',
data: {}, data: {},
query: {}, query: {},
headers: { headers: {
'Host': _domain, Host: _domain,
'Content-Type': 'application/json; charset=UTF-8', 'Content-Type': 'application/json; charset=UTF-8',
'X-Tsign-Open-Token': _accessToken, 'X-Tsign-Open-Token': _accessToken,
'X-Tsign-Open-App-Id': _app.AppId 'X-Tsign-Open-App-Id': _app.AppId,
} },
}, function (str, obj) { },
function (str, obj) {
console.log(str) console.log(str)
// callback(str) // callback(str)
res.status(200).json(JSON.parse(str)) res.status(200).json(JSON.parse(str))
}) }
)
} }
module.exports = { module.exports = {
_getAccessToken: _getAccessToken, _getAccessToken: _getAccessToken,
_getUploadUrl: _getUploadUrl, _getUploadUrl: _getUploadUrl,
_getInfoToUploadFile: _getInfoToUploadFile, _getInfoToUploadFile: _getInfoToUploadFile,
getOneStepUrl: getOneStepUrl, getOneStepUrl: getOneStepUrl,
getAfterSignFile: getAfterSignFile getAfterSignFile: getAfterSignFile,
} }
var com = require('@god/node-com') var com = require('@ezijing/node-com')
var _ReqHttp = com.Proxy.reqHttp var _ReqHttp = com.Proxy.reqHttp
var _MD5 = com.Tool.md5 var _MD5 = com.Tool.md5
...@@ -9,7 +9,7 @@ var conf = { ...@@ -9,7 +9,7 @@ var conf = {
StreamAppId: 1400255568, StreamAppId: 1400255568,
bizid: '33393', bizid: '33393',
sessionId: '', sessionId: '',
outStreamId: '' outStreamId: '',
} }
/* 根据腾讯云 - 创建混流 */ /* 根据腾讯云 - 创建混流 */
var getFlow = function (req, res) { var getFlow = function (req, res) {
...@@ -41,79 +41,83 @@ var _concelFlow = function (req, res) { ...@@ -41,79 +41,83 @@ var _concelFlow = function (req, res) {
/* 处理 混流建立 方式 */ /* 处理 混流建立 方式 */
var _dealCreateData = function (req, _time) { var _dealCreateData = function (req, _time) {
conf.sessionId = 'ne4MjXHKFce1yIwNMkKv9QtV6_hy0RoT' || _MD5('zyx_' + _time) conf.sessionId = 'ne4MjXHKFce1yIwNMkKv9QtV6_hy0RoT' || _MD5('zyx_' + _time)
conf.outStreamId = '33393_ca44d26966c309105baca4dbd10bb279' || ('stream_' + conf.sessionId) conf.outStreamId = '33393_ca44d26966c309105baca4dbd10bb279' || 'stream_' + conf.sessionId
console.log(_time, conf.AppId, conf.sessionId, conf.outStreamId, req.body) console.log(_time, conf.AppId, conf.sessionId, conf.outStreamId, req.body)
return JSON.stringify({ return JSON.stringify({
'timestamp': _time, // UNIX 时间戳数 timestamp: _time, // UNIX 时间戳数
'eventId': _time, // 取随机数即可,标识一次网络请求 eventId: _time, // 取随机数即可,标识一次网络请求
'interface': { interface: {
'interfaceName': 'Mix_StreamV2', // 固定值 interfaceName: 'Mix_StreamV2', // 固定值
'para': { para: {
'app_id': conf.AppId, // 填写直播 APPID app_id: conf.AppId, // 填写直播 APPID
'interface': 'mix_streamv2.start_mix_stream_advanced', // 固定值 interface: 'mix_streamv2.start_mix_stream_advanced', // 固定值
// 'interface': 'mix_streamv2.cancel_mix_stream', // 固定值 // 'interface': 'mix_streamv2.cancel_mix_stream', // 固定值
'mix_stream_template_id': 0, mix_stream_template_id: 0,
'mix_stream_session_id': conf.sessionId, // 标识一次网络请求 mix_stream_session_id: conf.sessionId, // 标识一次网络请求
'output_stream_id': conf.outStreamId, // 填输出流 ID output_stream_id: conf.outStreamId, // 填输出流 ID
'output_stream_type': 0, // 生成新流时,写1 output_stream_type: 0, // 生成新流时,写1
'input_stream_list': [{ input_stream_list: [
{
// 背景画面 // 背景画面
'input_stream_id': '33393_ca44d26966c309105baca4dbd10bb279', // 流 ID input_stream_id: '33393_ca44d26966c309105baca4dbd10bb279', // 流 ID
'layout_params': { layout_params: {
'image_layer': 1, // 图层号,背景填1 image_layer: 1, // 图层号,背景填1
'image_width': 640, image_width: 640,
'image_height': 360 image_height: 360,
} },
}, { },
{
// 小画面1 // 小画面1
'input_stream_id': '33393_9806f61c2d2193106b5bad448e80c3d8', // 流 ID input_stream_id: '33393_9806f61c2d2193106b5bad448e80c3d8', // 流 ID
'layout_params': { layout_params: {
'image_layer': 2, // 图层标识号 image_layer: 2, // 图层标识号
'image_width': 120, // 画面宽度 image_width: 120, // 画面宽度
'image_height': 90, // 画面高度 image_height: 90, // 画面高度
'location_x': 10, // x偏移:相对于背景画面左上角的横向偏移 location_x: 10, // x偏移:相对于背景画面左上角的横向偏移
'location_y': 10 // y偏移:相对于背景画面左上角的纵向偏移 location_y: 10, // y偏移:相对于背景画面左上角的纵向偏移
} },
}] },
} ],
} },
},
}) })
} }
/* 处理 混流取消 方式 */ /* 处理 混流取消 方式 */
var _dealCancelData = function (req, _time) { var _dealCancelData = function (req, _time) {
return JSON.stringify({ return JSON.stringify({
'timestamp': _time, // UNIX 时间戳数 timestamp: _time, // UNIX 时间戳数
'eventId': _time, // 混流事件ID,取时间戳即可 eventId: _time, // 混流事件ID,取时间戳即可
'interface': { interface: {
'interfaceName': 'Mix_StreamV2', // 固定值 interfaceName: 'Mix_StreamV2', // 固定值
'para': { para: {
'app_id': conf.AppId, app_id: conf.AppId,
'interface': 'mix_streamv2.cancel_mix_stream', // 取消混流 interface: 'mix_streamv2.cancel_mix_stream', // 取消混流
// 'interface': 'mix_streamv2.start_mix_stream_advanced', // 取消混流 // 'interface': 'mix_streamv2.start_mix_stream_advanced', // 取消混流
'mix_stream_session_id': conf.sessionId, mix_stream_session_id: conf.sessionId,
'output_stream_id': conf.outStreamId output_stream_id: conf.outStreamId,
} },
} },
}) })
} }
/* 鉴权 - 返回参数 */ /* 鉴权 - 返回参数 */
var _getOpt = function (_time) { var _getOpt = function (_time) {
/* 定义鉴权 */ /* 定义鉴权 */
var str = 'appid=' + conf.AppId + '&interface=Mix_StreamV2&t=' + (_time + 60) + '&sign=' + _MD5(conf.AppSecret + (_time + 60)) var str =
'appid=' + conf.AppId + '&interface=Mix_StreamV2&t=' + (_time + 60) + '&sign=' + _MD5(conf.AppSecret + (_time + 60))
var opt = { var opt = {
hostname: 'fcgi.video.qcloud.com', hostname: 'fcgi.video.qcloud.com',
path: '/common_access?' + str, path: '/common_access?' + str,
method: 'POST', method: 'POST',
headers: { headers: {
'Content-Type': 'application/json' 'Content-Type': 'application/json',
}, },
data: {} data: {},
} }
return opt return opt
} }
module.exports = { module.exports = {
getFlow getFlow,
} }
const fs = require('fs') const fs = require('fs')
const path = require('path') const path = require('path')
const com = require('@god/node-com') const com = require('@ezijing/node-com')
const Proxy = com.Proxy const Proxy = com.Proxy
const getData = (req, res) => { const getData = (req, res) => {
Proxy.reqHttps({ Proxy.reqHttps(
{
hostname: 'lms-api.ezijing.com', hostname: 'lms-api.ezijing.com',
path: '/v2/education/courses/' + req.path.replace(/\/abc\/test\/cba\//gi, ''), path: '/v2/education/courses/' + req.path.replace(/\/abc\/test\/cba\//gi, ''),
data: {}, data: {},
query: {}, query: {},
headers: { headers: {
'Host': 'lms-api.ezijing.com', Host: 'lms-api.ezijing.com',
'tenant': req.headers.tenant, tenant: req.headers.tenant,
'token': req.headers.token, token: req.headers.token,
'apikey': req.headers.apikey, apikey: req.headers.apikey,
'User-Agent': req.headers['user-agent'], 'User-Agent': req.headers['user-agent'],
'Content-Type': 'application/x-www-form-urlencoded' 'Content-Type': 'application/x-www-form-urlencoded',
} },
}, function (str, cookieStr) { },
function (str, cookieStr) {
console.error('接口读取数据', req.headers.token, str) console.error('接口读取数据', req.headers.token, str)
res.status(200).json(JSON.parse(str)) res.status(200).json(JSON.parse(str))
}) }
)
} }
module.exports = { module.exports = {
getData: getData getData: getData,
} }
const fs = require('fs') const fs = require('fs')
const path = require('path') const path = require('path')
const com = require('@god/node-com') const com = require('@ezijing/node-com')
const Proxy = com.Proxy const Proxy = com.Proxy
const md5 = com.Tool.md5 const md5 = com.Tool.md5
const use = (req, res) => { const use = (req, res) => {
Proxy.reqHttps({ Proxy.reqHttps(
{
hostname: 'zws-api.ezijing.com', hostname: 'zws-api.ezijing.com',
path: req.baseUrl, path: req.baseUrl,
method: req.method, method: req.method,
data: req.body || {}, data: req.body || {},
query: req.query || {}, query: req.query || {},
headers: { headers: {
'Host': 'zws-api.ezijing.com', Host: 'zws-api.ezijing.com',
'Cookie': req.headers.cookie || '', Cookie: req.headers.cookie || '',
'apikey': 'CXOIO7njD7o3RScs7MSHhvxeG4hbwX2S', apikey: 'CXOIO7njD7o3RScs7MSHhvxeG4hbwX2S',
'User-Agent': req.headers['user-agent'], 'User-Agent': req.headers['user-agent'],
'Content-Type': 'application/x-www-form-urlencoded' 'Content-Type': 'application/x-www-form-urlencoded',
} },
}, function (str, obj) { },
function (str, obj) {
console.error('获取cookie - 123456789', req.headers.cookie) console.error('获取cookie - 123456789', req.headers.cookie)
if (/image/gi.test(obj.resHeader['content-type'])) { if (/image/gi.test(obj.resHeader['content-type'])) {
// 这种方式不够高级,还要先生成一个图片文件,能不能直接返回一个文档流 // 这种方式不够高级,还要先生成一个图片文件,能不能直接返回一个文档流
res.header('Content-Type', obj.resHeader['content-type']) res.header('Content-Type', obj.resHeader['content-type'])
str = str.replace(/^data:image\/\w+;base64,/, "") str = str.replace(/^data:image\/\w+;base64,/, '')
let bf = new Buffer(str, 'base64') let bf = new Buffer(str, 'base64')
fs.writeFileSync('upload_tmp/image.' + md5(bf) + '.png', bf) fs.writeFileSync('upload_tmp/image.' + md5(bf) + '.png', bf)
fs.createReadStream('upload_tmp/image.' + md5(bf) + '.png').pipe(res) fs.createReadStream('upload_tmp/image.' + md5(bf) + '.png').pipe(res)
...@@ -34,9 +36,10 @@ const use = (req, res) => { ...@@ -34,9 +36,10 @@ const use = (req, res) => {
} else { } else {
res.status(200).json(JSON.parse(str)) res.status(200).json(JSON.parse(str))
} }
}) }
)
} }
module.exports = { module.exports = {
use: use use: use,
} }
// var com = require('@ezijing/node-com')
// var com = require('@god/node-com')
var callback = function (req, res) { var callback = function (req, res) {
var _body = req.body || {} var _body = req.body || {}
console.log(JSON.stringify(_body)) console.log(JSON.stringify(_body))
res.status(200).json({ 'msg': '正常' }) res.status(200).json({ msg: '正常' })
} }
module.exports = { module.exports = {
callback: callback callback: callback,
} }
var com = require('@ezijing/node-com')
var com = require('@god/node-com')
var _MD5 = com.Tool.md5 var _MD5 = com.Tool.md5
...@@ -11,14 +10,17 @@ var isRun = function (req, res) { ...@@ -11,14 +10,17 @@ var isRun = function (req, res) {
var apikey = req.headers.apikey || '' var apikey = req.headers.apikey || ''
var timestamp = Math.floor(new Date().getTime() / 100000000) + '00000000' var timestamp = Math.floor(new Date().getTime() / 100000000) + '00000000'
var md5Str = _MD5('godzyx.com' + timestamp) var md5Str = _MD5('godzyx.com' + timestamp)
if (operate === '1') { res.status(200).json({ 'MD5-auth': md5Str }); return } if (operate === '1') {
res.status(200).json({ 'MD5-auth': md5Str })
return
}
if (apikey === md5Str) { if (apikey === md5Str) {
res.status(200).json({ 'msg': '数据正在处理' }) res.status(200).json({ msg: '数据正在处理' })
} else { } else {
res.status(200).json({ 'msg': '拒绝访问该接口' }) res.status(200).json({ msg: '拒绝访问该接口' })
} }
} }
module.exports = { module.exports = {
isRun: isRun isRun: isRun,
} }
...@@ -38,7 +38,7 @@ function getsignature (req, res) { ...@@ -38,7 +38,7 @@ function getsignature (req, res) {
share_json.jsapi_ticket = JSON.parse(body).ticket share_json.jsapi_ticket = JSON.parse(body).ticket
share_json.noncestr = Math.random().toString(36).substr(2, 15) // 随机字符串 share_json.noncestr = Math.random().toString(36).substr(2, 15) // 随机字符串
share_json.timestamp = parseInt(new Date().getTime() / 1000) + '' // 事件戳 share_json.timestamp = parseInt(new Date().getTime() / 1000) + '' // 事件戳
share_json.url = req.body.url || req.headers.referer share_json.url = encodeURIComponent(req.body.url || req.headers.referer)
let str1 = 'jsapi_ticket=' + share_json.jsapi_ticket + '&noncestr=' + share_json.noncestr + '&timestamp=' + share_json.timestamp + '&url=' + share_json.url let str1 = 'jsapi_ticket=' + share_json.jsapi_ticket + '&noncestr=' + share_json.noncestr + '&timestamp=' + share_json.timestamp + '&url=' + share_json.url
let token = sha1(str1) let token = sha1(str1)
return err ? reject(err) : res.send({ return err ? reject(err) : res.send({
......
const fs = require('fs') const fs = require('fs')
const path = require('path') const path = require('path')
const com = require('@god/node-com') const com = require('@ezijing/node-com')
const _mkdir = com.Tool.Directory.mkdir const _mkdir = com.Tool.Directory.mkdir
...@@ -10,7 +10,7 @@ const getTable = (req, res) => { ...@@ -10,7 +10,7 @@ const getTable = (req, res) => {
_mkdir(path1.replace(/\/[^\/]*?$/gi, ''), () => { _mkdir(path1.replace(/\/[^\/]*?$/gi, ''), () => {
fs.writeFileSync(path1, JSON.stringify({}), 'utf8') fs.writeFileSync(path1, JSON.stringify({}), 'utf8')
}) })
res.status(200).json({ 'msg': '文件不存在,创建文件' }) res.status(200).json({ msg: '文件不存在,创建文件' })
return return
} }
let _json = JSON.parse(fs.readFileSync(path1).toString() || '{}') let _json = JSON.parse(fs.readFileSync(path1).toString() || '{}')
...@@ -21,7 +21,7 @@ const setTable = (req, res) => { ...@@ -21,7 +21,7 @@ const setTable = (req, res) => {
let path1 = path.resolve(process.cwd(), '../node-server-data/cloud-class.json') let path1 = path.resolve(process.cwd(), '../node-server-data/cloud-class.json')
if (!fs.existsSync(path1)) { if (!fs.existsSync(path1)) {
_mkdir(path1) _mkdir(path1)
res.status(200).json({ 'msg': '文件不存在,创建文件' }) res.status(200).json({ msg: '文件不存在,创建文件' })
return return
} }
let _json = JSON.parse(fs.readFileSync(path1).toString() || '{}') let _json = JSON.parse(fs.readFileSync(path1).toString() || '{}')
...@@ -38,5 +38,5 @@ const setTable = (req, res) => { ...@@ -38,5 +38,5 @@ const setTable = (req, res) => {
module.exports = { module.exports = {
getTable: getTable, getTable: getTable,
setTable: setTable setTable: setTable,
} }
const fs = require('fs') const fs = require('fs')
const path = require('path') const path = require('path')
const com = require('@god/node-com') const com = require('@ezijing/node-com')
const _mkdir = com.Tool.Directory.mkdir const _mkdir = com.Tool.Directory.mkdir
...@@ -10,7 +10,7 @@ const get = (req, res) => { ...@@ -10,7 +10,7 @@ const get = (req, res) => {
_mkdir(path1.replace(/\/[^\/]*?$/gi, ''), () => { _mkdir(path1.replace(/\/[^\/]*?$/gi, ''), () => {
fs.writeFileSync(path1, JSON.stringify({}), 'utf8') fs.writeFileSync(path1, JSON.stringify({}), 'utf8')
}) })
res.status(200).json({ 'msg': '文件不存在,创建文件' }) res.status(200).json({ msg: '文件不存在,创建文件' })
return return
} }
let _json = JSON.parse(fs.readFileSync(path1).toString() || '{}') let _json = JSON.parse(fs.readFileSync(path1).toString() || '{}')
...@@ -23,7 +23,7 @@ const set = (req, res) => { ...@@ -23,7 +23,7 @@ const set = (req, res) => {
let path1 = path.resolve(process.cwd(), '../node-server-data/wxchart-success.json') let path1 = path.resolve(process.cwd(), '../node-server-data/wxchart-success.json')
if (!fs.existsSync(path1)) { if (!fs.existsSync(path1)) {
_mkdir(path1.replace(/\/[^\/]*?$/gi, '')) _mkdir(path1.replace(/\/[^\/]*?$/gi, ''))
res.status(200).json({ 'msg': '文件不存在,创建文件' }) res.status(200).json({ msg: '文件不存在,创建文件' })
return return
} }
let _json = JSON.parse(fs.readFileSync(path1).toString() || '{}') let _json = JSON.parse(fs.readFileSync(path1).toString() || '{}')
...@@ -36,5 +36,5 @@ const set = (req, res) => { ...@@ -36,5 +36,5 @@ const set = (req, res) => {
module.exports = { module.exports = {
get: get, get: get,
set: set set: set,
} }
Markdown 格式
0%
您添加了 0 到此讨论。请谨慎行事。
请先完成此评论的编辑!
注册 或者 后发表评论