hlwyyWechatAssistant.sdk.js 2.9 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465
  1. /**
  2. * 简易互联网医院 企业微信消息推送 SDK,提供互联网医院 企业微信消息推送接口调用。
  3. */
  4. 'use strict';
  5. var wechatreqq = require('request');
  6. let configFile = require('../include/commons').CONFIG_FILE;
  7. let config = require('../resources/config/' + configFile);
  8. let log = require('./log.js');
  9. class HlwyyWechatAssistantSDK {
  10. constructor(){}
  11. static request(userName,idCard,phone,title,contentSrt,contentStringStr,url,params,handler){
  12. log.info("1:"+userName)
  13. log.info("2:"+idCard)
  14. log.info("3:"+phone)
  15. log.info("4:"+title)
  16. log.info("5:"+contentSrt)
  17. log.info("6:"+contentStringStr)
  18. log.info("7:"+params)
  19. log.info("8:"+"http://"+config.thirdApiMessageConfig.host+":"+config.thirdApiMessageConfig.port+config.thirdApiMessageConfig.model+config.thirdApiMessageConfig.enpoint+"?"+params)
  20. wechatreqq({
  21. url: "http://"+config.thirdApiMessageConfig.host+":"+config.thirdApiMessageConfig.port+config.thirdApiMessageConfig.model+config.thirdApiMessageConfig.enpoint+"?"+params,
  22. json: true,
  23. headers: {
  24. "content-type": "application/json",
  25. },
  26. method: 'POST',
  27. body: JSON.stringify(params)
  28. }, function(error, response, body) {
  29. if (!error && response.statusCode == 200) {
  30. log.info('请求居民微信模版消息接口发送模版消息->请求成功:', body);
  31. // console.log(body) // 请求成功的处理逻辑
  32. }else{
  33. // log.error('请求居民微信模版消息发送模版消息->请求失败:', body.toString());
  34. // log.error('请求居民微信模版消息发送模版消息->请求失败:', response.toString());
  35. log.error('请求居民微信模版消息发送模版消息->请求失败:', error.message);
  36. }
  37. });
  38. }
  39. static requestSms(params,handler){
  40. log.info("7:"+params)
  41. wechatreqq({
  42. url: "http://"+config.thirdApiMessageConfig.host+":"+config.thirdApiMessageConfig.port+"/open/noLogin/smsToDoctor?consult="+params,
  43. json: true,
  44. headers: {
  45. "content-type": "application/json",
  46. },
  47. method: 'GET'
  48. }, function(error, response, body) {
  49. if (!error && response.statusCode == 200) {
  50. log.info('短信发送->请求成功:', body);
  51. // console.log(body) // 请求成功的处理逻辑
  52. }else{
  53. // log.error('请求居民微信模版消息发送模版消息->请求失败:', body.toString());
  54. // log.error('请求居民微信模版消息发送模版消息->请求失败:', response.toString());
  55. log.error('短信发送->请求失败:', error.message);
  56. }
  57. });
  58. }
  59. }
  60. module.exports = HlwyyWechatAssistantSDK;