Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
5
51business
Project
Project
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
方斌
51business
Commits
ef964c83
Commit
ef964c83
authored
Nov 12, 2019
by
方斌
Browse files
Options
Browse Files
Download
Plain Diff
Merge branch 'master' of
https://t-git.51gjj.com/fangbin/51business
parents
d37c7e6a
fcd6346b
Pipeline
#16216
passed with stage
in 57 seconds
Changes
2
Pipelines
1
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
69 additions
and
6 deletions
+69
-6
wechat.js
app/controller/gjj/wechat.js
+16
-4
helper.js
app/extend/helper.js
+53
-2
No files found.
app/controller/gjj/wechat.js
View file @
ef964c83
...
...
@@ -35,24 +35,33 @@ class WechatController extends Controller {
ctx
.
failed
(
'获取openid失败2'
);
}
const
openid
=
wx_ret
.
openid
;
//在微信端需要关闭微信重新打开才会销毁cookie值,所以在这里重置cookie值
ctx
.
cookies
.
set
(
'openid'
,
openid
,
{
httpOnly
:
false
,
signed
:
false
,
path
:
'/'
,
overwrite
:
true
});
ctx
.
cookies
.
set
(
'token'
,
null
,
{
httpOnly
:
false
,
signed
:
false
,
path
:
'/'
,
overwrite
:
true
});
ctx
.
cookies
.
set
(
'user_id'
,
null
,
{
httpOnly
:
false
,
signed
:
false
,
path
:
'/'
,
overwrite
:
true
});
ctx
.
cookies
.
set
(
'app_user_id'
,
null
,
{
httpOnly
:
false
,
signed
:
false
,
path
:
'/'
,
overwrite
:
true
});
ctx
.
cookies
.
set
(
'jianbing_customer_id'
,
null
,
{
httpOnly
:
false
,
signed
:
false
,
path
:
'/'
,
overwrite
:
true
});
ctx
.
cookies
.
set
(
'auth_token'
,
null
,
{
httpOnly
:
false
,
signed
:
false
,
path
:
'/'
,
overwrite
:
true
});
const
redirect_url
=
this
.
app
.
config
.
PULIC_BASE_URL
+
REDIRECT_PAGE
;
//判断是否已绑定手机号
const
user_exist_url
=
`
${
this
.
app
.
config
.
NODE_BASE_URL
}
/user_api/v1/user/is_exist/
${
openid
}
`
;
const
bind_phone_result
=
await
ctx
.
helper
.
send_request
(
user_exist_url
,
{
type
:
5
},
{
method
:
'GET'
});
ctx
.
logger
.
info
(
JSON
.
stringify
({
bind_phone_result
:
bind_phone_result
}));
if
(
bind_phone_result
.
status
!==
200
)
{
ctx
.
redirect
(
redirect_url
+
`?channel_id=
${
channel_id
}
&type=noLogin
&openid=
${
openid
}
`
);
return
;
ctx
.
redirect
(
redirect_url
+
`?channel_id=
${
channel_id
}
&type=noLogin`
);
return
;
}
const
user_exist_ret
=
bind_phone_result
.
data
;
if
(
user_exist_ret
.
result
!=
'true'
)
{
//未绑定的手机号时
ctx
.
redirect
(
redirect_url
+
`?channel_id=
${
channel_id
}
&type=noLogin
&openid=
${
openid
}
`
);
return
;
ctx
.
redirect
(
redirect_url
+
`?channel_id=
${
channel_id
}
&type=noLogin`
);
return
;
}
const
user_id
=
user_exist_ret
.
uid
;
//已绑定手机的 继续 判断是否有导入公积金
await
this
.
user_login
({
code
,
openid
,
channel_id
});
//已绑定的用户 直接登录
const
login_result
=
await
this
.
user_login
({
code
,
openid
,
channel_id
});
//已绑定的用户 直接登录
if
(
login_result
.
anew
&&
!
login_result
.
token
)
{
ctx
.
redirect
(
redirect_url
+
`?channel_id=
${
channel_id
}
&type=noLogin`
);
return
;
}
const
gjj_exist_url
=
`
${
this
.
app
.
config
.
NODE_BASE_URL
}
/cassandra-server/gjj/list/
${
user_id
}
`
;
const
gjj_exist_result
=
await
ctx
.
helper
.
send_request
(
gjj_exist_url
,
{},
{
method
:
'GET'
});
...
...
@@ -155,6 +164,9 @@ class WechatController extends Controller {
}
if
(
!
user_login_data
.
token
||
!
user_login_data
.
uid
)
{
const
error_msg
=
user_login_data
.
error
?
user_login_data
.
error
:
'用户的登录失败'
;
if
(
error_msg
===
'需要重新授权'
)
{
return
{
anew
:
1
};
}
ctx
.
failed
(
error_msg
);
}
//获取用户信息
...
...
app/extend/helper.js
View file @
ef964c83
'use strict'
;
const
XML2JS
=
require
(
'xml2js'
);
const
crypto
=
require
(
'crypto'
);
const
NodeRSA
=
require
(
'node-rsa'
)
module
.
exports
=
{
// 获取 Token
...
...
@@ -84,7 +87,6 @@ module.exports = {
aes256_cbc_encrypt
(
key
,
data
)
{
const
iv
=
'
\
0
\
0
\
0
\
0
\
0
\
0
\
0
\
0
\
0
\
0
\
0
\
0
\
0
\
0
\
0
\
0'
;
const
crypto
=
require
(
'crypto'
);
const
cipher
=
crypto
.
createCipheriv
(
'aes-256-cbc'
,
key
,
iv
);
let
crypted
=
cipher
.
update
(
data
,
'utf8'
,
'binary'
);
crypted
+=
cipher
.
final
(
'binary'
);
...
...
@@ -94,7 +96,6 @@ module.exports = {
aes256_cbc_decrypt
(
key
,
crypted
)
{
const
iv
=
'
\
0
\
0
\
0
\
0
\
0
\
0
\
0
\
0
\
0
\
0
\
0
\
0
\
0
\
0
\
0
\
0'
;
const
crypto
=
require
(
'crypto'
);
crypted
=
new
Buffer
(
crypted
,
'base64'
).
toString
(
'binary'
);
const
decipher
=
crypto
.
createDecipheriv
(
'aes-256-cbc'
,
key
,
iv
);
let
decoded
=
decipher
.
update
(
crypted
,
'binary'
,
'utf8'
);
...
...
@@ -102,6 +103,28 @@ module.exports = {
return
decoded
;
},
rsaPublicDecrypt
(
publicKey
,
encryptContent
)
{
const
public_key
=
new
NodeRSA
(
publicKey
);
const
decrypt_data
=
public_key
.
decryptPublic
(
encryptContent
).
toString
(
'utf8'
);
return
decrypt_data
;
},
rsaPrivateEncrypt
(
privateKey
,
content
)
{
const
private_key
=
new
NodeRSA
(
privateKey
);
const
encrypt_data
=
private_key
.
encryptPrivate
(
content
,
'base64'
);
return
encrypt_data
;
},
rsaSign
()
{
},
rsaVerify
()
{
},
aes256_cbc_decrypt_weixin
(
key
,
crypted
)
{
let
aesKey
=
Buffer
.
from
(
key
+
'='
,
'base64'
);
...
...
@@ -342,6 +365,7 @@ module.exports = {
PrefixInteger
(
num
,
length
)
{
return
(
Array
(
length
).
join
(
'0'
)
+
num
).
slice
(
-
length
);
},
async
xmlTojson
(
data
)
{
const
ret_p
=
new
Promise
((
resolve
,
reject
)
=>
{
XML2JS
.
parseString
(
data
,
(
err
,
result
)
=>
{
...
...
@@ -358,6 +382,7 @@ module.exports = {
await
ret_p
.
then
((
resolve
,
reject
)
=>
{
ret_json
=
resolve
});
return
ret_json
;
},
jsonToxml
(
data
)
{
const
bulider
=
new
XML2JS
.
Builder
();
const
xml_params
=
bulider
.
buildObject
(
data
);
...
...
@@ -389,6 +414,32 @@ module.exports = {
location
=
provinece
+
city
;
return
location
;
},
//延时函数
async
sleep
(
time
)
{
return
new
Promise
(
function
(
resolve
,
reject
)
{
setTimeout
(
function
()
{
resolve
(
'ok'
);
},
time
);
});
},
//格式化地址
formatUrl
(
url
,
baseUrl
)
{
if
(
!
baseUrl
)
return
url
;
if
(
url
.
indexOf
(
'http'
)
===
0
)
return
url
;
let
formatUrl
=
''
;
const
baseUrlEndsWithSlash
=
baseUrl
.
endsWith
(
'/'
);
const
urlStartWithSlash
=
url
.
startsWith
(
'/'
);
if
(
baseUrlEndsWithSlash
&&
urlStartWithSlash
)
{
formatUrl
=
baseUrl
+
url
.
substring
(
1
);
}
else
if
(
baseUrlEndsWithSlash
||
urlStartWithSlash
)
{
formatUrl
=
baseUrl
+
url
;
}
else
{
formatUrl
=
baseUrl
+
'/'
+
url
;
}
return
formatUrl
;
}
};
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment