Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
T
taobao-mini-template
Project
Project
Details
Activity
Releases
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
2
Issues
2
List
Board
Labels
Milestones
Merge Requests
1
Merge Requests
1
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
qinhaitao
taobao-mini-template
Commits
67e19b13
Commit
67e19b13
authored
Nov 09, 2020
by
汪忙忙
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
增加风驰台接口请求类型
parent
ed15fb7d
Changes
3
Show whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
99 additions
and
27 deletions
+99
-27
app.js
c_client/client/app.js
+3
-2
package.json
c_client/client/package.json
+2
-1
request.js
c_client/client/tbcc-sdk/lib/request.js
+94
-24
No files found.
c_client/client/app.js
View file @
67e19b13
...
...
@@ -6,8 +6,9 @@ cloud.init({
});
App
({
requestType
:
'
yapi'
,
// cloud: 云函数, yapi: yapi 接口, ams: ams接口,
requestType
:
'
tornadoAPI'
,
// cloud: 云函数, yapi: yapi 接口, ams: ams接口,tornadoAPI: 风驰台接口
cloudName
:
'CommonToC'
,
// 主云函数项目名
tornadoAPI
:
'https://tornado.duibadev.com.cn/tbServer/api?db=db3000000027115325&proxyIp=172.16.75.54'
,
// 新增:当requestType: 'tornadoAPI'时,找服务端提供地址
cloud
,
tbcc
,
onLaunch
(
options
)
{
...
...
@@ -22,6 +23,6 @@ App({
*/
handleQuery
(
query
)
{
const
{
activityId
}
=
query
;
this
.
activityId
=
activityId
||
'
testId
'
;
this
.
activityId
=
activityId
||
'
5f8550a3964f97be3647a635
'
;
}
});
c_client/client/package.json
View file @
67e19b13
...
...
@@ -4,6 +4,7 @@
"main"
:
""
,
"license"
:
"MIT"
,
"dependencies"
:
{
"@tbmp/mp-cloud-sdk"
:
"*"
"@tbmp/mp-cloud-sdk"
:
"*"
,
"crypto"
:
"^1.0.1"
}
}
c_client/client/tbcc-sdk/lib/request.js
View file @
67e19b13
var
Buffer
=
require
(
"buffer"
).
Buffer
var
crypto
=
require
(
"crypto"
)
const
request
=
({
cloud
,
cloudName
,
requestType
=
'cloud'
,
mockUrl
})
=>
{
console
.
log
(
2
)
if
(
!
cloud
)
{
console
.
error
(
'请传入cloud'
);
return
false
;
...
...
@@ -8,13 +12,14 @@ const request = ({ cloud, cloudName, requestType = 'cloud', mockUrl }) => {
return
false
;
}
return
async
(
handle
,
method
=
'POST'
,
params
,
ext
=
{})
=>
{
const
{
activityId
}
=
getApp
();
const
{
activityId
,
tornadoAPI
,
nickName
=
''
,
tbcc
}
=
getApp
();
// 默认注入activityId
params
=
{
activityId
,
...
params
};
if
(
!
params
.
activityId
)
{
console
.
error
(
`
${
handle
}
:请传入activityId`
);
return
false
;
}
console
.
log
(
params
,
handle
)
const
_cloudName
=
ext
.
cloudName
||
cloudName
;
const
{
isShowLoading
}
=
ext
;
const
hideMyLoading
=
()
=>
{
...
...
@@ -27,6 +32,70 @@ const request = ({ cloud, cloudName, requestType = 'cloud', mockUrl }) => {
}
const
requestMock
=
()
=>
{
// 若请求的是风驰台的api
if
(
requestType
===
'tornadoAPI'
)
{
// 处理涉及的三个参数
let
matchRes
=
tornadoAPI
.
match
(
/db=
(\w
*
)
&proxyIp=
([\d]{1,3}\.[\d]{1,3}\.[\d]{1,3}\.[\d]{1,3})
/
)
let
db
=
matchRes
[
1
]
let
proxyIp
=
matchRes
[
2
]
let
data_
=
{
handler
:
handle
,
data
:
params
}
console
.
log
(
`data_`
,
data_
)
let
params_
=
{
db
,
proxyIp
,
data
:
data_
}
console
.
log
(
`params_`
,
params_
)
// nickName 转 md5 作为唯一的openId
if
(
!
nickName
)
{
tbcc
.
tb
.
getAuthUserInfo
().
catch
(
err
=>
{
console
.
log
(
'未授权成功'
,
err
);
}).
then
(
res
=>
{
cb
(
res
)
})
}
function
cb
({
nickName
})
{
if
(
!
db
||
!
proxyIp
)
{
my
.
confirm
({
title
:
'风驰台地址错误'
,
content
:
'请确认风驰台的地址是否正确,未查找到db和proxyIp'
,
confirmButtonText
:
'确定'
,
cancelButtonText
:
'取消'
});
return
false
}
params_
.
openId
=
md5
(
nickName
)
return
new
Promise
((
resolve
,
reject
)
=>
{
my
.
request
({
url
:
tornadoAPI
,
method
:
'post'
,
data
:
params_
,
dataType
:
'json'
}).
then
(({
data
:
res
})
=>
{
console
.
log
(
`调用风驰台返回结果`
,
res
)
hideMyLoading
();
if
(
res
&&
res
.
success
)
{
resolve
(
res
);
}
else
{
reject
(
res
);
}
}).
catch
((
e
)
=>
{
hideMyLoading
();
console
.
log
(
e
)
reject
();
});
})
function
md5
(
data
)
{
var
buf
=
new
Buffer
(
data
);
var
str
=
buf
.
toString
(
"binary"
);
return
crypto
.
createHash
(
"md5"
).
update
(
str
).
digest
(
"hex"
).
slice
(
0
,
30
);
}
}
}
else
{
const
mockUrlPrefix
=
{
ams
:
'https://ams.dui88.com/server/index.php?g=Web&c=Mock&o=simple&projectID=218&uri='
,
yapi
:
'https://docs.dui88.com/mock/140/'
...
...
@@ -50,6 +119,7 @@ const request = ({ cloud, cloudName, requestType = 'cloud', mockUrl }) => {
reject
();
});
})
}
};
const
requestCloud
=
()
=>
{
...
...
@@ -70,7 +140,7 @@ const request = ({ cloud, cloudName, requestType = 'cloud', mockUrl }) => {
});
};
return
[
'ams'
,
'yapi'
].
includes
(
requestType
)
?
requestMock
()
:
requestCloud
();
return
[
'ams'
,
'yapi'
,
'tornadoAPI'
].
includes
(
requestType
)
?
requestMock
()
:
requestCloud
();
};
};
...
...
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