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
938e2edc
Commit
938e2edc
authored
Nov 11, 2019
by
李尚科
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
fix
parent
131a7e54
Pipeline
#16157
passed with stage
in 8 seconds
Changes
2
Pipelines
1
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
62 additions
and
5 deletions
+62
-5
wechat.js
app/controller/gjj/wechat.js
+9
-3
helper.js
app/extend/helper.js
+53
-2
No files found.
app/controller/gjj/wechat.js
View file @
938e2edc
...
@@ -43,16 +43,19 @@ class WechatController extends Controller {
...
@@ -43,16 +43,19 @@ class WechatController extends Controller {
const
bind_phone_result
=
await
ctx
.
helper
.
send_request
(
user_exist_url
,
{
type
:
5
},
{
method
:
'GET'
});
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
}));
ctx
.
logger
.
info
(
JSON
.
stringify
({
bind_phone_result
:
bind_phone_result
}));
if
(
bind_phone_result
.
status
!==
200
)
{
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
;
const
user_exist_ret
=
bind_phone_result
.
data
;
if
(
user_exist_ret
.
result
!=
'true'
)
{
//未绑定的手机号时
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
;
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_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'
});
const
gjj_exist_result
=
await
ctx
.
helper
.
send_request
(
gjj_exist_url
,
{},
{
method
:
'GET'
});
...
@@ -155,6 +158,9 @@ class WechatController extends Controller {
...
@@ -155,6 +158,9 @@ class WechatController extends Controller {
}
}
if
(
!
user_login_data
.
token
||
!
user_login_data
.
uid
)
{
if
(
!
user_login_data
.
token
||
!
user_login_data
.
uid
)
{
const
error_msg
=
user_login_data
.
error
?
user_login_data
.
error
:
'用户的登录失败'
;
const
error_msg
=
user_login_data
.
error
?
user_login_data
.
error
:
'用户的登录失败'
;
if
(
error_msg
===
'需要重新授权'
)
{
return
{
anew
:
1
};
}
ctx
.
failed
(
error_msg
);
ctx
.
failed
(
error_msg
);
}
}
//获取用户信息
//获取用户信息
...
...
app/extend/helper.js
View file @
938e2edc
'use strict'
;
'use strict'
;
const
XML2JS
=
require
(
'xml2js'
);
const
XML2JS
=
require
(
'xml2js'
);
const
crypto
=
require
(
'crypto'
);
const
NodeRSA
=
require
(
'node-rsa'
)
module
.
exports
=
{
module
.
exports
=
{
// 获取 Token
// 获取 Token
...
@@ -84,7 +87,6 @@ module.exports = {
...
@@ -84,7 +87,6 @@ module.exports = {
aes256_cbc_encrypt
(
key
,
data
)
{
aes256_cbc_encrypt
(
key
,
data
)
{
const
iv
=
'
\
0
\
0
\
0
\
0
\
0
\
0
\
0
\
0
\
0
\
0
\
0
\
0
\
0
\
0
\
0
\
0'
;
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
);
const
cipher
=
crypto
.
createCipheriv
(
'aes-256-cbc'
,
key
,
iv
);
let
crypted
=
cipher
.
update
(
data
,
'utf8'
,
'binary'
);
let
crypted
=
cipher
.
update
(
data
,
'utf8'
,
'binary'
);
crypted
+=
cipher
.
final
(
'binary'
);
crypted
+=
cipher
.
final
(
'binary'
);
...
@@ -94,7 +96,6 @@ module.exports = {
...
@@ -94,7 +96,6 @@ module.exports = {
aes256_cbc_decrypt
(
key
,
crypted
)
{
aes256_cbc_decrypt
(
key
,
crypted
)
{
const
iv
=
'
\
0
\
0
\
0
\
0
\
0
\
0
\
0
\
0
\
0
\
0
\
0
\
0
\
0
\
0
\
0
\
0'
;
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'
);
crypted
=
new
Buffer
(
crypted
,
'base64'
).
toString
(
'binary'
);
const
decipher
=
crypto
.
createDecipheriv
(
'aes-256-cbc'
,
key
,
iv
);
const
decipher
=
crypto
.
createDecipheriv
(
'aes-256-cbc'
,
key
,
iv
);
let
decoded
=
decipher
.
update
(
crypted
,
'binary'
,
'utf8'
);
let
decoded
=
decipher
.
update
(
crypted
,
'binary'
,
'utf8'
);
...
@@ -102,6 +103,28 @@ module.exports = {
...
@@ -102,6 +103,28 @@ module.exports = {
return
decoded
;
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
)
{
aes256_cbc_decrypt_weixin
(
key
,
crypted
)
{
let
aesKey
=
Buffer
.
from
(
key
+
'='
,
'base64'
);
let
aesKey
=
Buffer
.
from
(
key
+
'='
,
'base64'
);
...
@@ -342,6 +365,7 @@ module.exports = {
...
@@ -342,6 +365,7 @@ module.exports = {
PrefixInteger
(
num
,
length
)
{
PrefixInteger
(
num
,
length
)
{
return
(
Array
(
length
).
join
(
'0'
)
+
num
).
slice
(
-
length
);
return
(
Array
(
length
).
join
(
'0'
)
+
num
).
slice
(
-
length
);
},
},
async
xmlTojson
(
data
)
{
async
xmlTojson
(
data
)
{
const
ret_p
=
new
Promise
((
resolve
,
reject
)
=>
{
const
ret_p
=
new
Promise
((
resolve
,
reject
)
=>
{
XML2JS
.
parseString
(
data
,
(
err
,
result
)
=>
{
XML2JS
.
parseString
(
data
,
(
err
,
result
)
=>
{
...
@@ -358,6 +382,7 @@ module.exports = {
...
@@ -358,6 +382,7 @@ module.exports = {
await
ret_p
.
then
((
resolve
,
reject
)
=>
{
ret_json
=
resolve
});
await
ret_p
.
then
((
resolve
,
reject
)
=>
{
ret_json
=
resolve
});
return
ret_json
;
return
ret_json
;
},
},
jsonToxml
(
data
)
{
jsonToxml
(
data
)
{
const
bulider
=
new
XML2JS
.
Builder
();
const
bulider
=
new
XML2JS
.
Builder
();
const
xml_params
=
bulider
.
buildObject
(
data
);
const
xml_params
=
bulider
.
buildObject
(
data
);
...
@@ -389,6 +414,32 @@ module.exports = {
...
@@ -389,6 +414,32 @@ module.exports = {
location
=
provinece
+
city
;
location
=
provinece
+
city
;
return
location
;
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