Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
DCloud
uni-pay
提交
8067e562
U
uni-pay
项目概览
DCloud
/
uni-pay
通知
798
Star
3
Fork
3
代码
文件
提交
分支
Tags
贡献者
分支图
Diff
Issue
1
列表
看板
标记
里程碑
合并请求
0
DevOps
流水线
流水线任务
计划
Wiki
0
Wiki
分析
仓库
DevOps
项目成员
Pages
U
uni-pay
项目概览
项目概览
详情
发布
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
Issue
1
Issue
1
列表
看板
标记
里程碑
合并请求
0
合并请求
0
Pages
DevOps
DevOps
流水线
流水线任务
计划
分析
分析
仓库分析
DevOps
Wiki
0
Wiki
成员
成员
收起侧边栏
关闭侧边栏
动态
分支图
创建新Issue
流水线任务
提交
Issue看板
前往新版Gitcode,体验更适合开发者的 AI 搜索 >>
提交
8067e562
编写于
1月 08, 2024
作者:
VK1688
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
【优化】config 支持 directory
上级
a2255209
变更
3
隐藏空白更改
内联
并排
Showing
3 changed file
with
65 addition
and
14 deletion
+65
-14
uni_modules/uni-pay/uniCloud/cloudfunctions/uni-pay-co/index.obj.js
...s/uni-pay/uniCloud/cloudfunctions/uni-pay-co/index.obj.js
+8
-3
uni_modules/uni-pay/uniCloud/cloudfunctions/uni-pay-co/libs/common.js
...uni-pay/uniCloud/cloudfunctions/uni-pay-co/libs/common.js
+24
-0
uni_modules/uni-pay/uniCloud/cloudfunctions/uni-pay-co/service/pay.js
...uni-pay/uniCloud/cloudfunctions/uni-pay-co/service/pay.js
+33
-11
未找到文件。
uni_modules/uni-pay/uniCloud/cloudfunctions/uni-pay-co/index.obj.js
浏览文件 @
8067e562
...
@@ -94,6 +94,7 @@ module.exports = {
...
@@ -94,6 +94,7 @@ module.exports = {
other
,
// 其他请求参数(会发送给第三方支付服务器)
other
,
// 其他请求参数(会发送给第三方支付服务器)
clientInfo
,
// 兼容云对象调用云对象模式
clientInfo
,
// 兼容云对象调用云对象模式
cloudInfo
,
// 兼容云对象调用云对象模式
cloudInfo
,
// 兼容云对象调用云对象模式
config_directory
,
}
=
data
;
}
=
data
;
if
(
!
clientInfo
)
clientInfo
=
this
.
getClientInfo
();
if
(
!
clientInfo
)
clientInfo
=
this
.
getClientInfo
();
...
@@ -116,6 +117,7 @@ module.exports = {
...
@@ -116,6 +117,7 @@ module.exports = {
other
,
other
,
clientInfo
,
clientInfo
,
cloudInfo
,
cloudInfo
,
config_directory
,
});
});
return
res
;
return
res
;
...
@@ -212,6 +214,7 @@ module.exports = {
...
@@ -212,6 +214,7 @@ module.exports = {
provider
,
provider
,
code
,
code
,
clientInfo
,
// 兼容云对象调用云对象模式
clientInfo
,
// 兼容云对象调用云对象模式
config_directory
,
}
=
data
;
}
=
data
;
if
(
!
clientInfo
)
clientInfo
=
this
.
getClientInfo
();
if
(
!
clientInfo
)
clientInfo
=
this
.
getClientInfo
();
...
@@ -219,7 +222,8 @@ module.exports = {
...
@@ -219,7 +222,8 @@ module.exports = {
res
=
await
service
.
pay
.
getOpenid
({
res
=
await
service
.
pay
.
getOpenid
({
provider
,
provider
,
code
,
code
,
clientInfo
clientInfo
,
config_directory
,
});
});
return
res
;
return
res
;
...
@@ -238,10 +242,11 @@ module.exports = {
...
@@ -238,10 +242,11 @@ module.exports = {
async
getProviderAppId
(
data
)
{
async
getProviderAppId
(
data
)
{
let
{
let
{
provider
,
provider
,
provider_pay_type
provider_pay_type
,
config_directory
,
}
=
data
;
}
=
data
;
// 注意,前往不要直接把 conifg 内的所有内容返回给前端
// 注意,前往不要直接把 conifg 内的所有内容返回给前端
let
conifg
=
service
.
pay
.
getConfig
();
let
conifg
=
service
.
pay
.
getConfig
(
data
);
try
{
try
{
return
{
return
{
errorCode
:
0
,
errorCode
:
0
,
...
...
uni_modules/uni-pay/uniCloud/cloudfunctions/uni-pay-co/libs/common.js
浏览文件 @
8067e562
...
@@ -289,5 +289,29 @@ common.camel2snakeJson = function(obj) {
...
@@ -289,5 +289,29 @@ common.camel2snakeJson = function(obj) {
return
parseObjectKeys
(
obj
,
'
camel2snake
'
);
return
parseObjectKeys
(
obj
,
'
camel2snake
'
);
};
};
// 2个对象合并
function
mergeObjects
(
obj1
,
obj2
)
{
// 创建一个新的对象来存储合并后的结果
const
result
=
{};
// 复制obj1的所有属性到result
for
(
let
key
in
obj1
)
{
if
(
typeof
obj1
[
key
]
===
'
object
'
&&
obj1
[
key
]
!==
null
)
{
result
[
key
]
=
mergeObjects
({},
obj1
[
key
]);
// 递归合并
}
else
{
result
[
key
]
=
obj1
[
key
];
}
}
// 合并obj2的属性到result
for
(
let
key
in
obj2
)
{
if
(
typeof
obj2
[
key
]
===
'
object
'
&&
obj2
[
key
]
!==
null
)
{
result
[
key
]
=
mergeObjects
(
result
[
key
]
||
{},
obj2
[
key
]);
// 递归合并
}
else
{
result
[
key
]
=
obj2
[
key
];
}
}
return
result
;
}
common
.
mergeObjects
=
mergeObjects
;
module
.
exports
=
common
;
module
.
exports
=
common
;
uni_modules/uni-pay/uniCloud/cloudfunctions/uni-pay-co/service/pay.js
浏览文件 @
8067e562
...
@@ -29,8 +29,19 @@ class service {
...
@@ -29,8 +29,19 @@ class service {
/**
/**
* 获取支付插件的完整配置
* 获取支付插件的完整配置
*/
*/
getConfig
()
{
getConfig
(
data
=
{})
{
return
config
;
let
{
config_directory
}
=
data
;
let
realityConfig
=
{};
if
(
config_directory
&&
config_directory
!==
"
default
"
)
{
const
directoryConfig
=
configCenter
({
pluginId
:
'
uni-pay
'
}).
requireFile
(
`
${
config_directory
}
/config.js`
);
// 深度合并配置,参数名相同时,以directoryConfig为主
realityConfig
=
libs
.
common
.
mergeObjects
(
config
,
directoryConfig
);
}
else
{
realityConfig
=
config
;
}
return
realityConfig
;
}
}
/**
/**
* 支付成功 - 异步通知
* 支付成功 - 异步通知
...
@@ -43,12 +54,17 @@ class service {
...
@@ -43,12 +54,17 @@ class service {
}
=
data
;
}
=
data
;
console
.
log
(
'
httpInfo:
'
,
httpInfo
);
console
.
log
(
'
httpInfo:
'
,
httpInfo
);
let
path
=
httpInfo
.
path
;
let
path
=
httpInfo
.
path
;
let
pay_type
=
path
.
substring
(
notifyPath
.
length
);
let
notifyPathSplit
=
path
.
substring
(
notifyPath
.
length
).
split
(
"
/
"
);
let
pay_type
=
notifyPathSplit
[
0
];
// 获取支付方式
let
provider
=
pay_type
.
split
(
"
-
"
)[
0
];
// 获取支付供应商
let
provider
=
pay_type
.
split
(
"
-
"
)[
0
];
// 获取支付供应商
let
provider_pay_type
=
pay_type
.
split
(
"
-
"
)[
1
];
// 获取支付方式
let
provider_pay_type
=
pay_type
.
split
(
"
-
"
)[
1
];
// 获取支付供应商对应的支付类型
let
config_directory
=
notifyPathSplit
[
1
];
// 获取使用的配置目录
let
original_data
=
libs
.
common
.
getNotifyData
({
httpInfo
,
provider
});
// 获取原始回调数据
let
original_data
=
libs
.
common
.
getNotifyData
({
httpInfo
,
provider
});
// 获取原始回调数据
// 初始化uniPayInstance
// 初始化uniPayInstance
let
uniPayInstance
=
await
this
.
initUniPayInstance
({
provider
,
provider_pay_type
});
let
uniPayInstance
=
await
this
.
initUniPayInstance
({
provider
,
provider_pay_type
,
config_directory
});
let
notifyType
=
await
uniPayInstance
.
checkNotifyType
(
httpInfo
);
let
notifyType
=
await
uniPayInstance
.
checkNotifyType
(
httpInfo
);
if
(
notifyType
!==
"
payment
"
)
{
if
(
notifyType
!==
"
payment
"
)
{
// 由于支付宝部分退款会触发支付成功的回调,但同时签名验证是算未通过的,为了避免支付宝重复推送,这里可以直接返回成功告知支付宝服务器,不用再推送过来了。
// 由于支付宝部分退款会触发支付成功的回调,但同时签名验证是算未通过的,为了避免支付宝重复推送,这里可以直接返回成功告知支付宝服务器,不用再推送过来了。
...
@@ -156,6 +172,7 @@ class service {
...
@@ -156,6 +172,7 @@ class service {
qr_code
,
// 是否强制使用扫码支付
qr_code
,
// 是否强制使用扫码支付
clientInfo
,
// 客户端信息
clientInfo
,
// 客户端信息
cloudInfo
,
// 云端信息
cloudInfo
,
// 云端信息
config_directory
=
"
default
"
,
// 支付配置所在目录
custom
,
// 自定义参数(不会发送给第三方支付服务器)
custom
,
// 自定义参数(不会发送给第三方支付服务器)
other
,
// 其他请求参数(会发送给第三方支付服务器)
other
,
// 其他请求参数(会发送给第三方支付服务器)
...
@@ -229,14 +246,14 @@ class service {
...
@@ -229,14 +246,14 @@ class service {
});
});
res
.
provider_pay_type
=
provider_pay_type
;
res
.
provider_pay_type
=
provider_pay_type
;
// 拼接实际异步回调地址
// 拼接实际异步回调地址
let
finalNotifyUrl
=
`
${
currentNotifyUrl
}${
notifyPath
}${
provider
}
-
${
provider_pay_type
}
`
;
let
finalNotifyUrl
=
`
${
currentNotifyUrl
}${
notifyPath
}${
provider
}
-
${
provider_pay_type
}
/
${
config_directory
}
`
;
// 获取uniPay交易类型
// 获取uniPay交易类型
let
tradeType
=
libs
.
common
.
getTradeType
({
provider
,
provider_pay_type
});
let
tradeType
=
libs
.
common
.
getTradeType
({
provider
,
provider_pay_type
});
let
uniPayConifg
=
await
this
.
getUniPayConfig
({
provider
,
provider_pay_type
});
let
uniPayConifg
=
await
this
.
getUniPayConfig
({
provider
,
provider_pay_type
,
config_directory
});
// 初始化uniPayInstance
// 初始化uniPayInstance
let
uniPayInstance
=
await
this
.
initUniPayInstance
({
provider
,
provider_pay_type
});
let
uniPayInstance
=
await
this
.
initUniPayInstance
({
provider
,
provider_pay_type
,
config_directory
});
// 获取支付信息
// 获取支付信息
let
getOrderInfoParam
=
{
let
getOrderInfoParam
=
{
...
@@ -331,6 +348,7 @@ class service {
...
@@ -331,6 +348,7 @@ class service {
await
dao
.
uniPayOrders
.
add
({
await
dao
.
uniPayOrders
.
add
({
provider
,
provider
,
provider_pay_type
,
provider_pay_type
,
config_directory
,
uni_platform
:
platform
,
uni_platform
:
platform
,
status
:
0
,
status
:
0
,
type
,
type
,
...
@@ -365,6 +383,7 @@ class service {
...
@@ -365,6 +383,7 @@ class service {
await
dao
.
uniPayOrders
.
updateById
(
payOrderInfo
.
_id
,
{
await
dao
.
uniPayOrders
.
updateById
(
payOrderInfo
.
_id
,
{
provider
,
provider
,
provider_pay_type
,
provider_pay_type
,
config_directory
,
});
});
}
}
// 自动删除3天前的订单(未付款订单)
// 自动删除3天前的订单(未付款订单)
...
@@ -691,6 +710,7 @@ class service {
...
@@ -691,6 +710,7 @@ class service {
provider
,
// 支付供应商
provider
,
// 支付供应商
code
,
// 用户登录获取的code
code
,
// 用户登录获取的code
clientInfo
,
// 客户端环境
clientInfo
,
// 客户端环境
config_directory
,
}
=
data
;
}
=
data
;
if
(
!
code
)
{
if
(
!
code
)
{
throw
{
errCode
:
ERROR
[
51002
]
};
throw
{
errCode
:
ERROR
[
51002
]
};
...
@@ -702,7 +722,7 @@ class service {
...
@@ -702,7 +722,7 @@ class service {
platform
,
platform
,
ua
ua
});
});
let
uniPayConifg
=
await
this
.
getUniPayConfig
({
provider
,
provider_pay_type
});
let
uniPayConifg
=
await
this
.
getUniPayConfig
({
provider
,
provider_pay_type
,
config_directory
});
if
(
provider
===
"
wxpay
"
)
{
if
(
provider
===
"
wxpay
"
)
{
return
await
libs
.
wxpay
.
getOpenid
({
return
await
libs
.
wxpay
.
getOpenid
({
config
:
uniPayConifg
,
config
:
uniPayConifg
,
...
@@ -859,13 +879,15 @@ class service {
...
@@ -859,13 +879,15 @@ class service {
/**
/**
* 获取对应支付配置
* 获取对应支付配置
* let uniPayConifg = await this.getUniPayConfig({ provider, provider_pay_type });
* let uniPayConifg = await this.getUniPayConfig({ provider, provider_pay_type
, config_directory
});
*/
*/
async
getUniPayConfig
(
data
=
{})
{
async
getUniPayConfig
(
data
=
{})
{
let
{
let
{
provider
,
provider
,
provider_pay_type
,
provider_pay_type
,
config_directory
}
=
data
;
}
=
data
;
let
config
=
this
.
getConfig
(
data
);
if
(
config
&&
config
[
provider
]
&&
config
[
provider
][
provider_pay_type
])
{
if
(
config
&&
config
[
provider
]
&&
config
[
provider
][
provider_pay_type
])
{
let
uniPayConfig
=
config
[
provider
][
provider_pay_type
];
let
uniPayConfig
=
config
[
provider
][
provider_pay_type
];
if
(
!
uniPayConfig
.
appId
&&
provider
!==
"
appleiap
"
)
{
if
(
!
uniPayConfig
.
appId
&&
provider
!==
"
appleiap
"
)
{
...
@@ -879,7 +901,7 @@ class service {
...
@@ -879,7 +901,7 @@ class service {
/**
/**
* 初始化uniPayInstance
* 初始化uniPayInstance
* let uniPayInstance = await service.pay.initUniPayInstance({ provider, provider_pay_type });
* let uniPayInstance = await service.pay.initUniPayInstance({ provider, provider_pay_type
, config_directory
});
*/
*/
async
initUniPayInstance
(
data
=
{})
{
async
initUniPayInstance
(
data
=
{})
{
let
{
let
{
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录