@ethan-utils/pay-gateway 1.4.0 → 1.4.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/7pay/types.d.ts +204 -0
- package/dist/index.cjs +7 -0
- package/ltzf/types.d.ts +507 -0
- package/package.json +5 -2
- package/types/7pay/types.d.ts +204 -0
- package/types/ltzf/types.d.ts +507 -0
package/7pay/types.d.ts
ADDED
|
@@ -0,0 +1,204 @@
|
|
|
1
|
+
declare global {
|
|
2
|
+
namespace SevenPay {
|
|
3
|
+
namespace Params {
|
|
4
|
+
/**
|
|
5
|
+
* 页面跳转支付参数
|
|
6
|
+
*/
|
|
7
|
+
export interface JumpPay {
|
|
8
|
+
/** 商品名称,不超过100字 */
|
|
9
|
+
name: string;
|
|
10
|
+
/** 订单金额,最多保留两位小数 */
|
|
11
|
+
money: string;
|
|
12
|
+
/** 支付方式,alipay/wxpay */
|
|
13
|
+
type: string;
|
|
14
|
+
/** 订单编号,唯一 */
|
|
15
|
+
out_trade_no: string;
|
|
16
|
+
/** 异步通知页面,不支持带参数 */
|
|
17
|
+
notify_url: string;
|
|
18
|
+
/** 商户唯一标识 */
|
|
19
|
+
pid: string;
|
|
20
|
+
/** 支付渠道ID,可选 */
|
|
21
|
+
cid?: string;
|
|
22
|
+
/** 附加内容,可选 */
|
|
23
|
+
param?: string;
|
|
24
|
+
/** 跳转页面,交易完成后跳转,不支持带参数 */
|
|
25
|
+
return_url: string;
|
|
26
|
+
/** 签名 */
|
|
27
|
+
sign?: string;
|
|
28
|
+
/** 签名方法,默认为MD5 */
|
|
29
|
+
sign_type?: "MD5";
|
|
30
|
+
}
|
|
31
|
+
/**
|
|
32
|
+
* API接口支付参数
|
|
33
|
+
*/
|
|
34
|
+
export interface ApiPay {
|
|
35
|
+
/** 商户唯一标识 */
|
|
36
|
+
pid: string;
|
|
37
|
+
/** 支付渠道ID,可选 */
|
|
38
|
+
cid?: string;
|
|
39
|
+
/** 支付方式,alipay/wxpay */
|
|
40
|
+
type: string;
|
|
41
|
+
/** 订单编号,唯一 */
|
|
42
|
+
out_trade_no: string;
|
|
43
|
+
/** 异步通知页面,不支持带参数 */
|
|
44
|
+
notify_url: string;
|
|
45
|
+
/** 商品名称,不超过100字 */
|
|
46
|
+
name: string;
|
|
47
|
+
/** 订单金额,最多保留两位小数 */
|
|
48
|
+
money: string;
|
|
49
|
+
/** 客户端IP地址 */
|
|
50
|
+
clientip: string;
|
|
51
|
+
/** 设备类型,可选 */
|
|
52
|
+
device?: string;
|
|
53
|
+
/** 附加内容,可选 */
|
|
54
|
+
param?: string;
|
|
55
|
+
/** 签名 */
|
|
56
|
+
sign?: string;
|
|
57
|
+
/** 签名方法,默认为MD5 */
|
|
58
|
+
sign_type?: "MD5";
|
|
59
|
+
}
|
|
60
|
+
/**
|
|
61
|
+
* 余额查询参数
|
|
62
|
+
*/
|
|
63
|
+
export interface BalanceQuery {
|
|
64
|
+
/** 操作类型,固定为balance */
|
|
65
|
+
act: "balance";
|
|
66
|
+
/** 商户唯一标识 */
|
|
67
|
+
pid: string;
|
|
68
|
+
/** 商户密钥 */
|
|
69
|
+
key: string;
|
|
70
|
+
}
|
|
71
|
+
/**
|
|
72
|
+
* 订单查询参数
|
|
73
|
+
*/
|
|
74
|
+
export interface OrderQuery {
|
|
75
|
+
/** 操作类型,固定为order */
|
|
76
|
+
act: "order";
|
|
77
|
+
/** 商户唯一标识 */
|
|
78
|
+
pid: string;
|
|
79
|
+
/** 商户密钥 */
|
|
80
|
+
key: string;
|
|
81
|
+
/** 平台订单号,可选 */
|
|
82
|
+
trade_no?: string;
|
|
83
|
+
/** 商户订单号,可选 */
|
|
84
|
+
out_trade_no?: string;
|
|
85
|
+
}
|
|
86
|
+
/**
|
|
87
|
+
* 退款参数
|
|
88
|
+
*/
|
|
89
|
+
export interface Refund {
|
|
90
|
+
/** 操作类型,固定为refund */
|
|
91
|
+
act: "refund";
|
|
92
|
+
/** 商户唯一标识 */
|
|
93
|
+
pid: string;
|
|
94
|
+
/** 商户密钥 */
|
|
95
|
+
key: string;
|
|
96
|
+
/** 平台订单号,可选 */
|
|
97
|
+
trade_no?: string;
|
|
98
|
+
/** 商户订单号,可选 */
|
|
99
|
+
out_trade_no?: string;
|
|
100
|
+
/** 退款金额,最多保留两位小数 */
|
|
101
|
+
money: string;
|
|
102
|
+
}
|
|
103
|
+
/**
|
|
104
|
+
* 支付结果通知参数
|
|
105
|
+
*/
|
|
106
|
+
export interface Notify {
|
|
107
|
+
pid: string;
|
|
108
|
+
name: string;
|
|
109
|
+
money: string;
|
|
110
|
+
out_trade_no: string;
|
|
111
|
+
trade_no: string;
|
|
112
|
+
param?: string;
|
|
113
|
+
trade_status: string;
|
|
114
|
+
type: string;
|
|
115
|
+
sign: string;
|
|
116
|
+
sign_type: "MD5";
|
|
117
|
+
}
|
|
118
|
+
/**
|
|
119
|
+
* 页面跳转支付业务入参类型
|
|
120
|
+
*/
|
|
121
|
+
export type JumpPayInput = Omit<
|
|
122
|
+
JumpPay,
|
|
123
|
+
"pid" | "cid" | "notify_url" | "return_url" | "sign" | "sign_type"
|
|
124
|
+
>;
|
|
125
|
+
/**
|
|
126
|
+
* API接口支付业务入参类型
|
|
127
|
+
*/
|
|
128
|
+
export type ApiPayInput = Omit<
|
|
129
|
+
ApiPay,
|
|
130
|
+
"pid" | "cid" | "notify_url" | "sign" | "sign_type"
|
|
131
|
+
>;
|
|
132
|
+
/**
|
|
133
|
+
* 余额查询业务入参类型
|
|
134
|
+
*/
|
|
135
|
+
export type BalanceQueryInput = Omit<BalanceQuery, "pid" | "key" | "act">;
|
|
136
|
+
/**
|
|
137
|
+
* 订单查询业务入参类型
|
|
138
|
+
*/
|
|
139
|
+
export type OrderQueryInput = Omit<OrderQuery, "pid" | "key" | "act">;
|
|
140
|
+
/**
|
|
141
|
+
* 退款业务入参类型
|
|
142
|
+
*/
|
|
143
|
+
export type RefundInput = Omit<Refund, "pid" | "key" | "act">;
|
|
144
|
+
/**
|
|
145
|
+
* 支付结果通知验签业务入参类型
|
|
146
|
+
*/
|
|
147
|
+
export type NotifyInput = Omit<Notify, "pid" | "sign" | "sign_type">;
|
|
148
|
+
}
|
|
149
|
+
namespace Response {
|
|
150
|
+
/**
|
|
151
|
+
* API接口支付响应
|
|
152
|
+
*/
|
|
153
|
+
export interface ApiPay {
|
|
154
|
+
code: number;
|
|
155
|
+
msg: string;
|
|
156
|
+
O_id?: string;
|
|
157
|
+
trade_no?: string;
|
|
158
|
+
payurl?: string;
|
|
159
|
+
qrcode?: string;
|
|
160
|
+
img?: string;
|
|
161
|
+
}
|
|
162
|
+
/**
|
|
163
|
+
* 余额查询响应
|
|
164
|
+
*/
|
|
165
|
+
export interface BalanceQuery {
|
|
166
|
+
code: number;
|
|
167
|
+
msg: string;
|
|
168
|
+
balance?: string;
|
|
169
|
+
}
|
|
170
|
+
/**
|
|
171
|
+
* 订单查询响应
|
|
172
|
+
*/
|
|
173
|
+
export interface OrderQuery {
|
|
174
|
+
code: number;
|
|
175
|
+
msg: string;
|
|
176
|
+
trade_no?: string;
|
|
177
|
+
out_trade_no?: string;
|
|
178
|
+
type?: string;
|
|
179
|
+
pid?: string;
|
|
180
|
+
addtime?: string;
|
|
181
|
+
endtime?: string;
|
|
182
|
+
name?: string;
|
|
183
|
+
money?: string;
|
|
184
|
+
status?: number;
|
|
185
|
+
param?: string;
|
|
186
|
+
buyer?: string;
|
|
187
|
+
}
|
|
188
|
+
/**
|
|
189
|
+
* 退款响应
|
|
190
|
+
*/
|
|
191
|
+
export interface Refund {
|
|
192
|
+
code: number;
|
|
193
|
+
msg: string;
|
|
194
|
+
}
|
|
195
|
+
/**
|
|
196
|
+
* 支付结果通知响应
|
|
197
|
+
*/
|
|
198
|
+
export type Notify = "success" | string;
|
|
199
|
+
}
|
|
200
|
+
}
|
|
201
|
+
}
|
|
202
|
+
|
|
203
|
+
// 导出 SevenPay 命名空间
|
|
204
|
+
export type { SevenPay };
|
package/dist/index.cjs
ADDED
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
Object.defineProperty(exports,`__esModule`,{value:!0});var e=Object.create,t=Object.defineProperty,n=Object.getOwnPropertyDescriptor,r=Object.getOwnPropertyNames,i=Object.getPrototypeOf,a=Object.prototype.hasOwnProperty,o=(e,n)=>{for(var r in n)t(e,r,{get:n[r],enumerable:!0})},s=(e,i,o,s)=>{if(i&&typeof i==`object`||typeof i==`function`)for(var c=r(i),l=0,u=c.length,d;l<u;l++)d=c[l],!a.call(e,d)&&d!==o&&t(e,d,{get:(e=>i[e]).bind(null,d),enumerable:!(s=n(i,d))||s.enumerable});return e},c=(n,r,a)=>(a=n==null?{}:e(i(n)),s(r||!n||!n.__esModule?t(a,`default`,{value:n,enumerable:!0}):a,n));const l=c(require(`crypto-js`)),u=c(require(`@ethan-utils/axios`));var d={};o(d,{appPay:()=>k,getPayOrder:()=>N,getRefundOrder:()=>P,getWechatOpenid:()=>M,h5JumpPay:()=>E,h5Pay:()=>T,jsapiConvenientPay:()=>O,jsapiPay:()=>D,miniProgramPay:()=>A,notify:()=>x,refundOrder:()=>j,scanPay:()=>w,setLtzfApiConfig:()=>_,signParams:()=>b});let f,p;const m=[{api:`scanPay`,fields:[`mch_id`,`out_trade_no`,`total_fee`,`body`,`timestamp`,`notify_url`]},{api:`h5Pay`,fields:[`mch_id`,`out_trade_no`,`total_fee`,`body`,`timestamp`,`notify_url`]},{api:`h5JumpPay`,fields:[`mch_id`,`out_trade_no`,`total_fee`,`body`,`timestamp`,`notify_url`]},{api:`jsapiPay`,fields:[`mch_id`,`out_trade_no`,`total_fee`,`body`,`openid`,`timestamp`,`notify_url`]},{api:`jsapiConvenient`,fields:[`mch_id`,`out_trade_no`,`total_fee`,`body`,`timestamp`,`notify_url`]},{api:`appPay`,fields:[`app_id`,`mch_id`,`out_trade_no`,`total_fee`,`body`,`timestamp`,`notify_url`]},{api:`miniProgramPay`,fields:[`mch_id`,`out_trade_no`,`total_fee`,`body`,`timestamp`,`notify_url`]},{api:`refundOrder`,fields:[`mch_id`,`out_trade_no`,`out_refund_no`,`timestamp`,`refund_fee`,`notify_url`]},{api:`getWechatOpenid`,fields:[`mch_id`,`timestamp`,`callback_url`]},{api:`getPayOrder`,fields:[`mch_id`,`out_trade_no`,`timestamp`]},{api:`getRefundOrder`,fields:[`mch_id`,`out_refund_no`,`timestamp`]},{api:`notify`,fields:[`code`,`timestamp`,`mch_id`,`order_no`,`out_trade_no`,`pay_no`,`total_fee`]},{api:`refundNotify`,fields:[`code`,`timestamp`,`mch_id`,`order_no`,`out_trade_no`,`pay_no`,`refund_no`,`out_refund_no`,`pay_channel`,`refund_fee`]}];let h={};const g=`ltzf 未初始化或未配置 key,请先调用 setLtzfApiConfig`;function _(e){p={...e,log:e.log!==!1},f=(0,u.createRequest)({baseURL:e.baseURL,timeout:e.timeout});function t(e){return!e||e.length<=4?`****`:e.slice(0,2)+`*`.repeat(e.length-4)+e.slice(-2)}p.signFilter&&(h=p.signFilter,p.log&&console.warn(`【ltzf warn】已启用自定义签名字段过滤,请确保安全性和正确性!`)),p.log&&(console.log(`【ltzf】配置初始化成功:`,{baseURL:e.baseURL,key:t(e.key),notifyUrl:e.notifyUrl,refundUrl:e.refundUrl,returnUrl:e.returnUrl,developerAppid:e.developerAppid,timeout:e.timeout,signFilter:!!e.signFilter}),console.warn(`【ltzf warn】config 项(如 mch_id、notifyUrl、returnUrl 等)无需在业务函数重复传参,SDK 已自动处理,即使文档标注必填也无需重复填写。`))}function v(e,t){function n(e){if(h[e])return h[e];let t=m.find(t=>t.api===e);return t?t.fields:[]}let r=n(t),i={};for(let t of r)e[t]!==void 0&&e[t]!==null&&e[t]!==``&&(i[t]=e[t]);return i}function y(){if(!f||!p||!p.key)throw Error(g);return!0}function b(e){y();let t=Object.fromEntries(Object.entries(e).filter(([e,t])=>e!==`sign`&&t!=null&&t!==``)),n=Object.keys(t).sort(),r=n.map(e=>`${e}=${t[e]}`).join(`&`),i=`${r}&key=${p.key}`;return l.default.MD5(i).toString().toUpperCase()}const x={verifyPayParams(e){return S(e)},verifyRefundParams(e){return C(e)}};function S(e){if(y(),!e.sign)return!1;let t=v(e,`notify`),n=b(t);return n===e.sign||n===e.sign.toUpperCase()||n===e.sign.toLowerCase()}function C(e){if(y(),!e.sign)return!1;let t=v(e,`refundNotify`),n=b(t);return n===e.sign||n===e.sign.toUpperCase()||n===e.sign.toLowerCase()}async function w(e){y();let t=p.mch_id,n=e.notify_url||p.notifyUrl,r=p.developerAppid,i=Math.floor(Date.now()/1e3).toString(),a=v({...e,mch_id:t,notify_url:n,developer_appid:r,timestamp:i},`scanPay`),o=b(a),s={...e,mch_id:t,notify_url:n,developer_appid:r,timestamp:i,sign:o},c=new URLSearchParams;Object.entries(s).forEach(([e,t])=>{t!==void 0&&c.append(e,String(t))}),p.log&&(console.log(`
|
|
2
|
+
=== 扫码支付 (scanPay) 请求日志 ===`),console.log(`请求参数:`,JSON.stringify(s,null,2)),console.log(`URL编码参数:`,c.toString()));let l=await f.post(`/api/wxpay/native`,c,{headers:{"Content-Type":`application/x-www-form-urlencoded`}});return p.log&&(console.log(`响应数据:`,JSON.stringify(l,null,2)),console.log(`=== 扫码支付 (scanPay) 请求完成 ===
|
|
3
|
+
`)),l}async function T(e){y();let t=p.mch_id,n=e.notify_url||p.notifyUrl,r=p.developerAppid,i=e.return_url||p.returnUrl,a=Math.floor(Date.now()/1e3).toString(),o=v({...e,mch_id:t,notify_url:n,developer_appid:r,return_url:i,timestamp:a},`h5Pay`),s=b(o),c={...e,mch_id:t,notify_url:n,developer_appid:r,return_url:i,timestamp:a,sign:s},l=new URLSearchParams;Object.entries(c).forEach(([e,t])=>{t!==void 0&&l.append(e,String(t))}),p.log&&(console.log(`
|
|
4
|
+
=== H5支付 (h5Pay) 请求日志 ===`),console.log(`请求参数:`,JSON.stringify(c,null,2)),console.log(`URL编码参数:`,l.toString()));let u=await f.post(`/api/wxpay/h5`,l,{headers:{"Content-Type":`application/x-www-form-urlencoded`}});return p.log&&(console.log(`响应数据:`,JSON.stringify(u,null,2)),console.log(`=== H5支付 (h5Pay) 请求完成 ===
|
|
5
|
+
`)),u}async function E(e){y();let t=p.mch_id,n=e.notify_url||p.notifyUrl,r=p.developerAppid,i=e.quit_url,a=e.return_url||p.returnUrl,o=Math.floor(Date.now()/1e3).toString(),s=v({...e,mch_id:t,notify_url:n,developer_appid:r,quit_url:i,return_url:a,timestamp:o},`h5JumpPay`),c=b(s),l={...e,mch_id:t,notify_url:n,developer_appid:r,quit_url:i,return_url:a,timestamp:o,sign:c},u=new URLSearchParams;Object.entries(l).forEach(([e,t])=>{t!==void 0&&u.append(e,String(t))}),p.log&&(console.log(`
|
|
6
|
+
=== H5跳转支付 (h5JumpPay) 请求日志 ===`),console.log(`请求参数:`,JSON.stringify(l,null,2)),console.log(`URL编码参数:`,u.toString()));let d=await f.post(`/api/wxpay/jump_h5`,u,{headers:{"Content-Type":`application/x-www-form-urlencoded`}});return p.log&&(console.log(`响应数据:`,JSON.stringify(d,null,2)),console.log(`=== H5跳转支付 (h5JumpPay) 请求完成 ===
|
|
7
|
+
`)),d}async function D(e){y();let t=p.mch_id,n=e.notify_url||p.notifyUrl,r=p.developerAppid,i=e.return_url||p.returnUrl,a=Math.floor(Date.now()/1e3).toString(),o=v({...e,mch_id:t,notify_url:n,developer_appid:r,return_url:i,timestamp:a},`jsapiPay`),s=b(o),c={...e,mch_id:t,notify_url:n,developer_appid:r,return_url:i,timestamp:a,sign:s},l=new URLSearchParams;Object.entries(c).forEach(([e,t])=>{t!==void 0&&l.append(e,String(t))}),p.log&&(console.log(`JSAPI支付 (jsapiPay) 请求日志:`),console.log(JSON.stringify(c,null,2)));let u=await f.post(`/api/wxpay/jsapi`,l,{headers:{"Content-Type":`application/x-www-form-urlencoded`}});return p.log&&(console.log(`JSAPI支付 (jsapiPay) 响应数据:`),console.log(JSON.stringify(u,null,2))),u}async function O(e){y();let t=p.mch_id,n=e.notify_url||p.notifyUrl,r=p.developerAppid,i=e.return_url||p.returnUrl,a=Math.floor(Date.now()/1e3).toString(),o=v({...e,mch_id:t,notify_url:n,developer_appid:r,return_url:i,timestamp:a},`jsapiConvenient`),s=b(o),c={...e,mch_id:t,notify_url:n,developer_appid:r,return_url:i,timestamp:a,sign:s},l=new URLSearchParams;Object.entries(c).forEach(([e,t])=>{t!==void 0&&l.append(e,String(t))}),p.log&&(console.log(`公众号支付便捷版 (jsapiConvenientPay) 请求日志:`),console.log(JSON.stringify(c,null,2)));let u=await f.post(`/api/wxpay/jsapi_convenient`,l,{headers:{"Content-Type":`application/x-www-form-urlencoded`}});return p.log&&(console.log(`公众号支付便捷版 (jsapiConvenientPay) 响应数据:`),console.log(JSON.stringify(u,null,2))),u}async function k(e){y();let t=e.notify_url||p.notifyUrl,n=p.developerAppid,r=p.mch_id,i=Math.floor(Date.now()/1e3).toString(),a=v({...e,notify_url:t,developer_appid:n,mch_id:r,timestamp:i},`appPay`),o=b(a),s={...e,notify_url:t,developer_appid:n,mch_id:r,timestamp:i,sign:o},c=new URLSearchParams;Object.entries(s).forEach(([e,t])=>{t!==void 0&&c.append(e,String(t))}),p.log&&(console.log(`APP支付 (appPay) 请求日志:`),console.log(JSON.stringify(s,null,2)));let l=await f.post(`/api/wxpay/app`,c,{headers:{"Content-Type":`application/x-www-form-urlencoded`}});return p.log&&(console.log(`APP支付 (appPay) 响应数据:`),console.log(JSON.stringify(l,null,2))),l}async function A(e){y();let t=p.mch_id,n=e.notify_url||p.notifyUrl,r=p.developerAppid,i=Math.floor(Date.now()/1e3).toString(),a=v({...e,mch_id:t,notify_url:n,developer_appid:r,timestamp:i},`miniProgramPay`),o=b(a),s={...e,mch_id:t,notify_url:n,developer_appid:r,timestamp:i,sign:o},c=new URLSearchParams;Object.entries(s).forEach(([e,t])=>{t!==void 0&&c.append(e,String(t))}),p.log&&(console.log(`小程序支付 (miniProgramPay) 请求日志:`),console.log(JSON.stringify(s,null,2)));let l=await f.post(`/api/wxpay/mini`,c,{headers:{"Content-Type":`application/x-www-form-urlencoded`}});return p.log&&(console.log(`小程序支付 (miniProgramPay) 响应数据:`),console.log(JSON.stringify(l,null,2))),l}async function j(e){y();let t=p.mch_id,n=e.notify_url||p.refundUrl,r=Math.floor(Date.now()/1e3).toString(),i=v({...e,mch_id:t,notify_url:n,timestamp:r},`refundOrder`),a=b(i),o={...e,mch_id:t,notify_url:n,timestamp:r,sign:a},s=new URLSearchParams;Object.entries(o).forEach(([e,t])=>{t!==void 0&&s.append(e,String(t))}),p.log&&(console.log(`订单退款 (refundOrder) 请求日志:`),console.log(JSON.stringify(o,null,2)));let c=await f.post(`/api/wxpay/refund_order`,s,{headers:{"Content-Type":`application/x-www-form-urlencoded`}});return p.log&&(console.log(`订单退款 (refundOrder) 响应数据:`),console.log(JSON.stringify(c,null,2))),c}async function M(e){y();let t=p.mch_id,n=Math.floor(Date.now()/1e3).toString(),r=v({...e,mch_id:t,timestamp:n},`getWechatOpenid`),i=b(r),a={...e,mch_id:t,timestamp:n,sign:i},o=new URLSearchParams;Object.entries(a).forEach(([e,t])=>{t!==void 0&&o.append(e,String(t))}),p.log&&(console.log(`获取微信Openid (getWechatOpenid) 请求日志:`),console.log(JSON.stringify(a,null,2)));let s=await f.post(`/api/wxpay/get_openid`,o,{headers:{"Content-Type":`application/x-www-form-urlencoded`}});return p.log&&(console.log(`获取微信Openid (getWechatOpenid) 响应数据:`),console.log(JSON.stringify(s,null,2))),s}async function N(e){y();let t=p.mch_id,n=Math.floor(Date.now()/1e3).toString(),r=v({...e,mch_id:t,timestamp:n},`getPayOrder`),i=b(r),a={...e,mch_id:t,timestamp:n,sign:i},o=new URLSearchParams;Object.entries(a).forEach(([e,t])=>{t!==void 0&&o.append(e,String(t))}),p.log&&(console.log(`查询订单 (getPayOrder) 请求日志:`),console.log(JSON.stringify(a,null,2)));let s=await f.post(`/api/wxpay/get_pay_order`,o,{headers:{"Content-Type":`application/x-www-form-urlencoded`}});return p.log&&(console.log(`查询订单 (getPayOrder) 响应数据:`),console.log(JSON.stringify(s,null,2))),s}async function P(e){y();let t=p.mch_id,n=Math.floor(Date.now()/1e3).toString(),r=v({...e,mch_id:t,timestamp:n},`getRefundOrder`),i=b(r),a={...e,mch_id:t,timestamp:n,sign:i},o=new URLSearchParams;Object.entries(a).forEach(([e,t])=>{t!==void 0&&o.append(e,String(t))}),p.log&&(console.log(`查询退款结果 (getRefundOrder) 请求日志:`),console.log(JSON.stringify(a,null,2)));let s=await f.post(`/api/wxpay/get_refund_order`,o,{headers:{"Content-Type":`application/x-www-form-urlencoded`}});return p.log&&(console.log(`查询退款结果 (getRefundOrder) 响应数据:`),console.log(JSON.stringify(s,null,2))),s}var F={};o(F,{apiPay:()=>W,balanceQuery:()=>G,jumpPay:()=>U,notify:()=>J,orderQuery:()=>K,refund:()=>q,setSevenPayApiConfig:()=>z});let I,L;const R=`7pay 未初始化或未配置 key/pid,请先调用 setSevenPayApiConfig`;function z(e){let t=e.baseURL;L={...e,baseURL:t,notify_url:e.notify_url,return_url:e.return_url,log:e.log!==!1},I=(0,u.createRequest)({baseURL:t,timeout:e.timeout});function n(e){return!e||e.length<=4?`****`:e.slice(0,2)+`*`.repeat(e.length-4)+e.slice(-2)}L.log&&(console.log(`【7pay】配置初始化成功:`,{baseURL:t,key:n(e.key),pid:e.pid,timeout:e.timeout,notify_url:e.notify_url,return_url:e.return_url}),console.warn(`【7pay warn】config 项(如 pid、cid、notify_url、return_url 等)无需在业务函数重复传参,SDK 已自动处理,即使文档标注必填也无需重复填写。`))}function B(){return!(!I||!L||!L.key||!L.pid)}function V(e){return Object.fromEntries(Object.entries(e).filter(([e,t])=>e!==`sign`&&e!==`sign_type`&&t!=null&&t!==``).sort(([e],[t])=>e.localeCompare(t)))}function H(e,t){let n=V(e),r=Object.entries(n).map(([e,t])=>`${e}=${t}`).join(`&`),i=r+t;return l.default.MD5(i).toString(l.default.enc.Hex).toLowerCase()}function U(e){if(!B())throw Error(R);let t={...e,pid:L.pid,cid:L.cid,notify_url:L.notify_url,return_url:L.return_url,sign_type:`MD5`,sign:``};t.sign=H(V({...t,sign:void 0,sign_type:void 0}),L.key);let n=L.baseURL.endsWith(`/`)?L.baseURL+`submit.php`:L.baseURL+`/submit.php`,r=Object.entries(t).map(([e,t])=>`${encodeURIComponent(e)}=${encodeURIComponent(String(t))}`).join(`&`);return`${n}?${r}`}async function W(e){if(!B())throw Error(R);let t={...e,pid:L.pid,cid:L.cid,notify_url:L.notify_url,sign_type:`MD5`,sign:``};t.sign=H(V({...t,sign:void 0,sign_type:void 0}),L.key);let n=new URLSearchParams;Object.entries(t).forEach(([e,t])=>n.append(e,String(t)));let r=await I.post(`/mapi.php`,n,{headers:{"Content-Type":`application/x-www-form-urlencoded`}});return r}async function G(){if(!B())throw Error(R);let e={act:`balance`,pid:L.pid,key:L.key},t=await I.get(`/api.php`,{params:e});return t}async function K(e){if(!B())throw Error(R);let t={act:`order`,pid:L.pid,key:L.key,...e},n=await I.get(`/api.php`,{params:t});return n}async function q(e){if(!B())throw Error(R);let t={act:`refund`,pid:L.pid,key:L.key,...e},n=new URLSearchParams;Object.entries(t).forEach(([e,t])=>{t!==void 0&&n.append(e,String(t))});let r=await I.post(`/api.php?act=refund`,n,{headers:{"Content-Type":`application/x-www-form-urlencoded`}});return r}const J={verifyPayParams(e){return Y(e)}};function Y(e){if(!B())throw Error(R);let t=V(e),n=H(t,L.key);return n===e.sign}function X(){console.log("你好,`@ethan-utils/pay-gateway` 支付网关!")}var Z={helloPayGateway:X,ltzf:d,sevenPay:F};exports.default=Z,exports.helloPayGateway=X,Object.defineProperty(exports,`ltzf`,{enumerable:!0,get:function(){return d}}),Object.defineProperty(exports,`sevenPay`,{enumerable:!0,get:function(){return F}});
|