const qywxconfig = await ctx.model("qy_wechat_config").query(qb => {
	qb.where("id", 3)
}).fetch();
var api = new module.QyWechatApi(qywxconfig.corpid, qywxconfig.corpsecret, async function() {
	let AccessToken = qywxconfig.AccessToken;
	if (AccessToken != null) {
		return JSON.parse(AccessToken);
	}
}, async function(token) {
	ctx.log(token);
	qywxconfig.AccessToken = JSON.stringify(token);
	await ctx.model("qy_wechat_config").forge(qywxconfig).save();
});
const result = await api.getSimplelist(1);
if(result.errcode==0){
	const datas=result.userlist;
	let data={},old={};
	for(let i=0;i<datas.length;i++){
		data={userid:datas[i].userid,name:datas[i].name,department:JSON.stringify(datas[i].department)};
		old = await ctx.model("qy_wechat_user").query(qb => {
			qb.where("userid", datas[i].userid)
		}).fetch();
		if(old){
			data.id=old.id;
		};
		await ctx.model("qy_wechat_user").forge(data).save();	
	};
	ctx.success("更新用户完成")
}else{
	throw new Error("更新用户信息出错");
}
//https://debug.ooooooyun.com/appid/719506243600/appkey/81386ea0-7e52-11ec-939e-431801fdfe6b/class/public/function/QWechatGetUser
      
      
    
        
        版权归属:
        
        Administrator
        
      
      
      
        
        许可协议:
        
          
          
        本文使用《署名-非商业性使用-相同方式共享 4.0 国际 (CC BY-NC-SA 4.0)》协议授权
          
        
      
    
      
      
      
评论区