Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
W
wechat_currency
Overview
Overview
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
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
huahua
wechat_currency
Commits
adf4a7cf
Commit
adf4a7cf
authored
Feb 03, 2024
by
huahua
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
提交
parent
828b15c5
Hide whitespace changes
Inline
Side-by-side
Showing
6 changed files
with
270 additions
and
159 deletions
+270
-159
pages/index/index.vue
+44
-28
pages/index/machineDetail.vue
+93
-15
static/icon_diy_anime_style.png
+0
-0
static/icon_diy_enhance_style.png
+0
-0
static/icon_diy_matting_style.png
+0
-0
util/script.js
+133
-116
No files found.
pages/index/index.vue
View file @
adf4a7cf
...
@@ -561,37 +561,53 @@
...
@@ -561,37 +561,53 @@
</uni-popup>
</uni-popup>
<!-- Ai转换 -->
<!-- Ai转换 -->
<uni-popup
ref=
"showAiChange"
type=
"center"
style=
"position: fixed; z-index: 9999; "
>
<!-- Ai转换 --
>
<view
style=
"height: 600upx;border-radius:20upx; background: #fff;width: 600upx;
"
>
<uni-popup
ref=
"showAiChange"
type=
"center"
style=
"position: fixed; z-index: 9999;
"
>
<image
src=
"../../static/img/icon_close_image.png"
style=
"width: 30upx;
<view
style=
"height: 950upx;border-radius:20upx; background: #fff;width: 600upx;"
>
padding: 30upx;
<image
src=
"../../static/img/icon_close_image.png"
style=
"width: 30upx;
position: absolute
;
padding: 30upx
;
right:0
;
position: absolute
;
top:0;
right:0;
z-index: 999;"
mode=
"widthFix"
@
click=
"showAiChangeClose()"
>
top:0;
</image
>
z-index: 999;"
mode=
"widthFix"
@
click=
"showAiChangeClose()"
>
<view
style=
"height: 400upx; padding-top: 80upx;width: 100%;
</image>
align-items: center
;
<view
style=
"height: 360upx; padding-top: 80upx;width: 100%
;
display: flex
;
align-items: center
;
flex-direction: row;
display: flex;
justify-content: center;"
>
flex-direction: row;
<view
style=
"align-items
: center;"
>
justify-content
: center;"
>
<image
style=
"width:160upx;height:160upx;"
src=
"../../static/icon_diy_anime_style.png"
<view
style=
"align-items: center;"
>
@
click=
"showAiChangeType(1)"
></image>
<image
style=
"width:160upx;height:160upx;"
src=
"../../static/icon_diy_anime_style.png"
<view
style=
"width:160upx;height:160upx;text-align: center;line-height: 160upx;"
>
动漫风格
@
click=
"showAiChangeType(1)"
></image>
</view>
<view
style=
"width:160upx;height:160upx;text-align: center;line-height: 160upx;"
>
动漫风格
</view>
</view>
<view
style=
"align-items: center;margin-left: 100upx;"
>
</view
>
<image
style=
"width:160upx;height:160upx; "
src=
"../../static/icon_diy_sketch_style.png"
<view
style=
"align-items: center;margin-left: 100upx;"
>
@
click=
"showAiChangeType(2)"
></image>
<image
style=
"width:160upx;height:160upx; "
src=
"../../static/icon_diy_sketch_style.png"
<view
style=
"width:160upx;height:160upx;text-align: center;line-height: 160upx;"
>
素描风格
@
click=
"showAiChangeType(2)"
></image>
</view>
<view
style=
"width:160upx;height:160upx;text-align: center;line-height: 160upx;"
>
素描风格
</view>
</view>
</view>
</view>
<view
style=
"font-size: 30upx;color:#333; width:100%;text-align: center;margin: auto; "
>
选中的图片必须带有清晰人物头像
</view>
</view>
</view>
</uni-popup>
<view
style=
"height: 360upx; padding-top: 40upx;width: 100%;
align-items: center;
display: flex;
flex-direction: row;
justify-content: center;"
>
<view
style=
"align-items: center;margin-left: 20upx;"
>
<image
style=
"width:160upx;height:160upx; "
src=
"../../static/icon_diy_matting_style.png"
@
click=
"showAiChangeType(3)"
></image>
<view
style=
"width:160upx;height:160upx;text-align: center;line-height: 160upx;"
>
人像抠图
</view>
</view>
<view
style=
"align-items: center;margin-left: 100upx;"
>
<image
style=
"width:160upx;height:160upx; "
src=
"../../static/icon_diy_enhance_style.png"
@
click=
"showAiChangeType(4)"
></image>
<view
style=
"width:160upx;height:160upx;text-align: center;line-height: 160upx;"
>
色彩增强
</view>
</view>
</view>
<view
style=
"font-size: 30upx;color:#333; width:100%;text-align: center;margin: auto;"
>
选中的图片必须带有清晰人物头像
</view>
</view>
</uni-popup>
<switchGoods
ref=
"switchGoods"
@
selectGoodItem=
"selectGoodItem"
></switchGoods>
<switchGoods
ref=
"switchGoods"
@
selectGoodItem=
"selectGoodItem"
></switchGoods>
<!--商品弹框 -->
<!--商品弹框 -->
...
@@ -3908,7 +3924,7 @@
...
@@ -3908,7 +3924,7 @@
this
.
infoListTouchEvent
=
infoListTouchEvent
;
this
.
infoListTouchEvent
=
infoListTouchEvent
;
this
.
infoListTouchEvent
.
bind
({
this
.
infoListTouchEvent
.
bind
({
doubleTap
:
function
(
e
)
{
doubleTap
:
function
(
e
)
{
th
is
.
isShowGif
=
false
;
th
at
.
isShowGif
=
false
;
if
(
items
[
index
].
type
==
0
)
{
if
(
items
[
index
].
type
==
0
)
{
that
.
state
=
true
that
.
state
=
true
that
.
$refs
.
index
.
init
();
that
.
$refs
.
index
.
init
();
...
...
pages/index/machineDetail.vue
View file @
adf4a7cf
<
template
>
<
template
>
<view
class=
"full-width full-height"
>
<view
class=
"full-width full-height"
>
<!-- 自定义头部 -->
<!-- 自定义头部 -->
<myhead
:worksid=
"worksid"
:title=
"myheadtext"
:color=
"'#fff'"
:titleShow=
"true"
:backShow=
"true"
:isBack
=
"true"
<myhead
:worksid=
"worksid"
:title=
"myheadtext"
:color=
"'#fff'"
:titleShow=
"true"
:backShow=
"true"
:isBack=
"true"
:background=
"'none'"
></myhead>
:background=
"'none'"
></myhead>
<view
style=
"position: relative;width: 100%; height: 100%; z-index: 2;"
>
<view
style=
"position: relative;width: 100%; height: 100%; z-index: 2;"
>
...
@@ -30,11 +30,16 @@
...
@@ -30,11 +30,16 @@
background: linear-gradient(92deg, #F29F3D, #67C4CA);
background: linear-gradient(92deg, #F29F3D, #67C4CA);
box-shadow: 0px 19px 48px 1px rgba(20, 31, 62, 0.35);
box-shadow: 0px 19px 48px 1px rgba(20, 31, 62, 0.35);
border-radius: 40px;"
>
border-radius: 40px;"
>
<view
style=
" text-align: center; line-height: 100upx; font-size: 36upx; font-weight: 500; color: #FFFFFF;"
>
<view
style=
" text-align: center; line-height: 100upx; font-size: 36upx; font-weight: 500; color: #FFFFFF;"
>
立即定制
</view>
立即定制
</view>
</view>
</view>
<!--
<view
@
click=
"toProxyApplet()"
v-if=
"list.is_open_manage == 1"
style=
"position: fixed; bottom: 35upx; text-align: center;left: 0; right: 0;font-size: 32upx; margin: auto; color: #fff;"
>
运营中心
</view>
-->
</view>
</view>
<!-- 错误提示信息 -->
<!-- 错误提示信息 -->
<view
v-if=
"statusloading == 2"
style=
"min-height: 100%;background: #131319 !important;"
>
<view
v-if=
"statusloading == 2"
style=
"min-height: 100%;background: #131319 !important;"
>
<view
class=
"start"
style=
"padding-bottom: 100upx; padding-top: 200upx;"
>
<view
class=
"start"
style=
"padding-bottom: 100upx; padding-top: 200upx;"
>
...
@@ -43,7 +48,8 @@
...
@@ -43,7 +48,8 @@
<view
@
click=
"tomakePhoneCall"
>
<view
@
click=
"tomakePhoneCall"
>
<view
class=
"start_text"
>
联系客服
</view>
<view
class=
"start_text"
>
联系客服
</view>
<view
class=
"start_text"
style=
"display: flex; justify-content: center; align-items: center;"
>
<view
class=
"start_text"
style=
"display: flex; justify-content: center; align-items: center;"
>
<image
src=
"../../static/phone.png"
mode=
""
style=
"width: 32upx; height: 32upx; margin-right: 5upx;"
></image>
<image
src=
"../../static/phone.png"
mode=
""
style=
"width: 32upx; height: 32upx; margin-right: 5upx;"
></image>
{{
phone
||
'18938664545'
}}
{{
phone
||
'18938664545'
}}
</view>
</view>
</view>
</view>
...
@@ -61,9 +67,19 @@
...
@@ -61,9 +67,19 @@
<Signin
ref=
"Signin"
></Signin>
<Signin
ref=
"Signin"
></Signin>
<view
v-if=
"statusloading == 1"
@
tap=
"toLineList"
<view
v-if=
"statusloading == 1"
@
tap=
"toLineList"
style=
"position: fixed; z-index: 99; right: 0; bottom:
2
00upx; width: 109upx; height: 123upx;"
>
style=
"position: fixed; z-index: 99; right: 0; bottom:
4
00upx; width: 109upx; height: 123upx;"
>
<image
src=
"../../static/liebiao.png"
mode=
""
style=
"width: 243upx; height: 123upx;"
></image>
<image
src=
"../../static/liebiao.png"
mode=
""
style=
"width: 243upx; height: 123upx;"
></image>
</view>
</view>
<view
@
click=
"toProxyApplet()"
v-if=
"list.is_open_manage == 1"
style=
"position: fixed; z-index: 99; right: 0; bottom: 280upx; display: flex;align-items: center;justify-content: center;
width: 100upx; height: 88upx; background: #43cf7c; border-radius: 44upx 0px 0px 44upx;"
>
<view
style=
"font-size: 24upx; font-weight: 800; color: #FFFFFF;"
>
<view>
运营
</view>
<view>
中心
</view>
</view>
</view>
<switchGoods
ref=
"switchGoods"
@
selectGoodItem=
"selectGoodItem"
></switchGoods>
<switchGoods
ref=
"switchGoods"
@
selectGoodItem=
"selectGoodItem"
></switchGoods>
<!--//商品弹框 -->
<!--//商品弹框 -->
...
@@ -78,6 +94,7 @@
...
@@ -78,6 +94,7 @@
import
Signin
from
'../index/Signin.vue'
;
import
Signin
from
'../index/Signin.vue'
;
import
myhead
from
'./head/head.vue'
;
import
myhead
from
'./head/head.vue'
;
import
switchGoods
from
'../index/switchGoods.vue'
;
//选择商品
import
switchGoods
from
'../index/switchGoods.vue'
;
//选择商品
import
Env
from
'@/util/Env.js'
;
export
default
{
export
default
{
components
:
{
components
:
{
...
@@ -103,10 +120,69 @@
...
@@ -103,10 +120,69 @@
currentIndex
:
0
,
currentIndex
:
0
,
selectItem
:
null
,
//选择对象
selectItem
:
null
,
//选择对象
name
:
""
,
name
:
""
,
show_admin_login
:
0
};
};
},
},
methods
:
{
methods
:
{
//调转代理小程序
toProxyApplet
()
{
var
url
=
Env
.
getBaseURL
();
var
envVersionName
=
"trial"
;
if
(
url
.
indexOf
(
"colorpark"
)
!=
-
1
)
{
envVersionName
=
"release"
;
}
wx
.
navigateToMiniProgram
({
appId
:
'wx9cd3934f286f3d71'
,
envVersion
:
envVersionName
,
path
:
'pages/index/start-up?machine_id='
+
this
.
machine_id
+
"&partner_id="
+
this
.
list
.
partner_id
+
"&appletType=6"
,
success
(
res
)
{
}
})
},
//调转代理小程序
/* toProxyApplet() {
var url = Env.getBaseURL();
var envVersionName = "trial";
if (url.indexOf("colorpark") != -1) {
envVersionName = "release";
}
wx.navigateToMiniProgram({
appId: 'wx9cd3934f286f3d71',
envVersion: envVersionName,
success(res) {
}
})
}, */
//首次进来检查是否
toFirstCheck
()
{
let
that
=
this
;
uni
.
login
({
provider
:
'weixin'
,
success
:
(
res
)
=>
{
userService
.
login
({
s
:
'Init.checkAdminAuth'
,
code
:
res
.
code
,
partner_id
:
that
.
list
.
partner_id
}).
then
(
result
=>
{
that
.
show_admin_login
=
result
.
show_admin_login
}).
catch
(
err
=>
{
});
},
fail
:
(
res
)
=>
{
}
});
},
//去排队列表
//去排队列表
toLineList
()
{
toLineList
()
{
...
@@ -160,7 +236,7 @@
...
@@ -160,7 +236,7 @@
//授权登录
//授权登录
tologo
(
type
)
{
tologo
(
type
)
{
//
先登陆
//先登陆
let
that
=
this
;
let
that
=
this
;
uni
.
login
({
uni
.
login
({
provider
:
'weixin'
,
provider
:
'weixin'
,
...
@@ -196,11 +272,12 @@
...
@@ -196,11 +272,12 @@
})
})
homeservice
.
WorksList
({
homeservice
.
WorksList
({
machine_id
:
this
.
machine_id
,
machine_id
:
this
.
machine_id
,
s
:
'machine.
newD
etail'
s
:
'machine.
d
etail'
}).
then
(
res
=>
{
}).
then
(
res
=>
{
this
.
statusloading
=
1
;
this
.
statusloading
=
1
;
if
(
res
)
{
if
(
res
)
{
this
.
list
=
res
;
this
.
list
=
res
;
this
.
toFirstCheck
();
this
.
myheadtext
=
this
.
machine_id
+
'-'
+
res
.
code
//头部标题栏
this
.
myheadtext
=
this
.
machine_id
+
'-'
+
res
.
code
//头部标题栏
}
}
uni
.
stopPullDownRefresh
();
uni
.
stopPullDownRefresh
();
...
@@ -209,7 +286,7 @@
...
@@ -209,7 +286,7 @@
this
.
msg
=
err
.
msg
this
.
msg
=
err
.
msg
this
.
statusloading
=
2
;
this
.
statusloading
=
2
;
this
.
phone
=
err
.
data
.
phone
||
'18938664545'
this
.
phone
=
err
.
data
.
phone
||
'18938664545'
this
.
myheadtext
=
'歇一歇'
this
.
myheadtext
=
'歇一歇'
uni
.
stopPullDownRefresh
();
uni
.
stopPullDownRefresh
();
uni
.
hideLoading
();
uni
.
hideLoading
();
});
});
...
@@ -236,14 +313,14 @@
...
@@ -236,14 +313,14 @@
//上拉刷新
//上拉刷新
onReachBottom
()
{
onReachBottom
()
{
},
},
//下拉加载
//下拉加载
onPullDownRefresh
()
{
onPullDownRefresh
()
{
this
.
getDetail
()
//获取数据
this
.
getDetail
()
//获取数据
},
},
//分享转发
//分享转发
onShareAppMessage
(
options
)
{
onShareAppMessage
(
options
)
{
var
that
=
this
;
var
that
=
this
;
...
@@ -269,11 +346,11 @@
...
@@ -269,11 +346,11 @@
this
.
Adlist
()
//轮播图
this
.
Adlist
()
//轮播图
this
.
getDetail
()
//获取数据
this
.
getDetail
()
//获取数据
},
},
onShow
()
{},
onShow
()
{},
onHide
()
{}
onHide
()
{}
};
};
</
script
>
</
script
>
...
@@ -348,4 +425,4 @@
...
@@ -348,4 +425,4 @@
transition
:
all
0.2s
ease-in
0s
;
transition
:
all
0.2s
ease-in
0s
;
z-index
:
20
;
z-index
:
20
;
}
}
</
style
>
</
style
>
\ No newline at end of file
static/icon_diy_anime_style.png
View replaced file @
828b15c5
View file @
adf4a7cf
37.3 KB
|
W:
|
H:
12.3 KB
|
W:
|
H:
2-up
Swipe
Onion skin
static/icon_diy_enhance_style.png
0 → 100644
View file @
adf4a7cf
10.9 KB
static/icon_diy_matting_style.png
0 → 100644
View file @
adf4a7cf
28.8 KB
util/script.js
View file @
adf4a7cf
...
@@ -11,162 +11,178 @@ import CryptoJS from 'crypto-js';
...
@@ -11,162 +11,178 @@ import CryptoJS from 'crypto-js';
// miniProgramType:小程序类型,比如:微信小程序传参数:wx,支付宝传参数:my,钉钉传参数:dd,注意不要传字符串;
// miniProgramType:小程序类型,比如:微信小程序传参数:wx,支付宝传参数:my,钉钉传参数:dd,注意不要传字符串;
// callback:结果的回调
// callback:结果的回调
// type 1: 人物动漫化 2:人物素描化
// type 1: 人物动漫化 2:人物素描化
function
callRecognizeBankCard
(
imageURL
,
miniProgramType
,
type
,
callback
)
{
function
callRecognizeBankCard
(
imageURL
,
miniProgramType
,
type
,
callback
)
{
const
accessKeyId
=
"LTAI5tDPiEBZgfqNcWBqaFEc"
;
//AccessKeySecret
const
accessKeyId
=
"LTAI5tDPiEBZgfqNcWBqaFEc"
;
const
accessKeySecret
=
"amI84BLFbHz6dhOVbuArrERmeemmnx"
;
//AccessKeySecret
//这里endpoint为API访问域名,与类目相关,具体类目的API访问域名请参考:https://help.aliyun.com/document_detail/143103.html
const
accessKeySecret
=
"amI84BLFbHz6dhOVbuArrERmeemmnx"
;
let
endpoint
=
"facebody.cn-shanghai.aliyuncs.com"
;
//这里endpoint为API访问域名,与类目相关,具体类目的API访问域名请参考:https://help.aliyun.com/document_detail/143103.html
//API Action,能力名称,请参考具体算法文档详情页中的Action参数,这里以银行卡识别为例:https://help.aliyun.com/document_detail/151893.html
const
endpoint
=
"facebody.cn-shanghai.aliyuncs.com"
;
let
Action
=
"GenerateHumanAnimeStyle"
;
//API Action,能力名称,请参考具体算法文档详情页中的Action参数,这里以银行卡识别为例:https://help.aliyun.com/document_detail/151893.html
//API_HTTP_METHOD推荐使用POST
let
Action
=
"GenerateHumanAnimeStyle"
;
const
API_HTTP_METHOD
=
"POST"
;
//API_HTTP_METHOD推荐使用POST
//API_VERSION为API版本,与类目相关,具体类目的API版本请参考:https://help.aliyun.com/document_detail/464194.html
const
API_HTTP_METHOD
=
"POST"
;
let
API_VERSION
=
"2019-12-30"
;
//API_VERSION为API版本,与类目相关,具体类目的API版本请参考:https://help.aliyun.com/document_detail/464194.html
const
request_
=
{};
const
API_VERSION
=
"2019-12-30"
;
if
(
type
==
2
)
{
const
request_
=
{};
Action
=
"GenerateHumanSketchStyle"
;
if
(
type
==
2
){
request_
[
"ReturnType"
]
=
"full"
;
Action
=
"GenerateHumanSketchStyle"
;
}
else
if
(
type
==
3
)
{
request_
[
"ReturnType"
]
=
"full"
;
Action
=
"SegmentHDBody"
;
}
else
{
endpoint
=
"imageseg.cn-shanghai.aliyuncs.com"
;
request_
[
"AlgoType"
]
=
"handdrawn"
;
}
else
if
(
type
==
4
)
{
}
Action
=
"EnhanceImageColor"
;
//系统参数
endpoint
=
"imageenhan.cn-shanghai.aliyuncs.com"
;
request_
[
"SignatureMethod"
]
=
"HMAC-SHA1"
;
API_VERSION
=
"2019-09-30"
;
request_
[
"SignatureNonce"
]
=
signNRandom
();
request_
[
"ImageURL"
]
=
imageURL
;
request_
[
"AccessKeyId"
]
=
accessKeyId
;
request_
[
"Mode"
]
=
"ln17_256"
;
request_
[
"SignatureVersion"
]
=
"1.0"
;
request_
[
"OutputFormat"
]
=
"png"
;
request_
[
"Timestamp"
]
=
getTimestamp
();
}
else
{
request_
[
"Format"
]
=
"JSON"
;
request_
[
"AlgoType"
]
=
"handdrawn"
;
request_
[
"RegionId"
]
=
"cn-shanghai"
;
}
request_
[
"Version"
]
=
API_VERSION
;
//系统参数
request_
[
"ImageURL"
]
=
imageURL
;
request_
[
"SignatureMethod"
]
=
"HMAC-SHA1"
;
request_
[
"Action"
]
=
Action
;
request_
[
"SignatureNonce"
]
=
signNRandom
();
callApiRequest
(
miniProgramType
,
request_
,
API_HTTP_METHOD
,
endpoint
,
accessKeySecret
,
callback
);
request_
[
"AccessKeyId"
]
=
accessKeyId
;
request_
[
"SignatureVersion"
]
=
"1.0"
;
request_
[
"Timestamp"
]
=
getTimestamp
();
request_
[
"Format"
]
=
"JSON"
;
request_
[
"RegionId"
]
=
"cn-shanghai"
;
request_
[
"Version"
]
=
API_VERSION
;
request_
[
"ImageURL"
]
=
imageURL
;
request_
[
"Action"
]
=
Action
;
callApiRequest
(
miniProgramType
,
request_
,
API_HTTP_METHOD
,
endpoint
,
accessKeySecret
,
callback
);
};
};
//请求数据
//请求数据
function
callApiRequest
(
miniProgramType
,
request_
,
API_HTTP_METHOD
,
endpoint
,
accessKeySecret
,
callback
)
{
function
callApiRequest
(
miniProgramType
,
request_
,
API_HTTP_METHOD
,
endpoint
,
accessKeySecret
,
callback
)
{
const
url
=
generateUrl
(
request_
,
API_HTTP_METHOD
,
endpoint
,
accessKeySecret
);
const
url
=
generateUrl
(
request_
,
API_HTTP_METHOD
,
endpoint
,
accessKeySecret
);
miniProgramType
.
request
({
miniProgramType
.
request
({
url
:
url
,
url
:
url
,
method
:
'POST'
,
method
:
'POST'
,
header
:
{
header
:
{
"ContentType"
:
"application/json"
"ContentType"
:
"application/json"
},
},
success
:
(
result
)
=>
{
success
:
(
result
)
=>
{
//
获取结果
//
获取结果
return
typeof
callback
==
"function"
&&
callback
(
result
.
data
)
return
typeof
callback
==
"function"
&&
callback
(
result
.
data
)
},
},
fail
:
(
error
)
=>
{
fail
:
(
error
)
=>
{
//
获取报错信息
//
获取报错信息
return
typeof
callback
==
"function"
&&
callback
(
error
.
data
)
return
typeof
callback
==
"function"
&&
callback
(
error
.
data
)
}
}
})
})
};
};
/**
* ========================================================================================================================
* 以下代码仅仅为了调用服务端接口计算签名,其逻辑可参考文档:https://help.aliyun.com/document_detail/144904.html
* 这里只是为了Web前端演示,所以将代码写在了Web前端
* 真正上线不建议将ACCESS_KEY_ID和ACCESS_KEY_SECRET写在Web前端上,会有泄漏风险,建议将请求API接口代码写到您的服务端
* ========================================================================================================================
*/
//随机数字
//随机数字
function
signNRandom
()
{
function
signNRandom
()
{
const
Rand
=
Math
.
random
()
const
Rand
=
Math
.
random
()
const
mineId
=
Math
.
round
(
Rand
*
100000000000000
)
const
mineId
=
Math
.
round
(
Rand
*
100000000000000
)
return
mineId
;
return
mineId
;
};
};
//Timestamp
function
getTimestamp
()
{
function
getTimestamp
()
{
let
date
=
new
Date
();
let
date
=
new
Date
();
let
YYYY
=
pad2
(
date
.
getUTCFullYear
());
let
YYYY
=
pad2
(
date
.
getUTCFullYear
());
let
MM
=
pad2
(
date
.
getUTCMonth
()
+
1
);
let
MM
=
pad2
(
date
.
getUTCMonth
()
+
1
);
let
DD
=
pad2
(
date
.
getUTCDate
());
let
DD
=
pad2
(
date
.
getUTCDate
());
let
HH
=
pad2
(
date
.
getUTCHours
());
let
HH
=
pad2
(
date
.
getUTCHours
());
let
mm
=
pad2
(
date
.
getUTCMinutes
());
let
mm
=
pad2
(
date
.
getUTCMinutes
());
let
ss
=
pad2
(
date
.
getUTCSeconds
());
let
ss
=
pad2
(
date
.
getUTCSeconds
());
return
`
${
YYYY
}
-
${
MM
}
-
${
DD
}
T
${
HH
}
:
${
mm
}
:
${
ss
}
Z`
;
return
`
${
YYYY
}
-
${
MM
}
-
${
DD
}
T
${
HH
}
:
${
mm
}
:
${
ss
}
Z`
;
};
};
function
pad2
(
num
)
{
function
pad2
(
num
)
{
if
(
num
<
10
)
{
if
(
num
<
10
)
{
return
'0'
+
num
;
return
'0'
+
num
;
}
}
return
''
+
num
;
return
''
+
num
;
};
};
function
ksort
(
params
)
{
function
ksort
(
params
)
{
let
keys
=
Object
.
keys
(
params
).
sort
();
let
keys
=
Object
.
keys
(
params
).
sort
();
let
newParams
=
{};
let
newParams
=
{};
keys
.
forEach
((
key
)
=>
{
keys
.
forEach
((
key
)
=>
{
newParams
[
key
]
=
params
[
key
];
newParams
[
key
]
=
params
[
key
];
});
});
return
newParams
;
return
newParams
;
};
};
function
createHmac
(
stringToSign
,
key
)
{
function
createHmac
(
stringToSign
,
key
)
{
const
CrypStringToSign
=
CryptoJS
.
HmacSHA1
(
CryptoJS
.
enc
.
Utf8
.
parse
(
stringToSign
),
key
);
const
CrypStringToSign
=
CryptoJS
.
HmacSHA1
(
CryptoJS
.
enc
.
Utf8
.
parse
(
stringToSign
),
key
);
const
base64
=
CryptoJS
.
enc
.
Base64
.
stringify
(
CrypStringToSign
);
const
base64
=
CryptoJS
.
enc
.
Base64
.
stringify
(
CrypStringToSign
);
return
base64
;
return
base64
;
};
};
function
encode
(
str
)
{
function
encode
(
str
)
{
var
result
=
encodeURIComponent
(
str
);
var
result
=
encodeURIComponent
(
str
);
return
result
.
replace
(
/!/g
,
'%21'
)
return
result
.
replace
(
/!/g
,
'%21'
)
.
replace
(
/'/g
,
'%27'
)
.
replace
(
/'/g
,
'%27'
)
.
replace
(
/
\(
/g
,
'%28'
)
.
replace
(
/
\(
/g
,
'%28'
)
.
replace
(
/
\)
/g
,
'%29'
)
.
replace
(
/
\)
/g
,
'%29'
)
.
replace
(
/
\*
/g
,
'%2A'
);
.
replace
(
/
\*
/g
,
'%2A'
);
};
};
function
sha1
(
stringToSign
,
key
)
{
function
sha1
(
stringToSign
,
key
)
{
return
createHmac
(
stringToSign
,
key
);
return
createHmac
(
stringToSign
,
key
);
};
};
function
getSignature
(
signedParams
,
method
,
secret
)
{
function
getSignature
(
signedParams
,
method
,
secret
)
{
var
stringToSign
=
`
${
method
}
&
${
encode
(
'/'
)}
&
${
encode
(
signedParams
)}
`
;
var
stringToSign
=
`
${
method
}
&
${
encode
(
'/'
)}
&
${
encode
(
signedParams
)}
`
;
const
key
=
secret
+
"&"
;
const
key
=
secret
+
"&"
;
return
sha1
(
stringToSign
,
key
);
return
sha1
(
stringToSign
,
key
);
};
};
//参数拼接
//参数拼接
function
objToParam
(
param
)
{
function
objToParam
(
param
)
{
if
(
Object
.
prototype
.
toString
.
call
(
param
)
!==
'[object Object]'
)
{
if
(
Object
.
prototype
.
toString
.
call
(
param
)
!==
'[object Object]'
)
{
return
''
;
return
''
;
}
}
let
queryParam
=
''
;
let
queryParam
=
''
;
for
(
let
key
in
param
)
{
for
(
let
key
in
param
)
{
if
(
param
.
hasOwnProperty
(
key
))
{
if
(
param
.
hasOwnProperty
(
key
))
{
let
value
=
param
[
key
];
let
value
=
param
[
key
];
queryParam
+=
toQueryPair
(
key
,
value
);
queryParam
+=
toQueryPair
(
key
,
value
);
}
}
}
}
return
queryParam
;
return
queryParam
;
};
};
function
toQueryPair
(
key
,
value
)
{
function
toQueryPair
(
key
,
value
)
{
if
(
typeof
value
==
'undefined'
)
{
if
(
typeof
value
==
'undefined'
)
{
return
`&
${
key
}
=`
;
return
`&
${
key
}
=`
;
}
}
return
`&
${
encodeURIComponent
(
key
)}
=
${
encodeURIComponent
(
value
)}
`
;
return
`&
${
encodeURIComponent
(
key
)}
=
${
encodeURIComponent
(
value
)}
`
;
};
};
function
generateUrl
(
request
,
httpMethod
,
endpoint
,
accessKeySecret
)
{
function
generateUrl
(
request
,
httpMethod
,
endpoint
,
accessKeySecret
)
{
//参数中key排序
//参数中key排序
const
sortParams
=
ksort
(
request
);
const
sortParams
=
ksort
(
request
);
//拼成参数
//拼成参数
const
sortQueryStringTmp
=
objToParam
(
sortParams
);
const
sortQueryStringTmp
=
objToParam
(
sortParams
);
const
sortedQueryString
=
sortQueryStringTmp
.
substring
(
1
);
// 去除第一个多余的&符号
const
sortedQueryString
=
sortQueryStringTmp
.
substring
(
1
);
// 去除第一个多余的&符号
//构造待签名的字符串
//构造待签名的字符串
const
Signture
=
getSignature
(
sortedQueryString
,
httpMethod
,
accessKeySecret
)
const
Signture
=
getSignature
(
sortedQueryString
,
httpMethod
,
accessKeySecret
)
//签名最后也要做特殊URL编码
//签名最后也要做特殊URL编码
request
[
"Signature"
]
=
encodeURIComponent
(
Signture
);
request
[
"Signature"
]
=
encodeURIComponent
(
Signture
);
//最终生成出合法请求的URL
//最终生成出合法请求的URL
const
finalUrl
=
"https://"
+
endpoint
+
"/?Signature="
+
encodeURIComponent
(
Signture
)
+
sortQueryStringTmp
;
const
finalUrl
=
"https://"
+
endpoint
+
"/?Signature="
+
encodeURIComponent
(
Signture
)
+
sortQueryStringTmp
;
return
finalUrl
;
return
finalUrl
;
};
};
//导出方法
//导出方法
module
.
exports
=
{
module
.
exports
=
{
callRecognizeBankCard
:
callRecognizeBankCard
,
callRecognizeBankCard
:
callRecognizeBankCard
,
signNRandom
:
signNRandom
,
signNRandom
:
signNRandom
,
getTimestamp
:
getTimestamp
,
getTimestamp
:
getTimestamp
,
generateUrl
:
generateUrl
,
generateUrl
:
generateUrl
,
createHmac
:
createHmac
createHmac
:
createHmac
}
}
\ No newline at end of file
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