test.js 3.2 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374
  1. us = {};
  2. // us.qs = require("querystring"); //引用文件解析包
  3. // us.http = require("http"); //引用http server服务
  4. // 引入Express模块
  5. const express = require('express');
  6. const qs = require('qs');
  7. const path = require('path');
  8. us.http = require("http"); //引用http server服务
  9. const http = require('http');
  10. // 创建Express应用
  11. const app = express();
  12. // 设置静态文件目录
  13. app.use(express.static(path.join(__dirname, '/')));
  14. us.server = us.http.createServer(function (reqo, reso) {
  15. // 定义路由
  16. // app.all('/', (req, res) => {
  17. //设置跨域
  18. reso.writeHead(200, {
  19. "Content-Type": "application/json",
  20. 'Access-Control-Allow-Origin': '*',
  21. "Connection": "keep-alive",
  22. 'Access-Control-Allow-Headers': 'Origin, No-Cache, X-Requested-With, If-Modified-Since, Pragma, Last-Modified, Cache-Control, Expires, Content-Type, X-E4M-With'
  23. });
  24. // http://apis.ssti.net.cn:80/taskcenterapp/sys/taskCenter/taskReceive/pushTask.do
  25. const options = {
  26. hostname: 'apis.ssti.net.cn',
  27. port: 80,
  28. path: '/taskcenterapp/sys/taskCenter/taskReceive/pushTask.do',
  29. method: 'POST',
  30. headers: {
  31. 'Content-Type': 'application/x-www-form-urlencoded',
  32. 'appId': '36dd21cde3b2f30a',
  33. 'accessToken': '463e95bdad1a9506bd1b271194f89383'
  34. }
  35. };
  36. const req = http.request(options, (res) => {
  37. console.log(`statusCode: ${res.statusCode}`);
  38. res.on('data', (data) => {
  39. console.log(data.toString());
  40. });
  41. });
  42. req.on('error', (error) => {
  43. console.error(error);
  44. });
  45. const bodyData = qs.stringify({ appId: "36dd21cde3b2f30a", taskInfo: '{"inserttasks":[{"app_id":"test11","assignments":[{"assign_dept":"图书部门","assign_id":"ampadmin","assign_name":"ampadmin"}],"biz_domain":"测试部门","biz_key":"bizkey_1000112","created_by_depts":"图书部门","created_by_ids":"ampadmin","created_by_names":"ampadmin","created_on":"2018-01-16 15:06:18","form_url":"https://baidu.com","form_url_view":"https://baidu.com","node_id":"1000112","node_name":"人事审核","priority":0,"process_delete_flag":0,"process_id":"leave_1233211932","process_instance_form_view":"https://taobao.com","process_instance_id":"1233211932","process_instance_image_url":"https://baidu.com","process_instance_initiator":"ampadmin","process_instance_initiator_dp":"图书部门","process_instance_initiator_id":"ampadmin","process_instance_start_date":"2018-01-16 15:06:18","process_instance_status":"RUNNING","process_instance_subject":"请假流程:ampadmin","process_name":"请假流程","process_version":"1.0","status":"ACTIVE","subject":"test_发起请假流程-tstsysys","task_delete_flag":0,"task_id":"1000112"}],"updatetasks":[]}' });
  46. req.write(bodyData);
  47. req.end();
  48. reso.end("")
  49. });
  50. // 启动服务器
  51. app.listen(3000, () => {
  52. console.log('Server is running on port 3000');
  53. });
  54. /**
  55. * 监听1473端口的处理
  56. *
  57. **/
  58. us.server.listen('1473', '', function () {
  59. //在控制台输出监听提示
  60. console.log("开始监听" + us.server.address().port + "......");
  61. });