hlwyyAssistant.sdk.js 3.2 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495
  1. /**
  2. * 简易互联网医院 企业微信消息推送 SDK,提供互联网医院 企业微信消息推送接口调用。
  3. */
  4. 'use strict';
  5. let http = require('http');
  6. var reqq = require('request');
  7. let querystring = require('querystring');
  8. let configFile = require('../include/commons').CONFIG_FILE;
  9. let config = require('../resources/config/' + configFile);
  10. let log = require('./log.js');
  11. class HlwyyAssistantSDK {
  12. constructor(){}
  13. static request(enterpriseId,title,doctor,description,url, params,handler){
  14. log.info("1:"+enterpriseId)
  15. log.info("2:"+title)
  16. log.info("3:"+doctor)
  17. log.info("4:"+description)
  18. log.info("5:"+url)
  19. // let userAgent = {
  20. // admin_token: adminToken,
  21. // token: token,
  22. // uid: userId,
  23. // imei: imei
  24. // };
  25. // var postData=querystring.stringify(params);
  26. //
  27. // let options = {
  28. // hostname: config.hlwyyDAServerConfig.host,
  29. // port: config.hlwyyDAServerConfig.port,
  30. // path: config.hlwyyDAServerConfig.model+config.hlwyyDAServerConfig.enpoint+"?"+params,
  31. // method: 'POST',
  32. // headers: {
  33. // // 'userAgent': JSON.stringify(userAgent),
  34. // 'Content-Type': 'application/x-www-form-urlencoded;text/html;charset=utf-8'
  35. // // 'Content-Type': 'application/json;charset=UTF-8'
  36. // }
  37. // ,
  38. // body:JSON.stringify({enterpriseId:enterpriseId,
  39. // title:title,
  40. // doctor:doctor,
  41. // description:description,
  42. // url:url})
  43. // };
  44. //
  45. // let requestData= JSON.stringify({enterpriseId:enterpriseId,
  46. // title:title,
  47. // doctor:doctor,
  48. // description:description,
  49. // url:url})
  50. reqq({
  51. url: "http://"+config.hlwyyDAServerConfig.host+":"+config.hlwyyDAServerConfig.port+config.hlwyyDAServerConfig.model+config.hlwyyDAServerConfig.enpoint+"?"+params,
  52. method: "POST",
  53. json: true,
  54. headers: {
  55. "content-type": "application/json",
  56. },
  57. body: params
  58. }, function(error, response, body) {
  59. if (!error && response.statusCode == 200) {
  60. log.info('企业微信消息推送->请求成功:', body);
  61. // console.log(body) // 请求成功的处理逻辑
  62. }else{
  63. log.error('企业微信消息推送->请求失败: ', error.message);
  64. }
  65. });
  66. //
  67. //
  68. // let req = http.request(options, function (res) {
  69. // res.setEncoding('utf-8');
  70. // res.on('data', function (chunk) {
  71. // log.info('企业微信消息推送->请求成功:', chunk);
  72. //
  73. // handler(null, chunk);
  74. // });
  75. // });
  76. //
  77. // req.on('error', function (err) {
  78. // log.error('企业微信消息推送->请求失败: ', err.message);
  79. //
  80. // handler(err, null);
  81. // });
  82. // req.write(postData);
  83. // req.end();
  84. }
  85. }
  86. module.exports = HlwyyAssistantSDK;