npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

skyline-wechat-enterprise-sdk

v0.2.0

Published

Wechat cryptor service. base on wechat-enterprise-sdk 0.2.0

Downloads

2

Readme

##微信企业号消息 Node SDK

项目启动

测试可能需要全局安装mocha

sudo npm install mocha -g

build可能需要全局安装babel

sudo npm install babel -g

###开发中可使用的命令:

npm run build
npm run test
npm run watch

##用法

在项目中引入:

npm i wechat-enterprise-sdk --save

然后在项目目录下建立config 目录并且在里面加入default.json 在default.json中加入

{
  "ENTERPRISE_WECHAT": {
    "corpid": "your corp id",
    "secret": "your corp secret",
    "token": "your token",
    "EncodingAESKey": "your EncodingAESKey"
  },
  //使用authAPI和suiteAuthAPI 需要填写这个属性,这个2个API供套件提供商使用
  "PROVIDER": {
    "corpid": "provider corpid",
    "providersecret": "provider secret"
  }"
}

##API

var wechat = require('wechat-enterprise-sdk');

msgAPI

主动发送消息API

var msgAPI = wechat.msgAPI;

####msgAPI.createChat 创建群聊方法

/**
  * 创建群聊的API
  * @param  string chatid   chatid
  * @param  string name     群聊名称
  * @param  string owner    owner id,企业号通讯录里面设置的id
  * @param  array  userlist 参与群聊的人
  * @return object<Thenjs>  Thenjs对象
  * @example
  * {
  * 	"errcode": "0",
  * 	"errmsg": "ok"
  * }
  */
msgAPI.createChat(chatid, name, owner, userlist)
.then((next, result) => {
	//result from wechat server @example
});

####msgAPI.sendMsg 发送消息,单聊或群聊

/**
  * 发送信息的接口
  * @param  string sendToId 对个人发送消息就是微信通讯录里面设置的id,群聊则是groupid
  * @param  string senderId ge
  * @param  string msgType  config.js 中定义的vaild msgtype
  * @param  string chatType config.js 中定义的vaild chattype
  * @param  string content  text类型的消息是消息体,其它类型的消息是media id
  * @return object<Thenjs>
  * @example
  * {
  * 	"errcode": 0,
  * 	"errmsg": "ok"
  * }
  */
  msgAPI.sendMsg(sendToId, senderId, msgType, chatType, content)
  .then((next, result) => {
    //result from wechat server @example
  });

####msgAPI.getChat 获取一个会话的详细信息

 /**
  * 获取一个会话的详细信息
  * @param  string chatid 单聊或者群聊
  * @return object<Thenjs>
  * @example
  * {
  * 	"errcode": 0,
  *  	"errmsg": "ok",
  *   "chat_info": {
  *   	"chatid": "235364212115767297",
  *    	"name": "企业应用中心",
  *     "owner": "zhangsan",
  *     "userlist": ["zhangsan", "lisi", "wangwu"]
  *    }
  * }
  */
  msgAPI.getChat(11211)
  .then((next, result) => {
    //result from wechat server @example
  });

####msgAPI.modifyChat 修改会话信息

/**
  * 修改话题
  * @param  object postdata
  * {
  *   "chatid": "235364212115767297",
  *   "op_user": "lisi",
  *   "name": "企业应用中心", 非必需
  *   "owner": "zhangsan",  非必需
  *   "add_user_list": ["zhaoli"], 非必需
  *   "del_user_list": ["zhangsan"] 非必需
  * }
  * @return object<Thenjs>
  * @example
  * {
  * 	"errcode": 0,
  * 	"errmsg": "ok"
  * }
  */
  msgAPI.modifyChat(postdata)
  .then((next, result) => {
    //result from wechat server @example
  });

####msgAPI.quitChat 退出话题

/**
  * 退出话题
  * @param  string chatid 群聊的chat id
  * @param  string userid 企业通讯录里面定义的user id,必需在要退出的群聊中
  * @return object<Thenjs>
  * @example
  * {
  * 	"errcode": 0,
  * 	"errmsg": "ok"
  * }
  */
  msgAPI.quitChat(chatid, userid)
  .then((next, result) => {
	//result from wechat server @example
  });

####msgAPI.clearNotify 清除消息未读标记

/**
  * 清除消息标记
  * @param  string userid 操作者,需要清除标记的用户
  * @param  string type   single / group
  * @param  string id     企业通讯录中定义的user id / 群聊 group id,与操作者对话的人或者操作者所在的群聊
  * @return object<Thenjs>
  * @example
  * {
  * 	"errcode": 0,
  * 	"errmsg": "ok"
  * }
  */
  msgAPI.clearNotify(userid, type, id)
  .then((next, result) => {
	//result from wechat server @example
  });

####msgAPI.muteChat 设置成员新消息勿打扰

 /**
  * 设置新消息免打扰
  * @param  object userlist
  * {
  * 	'user_mute_list': [
  * 		{
  * 			userid: 'yinan',
  * 			status: 0
  * 		},
  * 		{
  * 			userid: 'huaqiao',
  * 			status: 1
  * 		}
  * 	]
  * }
  * 默认值为0, 0是关闭,1是打开
  * @return object<Thenjs>
  * @example
  * {
  * 	"errcode": 0,
  * 	"errmsg": "ok",
  * 	"invaliduser":["asdfjjj"]
  * }
  */
  msgAPI.muteChat(userlist)
  .then((next, result) => {
	//result from wechat server @example
	//这里如果全部是不合法的userid, 返回的数据结构和example有差别:
	//{"errcode":40031,"errmsg":"invalid userid list"}
  });

###handlerAPI 被动响应微信消息API

var handlerAPI = wechat.handlerAPI;

####handlerAPI.verifyURL 在设置微信消息回调的时候,对设置的URL进行验证时需要用到的方法

/**
  * 验证URL
  * @param  string msgSignature 签名串,对应URL参数的msg_signature
  * @param  string timestamp    时间戳,对应URL参数的timestamp
  * @param  string nonce        随机串,对应URL参数的nonce
  * @param  string echostr      解密后的echostr
  * @return array               ret: errercode, reply echo str
  */
  var result = handlerAPI.verifyURL(msgSignature, timestamp, nonce, echostr);
  expect(result[0]).to.equal(0);
  //result[1]的指既为解密后的原始值,直接响应给微信即可通过验证

####handlerAPI.decryptMsg 设置微信消息回调链接成功后,所有的用户发给企业通讯录其他用户或者群聊中的消息都会发送给设置的回调的链接,此方法是对这些消息进行解密。

/**
  * 检验消息的真实性,并且获取解密后的明文
  * <ol>
  *    <li>利用收到的密文生成安全签名,进行签名验证</li>
  *    <li>若验证通过,则提取xml中的加密消息</li>
  *    <li>对消息进行解密</li>
  * </ol>
  * @param  string msgSignature get 到的消息签名
  * @param  string timestamp    默认为null,时间戳
  * @param  string nonce        随机字符串
  * @param  string postdata     post 的 xml
  * @param  string type         default 'message', 指定要解析的xml类型,如果值不为message则当作event解析
  * @return object<Thenjs>
  * @example
  * [
  * 	0,
  * 	{
  * 		"xml": {
  * 			"AgentType":"chat",
  * 			"ToUserName":"wx80850b023d7c38d9",
  * 			"ItemCount":"1",
  * 			"PackageId":"429496798487285866",
  * 			"Item": [
  * 				{
  * 					"FromUserName":"yinan",
  * 					"CreateTime":"1438850706",
  * 					"MsgType":"text",
  * 					"Content":"哈哈哈",
  * 					"MsgId":"6179816726305163297",
  * 					"Receiver": {
  * 						"Type":"single",
  * 						"Id":"huaqiao"
  * 					}
  * 				}
  * 			]
  * 		}
  * 	}
  * ]
  */
  handlerAPI.decryptMsg(msgSignature, timestamp = null, nonce, postdata)
  .then((next, result) => {
	// xml parsed result @example
	expect(result[0]).to.equal(0);
  });

membersAPI

成员/部门管理API

var membersAPI = wechat.membersAPI;

membersAPI.createDepartment

创建部门

membersAPI.updateDepartment

更新部门信息

membersAPI.deleteDepartment

删除部门,不可删除不为空的部门

membersAPI.getDepartment

获取部门信息

membersAPI.createMember

创建一个成员

membersAPI.updateMember

更新成员信息

membersAPI.deleteMember

删除成员

membersAPI.deleteMembers

批量删除成员

membersAPI.getMember

获取成员详细信息

membersAPI.getUserSimplelist

根据部门id获取部门下所有成员基本信息

membersAPI.getUserList

根据部门id获取部门下所有成员详细信息

membersAPI.inviteUser

向一个成员发送邀请,关注企业微信。优先微信邀请,如果成员信息中weixinid 为空则用邮件邀请,人应该以邮箱也为空则报错

authAPI

var authAPI = wechat.authAPI;

authAPI.getLoginInfo

获取企业管理员登陆信息

suiteAuthAPI

var suiteAuthAPI = new wechat.suiteAuthAPI(suiteid, suitesecret, ticket);

suiteAuthAPI.getPreAuthCode

获取预授权码

suiteAuthAPI.getSessionInfo

设置授权配置

suiteAuthAPI.getPermanentCode

获取企业号的永久授权码

suiteAuthAPI.getAuthInfo

获取企业号的授权信息

suiteAuthAPI.getAgent

获取企业号应用

suiteAuthAPI.setAgent

设置企业号应用

suiteAuthAPI.getCorpToken

获取企业号access_token