Skip to content

Commit 9fe9d5a

Browse files
committed
fix(pay-gateway): 修复蓝兔支付不正确返回类型
1 parent abc4ffe commit 9fe9d5a

File tree

8 files changed

+107
-72
lines changed

8 files changed

+107
-72
lines changed

.changeset/rude-paws-cross.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
"@ethan-utils/pay-gateway": patch
3+
---
4+
5+
修复蓝兔支付不正确返回类型

node-pkgs/pay-gateway/7pay/index.ts

Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -184,7 +184,7 @@ export async function apiPay(
184184
Object.entries(fullParams).forEach(([k, v]) =>
185185
urlParams.append(k, String(v)),
186186
);
187-
const res = await sevenPayApi.raw.post<SevenPay.Response.ApiPay>(
187+
const res = await sevenPayApi.post<SevenPay.Response.ApiPay>(
188188
"/mapi.php",
189189
urlParams,
190190
{
@@ -205,7 +205,7 @@ export async function balanceQuery(): Promise<SevenPay.Response.BalanceQuery> {
205205
pid: sevenPayConfig.pid,
206206
key: sevenPayConfig.key,
207207
};
208-
const res = await sevenPayApi.raw.get<SevenPay.Response.BalanceQuery>(
208+
const res = await sevenPayApi.get<SevenPay.Response.BalanceQuery>(
209209
"/api.php",
210210
{ params: query },
211211
);
@@ -227,10 +227,9 @@ export async function orderQuery(
227227
key: sevenPayConfig.key,
228228
...params,
229229
};
230-
const res = await sevenPayApi.raw.get<SevenPay.Response.OrderQuery>(
231-
"/api.php",
232-
{ params: query },
233-
);
230+
const res = await sevenPayApi.get<SevenPay.Response.OrderQuery>("/api.php", {
231+
params: query,
232+
});
234233
return res;
235234
}
236235

@@ -253,7 +252,7 @@ export async function refund(
253252
Object.entries(allParams).forEach(([k, v]) => {
254253
if (v !== undefined) urlParams.append(k, String(v));
255254
});
256-
const res = await sevenPayApi.raw.post<SevenPay.Response.Refund>(
255+
const res = await sevenPayApi.post<SevenPay.Response.Refund>(
257256
"/api.php?act=refund",
258257
urlParams,
259258
{

node-pkgs/pay-gateway/README.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,8 @@
66

77
### 7Pay 支付
88

9+
> ⚠️ **警告**:7Pay 支付功能封装未经过充分测试,请勿在生产环境中轻易使用。建议在正式使用前进行充分的测试验证。
10+
911
- `setSevenPayApiConfig(config)`:初始化 7Pay 配置
1012
- `jumpPay(params)`:生成跳转支付 URL
1113
- `apiPay(params)`:API 接口支付(POST)

node-pkgs/pay-gateway/USAGE.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,8 @@
1010

1111
## 7Pay 用法
1212

13+
> ⚠️ **重要警告**:7Pay 支付功能封装未经过充分测试,请勿在生产环境中轻易使用。建议在正式使用前进行充分的测试验证,确保功能稳定性和安全性。
14+
1315
### 1. 初始化配置
1416

1517
```ts

node-pkgs/pay-gateway/ltzf/index.ts

Lines changed: 54 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -382,7 +382,9 @@ function verifyRefundNotifyParams(params: LTZF.Params.RefundNotify): boolean {
382382
* @param {LTZF.Params.ScanPayInput} params - 扫码支付参数
383383
* @returns {Promise<LTZF.Response.ScanPay>} 支付结果
384384
*/
385-
export async function scanPay(params: LTZF.Params.ScanPayInput) {
385+
export async function scanPay(
386+
params: LTZF.Params.ScanPayInput,
387+
): Promise<LTZF.Response.ScanPay> {
386388
ensureLtzfConfig();
387389
const mch_id = ltzfConfig.mch_id;
388390
const notify_url = params.notify_url || ltzfConfig.notifyUrl;
@@ -413,7 +415,7 @@ export async function scanPay(params: LTZF.Params.ScanPayInput) {
413415
console.log("URL编码参数:", urlParams.toString());
414416
}
415417

416-
const response = await ltzfApi.raw.post<LTZF.Response.ScanPay>(
418+
const response = await ltzfApi.post<LTZF.Response.ScanPay>(
417419
"/api/wxpay/native",
418420
urlParams,
419421
{
@@ -423,7 +425,7 @@ export async function scanPay(params: LTZF.Params.ScanPayInput) {
423425

424426
// 响应日志输出
425427
if (ltzfConfig.log) {
426-
console.log("响应数据:", JSON.stringify(response.data, null, 2));
428+
console.log("响应数据:", JSON.stringify(response, null, 2));
427429
console.log("=== 扫码支付 (scanPay) 请求完成 ===\n");
428430
}
429431

@@ -435,7 +437,9 @@ export async function scanPay(params: LTZF.Params.ScanPayInput) {
435437
* @param {LTZF.Params.H5PayInput} params - H5支付参数
436438
* @returns {Promise<LTZF.Response.H5Pay>} 支付结果
437439
*/
438-
export async function h5Pay(params: LTZF.Params.H5PayInput) {
440+
export async function h5Pay(
441+
params: LTZF.Params.H5PayInput,
442+
): Promise<LTZF.Response.H5Pay> {
439443
ensureLtzfConfig();
440444
const mch_id = ltzfConfig.mch_id;
441445
const notify_url = params.notify_url || ltzfConfig.notifyUrl;
@@ -468,7 +472,7 @@ export async function h5Pay(params: LTZF.Params.H5PayInput) {
468472
console.log("URL编码参数:", urlParams.toString());
469473
}
470474

471-
const response = await ltzfApi.raw.post<LTZF.Response.H5Pay>(
475+
const response = await ltzfApi.post<LTZF.Response.H5Pay>(
472476
"/api/wxpay/wap",
473477
urlParams,
474478
{
@@ -478,7 +482,7 @@ export async function h5Pay(params: LTZF.Params.H5PayInput) {
478482

479483
// 响应日志输出
480484
if (ltzfConfig.log) {
481-
console.log("响应数据:", JSON.stringify(response.data, null, 2));
485+
console.log("响应数据:", JSON.stringify(response, null, 2));
482486
console.log("=== H5支付 (h5Pay) 请求完成 ===\n");
483487
}
484488

@@ -490,7 +494,9 @@ export async function h5Pay(params: LTZF.Params.H5PayInput) {
490494
* @param {LTZF.Params.H5JumpPayInput} params - H5跳转支付参数
491495
* @returns {Promise<LTZF.Response.H5JumpPay>} 支付结果
492496
*/
493-
export async function h5JumpPay(params: LTZF.Params.H5JumpPayInput) {
497+
export async function h5JumpPay(
498+
params: LTZF.Params.H5JumpPayInput,
499+
): Promise<LTZF.Response.H5JumpPay> {
494500
ensureLtzfConfig();
495501
const mch_id = ltzfConfig.mch_id;
496502
const notify_url = params.notify_url || ltzfConfig.notifyUrl;
@@ -533,8 +539,8 @@ export async function h5JumpPay(params: LTZF.Params.H5JumpPayInput) {
533539
console.log("URL编码参数:", urlParams.toString());
534540
}
535541

536-
const response = await ltzfApi.raw.post<LTZF.Response.H5JumpPay>(
537-
"/api/wxpay/jump_h5",
542+
const response = await ltzfApi.post<LTZF.Response.H5JumpPay>(
543+
"/api/wxpay/wap",
538544
urlParams,
539545
{
540546
headers: { "Content-Type": "application/x-www-form-urlencoded" },
@@ -543,7 +549,7 @@ export async function h5JumpPay(params: LTZF.Params.H5JumpPayInput) {
543549

544550
// 响应日志输出
545551
if (ltzfConfig.log) {
546-
console.log("响应数据:", JSON.stringify(response.data, null, 2));
552+
console.log("响应数据:", JSON.stringify(response, null, 2));
547553
console.log("=== H5跳转支付 (h5JumpPay) 请求完成 ===\n");
548554
}
549555

@@ -555,7 +561,9 @@ export async function h5JumpPay(params: LTZF.Params.H5JumpPayInput) {
555561
* @param {LTZF.Params.JsapiPayInput} params - 公众号支付参数
556562
* @returns {Promise<LTZF.Response.JsapiPay>} 支付结果
557563
*/
558-
export async function jsapiPay(params: LTZF.Params.JsapiPayInput) {
564+
export async function jsapiPay(
565+
params: LTZF.Params.JsapiPayInput,
566+
): Promise<LTZF.Response.JsapiPay> {
559567
ensureLtzfConfig();
560568
const mch_id = ltzfConfig.mch_id;
561569
const notify_url = params.notify_url || ltzfConfig.notifyUrl;
@@ -593,7 +601,7 @@ export async function jsapiPay(params: LTZF.Params.JsapiPayInput) {
593601
console.log(JSON.stringify(reqParams, null, 2));
594602
}
595603

596-
const response = await ltzfApi.raw.post<LTZF.Response.JsapiPay>(
604+
const response = await ltzfApi.post<LTZF.Response.JsapiPay>(
597605
"/api/wxpay/jsapi",
598606
urlParams,
599607
{
@@ -603,7 +611,7 @@ export async function jsapiPay(params: LTZF.Params.JsapiPayInput) {
603611

604612
if (ltzfConfig.log) {
605613
console.log("JSAPI支付 (jsapiPay) 响应数据:");
606-
console.log(JSON.stringify(response.data, null, 2));
614+
console.log(JSON.stringify(response, null, 2));
607615
}
608616

609617
return response;
@@ -616,7 +624,7 @@ export async function jsapiPay(params: LTZF.Params.JsapiPayInput) {
616624
*/
617625
export async function jsapiConvenientPay(
618626
params: LTZF.Params.JsapiConvenientInput,
619-
) {
627+
): Promise<LTZF.Response.JsapiConvenient> {
620628
ensureLtzfConfig();
621629
const mch_id = ltzfConfig.mch_id;
622630
const notify_url = params.notify_url || ltzfConfig.notifyUrl;
@@ -654,7 +662,7 @@ export async function jsapiConvenientPay(
654662
console.log(JSON.stringify(reqParams, null, 2));
655663
}
656664

657-
const response = await ltzfApi.raw.post<LTZF.Response.JsapiConvenient>(
665+
const response = await ltzfApi.post<LTZF.Response.JsapiConvenient>(
658666
"/api/wxpay/jsapi_convenient",
659667
urlParams,
660668
{
@@ -664,7 +672,7 @@ export async function jsapiConvenientPay(
664672

665673
if (ltzfConfig.log) {
666674
console.log("公众号支付便捷版 (jsapiConvenientPay) 响应数据:");
667-
console.log(JSON.stringify(response.data, null, 2));
675+
console.log(JSON.stringify(response, null, 2));
668676
}
669677

670678
return response;
@@ -675,7 +683,9 @@ export async function jsapiConvenientPay(
675683
* @param {LTZF.Params.AppPayInput} params - APP支付参数
676684
* @returns {Promise<LTZF.Response.AppPay>} 支付结果
677685
*/
678-
export async function appPay(params: LTZF.Params.AppPayInput) {
686+
export async function appPay(
687+
params: LTZF.Params.AppPayInput,
688+
): Promise<LTZF.Response.AppPay> {
679689
ensureLtzfConfig();
680690
const notify_url = params.notify_url || ltzfConfig.notifyUrl;
681691
const developer_appid = ltzfConfig.developerAppid;
@@ -710,7 +720,7 @@ export async function appPay(params: LTZF.Params.AppPayInput) {
710720
console.log(JSON.stringify(reqParams, null, 2));
711721
}
712722

713-
const response = await ltzfApi.raw.post<LTZF.Response.AppPay>(
723+
const response = await ltzfApi.post<LTZF.Response.AppPay>(
714724
"/api/wxpay/app",
715725
urlParams,
716726
{
@@ -720,7 +730,7 @@ export async function appPay(params: LTZF.Params.AppPayInput) {
720730

721731
if (ltzfConfig.log) {
722732
console.log("APP支付 (appPay) 响应数据:");
723-
console.log(JSON.stringify(response.data, null, 2));
733+
console.log(JSON.stringify(response, null, 2));
724734
}
725735

726736
return response;
@@ -731,7 +741,9 @@ export async function appPay(params: LTZF.Params.AppPayInput) {
731741
* @param {LTZF.Params.MiniProgramPayInput} params - 小程序支付参数
732742
* @returns {Promise<LTZF.Response.MiniProgramPay>} 支付结果
733743
*/
734-
export async function miniProgramPay(params: LTZF.Params.MiniProgramPayInput) {
744+
export async function miniProgramPay(
745+
params: LTZF.Params.MiniProgramPayInput,
746+
): Promise<LTZF.Response.MiniProgramPay> {
735747
ensureLtzfConfig();
736748
const mch_id = ltzfConfig.mch_id;
737749
const notify_url = params.notify_url || ltzfConfig.notifyUrl;
@@ -766,8 +778,8 @@ export async function miniProgramPay(params: LTZF.Params.MiniProgramPayInput) {
766778
console.log(JSON.stringify(reqParams, null, 2));
767779
}
768780

769-
const response = await ltzfApi.raw.post<LTZF.Response.MiniProgramPay>(
770-
"/api/wxpay/miniprogram",
781+
const response = await ltzfApi.post<LTZF.Response.MiniProgramPay>(
782+
"/api/wxpay/mini",
771783
urlParams,
772784
{
773785
headers: { "Content-Type": "application/x-www-form-urlencoded" },
@@ -776,7 +788,7 @@ export async function miniProgramPay(params: LTZF.Params.MiniProgramPayInput) {
776788

777789
if (ltzfConfig.log) {
778790
console.log("小程序支付 (miniProgramPay) 响应数据:");
779-
console.log(JSON.stringify(response.data, null, 2));
791+
console.log(JSON.stringify(response, null, 2));
780792
}
781793

782794
return response;
@@ -787,7 +799,9 @@ export async function miniProgramPay(params: LTZF.Params.MiniProgramPayInput) {
787799
* @param {LTZF.Params.RefundOrderInput} params - 退款参数
788800
* @returns {Promise<LTZF.Response.RefundOrder>} 退款结果
789801
*/
790-
export async function refundOrder(params: LTZF.Params.RefundOrderInput) {
802+
export async function refundOrder(
803+
params: LTZF.Params.RefundOrderInput,
804+
): Promise<LTZF.Response.RefundOrder> {
791805
ensureLtzfConfig();
792806
const mch_id = ltzfConfig.mch_id;
793807
const notify_url = params.notify_url || ltzfConfig.refundUrl;
@@ -819,7 +833,7 @@ export async function refundOrder(params: LTZF.Params.RefundOrderInput) {
819833
console.log(JSON.stringify(reqParams, null, 2));
820834
}
821835

822-
const response = await ltzfApi.raw.post<LTZF.Response.RefundOrder>(
836+
const response = await ltzfApi.post<LTZF.Response.RefundOrder>(
823837
"/api/wxpay/refund_order",
824838
urlParams,
825839
{
@@ -829,7 +843,7 @@ export async function refundOrder(params: LTZF.Params.RefundOrderInput) {
829843

830844
if (ltzfConfig.log) {
831845
console.log("订单退款 (refundOrder) 响应数据:");
832-
console.log(JSON.stringify(response.data, null, 2));
846+
console.log(JSON.stringify(response, null, 2));
833847
}
834848

835849
return response;
@@ -842,7 +856,7 @@ export async function refundOrder(params: LTZF.Params.RefundOrderInput) {
842856
*/
843857
export async function getWechatOpenid(
844858
params: LTZF.Params.GetWechatOpenidInput,
845-
) {
859+
): Promise<LTZF.Response.GetWechatOpenid> {
846860
ensureLtzfConfig();
847861
const mch_id = ltzfConfig.mch_id;
848862
const timestamp = Math.floor(Date.now() / 1000).toString();
@@ -867,8 +881,8 @@ export async function getWechatOpenid(
867881
console.log(JSON.stringify(reqParams, null, 2));
868882
}
869883

870-
const response = await ltzfApi.raw.post<LTZF.Response.GetWechatOpenid>(
871-
"/api/wxpay/get_wechat_openid",
884+
const response = await ltzfApi.post<LTZF.Response.GetWechatOpenid>(
885+
"/api/wxpay/get_openid",
872886
urlParams,
873887
{
874888
headers: { "Content-Type": "application/x-www-form-urlencoded" },
@@ -877,7 +891,7 @@ export async function getWechatOpenid(
877891

878892
if (ltzfConfig.log) {
879893
console.log("获取微信Openid (getWechatOpenid) 响应数据:");
880-
console.log(JSON.stringify(response.data, null, 2));
894+
console.log(JSON.stringify(response, null, 2));
881895
}
882896

883897
return response;
@@ -888,7 +902,9 @@ export async function getWechatOpenid(
888902
* @param {LTZF.Params.GetPayOrderInput} params - 查询订单参数
889903
* @returns {Promise<LTZF.Response.GetPayOrder>} 订单信息
890904
*/
891-
export async function getPayOrder(params: LTZF.Params.GetPayOrderInput) {
905+
export async function getPayOrder(
906+
params: LTZF.Params.GetPayOrderInput,
907+
): Promise<LTZF.Response.GetPayOrder> {
892908
ensureLtzfConfig();
893909
const mch_id = ltzfConfig.mch_id;
894910
const timestamp = Math.floor(Date.now() / 1000).toString();
@@ -913,7 +929,7 @@ export async function getPayOrder(params: LTZF.Params.GetPayOrderInput) {
913929
console.log(JSON.stringify(reqParams, null, 2));
914930
}
915931

916-
const response = await ltzfApi.raw.post<LTZF.Response.GetPayOrder>(
932+
const response = await ltzfApi.post<LTZF.Response.GetPayOrder>(
917933
"/api/wxpay/get_pay_order",
918934
urlParams,
919935
{
@@ -923,7 +939,7 @@ export async function getPayOrder(params: LTZF.Params.GetPayOrderInput) {
923939

924940
if (ltzfConfig.log) {
925941
console.log("查询订单 (getPayOrder) 响应数据:");
926-
console.log(JSON.stringify(response.data, null, 2));
942+
console.log(JSON.stringify(response, null, 2));
927943
}
928944

929945
return response;
@@ -934,7 +950,9 @@ export async function getPayOrder(params: LTZF.Params.GetPayOrderInput) {
934950
* @param {LTZF.Params.GetRefundOrderInput} params - 查询退款参数
935951
* @returns {Promise<LTZF.Response.GetRefundOrder>} 退款信息
936952
*/
937-
export async function getRefundOrder(params: LTZF.Params.GetRefundOrderInput) {
953+
export async function getRefundOrder(
954+
params: LTZF.Params.GetRefundOrderInput,
955+
): Promise<LTZF.Response.GetRefundOrder> {
938956
ensureLtzfConfig();
939957
const mch_id = ltzfConfig.mch_id;
940958
const timestamp = Math.floor(Date.now() / 1000).toString();
@@ -959,7 +977,7 @@ export async function getRefundOrder(params: LTZF.Params.GetRefundOrderInput) {
959977
console.log(JSON.stringify(reqParams, null, 2));
960978
}
961979

962-
const response = await ltzfApi.raw.post<LTZF.Response.GetRefundOrder>(
980+
const response = await ltzfApi.post<LTZF.Response.GetRefundOrder>(
963981
"/api/wxpay/get_refund_order",
964982
urlParams,
965983
{
@@ -969,7 +987,7 @@ export async function getRefundOrder(params: LTZF.Params.GetRefundOrderInput) {
969987

970988
if (ltzfConfig.log) {
971989
console.log("查询退款结果 (getRefundOrder) 响应数据:");
972-
console.log(JSON.stringify(response.data, null, 2));
990+
console.log(JSON.stringify(response, null, 2));
973991
}
974992

975993
return response;

0 commit comments

Comments
 (0)