Commit 61bda907 by 庄冰

feishu login

parent 84a73e50
......@@ -8,7 +8,8 @@ class feishuLoginService{
};
//用户登录
async checkAndLogin(pobj){
return system.getResultSuccess(null,"测试");
// return system.getResultSuccess(null,"测试");
try {
if(!pobj.code){
return system.getResultFail(-100, "code参数不能为空");
}
......@@ -34,41 +35,29 @@ class feishuLoginService{
var loginByUserNameParams={
"actionType": "getLoginByUserName",
"actionBody": {
"open_id":userAccessTokenObj.open_id
"open_id":userAccessTokenObj.open_id,
"channelUserId":userAccessTokenObj.open_id,// Y 渠道用户ID
"channelUserName":userAccessTokenObj.name,// N 渠道用户名
"nickName":userAccessTokenObj.name, // N 用户昵称
"head_url":userAccessTokenObj.avatar_url //头像
}
};
var loginByUserNameRes = await this.getLoginByUserName(loginByUserNameParams);
if(loginByUserNameRes && loginByUserNameRes.status==0){
return loginByUserNameRes;//获取userpin直接返回
}
// // 获取飞书用户信息
// var userInfoParams={
// user_access_token:userAccessTokenObj.access_token
// };
// var userInfoRes = await this.utilsFeishuSve.getUserInfo(userInfoParams);
// if(userInfoRes.status!=0){
// return userInfoRes;
// }
// var userInfoObj = userInfoRes.data;
//获取飞书用户信息
var userInfoParams={
user_access_token:userAccessTokenObj.access_token
};
var userInfoRes = await this.utilsFeishuSve.getUserInfo(userInfoParams);
if(userInfoRes.status!=0){
return userInfoRes;
}
var userInfoObj = userInfoRes.data;
var createUserParams = {
// uapp_id,channel_userid,channel_username,channel_nickname,open_id,he
};
loginByUserNameParams={
"actionType": "getLoginByUserName",
"actionBody": {
"open_id":userAccessTokenObj.open_id,
"channelUserId":userInfoObj.mobile,// Y 渠道用户ID
"channelUserName":userInfoObj.name,// N 渠道用户名
"mobile":userInfoObj.mobile, // N 渠道用户手机号
"nickName":userInfoObj.name, // N 用户昵称
"email":userInfoObj.eamil,//邮箱
"head_url":userInfoObj.avatar_url //头像
}
};
loginByUserNameRes = await this.getLoginByUserName(loginByUserNameParams);
if(loginByUserNameRes && loginByUserNameRes.status==0){
return loginByUserNameRes;//获取userpin直接返回
} catch (e) {
return system.getResultFail(-200,e.stack);
}
return system.getResultFail("获取userpin失败");
}
......
......@@ -148,7 +148,7 @@ class UtilsFeishuService{
var obj = {
user_access_token:pobj.user_access_token
};
var rtn = await this.execClient.execGet(obj, url);
var rtn = await this.execClient.execFeishuGet(obj, url);
if (!rtn || !rtn.stdout) {
return system.getResult(null, "execPost data is empty");
}
......
......@@ -7,7 +7,7 @@ class ExecClient {
this.cmdPostPattern = "curl --user admines:adminGSBes. -k -H 'Content-type: application/json' -d '{data}' {url}";
this.cmdGetPattern = "curl -G -X GET '{url}'";
this.cmdPushDataPostPattern = "curl -k -H 'Content-type: application/json' -H 'token:{tk}' -H 'request-id:{requestId}' -d '{data}' {url}";
this.cmdFeishuGetPattern = "curl -X GET -k -H 'Content-Type: application/json' -H 'Authorization: {Authorization}' -d '{data}' {url} ";
}
getUUID() {
var uuid = uuidv4();
......@@ -63,7 +63,18 @@ class ExecClient {
console.log(cmd);
return cmd;
}
FetchFeishuGetCmd(subData, url) {
var cmd = this.cmdFeishuGetPattern.replace(
/\{data\}/g, subData).replace(/\{url\}/g, url).replace(/\{Authorization\}/g, "Bearer "+subData.user_access_token);
console.log(cmd);
return cmd;
}
async execFeishuGet(subData, url) {
let cmd = this.FetchFeishuGetCmd(subData, url);
console.log(cmd);
var result = await this.exec(cmd);
return result;
}
async execGet(subData, url) {
let cmd = this.FetchGetCmd(subData, url);
console.log(cmd);
......
......@@ -353,7 +353,7 @@ module.exports = function (app) {
try {
// console.log(req,"/feishu/login++++++++++++++++++++++++++++++++++++++");
var client_ip = system.get_client_ip(req);
var result = await feishuLoginSve.checkAndLogin(req.body);
var result = await feishuLoginSve.checkAndLogin(req.query);
logCtl.info({
optitle: (new Date()).Format("yyyy-MM-dd hh:mm:ss") + "飞书小程序记录回调处理结果,method=login",
op: "app/config/routes/api.js/feishu/notify",
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment