Commit caa84b87 by 任晓松

tj

parent b1b694de
...@@ -167,30 +167,20 @@ class UtilsAuthService extends AppServiceBase { ...@@ -167,30 +167,20 @@ class UtilsAuthService extends AppServiceBase {
* @returns {Promise<void>} * @returns {Promise<void>}
*/ */
async channelUserLogin(pobj,actionBody,req){ async channelUserLogin(pobj,actionBody,req){
//360登录地址 let opResult = system.getResultSuccess()
let skipUrl = ''; let pin = actionBody.pin;
let opResult = system.getResult(null, "req Failure"); let result = await this.get360Token();
let token = result.access_token;
//----通过Authorization 获取用户信息 //360验证接口
let Authorization = req.headers["authorization"] || ""; let subData = "pin=" + pin + "&token=" + token
if(!Authorization){ let rtn = await this.restClient.execGet(subData,settings.requestUrl360());
opResult.data.redirectUrl = skipUrl;
opResult =system.getResultFail(-99,'用户未登录',{redirectUrl:'skipUrl'});
return opResult;
}
let icCompanyUrl = '';
let subData = {
Authorization:Authorization
}
let rtn = await this.execClient.execFqGet(subData,icCompanyUrl);
if (!rtn || !rtn.stdout) { if (!rtn || !rtn.stdout) {
return system.getResult(null, "execPost data is empty"); return system.getResult(null, "restPost data is empty");
} }
var userInfo = JSON.parse(rtn.stdout); let checkRet = JSON.parse(rtn.stdout);
//----结束 console.log(checkRet,'checkRet--------------')
//---渠道用户登录,有则返回userpin ,没有则注册用户并返回userpin //---渠道用户登录,有则返回userpin ,没有则注册用户并返回userpin
let channelUserId = userInfo.mobile; actionBody.channelUserId = pin;
actionBody.channelUserId = channelUserId;
let loginRt = await this.getLoginByUserName(pobj,actionBody); let loginRt = await this.getLoginByUserName(pobj,actionBody);
if (loginRt.status != 0 && loginRt.status != 2060) { if (loginRt.status != 0 && loginRt.status != 2060) {
return loginRt; return loginRt;
...@@ -203,5 +193,14 @@ class UtilsAuthService extends AppServiceBase { ...@@ -203,5 +193,14 @@ class UtilsAuthService extends AppServiceBase {
return opResult; return opResult;
} }
async get360Token(){
let rtn = await this.execClient.exec360GetToken(settings.tokenUrl360())
if (!rtn || !rtn.stdout) {
return system.getResult(null, "restPost data is empty");
}
let result = JSON.parse(rtn.stdout);
return result;
}
} }
module.exports = UtilsAuthService; module.exports = UtilsAuthService;
...@@ -2,6 +2,7 @@ var childproc = require('child_process'); ...@@ -2,6 +2,7 @@ var childproc = require('child_process');
const util = require('util'); const util = require('util');
const exec = util.promisify(require('child_process').exec); const exec = util.promisify(require('child_process').exec);
const uuidv4 = require('uuid/v4'); const uuidv4 = require('uuid/v4');
var settings = require("../../config/settings");
class ExecClient { class ExecClient {
constructor() { constructor() {
this.cmdPostPattern = "curl --user admines:adminGSBes. -k -H 'Content-type: application/json' -d '{data}' {url}"; this.cmdPostPattern = "curl --user admines:adminGSBes. -k -H 'Content-type: application/json' -d '{data}' {url}";
...@@ -9,7 +10,8 @@ class ExecClient { ...@@ -9,7 +10,8 @@ class ExecClient {
this.cmdPushDataPostPattern = "curl -k -H 'Content-type: application/json' -H 'token:{tk}' -H 'request-id:{requestId}' -d '{data}' {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} "; this.cmdFeishuGetPattern = "curl -X GET -k -H 'Content-Type: application/json' -H 'Authorization: {Authorization}' -d '{data}' {url} ";
this.cmdFeishuPostPattern = "curl -k -H 'Content-type: application/json' -H 'Authorization: {Authorization}' -d '{data}' {url}"; this.cmdFeishuPostPattern = "curl -k -H 'Content-type: application/json' -H 'Authorization: {Authorization}' -d '{data}' {url}";
//360
this.cmd360PostPattern = "curl -u gongsibao:qPa4PsVsxbQ847i5pOKSmfPKrzRoNKqx -d '{data}' -X POST {url}"
} }
getUUID() { getUUID() {
var uuid = uuidv4(); var uuid = uuidv4();
...@@ -80,11 +82,6 @@ class ExecClient { ...@@ -80,11 +82,6 @@ class ExecClient {
console.log(cmd); console.log(cmd);
return cmd; return cmd;
} }
FetchFqGetCmd(subData, url) {
var cmd = this.cmdFeishuGetPattern.replace(/\{url\}/g, url).replace(/\{Authorization\}/g, "Bearer " + subData.Authorization);
console.log(cmd);
return cmd;
}
//飞书小程序GET请求 //飞书小程序GET请求
FetchFeishuGetCmd(subData, url) { FetchFeishuGetCmd(subData, url) {
...@@ -106,8 +103,16 @@ class ExecClient { ...@@ -106,8 +103,16 @@ class ExecClient {
return result; return result;
} }
async execFqGet(subData, url) { Fetch360PostCmd(subData,url){
let cmd = this.FetchFqGetCmd(subData, url); var cmd = this.cmd360PostPattern.replace(
/\{data\}/g, subData).replace(/\{url\}/g, url);
console.log(cmd);
return cmd;
}
async exec360GetToken(url){
let obj = {"scope":"smart_business","grant_type":"client_credentials"}
let cmd = this.Fetch360PostCmd(qs.stringify(obj),url);
console.log(cmd); console.log(cmd);
var result = await this.exec(cmd); var result = await this.exec(cmd);
return result; return result;
......
...@@ -19,7 +19,6 @@ class RestClient { ...@@ -19,7 +19,6 @@ class RestClient {
this.cmdPostPattern5 = "curl -k --data '{data}' {url}"; this.cmdPostPattern5 = "curl -k --data '{data}' {url}";
// authorization=[token] // authorization=[token]
this.cmdPostpatternToken = "curl -k -H 'Content-type: application/json' -H 'authorization:{token}' -X POST {url}" this.cmdPostpatternToken = "curl -k -H 'Content-type: application/json' -H 'authorization:{token}' -X POST {url}"
} }
getUUID() { getUUID() {
var uuid = uuidv4(); var uuid = uuidv4();
...@@ -172,6 +171,12 @@ class RestClient { ...@@ -172,6 +171,12 @@ class RestClient {
var result = await this.exec(cmd); var result = await this.exec(cmd);
return result; return result;
} }
async execDeliveryPost(subdata,url){
let cmd = this.FetchPostCmd(subdata,url)
cmd += " -H 'XAPPKEY:647a68c9-da01-40d3-9763-1ffa0f64cf3f'"
var result = await this.exec(cmd);
return result;
}
test() { test() {
console.log("hello"); console.log("hello");
} }
......
...@@ -228,6 +228,20 @@ var settings = { ...@@ -228,6 +228,20 @@ var settings = {
return "https://m.ucommune.com/"// 6.29lin修改为测试环境。原因优客 目前还没有正式环境 return "https://m.ucommune.com/"// 6.29lin修改为测试环境。原因优客 目前还没有正式环境
} }
}, },
tokenUrl360:function(){
if (this.env == "dev") {
return "https://oauth2.e.360.cn/site/token"// 360测试环境
} else {
return ""//
}
},
requestUrl360:function(){
if (this.env == "dev") {
return "http://180.163.239.98:38085/"// 360测试环境
} else {
return ""//
}
},
aliUappId: function () { aliUappId: function () {
if (this.env == "dev") { if (this.env == "dev") {
return 18// uapp_id return 18// uapp_id
......
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