From a849c761c7b982ac79b206268403def83bcdf16a Mon Sep 17 00:00:00 2001 From: yansongda Date: Sun, 31 Dec 2023 18:00:00 +0800 Subject: [PATCH] =?UTF-8?q?change(internal):=20=E6=8C=89=E5=9C=BA=E6=99=AF?= =?UTF-8?q?=E5=AF=B9=E5=BE=AE=E4=BF=A1=E6=8F=92=E4=BB=B6=E8=BF=9B=E8=A1=8C?= =?UTF-8?q?=E5=88=86=E7=B1=BB=EF=BC=8C=E4=BC=98=E5=8C=96=E7=9B=B8=E5=85=B3?= =?UTF-8?q?=E4=BB=A3=E7=A0=81=20(#909)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .php-cs-fixer.php | 1 + CHANGELOG.md | 18 +- composer.json | 4 +- src/Contract/ProviderInterface.php | 13 +- src/Direction/CollectionDirection.php | 4 +- src/Direction/OriginResponseDirection.php | 6 +- src/Event.php | 2 +- src/Exception/ContainerException.php | 2 +- src/Exception/ContainerNotFoundException.php | 2 +- src/Exception/DecryptException.php | 19 ++ src/Exception/Exception.php | 41 ++-- src/Exception/InvalidConfigException.php | 2 +- src/Exception/InvalidParamsException.php | 2 +- src/Exception/InvalidResponseException.php | 2 +- src/Exception/InvalidSignException.php | 2 +- src/Exception/ServiceNotFoundException.php | 2 +- src/Functions.php | 213 ++++++++++++----- src/Logger.php | 2 +- src/Pay.php | 12 +- ...ugin.php => AddPayloadSignaturePlugin.php} | 8 +- src/Plugin/Alipay/CallbackPlugin.php | 14 +- src/Plugin/Alipay/FormatBizContentPlugin.php | 31 --- .../Alipay/FormatPayloadBizContentPlugin.php | 32 +++ .../Alipay/Pay/Agreement/SignPlugin.php | 4 +- .../Alipay/Pay/{Wap => H5}/ClosePlugin.php | 2 +- .../Alipay/Pay/{Wap => H5}/PayPlugin.php | 2 +- .../Pay/{Wap => H5}/QueryBillUrlPlugin.php | 2 +- .../Alipay/Pay/{Wap => H5}/QueryPlugin.php | 2 +- .../Pay/{Wap => H5}/QueryRefundPlugin.php | 2 +- .../Alipay/Pay/{Wap => H5}/RefundPlugin.php | 2 +- src/Plugin/Alipay/StartPlugin.php | 2 +- src/Plugin/Alipay/VerifySignaturePlugin.php | 7 +- src/Plugin/ParserPlugin.php | 2 +- src/Plugin/Unipay/CallbackPlugin.php | 2 +- src/Plugin/Wechat/AddPayloadBodyPlugin.php | 42 ++++ .../Wechat/AddPayloadSignaturePlugin.php | 99 ++++++++ src/Plugin/Wechat/AddRadarPlugin.php | 83 +++++++ src/Plugin/Wechat/CallbackPlugin.php | 30 ++- .../Wechat/Ecommerce/Refund/ApplyPlugin.php | 55 ----- .../Wechat/Ecommerce/Refund/QueryPlugin.php | 60 ----- .../Refund/QueryReturnAdvancePlugin.php | 56 ----- .../Ecommerce/Refund/ReturnAdvancePlugin.php | 56 ----- .../Extend/Complaints/CompletePlugin.php | 52 ++++ .../Complaints/DeleteCallbackPlugin.php | 32 +++ .../Extend/Complaints/QueryCallbackPlugin.php | 32 +++ .../Extend/Complaints/QueryDetailPlugin.php | 43 ++++ .../Extend/Complaints/QueryImagePlugin.php | 43 ++++ .../Complaints/QueryNegotiationPlugin.php | 54 +++++ .../Wechat/Extend/Complaints/QueryPlugin.php | 45 ++++ .../Extend/Complaints/ResponsePlugin.php | 52 ++++ .../Extend/Complaints/SetCallbackPlugin.php | 35 +++ .../Complaints/UpdateCallbackPlugin.php | 35 +++ .../Extend/Complaints/UpdateRefundPlugin.php | 43 ++++ .../ProfitSharing/AddReceiverPlugin.php | 132 +++++++++++ .../Extend/ProfitSharing/CreatePlugin.php | 134 +++++++++++ .../ProfitSharing/DeleteReceiverPlugin.php | 84 +++++++ .../ProfitSharing/DownloadBillPlugin.php | 43 ++++ .../ProfitSharing/QueryAmountsPlugin.php | 43 ++++ .../QueryMerchantConfigsPlugin.php | 50 ++++ .../Extend/ProfitSharing/QueryPlugin.php | 53 +++++ .../ProfitSharing/QueryReturnPlugin.php | 53 +++++ .../Extend/ProfitSharing/ReturnPlugin.php | 75 ++++++ .../Extend/ProfitSharing/UnfreezePlugin.php | 73 ++++++ .../Wechat/Fund/Balance/QueryDayEndPlugin.php | 36 --- .../Wechat/Fund/Balance/QueryPlugin.php | 35 --- .../Fund/Profitsharing/AddReceiverPlugin.php | 83 ------- .../Fund/Profitsharing/CreatePlugin.php | 89 ------- .../Profitsharing/DeleteReceiverPlugin.php | 44 ---- .../Fund/Profitsharing/DownloadBillPlugin.php | 43 ---- .../Fund/Profitsharing/QueryAmountsPlugin.php | 42 ---- .../QueryMerchantConfigsPlugin.php | 49 ---- .../Wechat/Fund/Profitsharing/QueryPlugin.php | 56 ----- .../Fund/Profitsharing/QueryReturnPlugin.php | 56 ----- .../Fund/Profitsharing/ReturnPlugin.php | 40 ---- .../Fund/Profitsharing/UnfreezePlugin.php | 40 ---- .../Fund/Transfer/CreateBillReceiptPlugin.php | 33 --- .../Transfer/CreateDetailReceiptPlugin.php | 33 --- .../Wechat/Fund/Transfer/CreatePlugin.php | 99 -------- .../Fund/Transfer/DownloadReceiptPlugin.php | 43 ---- .../Transfer/QueryBatchDetailIdPlugin.php | 60 ----- .../Fund/Transfer/QueryBatchIdPlugin.php | 64 ----- .../Fund/Transfer/QueryBillReceiptPlugin.php | 40 ---- .../Transfer/QueryDetailReceiptPlugin.php | 40 ---- .../Transfer/QueryOutBatchDetailNoPlugin.php | 60 ----- .../Fund/Transfer/QueryOutBatchNoPlugin.php | 64 ----- src/Plugin/Wechat/GeneralPlugin.php | 97 -------- src/Plugin/Wechat/GeneralV2Plugin.php | 42 ---- .../Wechat/Marketing/Coupon/CreatePlugin.php | 34 ++- .../Wechat/Marketing/Coupon/PausePlugin.php | 46 ++-- .../Marketing/Coupon/QueryCallbackPlugin.php | 44 ++++ .../Coupon/QueryCouponDetailPlugin.php | 48 ++-- .../Coupon/QueryStockDetailPlugin.php | 45 ++-- .../Coupon/QueryStockItemsPlugin.php | 60 ++--- .../Coupon/QueryStockMerchantsPlugin.php | 60 ++--- .../Coupon/QueryStockRefundFlowPlugin.php | 41 ++-- .../Coupon/QueryStockUseFlowPlugin.php | 41 ++-- .../Marketing/Coupon/QueryStocksPlugin.php | 53 +++-- .../Coupon/QueryUserCouponsPlugin.php | 63 ++--- .../Wechat/Marketing/Coupon/RestartPlugin.php | 45 ++-- .../Wechat/Marketing/Coupon/SendPlugin.php | 54 +++-- .../Marketing/Coupon/SetCallbackPlugin.php | 36 ++- .../Wechat/Marketing/Coupon/StartPlugin.php | 43 ++-- .../ECommerceBalance/QueryDayEndPlugin.php | 66 ++++++ .../ECommerceBalance/QueryPlugin.php | 53 +++++ .../Marketing/ECommerceRefund/ApplyPlugin.php | 60 +++++ .../ECommerceRefund/QueryByWxPlugin.php | 55 +++++ .../Marketing/ECommerceRefund/QueryPlugin.php | 55 +++++ .../QueryReturnAdvancePlugin.php | 55 +++++ .../ECommerceRefund/ReturnAdvancePlugin.php | 56 +++++ .../Marketing/Transfer/CreatePlugin.php | 104 ++++++++ .../Transfer/CreateReceiptDetailPlugin.php | 48 ++++ .../Transfer/CreateReceiptPlugin.php | 48 ++++ .../Transfer/DownloadReceiptPlugin.php | 53 +++++ .../Transfer/QueryBatchByWxPlugin.php | 54 +++++ .../Marketing/Transfer/QueryBatchPlugin.php | 54 +++++ .../Transfer/QueryDetailByWxPlugin.php | 55 +++++ .../Marketing/Transfer/QueryDetailPlugin.php | 55 +++++ .../Transfer/QueryReceiptDetailPlugin.php | 53 +++++ .../Marketing/Transfer/QueryReceiptPlugin.php | 53 +++++ src/Plugin/Wechat/Papay/ApplyPlugin.php | 21 -- .../Wechat/Papay/ContractOrderPlugin.php | 21 -- .../Wechat/Papay/OnlyContractPlugin.php | 70 ------ src/Plugin/Wechat/Pay/App/ClosePlugin.php | 70 +++++- .../Wechat/Pay/App/DownloadBillPlugin.php | 37 ++- .../Wechat/Pay/App/GetFlowBillPlugin.php | 10 - .../Wechat/Pay/App/GetFundBillPlugin.php | 45 ++++ .../Wechat/Pay/App/GetTradeBillPlugin.php | 39 ++- src/Plugin/Wechat/Pay/App/InvokePlugin.php | 111 +++++++++ .../Wechat/Pay/App/InvokePrepayPlugin.php | 64 ----- .../Wechat/Pay/App/InvokePrepayV2Plugin.php | 49 ---- src/Plugin/Wechat/Pay/App/PayPlugin.php | 78 ++++++ src/Plugin/Wechat/Pay/App/PrepayPlugin.php | 28 --- src/Plugin/Wechat/Pay/App/QueryByWxPlugin.php | 68 ++++++ src/Plugin/Wechat/Pay/App/QueryPlugin.php | 62 ++++- .../Wechat/Pay/App/QueryRefundPlugin.php | 48 +++- src/Plugin/Wechat/Pay/App/RefundPlugin.php | 67 +++++- .../Wechat/Pay/Combine/AppInvokePlugin.php | 111 +++++++++ .../Wechat/Pay/Combine/AppPayPlugin.php | 54 +++++ .../Wechat/Pay/Combine/AppPrepayPlugin.php | 19 -- src/Plugin/Wechat/Pay/Combine/ClosePlugin.php | 51 ++-- .../Wechat/Pay/Combine/DownloadBillPlugin.php | 37 ++- .../Wechat/Pay/Combine/GetFlowBillPlugin.php | 10 - .../Wechat/Pay/Combine/GetFundBillPlugin.php | 45 ++++ .../Wechat/Pay/Combine/GetTradeBillPlugin.php | 39 ++- src/Plugin/Wechat/Pay/Combine/H5PayPlugin.php | 55 +++++ .../Wechat/Pay/Combine/H5PrepayPlugin.php | 19 -- .../Pay/Combine/InvokeAppPrepayPlugin.php | 12 - .../Pay/Combine/InvokeJsapiPrepayPlugin.php | 12 - .../Pay/Combine/InvokeMiniPrepayPlugin.php | 12 - .../Wechat/Pay/Combine/JsapiInvokePlugin.php | 106 +++++++++ .../Wechat/Pay/Combine/JsapiPayPlugin.php | 55 +++++ .../Wechat/Pay/Combine/JsapiPrepayPlugin.php | 12 - .../Wechat/Pay/Combine/MiniInvokePlugin.php | 105 +++++++++ .../Wechat/Pay/Combine/MiniPayPlugin.php | 54 +++++ .../Wechat/Pay/Combine/MiniPrepayPlugin.php | 12 - .../Wechat/Pay/Combine/NativePayPlugin.php | 55 +++++ .../Wechat/Pay/Combine/NativePrepayPlugin.php | 19 -- src/Plugin/Wechat/Pay/Combine/QueryPlugin.php | 32 ++- .../Wechat/Pay/Combine/QueryRefundPlugin.php | 48 +++- .../Wechat/Pay/Combine/RefundPlugin.php | 67 +++++- src/Plugin/Wechat/Pay/Common/ClosePlugin.php | 76 ------ .../Wechat/Pay/Common/CombinePrepayPlugin.php | 50 ---- .../Wechat/Pay/Common/DownloadBillPlugin.php | 40 ---- .../Wechat/Pay/Common/GetFlowBillPlugin.php | 26 -- .../Wechat/Pay/Common/GetTradeBillPlugin.php | 26 -- .../Wechat/Pay/Common/InvokePrepayPlugin.php | 112 --------- .../Pay/Common/InvokePrepayV2Plugin.php | 40 ---- src/Plugin/Wechat/Pay/Common/PrepayPlugin.php | 70 ------ src/Plugin/Wechat/Pay/Common/QueryPlugin.php | 79 ------- .../Wechat/Pay/Common/QueryRefundPlugin.php | 53 ----- src/Plugin/Wechat/Pay/Common/RefundPlugin.php | 41 ---- src/Plugin/Wechat/Pay/H5/ClosePlugin.php | 70 +++++- .../Wechat/Pay/H5/DownloadBillPlugin.php | 37 ++- .../Wechat/Pay/H5/GetFlowBillPlugin.php | 10 - .../Wechat/Pay/H5/GetFundBillPlugin.php | 45 ++++ .../Wechat/Pay/H5/GetTradeBillPlugin.php | 39 ++- src/Plugin/Wechat/Pay/H5/PayPlugin.php | 81 +++++++ src/Plugin/Wechat/Pay/H5/PrepayPlugin.php | 23 -- src/Plugin/Wechat/Pay/H5/QueryByWxPlugin.php | 68 ++++++ src/Plugin/Wechat/Pay/H5/QueryPlugin.php | 62 ++++- .../Wechat/Pay/H5/QueryRefundPlugin.php | 48 +++- src/Plugin/Wechat/Pay/H5/RefundPlugin.php | 67 +++++- src/Plugin/Wechat/Pay/Jsapi/ClosePlugin.php | 70 +++++- .../Wechat/Pay/Jsapi/DownloadBillPlugin.php | 37 ++- .../Wechat/Pay/Jsapi/GetFlowBillPlugin.php | 10 - .../Wechat/Pay/Jsapi/GetFundBillPlugin.php | 45 ++++ .../Wechat/Pay/Jsapi/GetTradeBillPlugin.php | 39 ++- src/Plugin/Wechat/Pay/Jsapi/InvokePlugin.php | 106 +++++++++ .../Wechat/Pay/Jsapi/InvokePrepayPlugin.php | 10 - .../Wechat/Pay/Jsapi/InvokePrepayV2Plugin.php | 10 - src/Plugin/Wechat/Pay/Jsapi/PayPlugin.php | 87 +++++++ src/Plugin/Wechat/Pay/Jsapi/PrepayPlugin.php | 10 - .../Wechat/Pay/Jsapi/QueryByWxPlugin.php | 68 ++++++ src/Plugin/Wechat/Pay/Jsapi/QueryPlugin.php | 62 ++++- .../Wechat/Pay/Jsapi/QueryRefundPlugin.php | 48 +++- src/Plugin/Wechat/Pay/Jsapi/RefundPlugin.php | 67 +++++- src/Plugin/Wechat/Pay/Mini/ClosePlugin.php | 70 +++++- .../Wechat/Pay/Mini/DownloadBillPlugin.php | 37 ++- .../Wechat/Pay/Mini/GetFlowBillPlugin.php | 10 - .../Wechat/Pay/Mini/GetFundBillPlugin.php | 45 ++++ .../Wechat/Pay/Mini/GetTradeBillPlugin.php | 39 ++- src/Plugin/Wechat/Pay/Mini/InvokePlugin.php | 105 +++++++++ .../Wechat/Pay/Mini/InvokePrepayPlugin.php | 16 -- .../Wechat/Pay/Mini/InvokePrepayV2Plugin.php | 16 -- src/Plugin/Wechat/Pay/Mini/PayPlugin.php | 84 +++++++ src/Plugin/Wechat/Pay/Mini/PrepayPlugin.php | 31 --- .../Wechat/Pay/Mini/QueryByWxPlugin.php | 68 ++++++ src/Plugin/Wechat/Pay/Mini/QueryPlugin.php | 62 ++++- .../Wechat/Pay/Mini/QueryRefundPlugin.php | 48 +++- src/Plugin/Wechat/Pay/Mini/RefundPlugin.php | 67 +++++- src/Plugin/Wechat/Pay/Native/ClosePlugin.php | 70 +++++- .../Wechat/Pay/Native/DownloadBillPlugin.php | 37 ++- .../Wechat/Pay/Native/GetFlowBillPlugin.php | 10 - .../Wechat/Pay/Native/GetFundBillPlugin.php | 45 ++++ .../Wechat/Pay/Native/GetTradeBillPlugin.php | 39 ++- src/Plugin/Wechat/Pay/Native/PayPlugin.php | 81 +++++++ src/Plugin/Wechat/Pay/Native/PrepayPlugin.php | 23 -- .../Wechat/Pay/Native/QueryByWxPlugin.php | 68 ++++++ src/Plugin/Wechat/Pay/Native/QueryPlugin.php | 62 ++++- .../Wechat/Pay/Native/QueryRefundPlugin.php | 48 +++- src/Plugin/Wechat/Pay/Native/RefundPlugin.php | 67 +++++- src/Plugin/Wechat/Pay/Pos/PayPlugin.php | 19 -- src/Plugin/Wechat/Pay/Pos/QueryPlugin.php | 19 -- .../Wechat/Pay/Pos/QueryRefundPlugin.php | 19 -- .../Pay/Refund/RefundAbnormalPlugin.php | 116 +++++++++ src/Plugin/Wechat/PreparePlugin.php | 30 --- src/Plugin/Wechat/RadarSignPlugin.php | 163 ------------- .../{LaunchPlugin.php => ResponsePlugin.php} | 23 +- .../Complaints/CompleteComplaintPlugin.php | 54 ----- .../Risk/Complaints/DeleteCallbackPlugin.php | 32 --- .../Risk/Complaints/DownloadMediaPlugin.php | 43 ---- .../Risk/Complaints/QueryCallbackPlugin.php | 29 --- .../Complaints/QueryComplaintDetailPlugin.php | 40 ---- .../QueryComplaintNegotiationPlugin.php | 45 ---- .../Risk/Complaints/QueryComplaintsPlugin.php | 29 --- .../Complaints/ResponseComplaintPlugin.php | 57 ----- .../Risk/Complaints/SetCallbackPlugin.php | 21 -- .../Risk/Complaints/UpdateCallbackPlugin.php | 26 -- .../Risk/Complaints/UpdateRefundPlugin.php | 37 --- src/Plugin/Wechat/StartPlugin.php | 24 ++ src/Plugin/Wechat/VerifySignaturePlugin.php | 48 ++++ src/Plugin/Wechat/WechatPublicCertsPlugin.php | 24 +- src/Provider/AbstractProvider.php | 20 +- src/Provider/Alipay.php | 31 +-- src/Provider/Unipay.php | 15 +- src/Provider/Wechat.php | 31 +-- src/Rocket.php | 17 +- src/Service/ContainerServiceProvider.php | 2 +- src/Shortcut/Alipay/AppShortcut.php | 8 +- src/Shortcut/Alipay/CancelShortcut.php | 35 +-- src/Shortcut/Alipay/CloseShortcut.php | 49 ++-- src/Shortcut/Alipay/MiniShortcut.php | 8 +- src/Shortcut/Alipay/PosShortcut.php | 10 +- src/Shortcut/Alipay/QueryShortcut.php | 91 ++++--- src/Shortcut/Alipay/RefundShortcut.php | 53 ++--- src/Shortcut/Alipay/ScanShortcut.php | 8 +- src/Shortcut/Alipay/TransferShortcut.php | 8 +- src/Shortcut/Alipay/WapShortcut.php | 10 +- src/Shortcut/Alipay/WebShortcut.php | 8 +- src/Shortcut/Wechat/AppShortcut.php | 26 +- src/Shortcut/Wechat/CloseShortcut.php | 107 +++++++-- src/Shortcut/Wechat/MiniShortcut.php | 24 +- src/Shortcut/Wechat/MpShortcut.php | 24 +- src/Shortcut/Wechat/PapayShortcut.php | 87 ------- src/Shortcut/Wechat/PosShortcut.php | 18 -- src/Shortcut/Wechat/QueryShortcut.php | 223 ++++++++++++++++-- src/Shortcut/Wechat/RefundShortcut.php | 119 +++++++++- src/Shortcut/Wechat/ScanShortcut.php | 22 +- src/Shortcut/Wechat/TransferShortcut.php | 20 +- src/Shortcut/Wechat/WapShortcut.php | 22 +- src/Traits/GetUnipayCerts.php | 6 +- src/Traits/HasWechatEncryption.php | 61 ----- .../Direction/OriginResponseDirectionTest.php | 2 +- tests/FunctionTest.php | 188 +++++++++++---- ....php => AddPayloadSignaturePluginTest.php} | 8 +- ... => FormatPayloadBizContentPluginTest.php} | 8 +- .../Plugin/Alipay/Pay/Wap/ClosePluginTest.php | 2 +- tests/Plugin/Alipay/Pay/Wap/PayPluginTest.php | 2 +- .../Alipay/Pay/Wap/QueryBillUrlPluginTest.php | 2 +- .../Plugin/Alipay/Pay/Wap/QueryPluginTest.php | 2 +- .../Alipay/Pay/Wap/QueryRefundPluginTest.php | 2 +- .../Alipay/Pay/Wap/RefundPluginTest.php | 2 +- tests/Plugin/Alipay/StartPluginTest.php | 13 +- tests/Plugin/Unipay/PreparePluginTest.php | 4 +- .../Wechat/AddPayloadBodyPluginTest.php | 68 ++++++ ....php => AddPayloadSignaturePluginTest.php} | 140 ++++------- tests/Plugin/Wechat/AddRadarPluginTest.php | 60 +++++ tests/Plugin/Wechat/CallbackPluginTest.php | 7 +- .../Ecommerce/Refund/ApplyPluginTest.php | 112 --------- .../Ecommerce/Refund/QueryPluginTest.php | 76 ------ .../Refund/QueryReturnAdvancePluginTest.php | 63 ----- .../Refund/ReturnAdvancePluginTest.php | 65 ----- .../Extend/Complaints/CompletePluginTest.php | 72 ++++++ .../Complaints/DeleteCallbackPluginTest.php | 32 +++ .../Complaints/QueryCallbackPluginTest.php | 32 +++ .../Complaints/QueryDetailPluginTest.php | 51 ++++ .../Complaints/QueryImagePluginTest.php | 51 ++++ .../Complaints/QueryNegotiationPluginTest.php | 71 ++++++ .../Extend/Complaints/QueryPluginTest.php | 54 +++++ .../Extend/Complaints/ResponsePluginTest.php | 96 ++++++++ .../Complaints/SetCallbackPluginTest.php | 39 +++ .../Complaints/UpdateCallbackPluginTest.php | 39 +++ .../Complaints/UpdateRefundPluginTest.php | 57 +++++ .../ProfitSharing/AddReceiverPluginTest.php | 154 ++++++++++++ .../Extend/ProfitSharing/CreatePluginTest.php | 170 +++++++++++++ .../DeleteReceiverPluginTest.php | 90 +++++++ .../ProfitSharing}/DownloadBillPluginTest.php | 45 ++-- .../ProfitSharing/QueryAmountsPluginTest.php | 49 ++++ .../QueryMerchantConfigsPluginTest.php | 62 +++++ .../Extend/ProfitSharing/QueryPluginTest.php | 85 +++++++ .../ProfitSharing/QueryReturnPluginTest.php | 85 +++++++ .../Extend/ProfitSharing/ReturnPluginTest.php | 110 +++++++++ .../ProfitSharing/UnfreezePluginTest.php | 90 +++++++ .../Fund/Balance/QueryDayEndPluginTest.php | 63 ----- .../Profitsharing/AddReceiverPluginTest.php | 85 ------- .../Fund/Profitsharing/CreatePluginTest.php | 89 ------- .../DeleteReceiverPluginTest.php | 69 ------ .../QueryMerchantConfigsPluginTest.php | 51 ---- .../Fund/Profitsharing/QueryPluginTest.php | 89 ------- .../Profitsharing/QueryReturnPluginTest.php | 89 ------- .../Fund/Profitsharing/ReturnPluginTest.php | 68 ------ .../Fund/Profitsharing/UnfreezePluginTest.php | 68 ------ .../Transfer/CreateBillReceiptPluginTest.php | 67 ------ .../CreateDetailReceiptPluginTest.php | 80 ------- .../Wechat/Fund/Transfer/CreatePluginTest.php | 118 --------- .../Transfer/DownloadReceiptPluginTest.php | 52 ---- .../Transfer/QueryBatchDetailIdPluginTest.php | 98 -------- .../Fund/Transfer/QueryBatchIdPluginTest.php | 99 -------- .../Transfer/QueryBillReceiptPluginTest.php | 76 ------ .../Transfer/QueryDetailReceiptPluginTest.php | 63 ----- .../QueryOutBatchDetailNoPluginTest.php | 98 -------- .../Transfer/QueryOutBatchNoPluginTest.php | 99 -------- tests/Plugin/Wechat/GeneralPluginTest.php | 67 ------ tests/Plugin/Wechat/GeneralV2PluginTest.php | 46 ---- .../Marketing/Coupon/CreatePluginTest.php | 42 ++-- .../Marketing/Coupon/PausePluginTest.php | 50 +++- .../Coupon/QueryCallbackPluginTest.php | 51 ++++ .../Coupon/QueryCouponDetailPluginTest.php | 66 +++--- .../Coupon/QueryStockDetailPluginTest.php | 56 +++-- .../Coupon/QueryStockItemsPluginTest.php | 57 +++-- .../Coupon/QueryStockMerchantsPluginTest.php | 57 +++-- .../Coupon/QueryStockRefundFlowPluginTest.php | 39 ++- .../Coupon/QueryStockUseFlowPluginTest.php | 39 ++- .../Coupon/QueryStocksPluginTest.php | 64 +++-- .../Coupon/QueryUserCouponsPluginTest.php | 59 ++--- .../Marketing/Coupon/RestartPluginTest.php | 75 +++--- .../Marketing/Coupon/SendPluginTest.php | 80 +++---- .../Coupon/SetCallbackPluginTest.php | 45 +++- .../Marketing/Coupon/StartPluginTest.php | 75 +++--- .../QueryDayEndPluginTest.php | 78 ++++++ .../ECommerceBalance/QueryPluginTest.php | 78 ++++++ .../ECommerceRefund/ApplyPluginTest.php | 86 +++++++ .../ECommerceRefund/QueryByWxPluginTest.php | 78 ++++++ .../ECommerceRefund/QueryPluginTest.php | 79 +++++++ .../QueryReturnAdvancePluginTest.php | 80 +++++++ .../ReturnAdvancePluginTest.php | 80 +++++++ .../Marketing/Transfer/CreatePluginTest.php | 106 +++++++++ .../CreateReceiptDetailPluginTest.php | 50 ++++ .../Transfer/CreateReceiptPluginTest.php | 50 ++++ .../Transfer/DownloadReceiptPluginTest.php | 60 +++++ .../Transfer/QueryBatchByWxPluginTest.php | 61 +++++ .../Transfer/QueryBatchPluginTest.php | 61 +++++ .../Transfer/QueryDetailByWxPluginTest.php | 61 +++++ .../Transfer/QueryDetailPluginTest.php | 61 +++++ .../Transfer/QueryReceiptDetailPluginTest.php | 61 +++++ .../Transfer/QueryReceiptPluginTest.php | 61 +++++ tests/Plugin/Wechat/Papay/ApplyPluginTest.php | 46 ---- .../Wechat/Papay/ContractOrderPluginTest.php | 46 ---- .../Wechat/Papay/OnlyContractPluginTest.php | 61 ----- .../Plugin/Wechat/Pay/App/ClosePluginTest.php | 87 +++++++ .../App}/DownloadBillPluginTest.php | 45 ++-- .../Wechat/Pay/App/GetFundBillPluginTest.php | 49 ++++ .../Wechat/Pay/App/GetTradeBillPluginTest.php | 49 ++++ .../Wechat/Pay/App/InvokePluginTest.php | 108 +++++++++ .../Wechat/Pay/App/InvokePrepayPluginTest.php | 53 ----- .../Pay/App/InvokePrepayV2PluginTest.php | 39 --- tests/Plugin/Wechat/Pay/App/PayPluginTest.php | 97 ++++++++ .../Wechat/Pay/App/PrepayPluginTest.php | 75 ------ .../Wechat/Pay/App/QueryByWxPluginTest.php | 73 ++++++ .../Plugin/Wechat/Pay/App/QueryPluginTest.php | 73 ++++++ .../Wechat/Pay/App/QueryRefundPluginTest.php | 73 ++++++ .../Wechat/Pay/App/RefundPluginTest.php | 110 +++++++++ .../Pay/Combine/AppInvokePluginTest.php | 108 +++++++++ .../Wechat/Pay/Combine/AppPayPluginTest.php | 76 ++++++ .../Wechat/Pay/Combine/ClosePluginTest.php | 70 ++++++ .../Pay/Combine/DownloadBillPluginTest.php | 49 ++++ .../Pay/Combine/GetFundBillPluginTest.php | 49 ++++ .../Pay/Combine/GetTradeBillPluginTest.php | 49 ++++ .../Wechat/Pay/Combine/H5PayPluginTest.php | 76 ++++++ .../Pay/Combine/JsapiInvokePluginTest.php | 104 ++++++++ .../Wechat/Pay/Combine/JsapiPayPluginTest.php | 77 ++++++ .../Pay/Combine/MiniInvokePluginTest.php | 105 +++++++++ .../Wechat/Pay/Combine/MiniPayPluginTest.php | 78 ++++++ .../Pay/Combine/NativePayPluginTest.php | 76 ++++++ .../Combine}/QueryPluginTest.php | 43 ++-- .../Pay/Combine/QueryRefundPluginTest.php | 73 ++++++ .../Wechat/Pay/Combine/RefundPluginTest.php | 110 +++++++++ .../Wechat/Pay/Common/ClosePluginTest.php | 81 ------- .../Pay/Common/InvokePrepayPluginTest.php | 67 ------ .../Pay/Common/InvokePrepayV2PluginTest.php | 50 ---- .../Wechat/Pay/Common/PrepayPluginTest.php | 118 --------- .../Wechat/Pay/Common/QueryPluginTest.php | 86 ------- .../Pay/Common/QueryRefundPluginTest.php | 71 ------ .../Wechat/Pay/Common/RefundPluginTest.php | 91 ------- .../Plugin/Wechat/Pay/H5/ClosePluginTest.php | 87 +++++++ .../Wechat/Pay/H5/DownloadBillPluginTest.php | 49 ++++ .../Wechat/Pay/H5/GetFundBillPluginTest.php | 49 ++++ .../Wechat/Pay/H5/GetTradeBillPluginTest.php | 49 ++++ tests/Plugin/Wechat/Pay/H5/PayPluginTest.php | 97 ++++++++ .../Plugin/Wechat/Pay/H5/PrepayPluginTest.php | 145 ------------ .../Wechat/Pay/H5/QueryByWxPluginTest.php | 73 ++++++ .../Plugin/Wechat/Pay/H5/QueryPluginTest.php | 73 ++++++ .../Wechat/Pay/H5/QueryRefundPluginTest.php | 73 ++++++ .../Plugin/Wechat/Pay/H5/RefundPluginTest.php | 110 +++++++++ .../Wechat/Pay/Jsapi/ClosePluginTest.php | 87 +++++++ .../Pay/Jsapi/DownloadBillPluginTest.php | 49 ++++ .../Pay/Jsapi/GetFundBillPluginTest.php | 49 ++++ .../Pay/Jsapi/GetTradeBillPluginTest.php | 49 ++++ .../Wechat/Pay/Jsapi/InvokePluginTest.php | 104 ++++++++ .../Plugin/Wechat/Pay/Jsapi/PayPluginTest.php | 97 ++++++++ .../Wechat/Pay/Jsapi/QueryByWxPluginTest.php | 73 ++++++ .../Wechat/Pay/Jsapi/QueryPluginTest.php | 73 ++++++ .../Pay/Jsapi/QueryRefundPluginTest.php | 73 ++++++ .../Wechat/Pay/Jsapi/RefundPluginTest.php | 110 +++++++++ .../Wechat/Pay/Mini/ClosePluginTest.php | 87 +++++++ .../Pay/Mini/DownloadBillPluginTest.php | 49 ++++ .../Wechat/Pay/Mini/GetFundBillPluginTest.php | 49 ++++ .../Pay/Mini/GetTradeBillPluginTest.php | 49 ++++ .../Wechat/Pay/Mini/InvokePluginTest.php | 104 ++++++++ .../Pay/Mini/InvokePrepayPluginTest.php | 75 ------ .../Pay/Mini/InvokePrepayV2PluginTest.php | 38 --- .../Plugin/Wechat/Pay/Mini/PayPluginTest.php | 97 ++++++++ .../Wechat/Pay/Mini/PrepayPluginTest.php | 107 --------- .../Wechat/Pay/Mini/QueryByWxPluginTest.php | 73 ++++++ .../Wechat/Pay/Mini/QueryPluginTest.php | 73 ++++++ .../Wechat/Pay/Mini/QueryRefundPluginTest.php | 73 ++++++ .../Wechat/Pay/Mini/RefundPluginTest.php | 110 +++++++++ .../Wechat/Pay/Native/ClosePluginTest.php | 87 +++++++ .../Pay/Native/DownloadBillPluginTest.php | 49 ++++ .../Pay/Native/GetFundBillPluginTest.php | 49 ++++ .../Pay/Native/GetTradeBillPluginTest.php | 49 ++++ .../Wechat/Pay/Native/PayPluginTest.php | 97 ++++++++ .../Wechat/Pay/Native/PrepayPluginTest.php | 145 ------------ .../Wechat/Pay/Native/QueryByWxPluginTest.php | 73 ++++++ .../Wechat/Pay/Native/QueryPluginTest.php | 73 ++++++ .../Pay/Native/QueryRefundPluginTest.php | 73 ++++++ .../Wechat/Pay/Native/RefundPluginTest.php | 110 +++++++++ tests/Plugin/Wechat/Pay/Pos/PayPluginTest.php | 58 ----- .../Plugin/Wechat/Pay/Pos/QueryPluginTest.php | 34 --- .../Wechat/Pay/Pos/QueryRefundPluginTest.php | 34 --- .../Pay/Refund/RefundAbnormalPluginTest.php | 141 +++++++++++ ...hPluginTest.php => ResponsePluginTest.php} | 39 +-- .../CompleteComplaintPluginTest.php | 69 ------ .../Complaints/DeleteCallbackPluginTest.php | 42 ---- .../Complaints/DownloadMediaPluginTest.php | 52 ---- .../Complaints/QueryCallbackPluginTest.php | 40 ---- .../QueryComplaintDetailPluginTest.php | 53 ----- .../QueryComplaintNegotiationPluginTest.php | 53 ----- .../Complaints/QueryComplaintsPluginTest.php | 40 ---- .../ResponseComplaintPluginTest.php | 69 ------ .../Risk/Complaints/SetCallbackPluginTest.php | 39 --- .../Complaints/UpdateCallbackPluginTest.php | 40 ---- .../Complaints/UpdateRefundPluginTest.php | 53 ----- ...parePluginTest.php => StartPluginTest.php} | 13 +- .../Wechat/VerifySignaturePluginTest.php | 55 +++++ .../Wechat/WechatPublicCertsPluginTest.php | 33 +++ tests/Provider/AlipayTest.php | 79 ++++++- tests/Provider/WechatTest.php | 14 +- tests/Shortcut/Alipay/AppShortcutTest.php | 8 +- tests/Shortcut/Alipay/CancelShortcutTest.php | 28 +-- tests/Shortcut/Alipay/CloseShortcutTest.php | 42 ++-- tests/Shortcut/Alipay/MiniShortcutTest.php | 8 +- tests/Shortcut/Alipay/PosShortcutTest.php | 10 +- tests/Shortcut/Alipay/QueryShortcutTest.php | 84 +++---- tests/Shortcut/Alipay/RefundShortcutTest.php | 46 ++-- tests/Shortcut/Alipay/ScanShortcutTest.php | 8 +- .../Shortcut/Alipay/TransferShortcutTest.php | 8 +- tests/Shortcut/Alipay/WapShortcutTest.php | 10 +- tests/Shortcut/Alipay/WebShortcutTest.php | 8 +- tests/Shortcut/Wechat/AppShortcutTest.php | 44 ++++ tests/Shortcut/Wechat/CloseShortcutTest.php | 59 +++-- tests/Shortcut/Wechat/MiniShortcutTest.php | 42 ++++ tests/Shortcut/Wechat/MpShortcutTest.php | 42 ++++ tests/Shortcut/Wechat/PapayShortcutTest.php | 89 ------- tests/Shortcut/Wechat/PosShortcutTest.php | 28 --- tests/Shortcut/Wechat/QueryShortcutTest.php | 73 ++++-- tests/Shortcut/Wechat/RefundShortcutTest.php | 143 +++++++++++ tests/Shortcut/Wechat/ScanShortcutTest.php | 42 ++++ .../Shortcut/Wechat/TransferShortcutTest.php | 42 ++++ tests/Shortcut/Wechat/WapShortcutTest.php | 42 ++++ tests/TestCase.php | 17 +- tests/Traits/GetUnipayCertsTest.php | 6 +- tests/Traits/HasWechatEncryptionTest.php | 85 ------- 493 files changed, 16958 insertions(+), 9493 deletions(-) create mode 100644 src/Exception/DecryptException.php rename src/Plugin/Alipay/{AddSignaturePlugin.php => AddPayloadSignaturePlugin.php} (82%) delete mode 100644 src/Plugin/Alipay/FormatBizContentPlugin.php create mode 100644 src/Plugin/Alipay/FormatPayloadBizContentPlugin.php rename src/Plugin/Alipay/Pay/{Wap => H5}/ClosePlugin.php (94%) rename src/Plugin/Alipay/Pay/{Wap => H5}/PayPlugin.php (96%) rename src/Plugin/Alipay/Pay/{Wap => H5}/QueryBillUrlPlugin.php (94%) rename src/Plugin/Alipay/Pay/{Wap => H5}/QueryPlugin.php (94%) rename src/Plugin/Alipay/Pay/{Wap => H5}/QueryRefundPlugin.php (94%) rename src/Plugin/Alipay/Pay/{Wap => H5}/RefundPlugin.php (94%) create mode 100644 src/Plugin/Wechat/AddPayloadBodyPlugin.php create mode 100644 src/Plugin/Wechat/AddPayloadSignaturePlugin.php create mode 100644 src/Plugin/Wechat/AddRadarPlugin.php delete mode 100644 src/Plugin/Wechat/Ecommerce/Refund/ApplyPlugin.php delete mode 100644 src/Plugin/Wechat/Ecommerce/Refund/QueryPlugin.php delete mode 100644 src/Plugin/Wechat/Ecommerce/Refund/QueryReturnAdvancePlugin.php delete mode 100644 src/Plugin/Wechat/Ecommerce/Refund/ReturnAdvancePlugin.php create mode 100644 src/Plugin/Wechat/Extend/Complaints/CompletePlugin.php create mode 100644 src/Plugin/Wechat/Extend/Complaints/DeleteCallbackPlugin.php create mode 100644 src/Plugin/Wechat/Extend/Complaints/QueryCallbackPlugin.php create mode 100644 src/Plugin/Wechat/Extend/Complaints/QueryDetailPlugin.php create mode 100644 src/Plugin/Wechat/Extend/Complaints/QueryImagePlugin.php create mode 100644 src/Plugin/Wechat/Extend/Complaints/QueryNegotiationPlugin.php create mode 100644 src/Plugin/Wechat/Extend/Complaints/QueryPlugin.php create mode 100644 src/Plugin/Wechat/Extend/Complaints/ResponsePlugin.php create mode 100644 src/Plugin/Wechat/Extend/Complaints/SetCallbackPlugin.php create mode 100644 src/Plugin/Wechat/Extend/Complaints/UpdateCallbackPlugin.php create mode 100644 src/Plugin/Wechat/Extend/Complaints/UpdateRefundPlugin.php create mode 100644 src/Plugin/Wechat/Extend/ProfitSharing/AddReceiverPlugin.php create mode 100644 src/Plugin/Wechat/Extend/ProfitSharing/CreatePlugin.php create mode 100644 src/Plugin/Wechat/Extend/ProfitSharing/DeleteReceiverPlugin.php create mode 100644 src/Plugin/Wechat/Extend/ProfitSharing/DownloadBillPlugin.php create mode 100644 src/Plugin/Wechat/Extend/ProfitSharing/QueryAmountsPlugin.php create mode 100644 src/Plugin/Wechat/Extend/ProfitSharing/QueryMerchantConfigsPlugin.php create mode 100644 src/Plugin/Wechat/Extend/ProfitSharing/QueryPlugin.php create mode 100644 src/Plugin/Wechat/Extend/ProfitSharing/QueryReturnPlugin.php create mode 100644 src/Plugin/Wechat/Extend/ProfitSharing/ReturnPlugin.php create mode 100644 src/Plugin/Wechat/Extend/ProfitSharing/UnfreezePlugin.php delete mode 100644 src/Plugin/Wechat/Fund/Balance/QueryDayEndPlugin.php delete mode 100644 src/Plugin/Wechat/Fund/Balance/QueryPlugin.php delete mode 100644 src/Plugin/Wechat/Fund/Profitsharing/AddReceiverPlugin.php delete mode 100644 src/Plugin/Wechat/Fund/Profitsharing/CreatePlugin.php delete mode 100644 src/Plugin/Wechat/Fund/Profitsharing/DeleteReceiverPlugin.php delete mode 100644 src/Plugin/Wechat/Fund/Profitsharing/DownloadBillPlugin.php delete mode 100644 src/Plugin/Wechat/Fund/Profitsharing/QueryAmountsPlugin.php delete mode 100644 src/Plugin/Wechat/Fund/Profitsharing/QueryMerchantConfigsPlugin.php delete mode 100644 src/Plugin/Wechat/Fund/Profitsharing/QueryPlugin.php delete mode 100644 src/Plugin/Wechat/Fund/Profitsharing/QueryReturnPlugin.php delete mode 100644 src/Plugin/Wechat/Fund/Profitsharing/ReturnPlugin.php delete mode 100644 src/Plugin/Wechat/Fund/Profitsharing/UnfreezePlugin.php delete mode 100644 src/Plugin/Wechat/Fund/Transfer/CreateBillReceiptPlugin.php delete mode 100644 src/Plugin/Wechat/Fund/Transfer/CreateDetailReceiptPlugin.php delete mode 100644 src/Plugin/Wechat/Fund/Transfer/CreatePlugin.php delete mode 100644 src/Plugin/Wechat/Fund/Transfer/DownloadReceiptPlugin.php delete mode 100644 src/Plugin/Wechat/Fund/Transfer/QueryBatchDetailIdPlugin.php delete mode 100644 src/Plugin/Wechat/Fund/Transfer/QueryBatchIdPlugin.php delete mode 100644 src/Plugin/Wechat/Fund/Transfer/QueryBillReceiptPlugin.php delete mode 100644 src/Plugin/Wechat/Fund/Transfer/QueryDetailReceiptPlugin.php delete mode 100644 src/Plugin/Wechat/Fund/Transfer/QueryOutBatchDetailNoPlugin.php delete mode 100644 src/Plugin/Wechat/Fund/Transfer/QueryOutBatchNoPlugin.php delete mode 100644 src/Plugin/Wechat/GeneralPlugin.php delete mode 100644 src/Plugin/Wechat/GeneralV2Plugin.php create mode 100644 src/Plugin/Wechat/Marketing/Coupon/QueryCallbackPlugin.php create mode 100644 src/Plugin/Wechat/Marketing/ECommerceBalance/QueryDayEndPlugin.php create mode 100644 src/Plugin/Wechat/Marketing/ECommerceBalance/QueryPlugin.php create mode 100644 src/Plugin/Wechat/Marketing/ECommerceRefund/ApplyPlugin.php create mode 100644 src/Plugin/Wechat/Marketing/ECommerceRefund/QueryByWxPlugin.php create mode 100644 src/Plugin/Wechat/Marketing/ECommerceRefund/QueryPlugin.php create mode 100644 src/Plugin/Wechat/Marketing/ECommerceRefund/QueryReturnAdvancePlugin.php create mode 100644 src/Plugin/Wechat/Marketing/ECommerceRefund/ReturnAdvancePlugin.php create mode 100644 src/Plugin/Wechat/Marketing/Transfer/CreatePlugin.php create mode 100644 src/Plugin/Wechat/Marketing/Transfer/CreateReceiptDetailPlugin.php create mode 100644 src/Plugin/Wechat/Marketing/Transfer/CreateReceiptPlugin.php create mode 100644 src/Plugin/Wechat/Marketing/Transfer/DownloadReceiptPlugin.php create mode 100644 src/Plugin/Wechat/Marketing/Transfer/QueryBatchByWxPlugin.php create mode 100644 src/Plugin/Wechat/Marketing/Transfer/QueryBatchPlugin.php create mode 100644 src/Plugin/Wechat/Marketing/Transfer/QueryDetailByWxPlugin.php create mode 100644 src/Plugin/Wechat/Marketing/Transfer/QueryDetailPlugin.php create mode 100644 src/Plugin/Wechat/Marketing/Transfer/QueryReceiptDetailPlugin.php create mode 100644 src/Plugin/Wechat/Marketing/Transfer/QueryReceiptPlugin.php delete mode 100644 src/Plugin/Wechat/Papay/ApplyPlugin.php delete mode 100644 src/Plugin/Wechat/Papay/ContractOrderPlugin.php delete mode 100644 src/Plugin/Wechat/Papay/OnlyContractPlugin.php delete mode 100644 src/Plugin/Wechat/Pay/App/GetFlowBillPlugin.php create mode 100644 src/Plugin/Wechat/Pay/App/GetFundBillPlugin.php create mode 100644 src/Plugin/Wechat/Pay/App/InvokePlugin.php delete mode 100644 src/Plugin/Wechat/Pay/App/InvokePrepayPlugin.php delete mode 100644 src/Plugin/Wechat/Pay/App/InvokePrepayV2Plugin.php create mode 100644 src/Plugin/Wechat/Pay/App/PayPlugin.php delete mode 100644 src/Plugin/Wechat/Pay/App/PrepayPlugin.php create mode 100644 src/Plugin/Wechat/Pay/App/QueryByWxPlugin.php create mode 100644 src/Plugin/Wechat/Pay/Combine/AppInvokePlugin.php create mode 100644 src/Plugin/Wechat/Pay/Combine/AppPayPlugin.php delete mode 100644 src/Plugin/Wechat/Pay/Combine/AppPrepayPlugin.php delete mode 100644 src/Plugin/Wechat/Pay/Combine/GetFlowBillPlugin.php create mode 100644 src/Plugin/Wechat/Pay/Combine/GetFundBillPlugin.php create mode 100644 src/Plugin/Wechat/Pay/Combine/H5PayPlugin.php delete mode 100644 src/Plugin/Wechat/Pay/Combine/H5PrepayPlugin.php delete mode 100644 src/Plugin/Wechat/Pay/Combine/InvokeAppPrepayPlugin.php delete mode 100644 src/Plugin/Wechat/Pay/Combine/InvokeJsapiPrepayPlugin.php delete mode 100644 src/Plugin/Wechat/Pay/Combine/InvokeMiniPrepayPlugin.php create mode 100644 src/Plugin/Wechat/Pay/Combine/JsapiInvokePlugin.php create mode 100644 src/Plugin/Wechat/Pay/Combine/JsapiPayPlugin.php delete mode 100644 src/Plugin/Wechat/Pay/Combine/JsapiPrepayPlugin.php create mode 100644 src/Plugin/Wechat/Pay/Combine/MiniInvokePlugin.php create mode 100644 src/Plugin/Wechat/Pay/Combine/MiniPayPlugin.php delete mode 100644 src/Plugin/Wechat/Pay/Combine/MiniPrepayPlugin.php create mode 100644 src/Plugin/Wechat/Pay/Combine/NativePayPlugin.php delete mode 100644 src/Plugin/Wechat/Pay/Combine/NativePrepayPlugin.php delete mode 100644 src/Plugin/Wechat/Pay/Common/ClosePlugin.php delete mode 100644 src/Plugin/Wechat/Pay/Common/CombinePrepayPlugin.php delete mode 100644 src/Plugin/Wechat/Pay/Common/DownloadBillPlugin.php delete mode 100644 src/Plugin/Wechat/Pay/Common/GetFlowBillPlugin.php delete mode 100644 src/Plugin/Wechat/Pay/Common/GetTradeBillPlugin.php delete mode 100644 src/Plugin/Wechat/Pay/Common/InvokePrepayPlugin.php delete mode 100644 src/Plugin/Wechat/Pay/Common/InvokePrepayV2Plugin.php delete mode 100644 src/Plugin/Wechat/Pay/Common/PrepayPlugin.php delete mode 100644 src/Plugin/Wechat/Pay/Common/QueryPlugin.php delete mode 100644 src/Plugin/Wechat/Pay/Common/QueryRefundPlugin.php delete mode 100644 src/Plugin/Wechat/Pay/Common/RefundPlugin.php delete mode 100644 src/Plugin/Wechat/Pay/H5/GetFlowBillPlugin.php create mode 100644 src/Plugin/Wechat/Pay/H5/GetFundBillPlugin.php create mode 100644 src/Plugin/Wechat/Pay/H5/PayPlugin.php delete mode 100644 src/Plugin/Wechat/Pay/H5/PrepayPlugin.php create mode 100644 src/Plugin/Wechat/Pay/H5/QueryByWxPlugin.php delete mode 100644 src/Plugin/Wechat/Pay/Jsapi/GetFlowBillPlugin.php create mode 100644 src/Plugin/Wechat/Pay/Jsapi/GetFundBillPlugin.php create mode 100644 src/Plugin/Wechat/Pay/Jsapi/InvokePlugin.php delete mode 100644 src/Plugin/Wechat/Pay/Jsapi/InvokePrepayPlugin.php delete mode 100644 src/Plugin/Wechat/Pay/Jsapi/InvokePrepayV2Plugin.php create mode 100644 src/Plugin/Wechat/Pay/Jsapi/PayPlugin.php delete mode 100644 src/Plugin/Wechat/Pay/Jsapi/PrepayPlugin.php create mode 100644 src/Plugin/Wechat/Pay/Jsapi/QueryByWxPlugin.php delete mode 100644 src/Plugin/Wechat/Pay/Mini/GetFlowBillPlugin.php create mode 100644 src/Plugin/Wechat/Pay/Mini/GetFundBillPlugin.php create mode 100644 src/Plugin/Wechat/Pay/Mini/InvokePlugin.php delete mode 100644 src/Plugin/Wechat/Pay/Mini/InvokePrepayPlugin.php delete mode 100644 src/Plugin/Wechat/Pay/Mini/InvokePrepayV2Plugin.php create mode 100644 src/Plugin/Wechat/Pay/Mini/PayPlugin.php delete mode 100644 src/Plugin/Wechat/Pay/Mini/PrepayPlugin.php create mode 100644 src/Plugin/Wechat/Pay/Mini/QueryByWxPlugin.php delete mode 100644 src/Plugin/Wechat/Pay/Native/GetFlowBillPlugin.php create mode 100644 src/Plugin/Wechat/Pay/Native/GetFundBillPlugin.php create mode 100644 src/Plugin/Wechat/Pay/Native/PayPlugin.php delete mode 100644 src/Plugin/Wechat/Pay/Native/PrepayPlugin.php create mode 100644 src/Plugin/Wechat/Pay/Native/QueryByWxPlugin.php delete mode 100644 src/Plugin/Wechat/Pay/Pos/PayPlugin.php delete mode 100644 src/Plugin/Wechat/Pay/Pos/QueryPlugin.php delete mode 100644 src/Plugin/Wechat/Pay/Pos/QueryRefundPlugin.php create mode 100644 src/Plugin/Wechat/Pay/Refund/RefundAbnormalPlugin.php delete mode 100644 src/Plugin/Wechat/PreparePlugin.php delete mode 100644 src/Plugin/Wechat/RadarSignPlugin.php rename src/Plugin/Wechat/{LaunchPlugin.php => ResponsePlugin.php} (56%) delete mode 100644 src/Plugin/Wechat/Risk/Complaints/CompleteComplaintPlugin.php delete mode 100644 src/Plugin/Wechat/Risk/Complaints/DeleteCallbackPlugin.php delete mode 100644 src/Plugin/Wechat/Risk/Complaints/DownloadMediaPlugin.php delete mode 100644 src/Plugin/Wechat/Risk/Complaints/QueryCallbackPlugin.php delete mode 100644 src/Plugin/Wechat/Risk/Complaints/QueryComplaintDetailPlugin.php delete mode 100644 src/Plugin/Wechat/Risk/Complaints/QueryComplaintNegotiationPlugin.php delete mode 100644 src/Plugin/Wechat/Risk/Complaints/QueryComplaintsPlugin.php delete mode 100644 src/Plugin/Wechat/Risk/Complaints/ResponseComplaintPlugin.php delete mode 100644 src/Plugin/Wechat/Risk/Complaints/SetCallbackPlugin.php delete mode 100644 src/Plugin/Wechat/Risk/Complaints/UpdateCallbackPlugin.php delete mode 100644 src/Plugin/Wechat/Risk/Complaints/UpdateRefundPlugin.php create mode 100644 src/Plugin/Wechat/StartPlugin.php create mode 100644 src/Plugin/Wechat/VerifySignaturePlugin.php delete mode 100644 src/Shortcut/Wechat/PapayShortcut.php delete mode 100644 src/Shortcut/Wechat/PosShortcut.php delete mode 100644 src/Traits/HasWechatEncryption.php rename tests/Plugin/Alipay/{AddSignaturePluginTest.php => AddPayloadSignaturePluginTest.php} (87%) rename tests/Plugin/Alipay/{FormatBizContentPluginTest.php => FormatPayloadBizContentPluginTest.php} (83%) create mode 100644 tests/Plugin/Wechat/AddPayloadBodyPluginTest.php rename tests/Plugin/Wechat/{RadarSignPluginTest.php => AddPayloadSignaturePluginTest.php} (51%) create mode 100644 tests/Plugin/Wechat/AddRadarPluginTest.php delete mode 100644 tests/Plugin/Wechat/Ecommerce/Refund/ApplyPluginTest.php delete mode 100644 tests/Plugin/Wechat/Ecommerce/Refund/QueryPluginTest.php delete mode 100644 tests/Plugin/Wechat/Ecommerce/Refund/QueryReturnAdvancePluginTest.php delete mode 100644 tests/Plugin/Wechat/Ecommerce/Refund/ReturnAdvancePluginTest.php create mode 100644 tests/Plugin/Wechat/Extend/Complaints/CompletePluginTest.php create mode 100644 tests/Plugin/Wechat/Extend/Complaints/DeleteCallbackPluginTest.php create mode 100644 tests/Plugin/Wechat/Extend/Complaints/QueryCallbackPluginTest.php create mode 100644 tests/Plugin/Wechat/Extend/Complaints/QueryDetailPluginTest.php create mode 100644 tests/Plugin/Wechat/Extend/Complaints/QueryImagePluginTest.php create mode 100644 tests/Plugin/Wechat/Extend/Complaints/QueryNegotiationPluginTest.php create mode 100644 tests/Plugin/Wechat/Extend/Complaints/QueryPluginTest.php create mode 100644 tests/Plugin/Wechat/Extend/Complaints/ResponsePluginTest.php create mode 100644 tests/Plugin/Wechat/Extend/Complaints/SetCallbackPluginTest.php create mode 100644 tests/Plugin/Wechat/Extend/Complaints/UpdateCallbackPluginTest.php create mode 100644 tests/Plugin/Wechat/Extend/Complaints/UpdateRefundPluginTest.php create mode 100644 tests/Plugin/Wechat/Extend/ProfitSharing/AddReceiverPluginTest.php create mode 100644 tests/Plugin/Wechat/Extend/ProfitSharing/CreatePluginTest.php create mode 100644 tests/Plugin/Wechat/Extend/ProfitSharing/DeleteReceiverPluginTest.php rename tests/Plugin/Wechat/{Pay/Common => Extend/ProfitSharing}/DownloadBillPluginTest.php (51%) create mode 100644 tests/Plugin/Wechat/Extend/ProfitSharing/QueryAmountsPluginTest.php create mode 100644 tests/Plugin/Wechat/Extend/ProfitSharing/QueryMerchantConfigsPluginTest.php create mode 100644 tests/Plugin/Wechat/Extend/ProfitSharing/QueryPluginTest.php create mode 100644 tests/Plugin/Wechat/Extend/ProfitSharing/QueryReturnPluginTest.php create mode 100644 tests/Plugin/Wechat/Extend/ProfitSharing/ReturnPluginTest.php create mode 100644 tests/Plugin/Wechat/Extend/ProfitSharing/UnfreezePluginTest.php delete mode 100644 tests/Plugin/Wechat/Fund/Balance/QueryDayEndPluginTest.php delete mode 100644 tests/Plugin/Wechat/Fund/Profitsharing/AddReceiverPluginTest.php delete mode 100644 tests/Plugin/Wechat/Fund/Profitsharing/CreatePluginTest.php delete mode 100644 tests/Plugin/Wechat/Fund/Profitsharing/DeleteReceiverPluginTest.php delete mode 100644 tests/Plugin/Wechat/Fund/Profitsharing/QueryMerchantConfigsPluginTest.php delete mode 100644 tests/Plugin/Wechat/Fund/Profitsharing/QueryPluginTest.php delete mode 100644 tests/Plugin/Wechat/Fund/Profitsharing/QueryReturnPluginTest.php delete mode 100644 tests/Plugin/Wechat/Fund/Profitsharing/ReturnPluginTest.php delete mode 100644 tests/Plugin/Wechat/Fund/Profitsharing/UnfreezePluginTest.php delete mode 100644 tests/Plugin/Wechat/Fund/Transfer/CreateBillReceiptPluginTest.php delete mode 100644 tests/Plugin/Wechat/Fund/Transfer/CreateDetailReceiptPluginTest.php delete mode 100644 tests/Plugin/Wechat/Fund/Transfer/CreatePluginTest.php delete mode 100644 tests/Plugin/Wechat/Fund/Transfer/DownloadReceiptPluginTest.php delete mode 100644 tests/Plugin/Wechat/Fund/Transfer/QueryBatchDetailIdPluginTest.php delete mode 100644 tests/Plugin/Wechat/Fund/Transfer/QueryBatchIdPluginTest.php delete mode 100644 tests/Plugin/Wechat/Fund/Transfer/QueryBillReceiptPluginTest.php delete mode 100644 tests/Plugin/Wechat/Fund/Transfer/QueryDetailReceiptPluginTest.php delete mode 100644 tests/Plugin/Wechat/Fund/Transfer/QueryOutBatchDetailNoPluginTest.php delete mode 100644 tests/Plugin/Wechat/Fund/Transfer/QueryOutBatchNoPluginTest.php delete mode 100644 tests/Plugin/Wechat/GeneralPluginTest.php delete mode 100644 tests/Plugin/Wechat/GeneralV2PluginTest.php create mode 100644 tests/Plugin/Wechat/Marketing/Coupon/QueryCallbackPluginTest.php create mode 100644 tests/Plugin/Wechat/Marketing/ECommerceBalance/QueryDayEndPluginTest.php create mode 100644 tests/Plugin/Wechat/Marketing/ECommerceBalance/QueryPluginTest.php create mode 100644 tests/Plugin/Wechat/Marketing/ECommerceRefund/ApplyPluginTest.php create mode 100644 tests/Plugin/Wechat/Marketing/ECommerceRefund/QueryByWxPluginTest.php create mode 100644 tests/Plugin/Wechat/Marketing/ECommerceRefund/QueryPluginTest.php create mode 100644 tests/Plugin/Wechat/Marketing/ECommerceRefund/QueryReturnAdvancePluginTest.php create mode 100644 tests/Plugin/Wechat/Marketing/ECommerceRefund/ReturnAdvancePluginTest.php create mode 100644 tests/Plugin/Wechat/Marketing/Transfer/CreatePluginTest.php create mode 100644 tests/Plugin/Wechat/Marketing/Transfer/CreateReceiptDetailPluginTest.php create mode 100644 tests/Plugin/Wechat/Marketing/Transfer/CreateReceiptPluginTest.php create mode 100644 tests/Plugin/Wechat/Marketing/Transfer/DownloadReceiptPluginTest.php create mode 100644 tests/Plugin/Wechat/Marketing/Transfer/QueryBatchByWxPluginTest.php create mode 100644 tests/Plugin/Wechat/Marketing/Transfer/QueryBatchPluginTest.php create mode 100644 tests/Plugin/Wechat/Marketing/Transfer/QueryDetailByWxPluginTest.php create mode 100644 tests/Plugin/Wechat/Marketing/Transfer/QueryDetailPluginTest.php create mode 100644 tests/Plugin/Wechat/Marketing/Transfer/QueryReceiptDetailPluginTest.php create mode 100644 tests/Plugin/Wechat/Marketing/Transfer/QueryReceiptPluginTest.php delete mode 100644 tests/Plugin/Wechat/Papay/ApplyPluginTest.php delete mode 100644 tests/Plugin/Wechat/Papay/ContractOrderPluginTest.php delete mode 100644 tests/Plugin/Wechat/Papay/OnlyContractPluginTest.php create mode 100644 tests/Plugin/Wechat/Pay/App/ClosePluginTest.php rename tests/Plugin/Wechat/{Fund/Profitsharing => Pay/App}/DownloadBillPluginTest.php (50%) create mode 100644 tests/Plugin/Wechat/Pay/App/GetFundBillPluginTest.php create mode 100644 tests/Plugin/Wechat/Pay/App/GetTradeBillPluginTest.php create mode 100644 tests/Plugin/Wechat/Pay/App/InvokePluginTest.php delete mode 100644 tests/Plugin/Wechat/Pay/App/InvokePrepayPluginTest.php delete mode 100644 tests/Plugin/Wechat/Pay/App/InvokePrepayV2PluginTest.php create mode 100644 tests/Plugin/Wechat/Pay/App/PayPluginTest.php delete mode 100644 tests/Plugin/Wechat/Pay/App/PrepayPluginTest.php create mode 100644 tests/Plugin/Wechat/Pay/App/QueryByWxPluginTest.php create mode 100644 tests/Plugin/Wechat/Pay/App/QueryPluginTest.php create mode 100644 tests/Plugin/Wechat/Pay/App/QueryRefundPluginTest.php create mode 100644 tests/Plugin/Wechat/Pay/App/RefundPluginTest.php create mode 100644 tests/Plugin/Wechat/Pay/Combine/AppInvokePluginTest.php create mode 100644 tests/Plugin/Wechat/Pay/Combine/AppPayPluginTest.php create mode 100644 tests/Plugin/Wechat/Pay/Combine/ClosePluginTest.php create mode 100644 tests/Plugin/Wechat/Pay/Combine/DownloadBillPluginTest.php create mode 100644 tests/Plugin/Wechat/Pay/Combine/GetFundBillPluginTest.php create mode 100644 tests/Plugin/Wechat/Pay/Combine/GetTradeBillPluginTest.php create mode 100644 tests/Plugin/Wechat/Pay/Combine/H5PayPluginTest.php create mode 100644 tests/Plugin/Wechat/Pay/Combine/JsapiInvokePluginTest.php create mode 100644 tests/Plugin/Wechat/Pay/Combine/JsapiPayPluginTest.php create mode 100644 tests/Plugin/Wechat/Pay/Combine/MiniInvokePluginTest.php create mode 100644 tests/Plugin/Wechat/Pay/Combine/MiniPayPluginTest.php create mode 100644 tests/Plugin/Wechat/Pay/Combine/NativePayPluginTest.php rename tests/Plugin/Wechat/{Fund/Balance => Pay/Combine}/QueryPluginTest.php (52%) create mode 100644 tests/Plugin/Wechat/Pay/Combine/QueryRefundPluginTest.php create mode 100644 tests/Plugin/Wechat/Pay/Combine/RefundPluginTest.php delete mode 100644 tests/Plugin/Wechat/Pay/Common/ClosePluginTest.php delete mode 100644 tests/Plugin/Wechat/Pay/Common/InvokePrepayPluginTest.php delete mode 100644 tests/Plugin/Wechat/Pay/Common/InvokePrepayV2PluginTest.php delete mode 100644 tests/Plugin/Wechat/Pay/Common/PrepayPluginTest.php delete mode 100644 tests/Plugin/Wechat/Pay/Common/QueryPluginTest.php delete mode 100644 tests/Plugin/Wechat/Pay/Common/QueryRefundPluginTest.php delete mode 100644 tests/Plugin/Wechat/Pay/Common/RefundPluginTest.php create mode 100644 tests/Plugin/Wechat/Pay/H5/ClosePluginTest.php create mode 100644 tests/Plugin/Wechat/Pay/H5/DownloadBillPluginTest.php create mode 100644 tests/Plugin/Wechat/Pay/H5/GetFundBillPluginTest.php create mode 100644 tests/Plugin/Wechat/Pay/H5/GetTradeBillPluginTest.php create mode 100644 tests/Plugin/Wechat/Pay/H5/PayPluginTest.php delete mode 100644 tests/Plugin/Wechat/Pay/H5/PrepayPluginTest.php create mode 100644 tests/Plugin/Wechat/Pay/H5/QueryByWxPluginTest.php create mode 100644 tests/Plugin/Wechat/Pay/H5/QueryPluginTest.php create mode 100644 tests/Plugin/Wechat/Pay/H5/QueryRefundPluginTest.php create mode 100644 tests/Plugin/Wechat/Pay/H5/RefundPluginTest.php create mode 100644 tests/Plugin/Wechat/Pay/Jsapi/ClosePluginTest.php create mode 100644 tests/Plugin/Wechat/Pay/Jsapi/DownloadBillPluginTest.php create mode 100644 tests/Plugin/Wechat/Pay/Jsapi/GetFundBillPluginTest.php create mode 100644 tests/Plugin/Wechat/Pay/Jsapi/GetTradeBillPluginTest.php create mode 100644 tests/Plugin/Wechat/Pay/Jsapi/InvokePluginTest.php create mode 100644 tests/Plugin/Wechat/Pay/Jsapi/PayPluginTest.php create mode 100644 tests/Plugin/Wechat/Pay/Jsapi/QueryByWxPluginTest.php create mode 100644 tests/Plugin/Wechat/Pay/Jsapi/QueryPluginTest.php create mode 100644 tests/Plugin/Wechat/Pay/Jsapi/QueryRefundPluginTest.php create mode 100644 tests/Plugin/Wechat/Pay/Jsapi/RefundPluginTest.php create mode 100644 tests/Plugin/Wechat/Pay/Mini/ClosePluginTest.php create mode 100644 tests/Plugin/Wechat/Pay/Mini/DownloadBillPluginTest.php create mode 100644 tests/Plugin/Wechat/Pay/Mini/GetFundBillPluginTest.php create mode 100644 tests/Plugin/Wechat/Pay/Mini/GetTradeBillPluginTest.php create mode 100644 tests/Plugin/Wechat/Pay/Mini/InvokePluginTest.php delete mode 100644 tests/Plugin/Wechat/Pay/Mini/InvokePrepayPluginTest.php delete mode 100644 tests/Plugin/Wechat/Pay/Mini/InvokePrepayV2PluginTest.php create mode 100644 tests/Plugin/Wechat/Pay/Mini/PayPluginTest.php delete mode 100644 tests/Plugin/Wechat/Pay/Mini/PrepayPluginTest.php create mode 100644 tests/Plugin/Wechat/Pay/Mini/QueryByWxPluginTest.php create mode 100644 tests/Plugin/Wechat/Pay/Mini/QueryPluginTest.php create mode 100644 tests/Plugin/Wechat/Pay/Mini/QueryRefundPluginTest.php create mode 100644 tests/Plugin/Wechat/Pay/Mini/RefundPluginTest.php create mode 100644 tests/Plugin/Wechat/Pay/Native/ClosePluginTest.php create mode 100644 tests/Plugin/Wechat/Pay/Native/DownloadBillPluginTest.php create mode 100644 tests/Plugin/Wechat/Pay/Native/GetFundBillPluginTest.php create mode 100644 tests/Plugin/Wechat/Pay/Native/GetTradeBillPluginTest.php create mode 100644 tests/Plugin/Wechat/Pay/Native/PayPluginTest.php delete mode 100644 tests/Plugin/Wechat/Pay/Native/PrepayPluginTest.php create mode 100644 tests/Plugin/Wechat/Pay/Native/QueryByWxPluginTest.php create mode 100644 tests/Plugin/Wechat/Pay/Native/QueryPluginTest.php create mode 100644 tests/Plugin/Wechat/Pay/Native/QueryRefundPluginTest.php create mode 100644 tests/Plugin/Wechat/Pay/Native/RefundPluginTest.php delete mode 100644 tests/Plugin/Wechat/Pay/Pos/PayPluginTest.php delete mode 100644 tests/Plugin/Wechat/Pay/Pos/QueryPluginTest.php delete mode 100644 tests/Plugin/Wechat/Pay/Pos/QueryRefundPluginTest.php create mode 100644 tests/Plugin/Wechat/Pay/Refund/RefundAbnormalPluginTest.php rename tests/Plugin/Wechat/{LaunchPluginTest.php => ResponsePluginTest.php} (62%) delete mode 100644 tests/Plugin/Wechat/Risk/Complaints/CompleteComplaintPluginTest.php delete mode 100644 tests/Plugin/Wechat/Risk/Complaints/DeleteCallbackPluginTest.php delete mode 100644 tests/Plugin/Wechat/Risk/Complaints/DownloadMediaPluginTest.php delete mode 100644 tests/Plugin/Wechat/Risk/Complaints/QueryCallbackPluginTest.php delete mode 100644 tests/Plugin/Wechat/Risk/Complaints/QueryComplaintDetailPluginTest.php delete mode 100644 tests/Plugin/Wechat/Risk/Complaints/QueryComplaintNegotiationPluginTest.php delete mode 100644 tests/Plugin/Wechat/Risk/Complaints/QueryComplaintsPluginTest.php delete mode 100644 tests/Plugin/Wechat/Risk/Complaints/ResponseComplaintPluginTest.php delete mode 100644 tests/Plugin/Wechat/Risk/Complaints/SetCallbackPluginTest.php delete mode 100644 tests/Plugin/Wechat/Risk/Complaints/UpdateCallbackPluginTest.php delete mode 100644 tests/Plugin/Wechat/Risk/Complaints/UpdateRefundPluginTest.php rename tests/Plugin/Wechat/{PreparePluginTest.php => StartPluginTest.php} (69%) create mode 100644 tests/Plugin/Wechat/VerifySignaturePluginTest.php create mode 100644 tests/Plugin/Wechat/WechatPublicCertsPluginTest.php create mode 100644 tests/Shortcut/Wechat/AppShortcutTest.php create mode 100644 tests/Shortcut/Wechat/MiniShortcutTest.php create mode 100644 tests/Shortcut/Wechat/MpShortcutTest.php delete mode 100644 tests/Shortcut/Wechat/PapayShortcutTest.php delete mode 100644 tests/Shortcut/Wechat/PosShortcutTest.php create mode 100644 tests/Shortcut/Wechat/RefundShortcutTest.php create mode 100644 tests/Shortcut/Wechat/ScanShortcutTest.php create mode 100644 tests/Shortcut/Wechat/TransferShortcutTest.php create mode 100644 tests/Shortcut/Wechat/WapShortcutTest.php delete mode 100644 tests/Traits/HasWechatEncryptionTest.php diff --git a/.php-cs-fixer.php b/.php-cs-fixer.php index 1d27b98..98c0caa 100644 --- a/.php-cs-fixer.php +++ b/.php-cs-fixer.php @@ -19,5 +19,6 @@ return (new PhpCsFixer\Config()) 'import_functions' => true, ], 'multiline_whitespace_before_semicolons' => ['strategy' => 'no_multi_line'], + 'fully_qualified_strict_types' => true, ]) ->setFinder($finder); diff --git a/CHANGELOG.md b/CHANGELOG.md index 0850b31..00e87c0 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -3,19 +3,19 @@ ### added - feat: 新增 `InvalidSignException`(#903) +- feat: 新增 `DecryptException`(#906) ### changed -- change(internal): shortcut 完整标明各个插件,不使用 commonPlugin(#886) -- change(internal): 按场景对支付宝插件进行分类(#894) -- change(internal): 支付宝 shortcut 从 plugin 文件夹独立出来(#895) -- change(internal): DirectionInterface 方法由 `parse` 改为 `guide`(#896) - change: 查询API方法由 `find` 改为 `query`,同时参数只支持 array(#897) -- change: cancel 的 API 参数只支持 array,不再支持 string(#900) -- change: close 的 API 参数只支持 array,不再支持 string(#901) -- change(internal): 错误代码 const 命名规则统一(#902, #903) -- change(internal): 微信 shortcut 从 plugin 文件夹独立出来(#904) -- change(internal): 银联 shortcut 从 plugin 文件夹独立出来(#905) +- change: cancel/close 的 API 参数只支持 array,不再支持 string(#900, #901) +- change: 微信合单支付去掉独立的 `combine_app_id`,`combine_mch_id` 配置,复用其它配置(#909) +- change(internal): 按场景对 支付宝/微信/银联 插件进行分类 && 插件代码优化(#894, #909) +- change(internal): 将 支付/微信/银联 shortcut 从 plugin 文件夹独立出来(#895, #904, #905) +- change(internal): shortcut 完整标明各个插件,不使用 commonPlugin(#886) +- change(internal): DirectionInterface 方法由 `parse` 改为 `guide`(#896) +- change(internal): 错误代码 const 命名规则统一(#902, #903, #906, #909) +- change(internal): 调整 `ProviderInterface` 的返回参数,增加了 `Rocket` 返回(#909) ## v3.5.3 diff --git a/composer.json b/composer.json index b9e4cea..e4dfafa 100644 --- a/composer.json +++ b/composer.json @@ -27,12 +27,12 @@ "psr/container": "^1.1 || ^2.0", "psr/http-client": "^1.0", "psr/http-message": "^1.1 || ^2.0", - "yansongda/supports": "~4.0.0" + "yansongda/supports": "~4.0.4" }, "require-dev": { "phpunit/phpunit": "^9.0", "mockery/mockery": "^1.4", - "friendsofphp/php-cs-fixer": "^3.0", + "friendsofphp/php-cs-fixer": "^3.44", "phpstan/phpstan": "^1.0.0", "monolog/monolog": "^2.2", "symfony/var-dumper": "^5.1", diff --git a/src/Contract/ProviderInterface.php b/src/Contract/ProviderInterface.php index 8549a4a..0cdd483 100644 --- a/src/Contract/ProviderInterface.php +++ b/src/Contract/ProviderInterface.php @@ -10,6 +10,7 @@ use Psr\Http\Message\ServerRequestInterface; use Yansongda\Pay\Exception\ContainerException; use Yansongda\Pay\Exception\InvalidParamsException; use Yansongda\Pay\Exception\ServiceNotFoundException; +use Yansongda\Pay\Rocket; use Yansongda\Supports\Collection; interface ProviderInterface @@ -19,17 +20,17 @@ interface ProviderInterface * @throws InvalidParamsException * @throws ServiceNotFoundException */ - public function pay(array $plugins, array $params): null|array|Collection|MessageInterface; + public function pay(array $plugins, array $params): null|Collection|MessageInterface|Rocket; - public function query(array $order): array|Collection; + public function query(array $order): Collection|Rocket; - public function cancel(array $order): null|array|Collection; + public function cancel(array $order): Collection|Rocket; - public function close(array $order): null|array|Collection; + public function close(array $order): Collection|Rocket; - public function refund(array $order): array|Collection; + public function refund(array $order): Collection|Rocket; - public function callback(null|array|ServerRequestInterface $contents = null, ?array $params = null): Collection; + public function callback(null|array|ServerRequestInterface $contents = null, ?array $params = null): Collection|Rocket; public function success(): ResponseInterface; } diff --git a/src/Direction/CollectionDirection.php b/src/Direction/CollectionDirection.php index c895af6..ac74016 100644 --- a/src/Direction/CollectionDirection.php +++ b/src/Direction/CollectionDirection.php @@ -19,7 +19,7 @@ class CollectionDirection implements DirectionInterface public function guide(PackerInterface $packer, ?ResponseInterface $response): Collection { if (is_null($response)) { - throw new InvalidResponseException(Exception::RESPONSE_EMPTY); + throw new InvalidResponseException(Exception::RESPONSE_EMPTY, '响应异常: 响应为空,不能进行 direction'); } $body = (string) $response->getBody(); @@ -28,6 +28,6 @@ class CollectionDirection implements DirectionInterface return new Collection($result); } - throw new InvalidResponseException(Exception::RESPONSE_UNPACK_ERROR, 'Unpack Response Error', ['body' => $body, 'response' => $response]); + throw new InvalidResponseException(Exception::RESPONSE_UNPACK_ERROR, '响应异常: 解包错误', ['body' => $body, 'response' => $response]); } } diff --git a/src/Direction/OriginResponseDirection.php b/src/Direction/OriginResponseDirection.php index b558c4c..b56872a 100644 --- a/src/Direction/OriginResponseDirection.php +++ b/src/Direction/OriginResponseDirection.php @@ -17,10 +17,10 @@ class OriginResponseDirection implements DirectionInterface */ public function guide(PackerInterface $packer, ?ResponseInterface $response): ?ResponseInterface { - if (!is_null($response)) { - return $response; + if (is_null($response)) { + throw new InvalidResponseException(Exception::RESPONSE_EMPTY, '响应异常: 响应为空,不能进行 direction'); } - throw new InvalidResponseException(Exception::RESPONSE_CODE_WRONG); + return $response; } } diff --git a/src/Event.php b/src/Event.php index 8ab016c..f3256bf 100644 --- a/src/Event.php +++ b/src/Event.php @@ -33,6 +33,6 @@ class Event return; } - throw new InvalidConfigException(Exception\Exception::CONFIG_EVENT_INVALID); + throw new InvalidConfigException(Exception\Exception::CONFIG_EVENT_INVALID, '配置异常: 配置的 `EventDispatcherInterface` 不符合 PSR 规范'); } } diff --git a/src/Exception/ContainerException.php b/src/Exception/ContainerException.php index 5a6862a..ca1719a 100644 --- a/src/Exception/ContainerException.php +++ b/src/Exception/ContainerException.php @@ -9,7 +9,7 @@ use Throwable; class ContainerException extends Exception implements ContainerExceptionInterface { - public function __construct(string $message = '', int $code = self::CONTAINER_ERROR, mixed $extra = null, ?Throwable $previous = null) + public function __construct(string $message = '容器异常', int $code = self::CONTAINER_ERROR, mixed $extra = null, ?Throwable $previous = null) { parent::__construct($message, $code, $extra, $previous); } diff --git a/src/Exception/ContainerNotFoundException.php b/src/Exception/ContainerNotFoundException.php index b00026e..8e31903 100644 --- a/src/Exception/ContainerNotFoundException.php +++ b/src/Exception/ContainerNotFoundException.php @@ -8,7 +8,7 @@ use Throwable; class ContainerNotFoundException extends ContainerException { - public function __construct(string $message = 'Container Not Found', int $code = self::CONTAINER_NOT_FOUND, mixed $extra = null, ?Throwable $previous = null) + public function __construct(string $message = '容器未找到', int $code = self::CONTAINER_NOT_FOUND, mixed $extra = null, ?Throwable $previous = null) { parent::__construct($message, $code, $extra, $previous); } diff --git a/src/Exception/DecryptException.php b/src/Exception/DecryptException.php new file mode 100644 index 0000000..f2a869d --- /dev/null +++ b/src/Exception/DecryptException.php @@ -0,0 +1,19 @@ +extra = $extra; diff --git a/src/Exception/InvalidConfigException.php b/src/Exception/InvalidConfigException.php index e450a0b..2bc557f 100644 --- a/src/Exception/InvalidConfigException.php +++ b/src/Exception/InvalidConfigException.php @@ -8,7 +8,7 @@ use Throwable; class InvalidConfigException extends Exception { - public function __construct(int $code = self::CONFIG_ERROR, string $message = 'Config Error', mixed $extra = null, ?Throwable $previous = null) + public function __construct(int $code = self::CONFIG_ERROR, string $message = '配置异常', mixed $extra = null, ?Throwable $previous = null) { parent::__construct($message, $code, $extra, $previous); } diff --git a/src/Exception/InvalidParamsException.php b/src/Exception/InvalidParamsException.php index b6045b6..b899f4d 100644 --- a/src/Exception/InvalidParamsException.php +++ b/src/Exception/InvalidParamsException.php @@ -8,7 +8,7 @@ use Throwable; class InvalidParamsException extends Exception { - public function __construct(int $code = self::PARAMS_ERROR, string $message = 'Params Error', mixed $extra = null, ?Throwable $previous = null) + public function __construct(int $code = self::PARAMS_ERROR, string $message = '参数异常', mixed $extra = null, ?Throwable $previous = null) { parent::__construct($message, $code, $extra, $previous); } diff --git a/src/Exception/InvalidResponseException.php b/src/Exception/InvalidResponseException.php index 37ff855..8fdc9ec 100644 --- a/src/Exception/InvalidResponseException.php +++ b/src/Exception/InvalidResponseException.php @@ -12,7 +12,7 @@ class InvalidResponseException extends Exception public function __construct( int $code = self::RESPONSE_ERROR, - string $message = 'Provider response Error', + string $message = '响应异常', mixed $extra = null, ?Throwable $previous = null ) { diff --git a/src/Exception/InvalidSignException.php b/src/Exception/InvalidSignException.php index a2f070b..d75b7ca 100644 --- a/src/Exception/InvalidSignException.php +++ b/src/Exception/InvalidSignException.php @@ -12,7 +12,7 @@ class InvalidSignException extends Exception public function __construct( int $code = self::SIGN_ERROR, - string $message = 'Sign Error', + string $message = '签名异常', mixed $extra = null, ?Throwable $previous = null ) { diff --git a/src/Exception/ServiceNotFoundException.php b/src/Exception/ServiceNotFoundException.php index e323eaf..6b4be39 100644 --- a/src/Exception/ServiceNotFoundException.php +++ b/src/Exception/ServiceNotFoundException.php @@ -9,7 +9,7 @@ use Throwable; class ServiceNotFoundException extends Exception implements NotFoundExceptionInterface { - public function __construct(string $message = 'Service Not Found', int $code = self::SERVICE_NOT_FOUND, mixed $extra = null, ?Throwable $previous = null) + public function __construct(string $message = '服务未找到', int $code = self::SERVICE_NOT_FOUND, mixed $extra = null, ?Throwable $previous = null) { parent::__construct($message, $code, $extra, $previous); } diff --git a/src/Functions.php b/src/Functions.php index be3bf9c..9f431c9 100644 --- a/src/Functions.php +++ b/src/Functions.php @@ -4,23 +4,28 @@ declare(strict_types=1); namespace Yansongda\Pay; +use Closure; use Psr\Http\Message\ResponseInterface; use Psr\Http\Message\ServerRequestInterface; use Yansongda\Pay\Contract\ConfigInterface; use Yansongda\Pay\Contract\DirectionInterface; use Yansongda\Pay\Direction\NoHttpRequestDirection; use Yansongda\Pay\Exception\ContainerException; +use Yansongda\Pay\Exception\DecryptException; use Yansongda\Pay\Exception\Exception; use Yansongda\Pay\Exception\InvalidConfigException; use Yansongda\Pay\Exception\InvalidParamsException; -use Yansongda\Pay\Exception\InvalidResponseException; use Yansongda\Pay\Exception\InvalidSignException; use Yansongda\Pay\Exception\ServiceNotFoundException; use Yansongda\Pay\Plugin\ParserPlugin; -use Yansongda\Pay\Plugin\Wechat\PreparePlugin; -use Yansongda\Pay\Plugin\Wechat\RadarSignPlugin; +use Yansongda\Pay\Plugin\Wechat\AddPayloadBodyPlugin; +use Yansongda\Pay\Plugin\Wechat\AddPayloadSignaturePlugin; +use Yansongda\Pay\Plugin\Wechat\AddRadarPlugin; +use Yansongda\Pay\Plugin\Wechat\ResponsePlugin; +use Yansongda\Pay\Plugin\Wechat\StartPlugin; use Yansongda\Pay\Plugin\Wechat\WechatPublicCertsPlugin; use Yansongda\Pay\Provider\Wechat; +use Yansongda\Supports\Collection; use Yansongda\Supports\Str; function should_do_http_request(string $direction): bool @@ -47,23 +52,12 @@ function get_direction(mixed $direction): DirectionInterface } if (!$direction instanceof DirectionInterface) { - throw new InvalidConfigException(Exception::CONFIG_DIRECTION_INVALID); + throw new InvalidConfigException(Exception::CONFIG_DIRECTION_INVALID, '配置异常: 配置的 DirectionInterface 未实现 `DirectionInterface`'); } return $direction; } -/** - * @throws ContainerException - * @throws ServiceNotFoundException - */ -function get_alipay_config(array $params = []): array -{ - $alipay = Pay::get(ConfigInterface::class)->get('alipay'); - - return $alipay[get_tenant($params)] ?? []; -} - function get_public_cert(string $key): string { return Str::endsWith($key, ['.cer', '.crt', '.pem']) ? file_get_contents($key) : $key; @@ -80,18 +74,32 @@ function get_private_cert(string $key): string "\n-----END RSA PRIVATE KEY-----"; } +function filter_params(array $params, ?Closure $closure = null): array +{ + return array_filter($params, static fn ($v, $k) => !Str::startsWith($k, '_') && !is_null($v) && (empty($closure) || $closure($k, $v)), ARRAY_FILTER_USE_BOTH); +} + /** * @throws ContainerException - * @throws InvalidConfigException * @throws ServiceNotFoundException + */ +function get_alipay_config(array $params = []): array +{ + $alipay = Pay::get(ConfigInterface::class)->get('alipay'); + + return $alipay[get_tenant($params)] ?? []; +} + +/** + * @throws InvalidConfigException * @throws InvalidSignException */ -function verify_alipay_sign(array $params, string $contents, string $sign): void +function verify_alipay_sign(array $config, string $contents, string $sign): void { - $public = get_alipay_config($params)['alipay_public_cert_path'] ?? null; + $public = $config['alipay_public_cert_path'] ?? null; if (empty($public)) { - throw new InvalidConfigException(Exception::CONFIG_ALIPAY_INVALID, 'Missing Alipay Config -- [alipay_public_cert_path]'); + throw new InvalidConfigException(Exception::CONFIG_ALIPAY_INVALID, '配置异常: 缺少支付宝配置 -- [alipay_public_cert_path]'); } $result = 1 === openssl_verify( @@ -102,7 +110,7 @@ function verify_alipay_sign(array $params, string $contents, string $sign): void ); if (!$result) { - throw new InvalidSignException(Exception::SIGN_ERROR, 'Verify Alipay Sign Failed', func_get_args()); + throw new InvalidSignException(Exception::SIGN_ERROR, '签名异常: 验证支付宝签名失败', func_get_args()); } } @@ -110,35 +118,74 @@ function verify_alipay_sign(array $params, string $contents, string $sign): void * @throws ContainerException * @throws ServiceNotFoundException */ -function get_wechat_config(array $params): array +function get_wechat_config(array $params = []): array { $wechat = Pay::get(ConfigInterface::class)->get('wechat'); return $wechat[get_tenant($params)] ?? []; } -/** - * @throws ContainerException - * @throws ServiceNotFoundException - */ -function get_wechat_base_uri(array $params): string +function get_wechat_method(?Collection $payload): string { - $config = get_wechat_config($params); - - return Wechat::URL[$config['mode'] ?? Pay::MODE_NORMAL]; + return strtoupper($payload?->get('_method') ?? 'POST'); +} + +/** + * @throws InvalidParamsException + */ +function get_wechat_url(array $config, ?Collection $payload): string +{ + $url = $payload?->get('_url') ?? null; + + if (Pay::MODE_SERVICE === ($config['mode'] ?? Pay::MODE_NORMAL)) { + $url = $payload?->get('_service_url') ?? $url ?? null; + } + + if (empty($url)) { + throw new InvalidParamsException(Exception::PARAMS_WECHAT_URL_MISSING, '参数异常: 微信 `_url` 或 `_service_url` 参数缺失:你可能用错插件顺序,应该先使用 `业务插件`'); + } + + if (str_starts_with($url, 'http')) { + return $url; + } + + return Wechat::URL[$config['mode'] ?? Pay::MODE_NORMAL].$url; +} + +/** + * @throws InvalidParamsException + */ +function get_wechat_body(?Collection $payload): string +{ + $body = $payload?->get('_body') ?? null; + + if (is_null($body)) { + throw new InvalidParamsException(Exception::PARAMS_WECHAT_BODY_MISSING, '参数异常: 微信 `_body` 参数缺失:你可能用错插件顺序,应该先使用 `AddPayloadBodyPlugin`'); + } + + return $body; +} + +function get_wechat_type_key(array $params): string +{ + $key = ($params['_type'] ?? 'mp').'_app_id'; + + if ('app_app_id' === $key) { + $key = 'app_id'; + } + + return $key; } /** - * @throws ContainerException - * @throws ServiceNotFoundException * @throws InvalidConfigException */ -function get_wechat_sign(array $params, string $contents): string +function get_wechat_sign(array $config, string $contents): string { - $privateKey = get_wechat_config($params)['mch_secret_cert'] ?? null; + $privateKey = $config['mch_secret_cert'] ?? null; if (empty($privateKey)) { - throw new InvalidConfigException(Exception::CONFIG_WECHAT_INVALID, 'Missing Wechat Config -- [mch_secret_cert]'); + throw new InvalidConfigException(Exception::CONFIG_WECHAT_INVALID, '配置异常: 缺少微信配置 -- [mch_secret_cert]'); } $privateKey = get_private_cert($privateKey); @@ -158,7 +205,7 @@ function get_wechat_sign_v2(array $params, array $payload, bool $upper = true): $key = get_wechat_config($params)['mch_secret_key_v2'] ?? null; if (empty($key)) { - throw new InvalidConfigException(Exception::CONFIG_WECHAT_INVALID, 'Missing Wechat Config -- [mch_secret_key_v2]'); + throw new InvalidConfigException(Exception::CONFIG_WECHAT_INVALID, '配置异常: 缺少微信配置 -- [mch_secret_key_v2]'); } ksort($payload); @@ -176,11 +223,11 @@ function get_wechat_sign_v2(array $params, array $payload, bool $upper = true): /** * @throws ContainerException + * @throws DecryptException * @throws InvalidConfigException - * @throws InvalidResponseException - * @throws ServiceNotFoundException * @throws InvalidParamsException * @throws InvalidSignException + * @throws ServiceNotFoundException */ function verify_wechat_sign(ResponseInterface|ServerRequestInterface $message, array $params): void { @@ -198,7 +245,7 @@ function verify_wechat_sign(ResponseInterface|ServerRequestInterface $message, a $public = get_wechat_config($params)['wechat_public_cert_path'][$wechatSerial] ?? null; if (empty($sign)) { - throw new InvalidSignException(Exception::SIGN_EMPTY, $body, ['headers' => $message->getHeaders(), 'body' => $body]); + throw new InvalidSignException(Exception::SIGN_EMPTY, '签名异常: 微信签名为空', ['headers' => $message->getHeaders(), 'body' => $body]); } $public = get_public_cert( @@ -213,7 +260,7 @@ function verify_wechat_sign(ResponseInterface|ServerRequestInterface $message, a ); if (!$result) { - throw new InvalidSignException(Exception::SIGN_ERROR, 'Verify Wechat Sign Failed', ['headers' => $message->getHeaders(), 'body' => $body]); + throw new InvalidSignException(Exception::SIGN_ERROR, '签名异常: 验证微信签名失败', ['headers' => $message->getHeaders(), 'body' => $body]); } } @@ -228,31 +275,31 @@ function encrypt_wechat_contents(string $contents, string $publicKey): ?string /** * @throws ContainerException + * @throws DecryptException * @throws InvalidConfigException - * @throws ServiceNotFoundException * @throws InvalidParamsException - * @throws InvalidResponseException + * @throws ServiceNotFoundException */ function reload_wechat_public_certs(array $params, ?string $serialNo = null): string { $data = Pay::wechat()->pay( - [PreparePlugin::class, WechatPublicCertsPlugin::class, RadarSignPlugin::class, ParserPlugin::class], + [StartPlugin::class, WechatPublicCertsPlugin::class, AddPayloadBodyPlugin::class, AddPayloadSignaturePlugin::class, AddRadarPlugin::class, ResponsePlugin::class, ParserPlugin::class], $params )->get('data', []); - foreach ($data as $item) { - $certs[$item['serial_no']] = decrypt_wechat_resource($item['encrypt_certificate'], $params)['ciphertext'] ?? ''; - } - $wechatConfig = get_wechat_config($params); + foreach ($data as $item) { + $certs[$item['serial_no']] = decrypt_wechat_resource($item['encrypt_certificate'], $wechatConfig)['ciphertext'] ?? ''; + } + Pay::get(ConfigInterface::class)->set( 'wechat.'.get_tenant($params).'.wechat_public_cert_path', ((array) ($wechatConfig['wechat_public_cert_path'] ?? [])) + ($certs ?? []), ); if (!is_null($serialNo) && empty($certs[$serialNo])) { - throw new InvalidConfigException(Exception::CONFIG_WECHAT_INVALID, 'Get Wechat Public Cert Error'); + throw new InvalidConfigException(Exception::CONFIG_WECHAT_INVALID, '配置异常: 获取微信 wechat_public_cert_path 配置失败'); } return $certs[$serialNo] ?? ''; @@ -260,10 +307,10 @@ function reload_wechat_public_certs(array $params, ?string $serialNo = null): st /** * @throws ContainerException + * @throws DecryptException * @throws InvalidConfigException - * @throws ServiceNotFoundException * @throws InvalidParamsException - * @throws InvalidResponseException + * @throws ServiceNotFoundException */ function get_wechat_public_certs(array $params = [], ?string $path = null): void { @@ -283,34 +330,32 @@ function get_wechat_public_certs(array $params = [], ?string $path = null): void } /** - * @throws ContainerException * @throws InvalidConfigException - * @throws InvalidResponseException - * @throws ServiceNotFoundException + * @throws DecryptException */ -function decrypt_wechat_resource(array $resource, array $params): array +function decrypt_wechat_resource(array $resource, array $config): array { $ciphertext = base64_decode($resource['ciphertext'] ?? ''); - $secret = get_wechat_config($params)['mch_secret_key'] ?? null; + $secret = $config['mch_secret_key'] ?? null; if (strlen($ciphertext) <= Wechat::AUTH_TAG_LENGTH_BYTE) { - throw new InvalidResponseException(Exception::RESPONSE_CIPHERTEXT_PARAMS_INVALID); + throw new DecryptException(Exception::DECRYPT_WECHAT_CIPHERTEXT_PARAMS_INVALID, '加解密异常: ciphertext 位数过短'); } if (is_null($secret) || Wechat::MCH_SECRET_KEY_LENGTH_BYTE != strlen($secret)) { - throw new InvalidConfigException(Exception::CONFIG_WECHAT_INVALID, 'Missing Wechat Config -- [mch_secret_key]'); + throw new InvalidConfigException(Exception::CONFIG_WECHAT_INVALID, '配置异常: 缺少微信配置 -- [mch_secret_key]'); } $resource['ciphertext'] = match ($resource['algorithm'] ?? '') { 'AEAD_AES_256_GCM' => decrypt_wechat_resource_aes_256_gcm($ciphertext, $secret, $resource['nonce'] ?? '', $resource['associated_data'] ?? ''), - default => throw new InvalidResponseException(Exception::RESPONSE_DECRYPTED_METHOD_INVALID), + default => throw new DecryptException(Exception::DECRYPT_WECHAT_DECRYPTED_METHOD_INVALID, '加解密异常: algorithm 不支持'), }; return $resource; } /** - * @throws InvalidResponseException + * @throws DecryptException */ function decrypt_wechat_resource_aes_256_gcm(string $ciphertext, string $secret, string $nonce, string $associatedData): array|string { @@ -324,17 +369,61 @@ function decrypt_wechat_resource_aes_256_gcm(string $ciphertext, string $secret, $associatedData ); + if (false === $decrypted) { + throw new DecryptException(Exception::DECRYPT_WECHAT_ENCRYPTED_DATA_INVALID, '加解密异常: 解密失败,请检查微信 mch_secret_key 是否正确'); + } + if ('certificate' !== $associatedData) { - $decrypted = json_decode(strval($decrypted), true); + $decrypted = json_decode($decrypted, true); if (JSON_ERROR_NONE !== json_last_error()) { - throw new InvalidResponseException(Exception::RESPONSE_ENCRYPTED_DATA_INVALID); + throw new DecryptException(Exception::DECRYPT_WECHAT_ENCRYPTED_DATA_INVALID, '加解密异常: 待解密数据非正常数据'); } } return $decrypted; } +/** + * @throws ContainerException + * @throws DecryptException + * @throws InvalidConfigException + * @throws InvalidParamsException + * @throws ServiceNotFoundException + */ +function get_wechat_serial_no(array $params): string +{ + if (!empty($params['_serial_no'])) { + return $params['_serial_no']; + } + + $config = get_wechat_config($params); + + if (empty($config['wechat_public_cert_path'])) { + reload_wechat_public_certs($params); + + $config = get_wechat_config($params); + } + + mt_srand(); + + return strval(array_rand($config['wechat_public_cert_path'])); +} + +/** + * @throws InvalidParamsException + */ +function get_wechat_public_key(array $config, string $serialNo): string +{ + $publicKey = $config['wechat_public_cert_path'][$serialNo] ?? null; + + if (empty($publicKey)) { + throw new InvalidParamsException(Exception::PARAMS_WECHAT_SERIAL_NOT_FOUND, '参数异常: 微信公钥序列号为找到 -'.$serialNo); + } + + return $publicKey; +} + /** * @throws ContainerException * @throws ServiceNotFoundException @@ -356,7 +445,7 @@ function verify_unipay_sign(array $params, string $contents, string $sign): void { if (empty($params['signPubKeyCert']) && empty($public = get_unipay_config($params)['unipay_public_cert_path'] ?? null)) { - throw new InvalidConfigException(Exception::CONFIG_UNIPAY_INVALID, 'Missing Unipay Config -- [unipay_public_cert_path]'); + throw new InvalidConfigException(Exception::CONFIG_UNIPAY_INVALID, '配置异常: 缺少银联配置 -- [unipay_public_cert_path]'); } $result = 1 === openssl_verify( @@ -367,6 +456,6 @@ function verify_unipay_sign(array $params, string $contents, string $sign): void ); if (!$result) { - throw new InvalidSignException(Exception::SIGN_ERROR, 'Verify Unipay Sign Failed', func_get_args()); + throw new InvalidSignException(Exception::SIGN_ERROR, '签名异常: 验证银联签名失败', func_get_args()); } } diff --git a/src/Logger.php b/src/Logger.php index afd64be..0313419 100644 --- a/src/Logger.php +++ b/src/Logger.php @@ -43,6 +43,6 @@ class Logger return; } - throw new InvalidConfigException(Exception\Exception::CONFIG_LOGGER_INVALID); + throw new InvalidConfigException(Exception\Exception::CONFIG_LOGGER_INVALID, '配置异常: 配置的 `LoggerInterface` 不符合 PSR 规范'); } } diff --git a/src/Pay.php b/src/Pay.php index a738a63..8905a6d 100644 --- a/src/Pay.php +++ b/src/Pay.php @@ -137,10 +137,10 @@ class Pay } catch (ContainerNotFoundException $e) { throw $e; } catch (Throwable $e) { - throw new ContainerException($e->getMessage()); + throw new ContainerException('容器异常: '.$e->getMessage()); } - throw new ContainerException('Current container does NOT support `set` method'); + throw new ContainerException('容器异常: 当前容器类型不支持 `set` 方法'); } /** @@ -159,7 +159,7 @@ class Pay } catch (ContainerNotFoundException $e) { throw $e; } catch (Throwable $e) { - throw new ContainerException($e->getMessage()); + throw new ContainerException('容器异常: '.$e->getMessage()); } $parameters = array_values($parameters); @@ -176,11 +176,11 @@ class Pay try { return Pay::getContainer()->get($service); } catch (NotFoundExceptionInterface $e) { - throw new ServiceNotFoundException($e->getMessage()); + throw new ServiceNotFoundException('服务未找到: '.$e->getMessage()); } catch (ContainerNotFoundException $e) { throw $e; } catch (Throwable $e) { - throw new ContainerException($e->getMessage()); + throw new ContainerException('容器异常: '.$e->getMessage()); } } @@ -210,7 +210,7 @@ class Pay return (self::$container)(); } - throw new ContainerNotFoundException('`getContainer()` failed! Maybe you should `setContainer()` first', Exception\Exception::CONTAINER_NOT_FOUND); + throw new ContainerNotFoundException('容器未找到: `getContainer()` failed! Maybe you should `setContainer()` first', Exception\Exception::CONTAINER_NOT_FOUND); } public static function hasContainer(): bool diff --git a/src/Plugin/Alipay/AddSignaturePlugin.php b/src/Plugin/Alipay/AddPayloadSignaturePlugin.php similarity index 82% rename from src/Plugin/Alipay/AddSignaturePlugin.php rename to src/Plugin/Alipay/AddPayloadSignaturePlugin.php index ecbc081..e444bdf 100644 --- a/src/Plugin/Alipay/AddSignaturePlugin.php +++ b/src/Plugin/Alipay/AddPayloadSignaturePlugin.php @@ -16,7 +16,7 @@ use Yansongda\Pay\Rocket; use function Yansongda\Pay\get_alipay_config; use function Yansongda\Pay\get_private_cert; -class AddSignaturePlugin implements PluginInterface +class AddPayloadSignaturePlugin implements PluginInterface { /** * @throws ContainerException @@ -25,11 +25,11 @@ class AddSignaturePlugin implements PluginInterface */ public function assembly(Rocket $rocket, Closure $next): Rocket { - Logger::debug('[Alipay][AddSignaturePlugin] 插件开始装载', ['rocket' => $rocket]); + Logger::debug('[Alipay][AddPayloadSignaturePlugin] 插件开始装载', ['rocket' => $rocket]); $rocket->mergePayload(['sign' => $this->getSign($rocket)]); - Logger::info('[Alipay][AddSignaturePlugin] 插件装载完毕', ['rocket' => $rocket]); + Logger::info('[Alipay][AddPayloadSignaturePlugin] 插件装载完毕', ['rocket' => $rocket]); return $next($rocket); } @@ -60,7 +60,7 @@ class AddSignaturePlugin implements PluginInterface $privateKey = get_alipay_config($params)['app_secret_cert'] ?? null; if (is_null($privateKey)) { - throw new InvalidConfigException(Exception::CONFIG_ALIPAY_INVALID, 'Missing Alipay Config -- [app_secret_cert]'); + throw new InvalidConfigException(Exception::CONFIG_ALIPAY_INVALID, '配置异常: 缺少支付宝配置 -- [app_secret_cert]'); } return get_private_cert($privateKey); diff --git a/src/Plugin/Alipay/CallbackPlugin.php b/src/Plugin/Alipay/CallbackPlugin.php index 519bdde..6eed1ec 100644 --- a/src/Plugin/Alipay/CallbackPlugin.php +++ b/src/Plugin/Alipay/CallbackPlugin.php @@ -15,8 +15,9 @@ use Yansongda\Pay\Exception\ServiceNotFoundException; use Yansongda\Pay\Logger; use Yansongda\Pay\Rocket; use Yansongda\Supports\Collection; -use Yansongda\Supports\Str; +use function Yansongda\Pay\filter_params; +use function Yansongda\Pay\get_alipay_config; use function Yansongda\Pay\verify_alipay_sign; class CallbackPlugin implements PluginInterface @@ -35,10 +36,12 @@ class CallbackPlugin implements PluginInterface $sign = $rocket->getParams()['sign'] ?? false; if (!$sign) { - throw new InvalidSignException(Exception::SIGN_EMPTY, 'Callback Empty Sign', $rocket->getParams()); + throw new InvalidSignException(Exception::SIGN_EMPTY, '签名异常: 支付宝回调签名为空', $rocket->getParams()); } - verify_alipay_sign($rocket->getParams(), $this->getSignContent($rocket->getPayload()), $sign); + $config = get_alipay_config($rocket->getParams()); + + verify_alipay_sign($config, $this->getSignContent($rocket->getPayload()), $sign); $rocket->setDirection(NoHttpRequestDirection::class) ->setDestination($rocket->getPayload()); @@ -50,10 +53,9 @@ class CallbackPlugin implements PluginInterface protected function formatPayload(Rocket $rocket): void { - $payload = (new Collection($rocket->getParams())) - ->filter(fn ($v, $k) => '' !== $v && !is_null($v) && 'sign' != $k && 'sign_type' != $k && !Str::startsWith($k, '_')); + $payload = filter_params($rocket->getParams(), fn ($k, $v) => '' !== $v && 'sign' != $k && 'sign_type' != $k); - $rocket->setPayload($payload); + $rocket->setPayload(new Collection($payload)); } protected function getSignContent(Collection $payload): string diff --git a/src/Plugin/Alipay/FormatBizContentPlugin.php b/src/Plugin/Alipay/FormatBizContentPlugin.php deleted file mode 100644 index 12d20ff..0000000 --- a/src/Plugin/Alipay/FormatBizContentPlugin.php +++ /dev/null @@ -1,31 +0,0 @@ - $rocket]); - - $payload = $rocket->getPayload()->filter(fn ($v, $k) => '' !== $v && !is_null($v) && 'sign' != $k); - - $contents = array_filter($payload->get('biz_content', []), fn ($v, $k) => !Str::startsWith(strval($k), '_'), ARRAY_FILTER_USE_BOTH); - - $rocket->setPayload( - $payload->merge(['biz_content' => json_encode($contents)]) - ); - - Logger::info('[Alipay][FormatBizContentPlugin] 插件装载完毕', ['rocket' => $rocket]); - - return $next($rocket); - } -} diff --git a/src/Plugin/Alipay/FormatPayloadBizContentPlugin.php b/src/Plugin/Alipay/FormatPayloadBizContentPlugin.php new file mode 100644 index 0000000..35b64f5 --- /dev/null +++ b/src/Plugin/Alipay/FormatPayloadBizContentPlugin.php @@ -0,0 +1,32 @@ + $rocket]); + + $payload = $rocket->getPayload(); + + $rocket->setPayload(new Collection(array_merge( + filter_params($payload->all(), fn ($k, $v) => '' !== $v && !is_null($v) && 'sign' != $k), + ['biz_content' => json_encode(filter_params($payload->get('biz_content', [])))] + ))); + + Logger::info('[Alipay][FormatPayloadBizContentPlugin] 插件装载完毕', ['rocket' => $rocket]); + + return $next($rocket); + } +} diff --git a/src/Plugin/Alipay/Pay/Agreement/SignPlugin.php b/src/Plugin/Alipay/Pay/Agreement/SignPlugin.php index 1dc1500..8d02164 100644 --- a/src/Plugin/Alipay/Pay/Agreement/SignPlugin.php +++ b/src/Plugin/Alipay/Pay/Agreement/SignPlugin.php @@ -17,7 +17,7 @@ class SignPlugin implements PluginInterface { public function assembly(Rocket $rocket, Closure $next): Rocket { - Logger::debug('[Alipay][Pay][Agreement][AddSignaturePlugin] 插件开始装载', ['rocket' => $rocket]); + Logger::debug('[Alipay][Pay][Agreement][SignPlugin] 插件开始装载', ['rocket' => $rocket]); $rocket->setDirection(ResponseDirection::class) ->mergePayload([ @@ -25,7 +25,7 @@ class SignPlugin implements PluginInterface 'biz_content' => $rocket->getParams(), ]); - Logger::info('[Alipay][Pay][Agreement][AddSignaturePlugin] 插件装载完毕', ['rocket' => $rocket]); + Logger::info('[Alipay][Pay][Agreement][SignPlugin] 插件装载完毕', ['rocket' => $rocket]); return $next($rocket); } diff --git a/src/Plugin/Alipay/Pay/Wap/ClosePlugin.php b/src/Plugin/Alipay/Pay/H5/ClosePlugin.php similarity index 94% rename from src/Plugin/Alipay/Pay/Wap/ClosePlugin.php rename to src/Plugin/Alipay/Pay/H5/ClosePlugin.php index ca67dca..5a6cd19 100644 --- a/src/Plugin/Alipay/Pay/Wap/ClosePlugin.php +++ b/src/Plugin/Alipay/Pay/H5/ClosePlugin.php @@ -2,7 +2,7 @@ declare(strict_types=1); -namespace Yansongda\Pay\Plugin\Alipay\Pay\Wap; +namespace Yansongda\Pay\Plugin\Alipay\Pay\H5; use Closure; use Yansongda\Pay\Contract\PluginInterface; diff --git a/src/Plugin/Alipay/Pay/Wap/PayPlugin.php b/src/Plugin/Alipay/Pay/H5/PayPlugin.php similarity index 96% rename from src/Plugin/Alipay/Pay/Wap/PayPlugin.php rename to src/Plugin/Alipay/Pay/H5/PayPlugin.php index b3db5e6..487bc22 100644 --- a/src/Plugin/Alipay/Pay/Wap/PayPlugin.php +++ b/src/Plugin/Alipay/Pay/H5/PayPlugin.php @@ -2,7 +2,7 @@ declare(strict_types=1); -namespace Yansongda\Pay\Plugin\Alipay\Pay\Wap; +namespace Yansongda\Pay\Plugin\Alipay\Pay\H5; use Closure; use Yansongda\Pay\Contract\PluginInterface; diff --git a/src/Plugin/Alipay/Pay/Wap/QueryBillUrlPlugin.php b/src/Plugin/Alipay/Pay/H5/QueryBillUrlPlugin.php similarity index 94% rename from src/Plugin/Alipay/Pay/Wap/QueryBillUrlPlugin.php rename to src/Plugin/Alipay/Pay/H5/QueryBillUrlPlugin.php index f48fa33..8398a05 100644 --- a/src/Plugin/Alipay/Pay/Wap/QueryBillUrlPlugin.php +++ b/src/Plugin/Alipay/Pay/H5/QueryBillUrlPlugin.php @@ -2,7 +2,7 @@ declare(strict_types=1); -namespace Yansongda\Pay\Plugin\Alipay\Pay\Wap; +namespace Yansongda\Pay\Plugin\Alipay\Pay\H5; use Closure; use Yansongda\Pay\Contract\PluginInterface; diff --git a/src/Plugin/Alipay/Pay/Wap/QueryPlugin.php b/src/Plugin/Alipay/Pay/H5/QueryPlugin.php similarity index 94% rename from src/Plugin/Alipay/Pay/Wap/QueryPlugin.php rename to src/Plugin/Alipay/Pay/H5/QueryPlugin.php index 3e1fd3b..747ae07 100644 --- a/src/Plugin/Alipay/Pay/Wap/QueryPlugin.php +++ b/src/Plugin/Alipay/Pay/H5/QueryPlugin.php @@ -2,7 +2,7 @@ declare(strict_types=1); -namespace Yansongda\Pay\Plugin\Alipay\Pay\Wap; +namespace Yansongda\Pay\Plugin\Alipay\Pay\H5; use Closure; use Yansongda\Pay\Contract\PluginInterface; diff --git a/src/Plugin/Alipay/Pay/Wap/QueryRefundPlugin.php b/src/Plugin/Alipay/Pay/H5/QueryRefundPlugin.php similarity index 94% rename from src/Plugin/Alipay/Pay/Wap/QueryRefundPlugin.php rename to src/Plugin/Alipay/Pay/H5/QueryRefundPlugin.php index 8aa8578..14328f7 100644 --- a/src/Plugin/Alipay/Pay/Wap/QueryRefundPlugin.php +++ b/src/Plugin/Alipay/Pay/H5/QueryRefundPlugin.php @@ -2,7 +2,7 @@ declare(strict_types=1); -namespace Yansongda\Pay\Plugin\Alipay\Pay\Wap; +namespace Yansongda\Pay\Plugin\Alipay\Pay\H5; use Closure; use Yansongda\Pay\Contract\PluginInterface; diff --git a/src/Plugin/Alipay/Pay/Wap/RefundPlugin.php b/src/Plugin/Alipay/Pay/H5/RefundPlugin.php similarity index 94% rename from src/Plugin/Alipay/Pay/Wap/RefundPlugin.php rename to src/Plugin/Alipay/Pay/H5/RefundPlugin.php index 15dc451..aa1704d 100644 --- a/src/Plugin/Alipay/Pay/Wap/RefundPlugin.php +++ b/src/Plugin/Alipay/Pay/H5/RefundPlugin.php @@ -2,7 +2,7 @@ declare(strict_types=1); -namespace Yansongda\Pay\Plugin\Alipay\Pay\Wap; +namespace Yansongda\Pay\Plugin\Alipay\Pay\H5; use Closure; use Yansongda\Pay\Contract\PluginInterface; diff --git a/src/Plugin/Alipay/StartPlugin.php b/src/Plugin/Alipay/StartPlugin.php index b1787d4..0a49536 100644 --- a/src/Plugin/Alipay/StartPlugin.php +++ b/src/Plugin/Alipay/StartPlugin.php @@ -106,7 +106,7 @@ class StartPlugin implements PluginInterface $path = $config['app_public_cert_path'] ?? null; if (is_null($path)) { - throw new InvalidConfigException(Exception::CONFIG_ALIPAY_INVALID, 'Missing Alipay Config -- [app_public_cert_path]'); + throw new InvalidConfigException(Exception::CONFIG_ALIPAY_INVALID, '配置异常: 缺少支付宝配置 -- [app_public_cert_path]'); } $ssl = openssl_x509_parse(get_public_cert($path)); diff --git a/src/Plugin/Alipay/VerifySignaturePlugin.php b/src/Plugin/Alipay/VerifySignaturePlugin.php index fdd5a1b..0635c7c 100644 --- a/src/Plugin/Alipay/VerifySignaturePlugin.php +++ b/src/Plugin/Alipay/VerifySignaturePlugin.php @@ -14,6 +14,7 @@ use Yansongda\Pay\Exception\ServiceNotFoundException; use Yansongda\Pay\Logger; use Yansongda\Pay\Rocket; +use function Yansongda\Pay\get_alipay_config; use function Yansongda\Pay\should_do_http_request; use function Yansongda\Pay\verify_alipay_sign; @@ -42,10 +43,12 @@ class VerifySignaturePlugin implements PluginInterface $result = $destination->except('_sign')->all(); if ('' === $sign || empty($result)) { - throw new InvalidSignException(Exception::SIGN_EMPTY, 'Verify Alipay Response Sign Failed: sign is empty', $destination); + throw new InvalidSignException(Exception::SIGN_EMPTY, '签名异常: 验证支付宝签名失败-支付宝签名为空', $destination); } - verify_alipay_sign($rocket->getParams(), json_encode($result, JSON_UNESCAPED_UNICODE), $sign); + $config = get_alipay_config($rocket->getParams()); + + verify_alipay_sign($config, json_encode($result, JSON_UNESCAPED_UNICODE), $sign); Logger::info('[Alipay][VerifySignaturePlugin] 插件装载完毕', ['rocket' => $rocket]); diff --git a/src/Plugin/ParserPlugin.php b/src/Plugin/ParserPlugin.php index e8decab..0633d11 100644 --- a/src/Plugin/ParserPlugin.php +++ b/src/Plugin/ParserPlugin.php @@ -56,7 +56,7 @@ class ParserPlugin implements PluginInterface $packer = is_string($packer) ? Pay::get($packer) : $packer; if (!$packer instanceof PackerInterface) { - throw new InvalidConfigException(Exception::CONFIG_PACKER_INVALID); + throw new InvalidConfigException(Exception::CONFIG_PACKER_INVALID, '配置参数异常: 配置的 `PackerInterface` 未实现 `PackerInterface`'); } return $packer; diff --git a/src/Plugin/Unipay/CallbackPlugin.php b/src/Plugin/Unipay/CallbackPlugin.php index 5f2460e..2271a30 100644 --- a/src/Plugin/Unipay/CallbackPlugin.php +++ b/src/Plugin/Unipay/CallbackPlugin.php @@ -37,7 +37,7 @@ class CallbackPlugin implements PluginInterface $signature = $params['signature'] ?? false; if (!$signature) { - throw new InvalidSignException(Exception::SIGN_EMPTY, '', $params); + throw new InvalidSignException(Exception::SIGN_EMPTY, '签名异常: 银联签名为空', $params); } verify_unipay_sign($params, $rocket->getPayload()->sortKeys()->toString(), $signature); diff --git a/src/Plugin/Wechat/AddPayloadBodyPlugin.php b/src/Plugin/Wechat/AddPayloadBodyPlugin.php new file mode 100644 index 0000000..a2ab08a --- /dev/null +++ b/src/Plugin/Wechat/AddPayloadBodyPlugin.php @@ -0,0 +1,42 @@ +jsonPacker = $jsonPacker ?? new JsonPacker(); + } + + public function assembly(Rocket $rocket, Closure $next): Rocket + { + Logger::debug('[Wechat][AddPayloadBodyPlugin] 插件开始装载', ['rocket' => $rocket]); + + $rocket->mergePayload(['_body' => $this->getBody($rocket->getPayload())]); + + Logger::info('[Wechat][AddPayloadBodyPlugin] 插件装载完毕', ['rocket' => $rocket]); + + return $next($rocket); + } + + protected function getBody(?Collection $payload): string + { + $actualPayload = filter_params($payload->all()); + + return empty($actualPayload) ? '' : $this->jsonPacker->pack($actualPayload); + } +} diff --git a/src/Plugin/Wechat/AddPayloadSignaturePlugin.php b/src/Plugin/Wechat/AddPayloadSignaturePlugin.php new file mode 100644 index 0000000..091d3f6 --- /dev/null +++ b/src/Plugin/Wechat/AddPayloadSignaturePlugin.php @@ -0,0 +1,99 @@ + $rocket]); + + $config = get_wechat_config($rocket->getParams()); + $payload = $rocket->getPayload(); + + $timestamp = time(); + $random = Str::random(32); + $signContent = $this->getSignatureContent($config, $payload, $timestamp, $random); + $signature = $this->getSignature($config, $timestamp, $random, $signContent); + + $rocket->mergePayload(['_authorization' => $signature]); + + Logger::info('[Wechat][AddPayloadSignaturePlugin] 插件装载完毕', ['rocket' => $rocket]); + + return $next($rocket); + } + + /** + * @throws InvalidParamsException + */ + protected function getSignatureContent(array $config, ?Collection $payload, int $timestamp, string $random): string + { + $url = get_wechat_url($config, $payload); + $urlPath = parse_url($url, PHP_URL_PATH); + $urlQuery = parse_url($url, PHP_URL_QUERY); + + return get_wechat_method($payload)."\n". + $urlPath.(empty($urlQuery) ? '' : '?'.$urlQuery)."\n". + $timestamp."\n". + $random."\n". + get_wechat_body($payload)."\n"; + } + + /** + * @throws InvalidConfigException + */ + protected function getSignature(array $config, int $timestamp, string $random, string $contents): string + { + $mchPublicCertPath = $config['mch_public_cert_path'] ?? null; + + if (empty($mchPublicCertPath)) { + throw new InvalidConfigException(Exception::CONFIG_WECHAT_INVALID, '配置异常: 缺少微信配置 -- [mch_public_cert_path]'); + } + + $ssl = openssl_x509_parse(get_public_cert($mchPublicCertPath)); + + if (empty($ssl['serialNumberHex'])) { + throw new InvalidConfigException(Exception::CONFIG_WECHAT_INVALID, '配置异常: 解析微信配置 [mch_public_cert_path] 出错'); + } + + $auth = sprintf( + 'mchid="%s",nonce_str="%s",timestamp="%d",serial_no="%s",signature="%s"', + $config['mch_id'] ?? '', + $random, + $timestamp, + $ssl['serialNumberHex'], + get_wechat_sign($config, $contents), + ); + + return 'WECHATPAY2-SHA256-RSA2048 '.$auth; + } +} diff --git a/src/Plugin/Wechat/AddRadarPlugin.php b/src/Plugin/Wechat/AddRadarPlugin.php new file mode 100644 index 0000000..014c7de --- /dev/null +++ b/src/Plugin/Wechat/AddRadarPlugin.php @@ -0,0 +1,83 @@ + $rocket]); + + $params = $rocket->getParams(); + $payload = $rocket->getPayload(); + $config = get_wechat_config($params); + + $rocket->setRadar(new Request( + get_wechat_method($payload), + get_wechat_url($config, $payload), + $this->getHeaders($payload), + get_wechat_body($payload), + )); + + Logger::info('[Wechat][AddRadarPlugin] 插件装载完毕', ['rocket' => $rocket]); + + return $next($rocket); + } + + /** + * @throws InvalidParamsException + */ + protected function getHeaders(?Collection $payload): array + { + $authorization = $payload?->get('_authorization') ?? null; + + if (empty($authorization)) { + throw new InvalidParamsException(Exception::PARAMS_WECHAT_AUTHORIZATION_MISSING, '参数异常: 微信 `_authorization` 参数缺失:你可能用错插件顺序,应该先使用 `AddPayloadSignaturePlugin`, 再使用 `AddRadarPlugin`'); + } + + $headers = [ + 'Accept' => 'application/json, text/plain, application/x-gzip', + 'User-Agent' => 'yansongda/pay-v3', + 'Content-Type' => 'application/json; charset=utf-8', + 'Authorization' => $authorization, + ]; + + // 当 body 里有加密内容时,需要传递此参数用于微信区分 + if ($payload->has('_serial_no')) { + $headers['Wechatpay-Serial'] = $payload->get('_serial_no'); + } + + if ($payload->has('_content-type')) { + $headers['Content-Type'] = $payload->get('_content-type'); + } + + if ($payload->has('_accept')) { + $headers['Accept'] = $payload->get('_accept'); + } + + return $headers; + } +} diff --git a/src/Plugin/Wechat/CallbackPlugin.php b/src/Plugin/Wechat/CallbackPlugin.php index 15cd2ce..da6741c 100644 --- a/src/Plugin/Wechat/CallbackPlugin.php +++ b/src/Plugin/Wechat/CallbackPlugin.php @@ -9,16 +9,18 @@ use Psr\Http\Message\ServerRequestInterface; use Yansongda\Pay\Contract\PluginInterface; use Yansongda\Pay\Direction\NoHttpRequestDirection; use Yansongda\Pay\Exception\ContainerException; +use Yansongda\Pay\Exception\DecryptException; use Yansongda\Pay\Exception\Exception; use Yansongda\Pay\Exception\InvalidConfigException; use Yansongda\Pay\Exception\InvalidParamsException; -use Yansongda\Pay\Exception\InvalidResponseException; +use Yansongda\Pay\Exception\InvalidSignException; use Yansongda\Pay\Exception\ServiceNotFoundException; use Yansongda\Pay\Logger; use Yansongda\Pay\Rocket; use Yansongda\Supports\Collection; use function Yansongda\Pay\decrypt_wechat_resource; +use function Yansongda\Pay\get_wechat_config; use function Yansongda\Pay\verify_wechat_sign; class CallbackPlugin implements PluginInterface @@ -26,28 +28,31 @@ class CallbackPlugin implements PluginInterface /** * @throws ContainerException * @throws InvalidConfigException - * @throws ServiceNotFoundException - * @throws InvalidResponseException * @throws InvalidParamsException + * @throws InvalidSignException + * @throws ServiceNotFoundException + * @throws DecryptException */ public function assembly(Rocket $rocket, Closure $next): Rocket { - Logger::debug('[wechat][CallbackPlugin] 插件开始装载', ['rocket' => $rocket]); + Logger::debug('[Wechat][CallbackPlugin] 插件开始装载', ['rocket' => $rocket]); - $this->formatRequestAndParams($rocket); + $this->init($rocket); + + $params = $rocket->getParams(); /* @phpstan-ignore-next-line */ - verify_wechat_sign($rocket->getDestinationOrigin(), $rocket->getParams()); + verify_wechat_sign($rocket->getDestinationOrigin(), $params); $body = json_decode((string) $rocket->getDestination()->getBody(), true); $rocket->setDirection(NoHttpRequestDirection::class)->setPayload(new Collection($body)); - $body['resource'] = decrypt_wechat_resource($body['resource'] ?? [], $rocket->getParams()); + $body['resource'] = decrypt_wechat_resource($body['resource'] ?? [], get_wechat_config($params)); $rocket->setDestination(new Collection($body)); - Logger::info('[wechat][CallbackPlugin] 插件装载完毕', ['rocket' => $rocket]); + Logger::info('[Wechat][CallbackPlugin] 插件装载完毕', ['rocket' => $rocket]); return $next($rocket); } @@ -55,16 +60,17 @@ class CallbackPlugin implements PluginInterface /** * @throws InvalidParamsException */ - protected function formatRequestAndParams(Rocket $rocket): void + protected function init(Rocket $rocket): void { - $request = $rocket->getParams()['request'] ?? null; + $request = $rocket->getParams()['_request'] ?? null; + $params = $rocket->getParams()['_params'] ?? []; if (!$request instanceof ServerRequestInterface) { - throw new InvalidParamsException(Exception::PARAMS_REQUEST_EMPTY); + throw new InvalidParamsException(Exception::PARAMS_CALLBACK_REQUEST_INVALID, '参数异常: 微信回调参数不正确'); } $rocket->setDestination(clone $request) ->setDestinationOrigin($request) - ->setParams($rocket->getParams()['params'] ?? []); + ->setParams($params); } } diff --git a/src/Plugin/Wechat/Ecommerce/Refund/ApplyPlugin.php b/src/Plugin/Wechat/Ecommerce/Refund/ApplyPlugin.php deleted file mode 100644 index 95a6ee4..0000000 --- a/src/Plugin/Wechat/Ecommerce/Refund/ApplyPlugin.php +++ /dev/null @@ -1,55 +0,0 @@ -getParams()); - $payload = $rocket->getPayload(); - $key = $this->getConfigKey($rocket->getParams()); - - $wechatId = [ - 'sub_mchid' => $payload->get('sub_mchid', $config['sub_mch_id'] ?? ''), - 'sp_appid' => $payload->get('sp_appid', $config[$key] ?? ''), - ]; - - if (!$payload->has('notify_url')) { - $wechatId['notify_url'] = $config['notify_url'] ?? null; - } - - $rocket->mergePayload($wechatId); - } -} diff --git a/src/Plugin/Wechat/Ecommerce/Refund/QueryPlugin.php b/src/Plugin/Wechat/Ecommerce/Refund/QueryPlugin.php deleted file mode 100644 index a052854..0000000 --- a/src/Plugin/Wechat/Ecommerce/Refund/QueryPlugin.php +++ /dev/null @@ -1,60 +0,0 @@ -getPayload(); - $config = get_wechat_config($rocket->getParams()); - $subMchId = $payload->get('sub_mchid', $config['sub_mch_id'] ?? ''); - - if ($payload->has('refund_id')) { - return 'v3/ecommerce/refunds/id/'.$payload->get('refund_id').'?sub_mchid='.$subMchId; - } - - if ($payload->has('out_refund_no')) { - return 'v3/ecommerce/refunds/out-refund-no/'.$payload->get('out_refund_no').'?sub_mchid='.$subMchId; - } - - throw new InvalidParamsException(Exception::PARAMS_NECESSARY_PARAMS_MISSING); - } - - protected function getMethod(): string - { - return 'GET'; - } - - protected function doSomething(Rocket $rocket): void - { - $rocket->setPayload(null); - } -} diff --git a/src/Plugin/Wechat/Ecommerce/Refund/QueryReturnAdvancePlugin.php b/src/Plugin/Wechat/Ecommerce/Refund/QueryReturnAdvancePlugin.php deleted file mode 100644 index b5ec95c..0000000 --- a/src/Plugin/Wechat/Ecommerce/Refund/QueryReturnAdvancePlugin.php +++ /dev/null @@ -1,56 +0,0 @@ -getPayload(); - $config = get_wechat_config($rocket->getParams()); - $subMchId = $payload->get('sub_mchid', $config['sub_mch_id'] ?? ''); - - if (!$payload->has('refund_id')) { - throw new InvalidParamsException(Exception::PARAMS_NECESSARY_PARAMS_MISSING); - } - - return 'v3/ecommerce/refunds/'.$payload->get('refund_id').'/return-advance?sub_mchid='.$subMchId; - } - - protected function getMethod(): string - { - return 'GET'; - } - - protected function doSomething(Rocket $rocket): void - { - $rocket->setPayload(null); - } -} diff --git a/src/Plugin/Wechat/Ecommerce/Refund/ReturnAdvancePlugin.php b/src/Plugin/Wechat/Ecommerce/Refund/ReturnAdvancePlugin.php deleted file mode 100644 index 3a28a1e..0000000 --- a/src/Plugin/Wechat/Ecommerce/Refund/ReturnAdvancePlugin.php +++ /dev/null @@ -1,56 +0,0 @@ -getPayload(); - - if (!$payload->has('refund_id')) { - throw new InvalidParamsException(Exception::PARAMS_NECESSARY_PARAMS_MISSING); - } - - return 'v3/ecommerce/refunds/'.$payload->get('refund_id').'/return-advance'; - } - - /** - * @throws ContainerException - * @throws ServiceNotFoundException - */ - protected function doSomething(Rocket $rocket): void - { - $config = get_wechat_config($rocket->getParams()); - - $rocket->setPayload(new Collection([ - 'sub_mchid' => $rocket->getPayload()->get('sub_mchid', $config['sub_mch_id'] ?? ''), - ])); - } -} diff --git a/src/Plugin/Wechat/Extend/Complaints/CompletePlugin.php b/src/Plugin/Wechat/Extend/Complaints/CompletePlugin.php new file mode 100644 index 0000000..04576f5 --- /dev/null +++ b/src/Plugin/Wechat/Extend/Complaints/CompletePlugin.php @@ -0,0 +1,52 @@ + $rocket]); + + $config = get_wechat_config($rocket->getParams()); + $payload = $rocket->getPayload(); + $complaintId = $payload?->get('complaint_id') ?? null; + + if (empty($complaintId)) { + throw new InvalidParamsException(Exception::PARAMS_NECESSARY_PARAMS_MISSING, '参数异常: 反馈处理完成,参数缺少 `complaint_id`'); + } + + $rocket->setPayload([ + '_method' => 'POST', + '_url' => 'v3/merchant-service/complaints-v2/'.$complaintId.'/complete', + '_service_url' => 'v3/merchant-service/complaints-v2/'.$complaintId.'/complete', + 'complainted_mchid' => $payload->get('complainted_mchid') ?? $config['mch_id'], + ]); + + Logger::info('[Wechat][Extend][Complaints][CompletePlugin] 插件装载完毕', ['rocket' => $rocket]); + + return $next($rocket); + } +} diff --git a/src/Plugin/Wechat/Extend/Complaints/DeleteCallbackPlugin.php b/src/Plugin/Wechat/Extend/Complaints/DeleteCallbackPlugin.php new file mode 100644 index 0000000..1c1da91 --- /dev/null +++ b/src/Plugin/Wechat/Extend/Complaints/DeleteCallbackPlugin.php @@ -0,0 +1,32 @@ + $rocket]); + + $rocket->setPayload([ + '_method' => 'DELETE', + '_url' => 'v3/merchant-service/complaint-notifications', + '_service_url' => 'v3/merchant-service/complaint-notifications', + ]); + + Logger::info('[Wechat][Extend][Complaints][DeleteCallbackPlugin] 插件装载完毕', ['rocket' => $rocket]); + + return $next($rocket); + } +} diff --git a/src/Plugin/Wechat/Extend/Complaints/QueryCallbackPlugin.php b/src/Plugin/Wechat/Extend/Complaints/QueryCallbackPlugin.php new file mode 100644 index 0000000..04f0caa --- /dev/null +++ b/src/Plugin/Wechat/Extend/Complaints/QueryCallbackPlugin.php @@ -0,0 +1,32 @@ + $rocket]); + + $rocket->setPayload([ + '_method' => 'GET', + '_url' => 'v3/merchant-service/complaint-notifications', + '_service_url' => 'v3/merchant-service/complaint-notifications', + ]); + + Logger::info('[Wechat][Extend][Complaints][QueryCallbackPlugin] 插件装载完毕', ['rocket' => $rocket]); + + return $next($rocket); + } +} diff --git a/src/Plugin/Wechat/Extend/Complaints/QueryDetailPlugin.php b/src/Plugin/Wechat/Extend/Complaints/QueryDetailPlugin.php new file mode 100644 index 0000000..69b8cc1 --- /dev/null +++ b/src/Plugin/Wechat/Extend/Complaints/QueryDetailPlugin.php @@ -0,0 +1,43 @@ + $rocket]); + + $complaintId = $rocket->getPayload()?->get('complaint_id') ?? null; + + if (empty($complaintId)) { + throw new InvalidParamsException(Exception::PARAMS_NECESSARY_PARAMS_MISSING, '参数异常: 查询投诉单详情,参数缺少 `complaint_id`'); + } + + $rocket->setPayload([ + '_method' => 'GET', + '_url' => 'v3/merchant-service/complaints-v2/'.$complaintId, + '_service_url' => 'v3/merchant-service/complaints-v2/'.$complaintId, + ]); + + Logger::info('[Wechat][Extend][Complaints][QueryDetailPlugin] 插件装载完毕', ['rocket' => $rocket]); + + return $next($rocket); + } +} diff --git a/src/Plugin/Wechat/Extend/Complaints/QueryImagePlugin.php b/src/Plugin/Wechat/Extend/Complaints/QueryImagePlugin.php new file mode 100644 index 0000000..abfc716 --- /dev/null +++ b/src/Plugin/Wechat/Extend/Complaints/QueryImagePlugin.php @@ -0,0 +1,43 @@ + $rocket]); + + $mediaId = $rocket->getPayload()?->get('media_id') ?? null; + + if (empty($mediaId)) { + throw new InvalidParamsException(Exception::PARAMS_NECESSARY_PARAMS_MISSING, '参数异常: 图片请求接口,参数缺少 `media_id`'); + } + + $rocket->setPayload([ + '_method' => 'GET', + '_url' => 'v3/merchant-service/images/'.$mediaId, + '_service_url' => 'v3/merchant-service/images/'.$mediaId, + ]); + + Logger::info('[Wechat][Extend][Complaints][QueryImagePlugin] 插件装载完毕', ['rocket' => $rocket]); + + return $next($rocket); + } +} diff --git a/src/Plugin/Wechat/Extend/Complaints/QueryNegotiationPlugin.php b/src/Plugin/Wechat/Extend/Complaints/QueryNegotiationPlugin.php new file mode 100644 index 0000000..79bcb98 --- /dev/null +++ b/src/Plugin/Wechat/Extend/Complaints/QueryNegotiationPlugin.php @@ -0,0 +1,54 @@ + $rocket]); + + $payload = $rocket->getPayload(); + $complaintId = $payload?->get('complaint_id') ?? null; + + if (empty($complaintId)) { + throw new InvalidParamsException(Exception::PARAMS_NECESSARY_PARAMS_MISSING, '参数异常: 查询投诉单协商历史,参数缺少 `complaint_id`'); + } + + $query = $this->normal($payload); + + $rocket->setPayload([ + '_method' => 'GET', + '_url' => 'v3/merchant-service/complaints-v2/'.$complaintId.'/negotiation-historys'.$query, + '_service_url' => 'v3/merchant-service/complaints-v2/'.$complaintId.'/negotiation-historys'.$query, + ]); + + Logger::info('[Wechat][Extend][Complaints][QueryNegotiationPlugin] 插件装载完毕', ['rocket' => $rocket]); + + return $next($rocket); + } + + protected function normal(Collection $payload): string + { + $query = $payload->except('complaint_id')->query(); + + return empty($query) ? '' : '?'.$query; + } +} diff --git a/src/Plugin/Wechat/Extend/Complaints/QueryPlugin.php b/src/Plugin/Wechat/Extend/Complaints/QueryPlugin.php new file mode 100644 index 0000000..895af50 --- /dev/null +++ b/src/Plugin/Wechat/Extend/Complaints/QueryPlugin.php @@ -0,0 +1,45 @@ + $rocket]); + + $payload = $rocket->getPayload(); + + if (is_null($payload)) { + throw new InvalidParamsException(Exception::PARAMS_NECESSARY_PARAMS_MISSING, '参数异常: 查询投诉单列表,缺少必要参数'); + } + + $query = $payload->query(); + + $rocket->setPayload([ + '_method' => 'GET', + '_url' => 'v3/merchant-service/complaints-v2?'.$query, + '_service_url' => 'v3/merchant-service/complaints-v2?'.$query, + ]); + + Logger::info('[Wechat][Extend][Complaints][QueryPlugin] 插件装载完毕', ['rocket' => $rocket]); + + return $next($rocket); + } +} diff --git a/src/Plugin/Wechat/Extend/Complaints/ResponsePlugin.php b/src/Plugin/Wechat/Extend/Complaints/ResponsePlugin.php new file mode 100644 index 0000000..a397175 --- /dev/null +++ b/src/Plugin/Wechat/Extend/Complaints/ResponsePlugin.php @@ -0,0 +1,52 @@ + $rocket]); + + $config = get_wechat_config($rocket->getParams()); + $payload = $rocket->getPayload(); + $complaintId = $payload?->get('complaint_id') ?? null; + + if (empty($complaintId)) { + throw new InvalidParamsException(Exception::PARAMS_NECESSARY_PARAMS_MISSING, '参数异常: 回复用户,参数缺少 `complaint_id`'); + } + + $rocket->mergePayload([ + '_method' => 'POST', + '_url' => 'v3/merchant-service/complaints-v2/'.$complaintId.'/response', + '_service_url' => 'v3/merchant-service/complaints-v2/'.$complaintId.'/response', + 'complainted_mchid' => $payload->get('complainted_mchid', $config['mch_id']), + ])->exceptPayload('complaint_id'); + + Logger::info('[Wechat][Extend][Complaints][ResponsePlugin] 插件装载完毕', ['rocket' => $rocket]); + + return $next($rocket); + } +} diff --git a/src/Plugin/Wechat/Extend/Complaints/SetCallbackPlugin.php b/src/Plugin/Wechat/Extend/Complaints/SetCallbackPlugin.php new file mode 100644 index 0000000..29813a3 --- /dev/null +++ b/src/Plugin/Wechat/Extend/Complaints/SetCallbackPlugin.php @@ -0,0 +1,35 @@ + $rocket]); + + $payload = $rocket->getPayload(); + + $rocket->setPayload([ + '_method' => 'POST', + '_url' => 'v3/merchant-service/complaint-notifications', + '_service_url' => 'v3/merchant-service/complaint-notifications', + 'url' => $payload?->get('url', '') ?? '', + ]); + + Logger::info('[Wechat][Extend][Complaints][SetCallbackPlugin] 插件装载完毕', ['rocket' => $rocket]); + + return $next($rocket); + } +} diff --git a/src/Plugin/Wechat/Extend/Complaints/UpdateCallbackPlugin.php b/src/Plugin/Wechat/Extend/Complaints/UpdateCallbackPlugin.php new file mode 100644 index 0000000..a7d0332 --- /dev/null +++ b/src/Plugin/Wechat/Extend/Complaints/UpdateCallbackPlugin.php @@ -0,0 +1,35 @@ + $rocket]); + + $payload = $rocket->getPayload(); + + $rocket->setPayload([ + '_method' => 'PUT', + '_url' => 'v3/merchant-service/complaint-notifications', + '_service_url' => 'v3/merchant-service/complaint-notifications', + 'url' => $payload?->get('url', '') ?? '', + ]); + + Logger::info('[Wechat][Extend][Complaints][UpdateCallbackPlugin] 插件装载完毕', ['rocket' => $rocket]); + + return $next($rocket); + } +} diff --git a/src/Plugin/Wechat/Extend/Complaints/UpdateRefundPlugin.php b/src/Plugin/Wechat/Extend/Complaints/UpdateRefundPlugin.php new file mode 100644 index 0000000..4ed1be8 --- /dev/null +++ b/src/Plugin/Wechat/Extend/Complaints/UpdateRefundPlugin.php @@ -0,0 +1,43 @@ + $rocket]); + + $complaintId = $rocket->getPayload()?->get('complaint_id') ?? null; + + if (empty($complaintId)) { + throw new InvalidParamsException(Exception::PARAMS_NECESSARY_PARAMS_MISSING, '参数异常: 更新退款审批结果,参数缺少 `complaint_id`'); + } + + $rocket->mergePayload([ + '_method' => 'POST', + '_url' => 'v3/merchant-service/complaints-v2/'.$complaintId.'/update-refund-progress', + '_service_url' => 'v3/merchant-service/complaints-v2/'.$complaintId.'/update-refund-progress', + ])->exceptPayload('complaint_id'); + + Logger::info('[Wechat][Extend][Complaints][UpdateRefundPlugin] 插件装载完毕', ['rocket' => $rocket]); + + return $next($rocket); + } +} diff --git a/src/Plugin/Wechat/Extend/ProfitSharing/AddReceiverPlugin.php b/src/Plugin/Wechat/Extend/ProfitSharing/AddReceiverPlugin.php new file mode 100644 index 0000000..07c4ab9 --- /dev/null +++ b/src/Plugin/Wechat/Extend/ProfitSharing/AddReceiverPlugin.php @@ -0,0 +1,132 @@ + $rocket]); + + $params = $rocket->getParams(); + $config = get_wechat_config($params); + $payload = $rocket->getPayload(); + + if (is_null($payload)) { + throw new InvalidParamsException(Exception::PARAMS_NECESSARY_PARAMS_MISSING, '参数异常: 缺少分账参数'); + } + + if (Pay::MODE_SERVICE === ($config['mode'] ?? Pay::MODE_NORMAL)) { + $data = $this->service($payload, $params, $config); + } + + $rocket->mergePayload(array_merge( + [ + '_method' => 'POST', + '_url' => 'v3/profitsharing/receivers/add', + '_service_url' => 'v3/profitsharing/receivers/add', + ], + $data ?? $this->normal($payload, $params, $config), + )); + + Logger::info('[Wechat][Extend][ProfitSharing][AddReceiverPlugin] 插件装载完毕', ['rocket' => $rocket]); + + return $next($rocket); + } + + /** + * @throws ContainerException + * @throws DecryptException + * @throws InvalidConfigException + * @throws InvalidParamsException + * @throws ServiceNotFoundException + */ + protected function normal(Collection $payload, array $params, array $config): array + { + $data = [ + 'appid' => $config[get_wechat_type_key($params)] ?? '', + ]; + + if (!$payload->has('name')) { + return $data; + } + + return array_merge($data, $this->encryptSensitiveData($params, $config, $payload)); + } + + /** + * @throws ContainerException + * @throws DecryptException + * @throws InvalidConfigException + * @throws InvalidParamsException + * @throws ServiceNotFoundException + */ + protected function service(Collection $payload, array $params, array $config): array + { + $wechatTypeKey = get_wechat_type_key($params); + + $data = [ + 'sub_mchid' => $payload->get('sub_mchid', $config['sub_mch_id'] ?? ''), + 'appid' => $config[$wechatTypeKey] ?? '', + ]; + + if ('PERSONAL_SUB_OPENID' === $payload->get('type')) { + $data['sub_appid'] = $config['sub_'.$wechatTypeKey] ?? ''; + } + + if (!$payload->has('name')) { + return $data; + } + + return array_merge($data, $this->encryptSensitiveData($params, $config, $payload)); + } + + /** + * @throws ContainerException + * @throws DecryptException + * @throws InvalidConfigException + * @throws InvalidParamsException + * @throws ServiceNotFoundException + */ + protected function encryptSensitiveData(array $params, array $config, Collection $payload): array + { + $data['_serial_no'] = get_wechat_serial_no($params); + $publicKey = get_wechat_public_key($config, $data['_serial_no']); + + $data['name'] = encrypt_wechat_contents($payload->get('name'), $publicKey); + + return $data; + } +} diff --git a/src/Plugin/Wechat/Extend/ProfitSharing/CreatePlugin.php b/src/Plugin/Wechat/Extend/ProfitSharing/CreatePlugin.php new file mode 100644 index 0000000..5b70af1 --- /dev/null +++ b/src/Plugin/Wechat/Extend/ProfitSharing/CreatePlugin.php @@ -0,0 +1,134 @@ + $rocket]); + + $params = $rocket->getParams(); + $config = get_wechat_config($params); + $payload = $rocket->getPayload(); + + if (is_null($payload)) { + throw new InvalidParamsException(Exception::PARAMS_NECESSARY_PARAMS_MISSING, '参数异常: 缺少分账参数'); + } + + if (Pay::MODE_SERVICE === ($config['mode'] ?? Pay::MODE_NORMAL)) { + $data = $this->service($payload, $params, $config); + } + + $rocket->mergePayload(array_merge( + [ + '_method' => 'POST', + '_url' => 'v3/profitsharing/orders', + '_service_url' => 'v3/profitsharing/orders', + ], + $data ?? $this->normal($payload, $params, $config), + )); + + Logger::info('[Wechat][Extend][ProfitSharing][CreatePlugin] 插件装载完毕', ['rocket' => $rocket]); + + return $next($rocket); + } + + /** + * @throws ContainerException + * @throws DecryptException + * @throws InvalidConfigException + * @throws InvalidParamsException + * @throws ServiceNotFoundException + */ + protected function normal(Collection $payload, array $params, array $config): array + { + $data = [ + 'appid' => $config[get_wechat_type_key($params)] ?? '', + ]; + + if (!$payload->has('receivers.0.name')) { + return $data; + } + + return array_merge($data, $this->encryptSensitiveData($params, $config, $payload)); + } + + /** + * @throws ContainerException + * @throws DecryptException + * @throws InvalidConfigException + * @throws InvalidParamsException + * @throws ServiceNotFoundException + */ + protected function service(Collection $payload, array $params, array $config): array + { + $wechatTypeKey = get_wechat_type_key($params); + + $data = [ + 'sub_mchid' => $payload->get('sub_mchid', $config['sub_mch_id'] ?? ''), + 'appid' => $config[$wechatTypeKey] ?? '', + ]; + + if ('PERSONAL_SUB_OPENID' === $payload->get('receivers.0.type')) { + $data['sub_appid'] = $config['sub_'.$wechatTypeKey] ?? ''; + } + + if (!$payload->has('receivers.0.name')) { + return $data; + } + + return array_merge($data, $this->encryptSensitiveData($params, $config, $payload)); + } + + /** + * @throws ContainerException + * @throws DecryptException + * @throws InvalidConfigException + * @throws InvalidParamsException + * @throws ServiceNotFoundException + */ + protected function encryptSensitiveData(array $params, array $config, Collection $payload): array + { + $data['_serial_no'] = get_wechat_serial_no($params); + $publicKey = get_wechat_public_key($config, $data['_serial_no']); + + foreach ($payload->get('receivers', []) as $key => $list) { + $data['receivers'][$key]['name'] = encrypt_wechat_contents($list['name'], $publicKey); + } + + return $data; + } +} diff --git a/src/Plugin/Wechat/Extend/ProfitSharing/DeleteReceiverPlugin.php b/src/Plugin/Wechat/Extend/ProfitSharing/DeleteReceiverPlugin.php new file mode 100644 index 0000000..09f476b --- /dev/null +++ b/src/Plugin/Wechat/Extend/ProfitSharing/DeleteReceiverPlugin.php @@ -0,0 +1,84 @@ + $rocket]); + + $params = $rocket->getParams(); + $config = get_wechat_config($params); + $payload = $rocket->getPayload(); + + if (is_null($payload)) { + throw new InvalidParamsException(Exception::PARAMS_NECESSARY_PARAMS_MISSING, '参数异常: 缺少分账参数'); + } + + if (Pay::MODE_SERVICE === ($config['mode'] ?? Pay::MODE_NORMAL)) { + $data = $this->service($payload, $params, $config); + } + + $rocket->mergePayload(array_merge( + [ + '_method' => 'POST', + '_url' => 'v3/profitsharing/receivers/delete', + '_service_url' => 'v3/profitsharing/receivers/delete', + ], + $data ?? $this->normal($params, $config), + )); + + Logger::info('[Wechat][Extend][ProfitSharing][DeleteReceiverPlugin] 插件装载完毕', ['rocket' => $rocket]); + + return $next($rocket); + } + + protected function normal(array $params, array $config): array + { + return [ + 'appid' => $config[get_wechat_type_key($params)] ?? '', + ]; + } + + protected function service(Collection $payload, array $params, array $config): array + { + $wechatTypeKEY = get_wechat_type_key($params); + + $data = [ + 'sub_mchid' => $payload->get('sub_mchid', $config['sub_mch_id'] ?? ''), + 'appid' => $config[$wechatTypeKEY] ?? '', + ]; + + if ('PERSONAL_SUB_OPENID' === $payload->get('type')) { + $data['sub_appid'] = $config['sub_'.$wechatTypeKEY] ?? ''; + } + + return $data; + } +} diff --git a/src/Plugin/Wechat/Extend/ProfitSharing/DownloadBillPlugin.php b/src/Plugin/Wechat/Extend/ProfitSharing/DownloadBillPlugin.php new file mode 100644 index 0000000..c0159cc --- /dev/null +++ b/src/Plugin/Wechat/Extend/ProfitSharing/DownloadBillPlugin.php @@ -0,0 +1,43 @@ + $rocket]); + + $downloadUrl = $rocket->getPayload()?->get('download_url') ?? null; + + if (empty($downloadUrl)) { + throw new InvalidParamsException(Exception::PARAMS_NECESSARY_PARAMS_MISSING, '参数异常: 下载电子回单,参数缺少 `download_url`'); + } + + $rocket->setPayload([ + '_method' => 'GET', + '_url' => $downloadUrl, + '_service_url' => $downloadUrl, + ]); + + Logger::info('[Wechat][Extend][ProfitSharing][DownloadBillPlugin] 插件装载完毕', ['rocket' => $rocket]); + + return $next($rocket); + } +} diff --git a/src/Plugin/Wechat/Extend/ProfitSharing/QueryAmountsPlugin.php b/src/Plugin/Wechat/Extend/ProfitSharing/QueryAmountsPlugin.php new file mode 100644 index 0000000..69e9d5d --- /dev/null +++ b/src/Plugin/Wechat/Extend/ProfitSharing/QueryAmountsPlugin.php @@ -0,0 +1,43 @@ + $rocket]); + + $transactionId = $rocket->getPayload()?->get('transaction_id'); + + if (is_null($transactionId)) { + throw new InvalidParamsException(Exception::PARAMS_NECESSARY_PARAMS_MISSING, '参数异常: 查询剩余待分金额,参数缺少 `transaction_id`'); + } + + $rocket->setPayload([ + '_method' => 'GET', + '_url' => 'v3/profitsharing/transactions/'.$transactionId.'/amounts', + '_service_url' => 'v3/profitsharing/transactions/'.$transactionId.'/amounts', + ]); + + Logger::info('[Wechat][Extend][ProfitSharing][QueryAmountsPlugin] 插件装载完毕', ['rocket' => $rocket]); + + return $next($rocket); + } +} diff --git a/src/Plugin/Wechat/Extend/ProfitSharing/QueryMerchantConfigsPlugin.php b/src/Plugin/Wechat/Extend/ProfitSharing/QueryMerchantConfigsPlugin.php new file mode 100644 index 0000000..b415b12 --- /dev/null +++ b/src/Plugin/Wechat/Extend/ProfitSharing/QueryMerchantConfigsPlugin.php @@ -0,0 +1,50 @@ + $rocket]); + + $payload = $rocket->getPayload(); + $config = get_wechat_config($rocket->getParams()); + $subMchId = $payload?->get('sub_mch_id') ?? $config['sub_mch_id'] ?? 'null'; + + if (Pay::MODE_NORMAL === ($config['mode'] ?? Pay::MODE_NORMAL)) { + throw new InvalidParamsException(Exception::PARAMS_PLUGIN_ONLY_SUPPORT_SERVICE_MODE, '参数异常: 查询最大分账比例,只支持服务商模式,当前配置为普通商户模式'); + } + + $rocket->setPayload([ + '_method' => 'GET', + '_service_url' => 'v3/profitsharing/merchant-configs/'.$subMchId, + ]); + + Logger::info('[Wechat][Extend][ProfitSharing][QueryMerchantConfigsPlugin] 插件装载完毕', ['rocket' => $rocket]); + + return $next($rocket); + } +} diff --git a/src/Plugin/Wechat/Extend/ProfitSharing/QueryPlugin.php b/src/Plugin/Wechat/Extend/ProfitSharing/QueryPlugin.php new file mode 100644 index 0000000..6c1cfca --- /dev/null +++ b/src/Plugin/Wechat/Extend/ProfitSharing/QueryPlugin.php @@ -0,0 +1,53 @@ + $rocket]); + + $config = get_wechat_config($rocket->getParams()); + $payload = $rocket->getPayload(); + $outOrderNo = $payload?->get('out_order_no') ?? null; + $transactionId = $payload?->get('transaction_id') ?? null; + $subMchId = $payload?->get('sub_mchid') ?? $config['sub_mch_id'] ?? 'null'; + + if (empty($outOrderNo) || empty($transactionId)) { + throw new InvalidParamsException(Exception::PARAMS_NECESSARY_PARAMS_MISSING, '参数异常: 查询分账结果, 缺少必要参数 `out_order_no`, `transaction_id`'); + } + + $rocket->setPayload([ + '_method' => 'GET', + '_url' => 'v3/profitsharing/orders/'.$outOrderNo.'?transaction_id='.$transactionId, + '_service_url' => 'v3/profitsharing/orders/'.$outOrderNo.'?sub_mchid='.$subMchId.'&transaction_id='.$transactionId, + ]); + + Logger::info('[Wechat][Extend][ProfitSharing][QueryPlugin] 插件装载完毕', ['rocket' => $rocket]); + + return $next($rocket); + } +} diff --git a/src/Plugin/Wechat/Extend/ProfitSharing/QueryReturnPlugin.php b/src/Plugin/Wechat/Extend/ProfitSharing/QueryReturnPlugin.php new file mode 100644 index 0000000..40e9293 --- /dev/null +++ b/src/Plugin/Wechat/Extend/ProfitSharing/QueryReturnPlugin.php @@ -0,0 +1,53 @@ + $rocket]); + + $config = get_wechat_config($rocket->getParams()); + $payload = $rocket->getPayload(); + $outOrderNo = $payload?->get('out_order_no') ?? null; + $outReturnNo = $payload?->get('out_return_no') ?? null; + $subMchId = $payload?->get('sub_mchid') ?? $config['sub_mch_id'] ?? 'null'; + + if (empty($outOrderNo) || empty($outReturnNo)) { + throw new InvalidParamsException(Exception::PARAMS_NECESSARY_PARAMS_MISSING, '参数异常: 查询分账结果, 缺少必要参数 `out_order_no`, `out_return_no`'); + } + + $rocket->setPayload([ + '_method' => 'GET', + '_url' => 'v3/profitsharing/return-orders/'.$outReturnNo.'?out_order_no='.$outOrderNo, + '_service_url' => 'v3/profitsharing/return-orders/'.$outReturnNo.'?sub_mchid='.$subMchId.'&out_order_no='.$outOrderNo, + ]); + + Logger::info('[Wechat][Extend][ProfitSharing][QueryReturnPlugin] 插件装载完毕', ['rocket' => $rocket]); + + return $next($rocket); + } +} diff --git a/src/Plugin/Wechat/Extend/ProfitSharing/ReturnPlugin.php b/src/Plugin/Wechat/Extend/ProfitSharing/ReturnPlugin.php new file mode 100644 index 0000000..d9a9e91 --- /dev/null +++ b/src/Plugin/Wechat/Extend/ProfitSharing/ReturnPlugin.php @@ -0,0 +1,75 @@ + $rocket]); + + $params = $rocket->getParams(); + $config = get_wechat_config($params); + $payload = $rocket->getPayload(); + + if (is_null($payload)) { + throw new InvalidParamsException(Exception::PARAMS_NECESSARY_PARAMS_MISSING, '参数异常: 缺少分账参数'); + } + + if (Pay::MODE_SERVICE === ($config['mode'] ?? Pay::MODE_NORMAL)) { + $data = $this->service($payload, $config); + } + + $rocket->mergePayload(array_merge( + [ + '_method' => 'POST', + '_url' => 'v3/profitsharing/return-orders', + '_service_url' => 'v3/profitsharing/return-orders', + ], + $data ?? $this->normal($payload, $config), + )); + + Logger::info('[Wechat][Extend][ProfitSharing][ReturnPlugin] 插件装载完毕', ['rocket' => $rocket]); + + return $next($rocket); + } + + protected function normal(Collection $payload, array $config): array + { + return [ + 'return_mchid' => $payload->get('return_mchid', $config['mch_id'] ?? ''), + ]; + } + + protected function service(Collection $payload, array $config): array + { + return [ + 'sub_mchid' => $payload->get('sub_mchid', $config['sub_mch_id'] ?? ''), + 'return_mchid' => $payload->get('return_mchid', $config['mch_id'] ?? ''), + ]; + } +} diff --git a/src/Plugin/Wechat/Extend/ProfitSharing/UnfreezePlugin.php b/src/Plugin/Wechat/Extend/ProfitSharing/UnfreezePlugin.php new file mode 100644 index 0000000..0aaf588 --- /dev/null +++ b/src/Plugin/Wechat/Extend/ProfitSharing/UnfreezePlugin.php @@ -0,0 +1,73 @@ + $rocket]); + + $params = $rocket->getParams(); + $config = get_wechat_config($params); + $payload = $rocket->getPayload(); + + if (is_null($payload)) { + throw new InvalidParamsException(Exception::PARAMS_NECESSARY_PARAMS_MISSING, '参数异常: 缺少分账参数'); + } + + if (Pay::MODE_SERVICE === ($config['mode'] ?? Pay::MODE_NORMAL)) { + $data = $this->service($payload, $config); + } + + $rocket->mergePayload(array_merge( + [ + '_method' => 'POST', + '_url' => 'v3/profitsharing/orders/unfreeze', + '_service_url' => 'v3/profitsharing/orders/unfreeze', + ], + $data ?? $this->normal(), + )); + + Logger::info('[Wechat][Extend][ProfitSharing][UnfreezePlugin] 插件装载完毕', ['rocket' => $rocket]); + + return $next($rocket); + } + + protected function normal(): array + { + return []; + } + + protected function service(Collection $payload, array $config): array + { + return [ + 'sub_mchid' => $payload->get('sub_mchid', $config['sub_mch_id'] ?? ''), + 'notify_url' => $payload->get('notify_url', $config['notify_url'] ?? null), + ]; + } +} diff --git a/src/Plugin/Wechat/Fund/Balance/QueryDayEndPlugin.php b/src/Plugin/Wechat/Fund/Balance/QueryDayEndPlugin.php deleted file mode 100644 index b97d908..0000000 --- a/src/Plugin/Wechat/Fund/Balance/QueryDayEndPlugin.php +++ /dev/null @@ -1,36 +0,0 @@ -getPayload(); - - if (!$payload->has('account_type') || !$payload->has('date')) { - throw new InvalidParamsException(Exception::PARAMS_NECESSARY_PARAMS_MISSING); - } - - return 'v3/merchant/fund/dayendbalance/'. - $payload->get('account_type'). - '?date='.$payload->get('date'); - } -} diff --git a/src/Plugin/Wechat/Fund/Balance/QueryPlugin.php b/src/Plugin/Wechat/Fund/Balance/QueryPlugin.php deleted file mode 100644 index b100d74..0000000 --- a/src/Plugin/Wechat/Fund/Balance/QueryPlugin.php +++ /dev/null @@ -1,35 +0,0 @@ -getPayload(); - - if (!$payload->has('account_type')) { - throw new InvalidParamsException(Exception::PARAMS_NECESSARY_PARAMS_MISSING); - } - - return 'v3/merchant/fund/balance/'. - $payload->get('account_type'); - } -} diff --git a/src/Plugin/Wechat/Fund/Profitsharing/AddReceiverPlugin.php b/src/Plugin/Wechat/Fund/Profitsharing/AddReceiverPlugin.php deleted file mode 100644 index 6510ca5..0000000 --- a/src/Plugin/Wechat/Fund/Profitsharing/AddReceiverPlugin.php +++ /dev/null @@ -1,83 +0,0 @@ -getParams(); - $config = get_wechat_config($rocket->getParams()); - $extra = $this->getWechatId($config, $rocket->getPayload()); - - if (!empty($params['name'] ?? '')) { - $params = $this->loadSerialNo($params); - - $name = $this->getEncryptUserName($params); - $params['name'] = $name; - $extra['name'] = $name; - $rocket->setParams($params); - } - - $rocket->mergePayload($extra); - } - - protected function getUri(Rocket $rocket): string - { - return 'v3/profitsharing/receivers/add'; - } - - protected function getWechatId(array $config, Collection $payload): array - { - $wechatId = [ - 'appid' => $config['mp_app_id'] ?? null, - ]; - - if (Pay::MODE_SERVICE === ($config['mode'] ?? null)) { - $wechatId['sub_mchid'] = $payload->get('sub_mchid', $config['sub_mch_id'] ?? ''); - } - - return $wechatId; - } - - /** - * @throws ContainerException - * @throws InvalidParamsException - * @throws ServiceNotFoundException - */ - protected function getEncryptUserName(array $params): string - { - $name = $params['name'] ?? ''; - $publicKey = $this->getPublicKey($params, $params['_serial_no'] ?? ''); - - return encrypt_wechat_contents($name, $publicKey); - } -} diff --git a/src/Plugin/Wechat/Fund/Profitsharing/CreatePlugin.php b/src/Plugin/Wechat/Fund/Profitsharing/CreatePlugin.php deleted file mode 100644 index 9f4cc66..0000000 --- a/src/Plugin/Wechat/Fund/Profitsharing/CreatePlugin.php +++ /dev/null @@ -1,89 +0,0 @@ -getPayload(); - $params = $this->loadSerialNo($rocket->getParams()); - - $extra = $this->getWechatExtra($params, $payload); - $extra['receivers'] = $this->getReceivers($params); - - $rocket->setParams($params); - $rocket->mergePayload($extra); - } - - protected function getUri(Rocket $rocket): string - { - return 'v3/profitsharing/orders'; - } - - /** - * @throws ContainerException - * @throws ServiceNotFoundException - */ - protected function getWechatExtra(array $params, Collection $payload): array - { - $config = get_wechat_config($params); - - $extra = [ - 'appid' => $config['mp_app_id'] ?? null, - ]; - - if (Pay::MODE_SERVICE === ($config['mode'] ?? null)) { - $extra['sub_mchid'] = $payload->get('sub_mchid', $config['sub_mch_id'] ?? ''); - } - - return $extra; - } - - /** - * @throws ContainerException - * @throws InvalidParamsException - * @throws ServiceNotFoundException - */ - protected function getReceivers(array $params): array - { - $publicKey = $this->getPublicKey($params, $params['_serial_no'] ?? ''); - $receivers = $params['receivers'] ?? []; - - foreach ($receivers as $key => $receiver) { - if (!empty($receiver['name'])) { - $receivers[$key]['name'] = encrypt_wechat_contents($receiver['name'], $publicKey); - } - } - - return $receivers; - } -} diff --git a/src/Plugin/Wechat/Fund/Profitsharing/DeleteReceiverPlugin.php b/src/Plugin/Wechat/Fund/Profitsharing/DeleteReceiverPlugin.php deleted file mode 100644 index 5dd692e..0000000 --- a/src/Plugin/Wechat/Fund/Profitsharing/DeleteReceiverPlugin.php +++ /dev/null @@ -1,44 +0,0 @@ -getParams()); - - $wechatId = [ - 'appid' => $config['mp_app_id'] ?? null, - ]; - - if (Pay::MODE_SERVICE === ($config['mode'] ?? null)) { - $wechatId['sub_mchid'] = $rocket->getPayload() - ->get('sub_mchid', $config['sub_mch_id'] ?? ''); - } - - $rocket->mergePayload($wechatId); - } - - protected function getUri(Rocket $rocket): string - { - return 'v3/profitsharing/receivers/delete'; - } -} diff --git a/src/Plugin/Wechat/Fund/Profitsharing/DownloadBillPlugin.php b/src/Plugin/Wechat/Fund/Profitsharing/DownloadBillPlugin.php deleted file mode 100644 index f0fd516..0000000 --- a/src/Plugin/Wechat/Fund/Profitsharing/DownloadBillPlugin.php +++ /dev/null @@ -1,43 +0,0 @@ -getPayload(); - - if (!$payload->has('download_url')) { - throw new InvalidParamsException(Exception::PARAMS_NECESSARY_PARAMS_MISSING); - } - - return $payload->get('download_url'); - } - - protected function getMethod(): string - { - return 'GET'; - } - - protected function doSomething(Rocket $rocket): void - { - $rocket->setDirection(OriginResponseDirection::class); - - $rocket->setPayload(null); - } -} diff --git a/src/Plugin/Wechat/Fund/Profitsharing/QueryAmountsPlugin.php b/src/Plugin/Wechat/Fund/Profitsharing/QueryAmountsPlugin.php deleted file mode 100644 index a87359c..0000000 --- a/src/Plugin/Wechat/Fund/Profitsharing/QueryAmountsPlugin.php +++ /dev/null @@ -1,42 +0,0 @@ -setPayload(null); - } - - /** - * @throws InvalidParamsException - */ - protected function getUri(Rocket $rocket): string - { - $payload = $rocket->getPayload(); - - if (!$payload->has('transaction_id')) { - throw new InvalidParamsException(Exception::PARAMS_NECESSARY_PARAMS_MISSING); - } - - return 'v3/profitsharing/transactions/'. - $payload->get('transaction_id'). - '/amounts'; - } -} diff --git a/src/Plugin/Wechat/Fund/Profitsharing/QueryMerchantConfigsPlugin.php b/src/Plugin/Wechat/Fund/Profitsharing/QueryMerchantConfigsPlugin.php deleted file mode 100644 index 04f4c1f..0000000 --- a/src/Plugin/Wechat/Fund/Profitsharing/QueryMerchantConfigsPlugin.php +++ /dev/null @@ -1,49 +0,0 @@ -setPayload(null); - } - - /** - * @throws ContainerException - * @throws InvalidParamsException - * @throws ServiceNotFoundException - */ - protected function getUri(Rocket $rocket): string - { - $config = get_wechat_config($rocket->getParams()); - $payload = $rocket->getPayload(); - - if (Pay::MODE_SERVICE !== ($config['mode'] ?? Pay::MODE_NORMAL)) { - throw new InvalidParamsException(Exception::PARAMS_METHOD_NOT_SUPPORTED); - } - - return 'v3/profitsharing/merchant-configs/'. - $payload->get('sub_mchid', $config['sub_mch_id'] ?? ''); - } -} diff --git a/src/Plugin/Wechat/Fund/Profitsharing/QueryPlugin.php b/src/Plugin/Wechat/Fund/Profitsharing/QueryPlugin.php deleted file mode 100644 index 390f419..0000000 --- a/src/Plugin/Wechat/Fund/Profitsharing/QueryPlugin.php +++ /dev/null @@ -1,56 +0,0 @@ -setPayload(null); - } - - /** - * @throws ContainerException - * @throws InvalidParamsException - * @throws ServiceNotFoundException - */ - protected function getUri(Rocket $rocket): string - { - $payload = $rocket->getPayload(); - $config = get_wechat_config($rocket->getParams()); - - if (!$payload->has('out_order_no') || !$payload->has('transaction_id')) { - throw new InvalidParamsException(Exception::PARAMS_NECESSARY_PARAMS_MISSING); - } - - $url = 'v3/profitsharing/orders/'. - $payload->get('out_order_no'). - '?transaction_id='.$payload->get('transaction_id'); - - if (Pay::MODE_SERVICE === ($config['mode'] ?? null)) { - $url .= '&sub_mchid='.$payload->get('sub_mchid', $config['sub_mch_id'] ?? ''); - } - - return $url; - } -} diff --git a/src/Plugin/Wechat/Fund/Profitsharing/QueryReturnPlugin.php b/src/Plugin/Wechat/Fund/Profitsharing/QueryReturnPlugin.php deleted file mode 100644 index 286dc98..0000000 --- a/src/Plugin/Wechat/Fund/Profitsharing/QueryReturnPlugin.php +++ /dev/null @@ -1,56 +0,0 @@ -setPayload(null); - } - - /** - * @throws ContainerException - * @throws InvalidParamsException - * @throws ServiceNotFoundException - */ - protected function getUri(Rocket $rocket): string - { - $payload = $rocket->getPayload(); - $config = get_wechat_config($rocket->getParams()); - - if (!$payload->has('out_return_no') || !$payload->has('out_order_no')) { - throw new InvalidParamsException(Exception::PARAMS_NECESSARY_PARAMS_MISSING); - } - - $url = 'v3/profitsharing/return-orders/'. - $payload->get('out_return_no'). - '?out_order_no='.$payload->get('out_order_no'); - - if (Pay::MODE_SERVICE === ($config['mode'] ?? null)) { - $url .= '&sub_mchid='.$payload->get('sub_mchid', $config['sub_mch_id'] ?? ''); - } - - return $url; - } -} diff --git a/src/Plugin/Wechat/Fund/Profitsharing/ReturnPlugin.php b/src/Plugin/Wechat/Fund/Profitsharing/ReturnPlugin.php deleted file mode 100644 index 5e0f37a..0000000 --- a/src/Plugin/Wechat/Fund/Profitsharing/ReturnPlugin.php +++ /dev/null @@ -1,40 +0,0 @@ -getParams()); - - if (Pay::MODE_SERVICE === ($config['mode'] ?? null)) { - $rocket->mergePayload([ - 'sub_mchid' => $rocket->getPayload() - ->get('sub_mchid', $config['sub_mch_id'] ?? ''), - ]); - } - } - - protected function getUri(Rocket $rocket): string - { - return 'v3/profitsharing/return-orders'; - } -} diff --git a/src/Plugin/Wechat/Fund/Profitsharing/UnfreezePlugin.php b/src/Plugin/Wechat/Fund/Profitsharing/UnfreezePlugin.php deleted file mode 100644 index 5ccb837..0000000 --- a/src/Plugin/Wechat/Fund/Profitsharing/UnfreezePlugin.php +++ /dev/null @@ -1,40 +0,0 @@ -getPayload(); - $config = get_wechat_config($rocket->getParams()); - - if (Pay::MODE_SERVICE === ($config['mode'] ?? null) && !$payload->has('sub_mchid')) { - $rocket->mergePayload([ - 'sub_mchid' => $config['sub_mch_id'] ?? '', - ]); - } - } - - protected function getUri(Rocket $rocket): string - { - return 'v3/profitsharing/orders/unfreeze'; - } -} diff --git a/src/Plugin/Wechat/Fund/Transfer/CreateBillReceiptPlugin.php b/src/Plugin/Wechat/Fund/Transfer/CreateBillReceiptPlugin.php deleted file mode 100644 index b1539a5..0000000 --- a/src/Plugin/Wechat/Fund/Transfer/CreateBillReceiptPlugin.php +++ /dev/null @@ -1,33 +0,0 @@ -getPayload(); - - if (!$payload->has('out_batch_no')) { - throw new InvalidParamsException(Exception::PARAMS_NECESSARY_PARAMS_MISSING); - } - } - - protected function getUri(Rocket $rocket): string - { - return 'v3/transfer/bill-receipt'; - } -} diff --git a/src/Plugin/Wechat/Fund/Transfer/CreateDetailReceiptPlugin.php b/src/Plugin/Wechat/Fund/Transfer/CreateDetailReceiptPlugin.php deleted file mode 100644 index 4a970e1..0000000 --- a/src/Plugin/Wechat/Fund/Transfer/CreateDetailReceiptPlugin.php +++ /dev/null @@ -1,33 +0,0 @@ -getPayload(); - - if (!$payload->has('out_detail_no') || !$payload->has('accept_type')) { - throw new InvalidParamsException(Exception::PARAMS_NECESSARY_PARAMS_MISSING); - } - } - - protected function getUri(Rocket $rocket): string - { - return 'v3/transfer-detail/electronic-receipts'; - } -} diff --git a/src/Plugin/Wechat/Fund/Transfer/CreatePlugin.php b/src/Plugin/Wechat/Fund/Transfer/CreatePlugin.php deleted file mode 100644 index a8459a4..0000000 --- a/src/Plugin/Wechat/Fund/Transfer/CreatePlugin.php +++ /dev/null @@ -1,99 +0,0 @@ -getParams(); - $extra = $this->getWechatId($params, $rocket->getPayload()); - - if (!empty($params['transfer_detail_list'][0]['user_name'] ?? '')) { - $params = $this->loadSerialNo($params); - - $rocket->setParams($params); - - $extra['transfer_detail_list'] = $this->getEncryptUserName($params); - } - - $rocket->mergePayload($extra); - } - - protected function getUri(Rocket $rocket): string - { - return 'v3/transfer/batches'; - } - - protected function getPartnerUri(Rocket $rocket): string - { - return 'v3/partner-transfer/batches'; - } - - /** - * @throws ContainerException - * @throws ServiceNotFoundException - */ - protected function getWechatId(array $params, Collection $payload): array - { - $config = get_wechat_config($params); - $key = $this->getConfigKey($params); - - $appId = [ - 'appid' => $payload->get('appid', $config[$key] ?? ''), - ]; - - if (Pay::MODE_SERVICE === ($config['mode'] ?? null)) { - $appId = [ - 'sub_mchid' => $payload->get('sub_mchid', $config['sub_mch_id'] ?? ''), - ]; - } - - return $appId; - } - - /** - * @throws ContainerException - * @throws InvalidParamsException - * @throws ServiceNotFoundException - */ - protected function getEncryptUserName(array $params): array - { - $lists = $params['transfer_detail_list'] ?? []; - $publicKey = $this->getPublicKey($params, $params['_serial_no'] ?? ''); - - foreach ($lists as $key => $list) { - $lists[$key]['user_name'] = encrypt_wechat_contents($list['user_name'], $publicKey); - } - - return $lists; - } -} diff --git a/src/Plugin/Wechat/Fund/Transfer/DownloadReceiptPlugin.php b/src/Plugin/Wechat/Fund/Transfer/DownloadReceiptPlugin.php deleted file mode 100644 index 74efe2e..0000000 --- a/src/Plugin/Wechat/Fund/Transfer/DownloadReceiptPlugin.php +++ /dev/null @@ -1,43 +0,0 @@ -getPayload(); - - if (!$payload->has('download_url')) { - throw new InvalidParamsException(Exception::PARAMS_NECESSARY_PARAMS_MISSING); - } - - return $payload->get('download_url'); - } - - protected function getMethod(): string - { - return 'GET'; - } - - protected function doSomething(Rocket $rocket): void - { - $rocket->setDirection(OriginResponseDirection::class); - - $rocket->setPayload(null); - } -} diff --git a/src/Plugin/Wechat/Fund/Transfer/QueryBatchDetailIdPlugin.php b/src/Plugin/Wechat/Fund/Transfer/QueryBatchDetailIdPlugin.php deleted file mode 100644 index 7083c86..0000000 --- a/src/Plugin/Wechat/Fund/Transfer/QueryBatchDetailIdPlugin.php +++ /dev/null @@ -1,60 +0,0 @@ -setPayload(null); - } - - /** - * @throws InvalidParamsException - */ - protected function getUri(Rocket $rocket): string - { - $payload = $rocket->getPayload(); - - if (!$payload->has('batch_id') || !$payload->get('detail_id')) { - throw new InvalidParamsException(Exception::PARAMS_NECESSARY_PARAMS_MISSING); - } - - return 'v3/transfer/batches/batch-id/'. - $payload->get('batch_id'). - '/details/detail-id/'. - $payload->get('detail_id'); - } - - /** - * @throws InvalidParamsException - */ - protected function getPartnerUri(Rocket $rocket): string - { - $payload = $rocket->getPayload(); - - if (!$payload->has('batch_id') || !$payload->has('detail_id')) { - throw new InvalidParamsException(Exception::PARAMS_NECESSARY_PARAMS_MISSING); - } - - return 'v3/partner-transfer/batches/batch-id/'. - $payload->get('batch_id'). - '/details/detail-id/'. - $payload->get('detail_id'); - } -} diff --git a/src/Plugin/Wechat/Fund/Transfer/QueryBatchIdPlugin.php b/src/Plugin/Wechat/Fund/Transfer/QueryBatchIdPlugin.php deleted file mode 100644 index de13c79..0000000 --- a/src/Plugin/Wechat/Fund/Transfer/QueryBatchIdPlugin.php +++ /dev/null @@ -1,64 +0,0 @@ -setPayload(null); - } - - /** - * @throws InvalidParamsException - */ - protected function getUri(Rocket $rocket): string - { - $payload = $rocket->getPayload(); - - if (!$payload->has('batch_id') || !$payload->has('need_query_detail')) { - throw new InvalidParamsException(Exception::PARAMS_NECESSARY_PARAMS_MISSING); - } - - $batchId = $payload->get('batch_id'); - - $payload->forget('batch_id'); - - return 'v3/transfer/batches/batch-id/'.$batchId. - '?'.$payload->query(); - } - - /** - * @throws InvalidParamsException - */ - protected function getPartnerUri(Rocket $rocket): string - { - $payload = $rocket->getPayload(); - - if (!$payload->has('batch_id') || !$payload->has('need_query_detail')) { - throw new InvalidParamsException(Exception::PARAMS_NECESSARY_PARAMS_MISSING); - } - - $batchId = $payload->get('batch_id'); - - $payload->forget('batch_id'); - - return 'v3/partner-transfer/batches/batch-id/'.$batchId. - '?'.$payload->query(); - } -} diff --git a/src/Plugin/Wechat/Fund/Transfer/QueryBillReceiptPlugin.php b/src/Plugin/Wechat/Fund/Transfer/QueryBillReceiptPlugin.php deleted file mode 100644 index 781eca2..0000000 --- a/src/Plugin/Wechat/Fund/Transfer/QueryBillReceiptPlugin.php +++ /dev/null @@ -1,40 +0,0 @@ -setPayload(null); - } - - /** - * @throws InvalidParamsException - */ - protected function getUri(Rocket $rocket): string - { - $payload = $rocket->getPayload(); - - if (!$payload->has('out_batch_no')) { - throw new InvalidParamsException(Exception::PARAMS_NECESSARY_PARAMS_MISSING); - } - - return 'v3/transfer/bill-receipt/'.$payload->get('out_batch_no'); - } -} diff --git a/src/Plugin/Wechat/Fund/Transfer/QueryDetailReceiptPlugin.php b/src/Plugin/Wechat/Fund/Transfer/QueryDetailReceiptPlugin.php deleted file mode 100644 index 2a120cc..0000000 --- a/src/Plugin/Wechat/Fund/Transfer/QueryDetailReceiptPlugin.php +++ /dev/null @@ -1,40 +0,0 @@ -getPayload(); - - if (!$payload->has('out_detail_no') || !$payload->has('accept_type')) { - throw new InvalidParamsException(Exception::PARAMS_NECESSARY_PARAMS_MISSING); - } - - $rocket->setPayload(null); - } - - protected function getUri(Rocket $rocket): string - { - return 'v3/transfer-detail/electronic-receipts?'.$rocket->getPayload()->query(); - } -} diff --git a/src/Plugin/Wechat/Fund/Transfer/QueryOutBatchDetailNoPlugin.php b/src/Plugin/Wechat/Fund/Transfer/QueryOutBatchDetailNoPlugin.php deleted file mode 100644 index d3d860d..0000000 --- a/src/Plugin/Wechat/Fund/Transfer/QueryOutBatchDetailNoPlugin.php +++ /dev/null @@ -1,60 +0,0 @@ -setPayload(null); - } - - /** - * @throws InvalidParamsException - */ - protected function getUri(Rocket $rocket): string - { - $payload = $rocket->getPayload(); - - if (!$payload->has('out_batch_no') || !$payload->has('out_detail_no')) { - throw new InvalidParamsException(Exception::PARAMS_NECESSARY_PARAMS_MISSING); - } - - return 'v3/transfer/batches/out-batch-no/'. - $payload->get('out_batch_no'). - '/details/out-detail-no/'. - $payload->get('out_detail_no'); - } - - /** - * @throws InvalidParamsException - */ - protected function getPartnerUri(Rocket $rocket): string - { - $payload = $rocket->getPayload(); - - if (!$payload->has('out_batch_no') || !$payload->has('out_detail_no')) { - throw new InvalidParamsException(Exception::PARAMS_NECESSARY_PARAMS_MISSING); - } - - return 'v3/partner-transfer/batches/out-batch-no/'. - $payload->get('out_batch_no'). - '/details/out-detail-no/'. - $payload->get('out_detail_no'); - } -} diff --git a/src/Plugin/Wechat/Fund/Transfer/QueryOutBatchNoPlugin.php b/src/Plugin/Wechat/Fund/Transfer/QueryOutBatchNoPlugin.php deleted file mode 100644 index 2882610..0000000 --- a/src/Plugin/Wechat/Fund/Transfer/QueryOutBatchNoPlugin.php +++ /dev/null @@ -1,64 +0,0 @@ -setPayload(null); - } - - /** - * @throws InvalidParamsException - */ - protected function getUri(Rocket $rocket): string - { - $payload = $rocket->getPayload(); - - if (!$payload->has('out_batch_no') || !$payload->has('need_query_detail')) { - throw new InvalidParamsException(Exception::PARAMS_NECESSARY_PARAMS_MISSING); - } - - $outBatchNo = $payload->get('out_batch_no'); - - $payload->forget('out_batch_no'); - - return 'v3/transfer/batches/out-batch-no/'.$outBatchNo. - '?'.$payload->query(); - } - - /** - * @throws InvalidParamsException - */ - protected function getPartnerUri(Rocket $rocket): string - { - $payload = $rocket->getPayload(); - - if (!$payload->has('out_batch_no') || !$payload->has('need_query_detail')) { - throw new InvalidParamsException(Exception::PARAMS_NECESSARY_PARAMS_MISSING); - } - - $outBatchNo = $payload->get('out_batch_no'); - - $payload->forget('out_batch_no'); - - return 'v3/partner-transfer/batches/out-batch-no/'.$outBatchNo. - '?'.$payload->query(); - } -} diff --git a/src/Plugin/Wechat/GeneralPlugin.php b/src/Plugin/Wechat/GeneralPlugin.php deleted file mode 100644 index aa0cb03..0000000 --- a/src/Plugin/Wechat/GeneralPlugin.php +++ /dev/null @@ -1,97 +0,0 @@ - $rocket]); - - $rocket->setRadar($this->getRequest($rocket)); - $this->doSomething($rocket); - - Logger::info('[wechat][GeneralPlugin] 通用插件装载完毕', ['rocket' => $rocket]); - - return $next($rocket); - } - - /** - * @throws ContainerException - * @throws ServiceNotFoundException - */ - protected function getRequest(Rocket $rocket): RequestInterface - { - return new Request( - $this->getMethod(), - $this->getUrl($rocket), - $this->getHeaders(), - ); - } - - protected function getMethod(): string - { - return 'POST'; - } - - /** - * @throws ContainerException - * @throws ServiceNotFoundException - */ - protected function getUrl(Rocket $rocket): string - { - $params = $rocket->getParams(); - - $url = Pay::MODE_SERVICE === (get_wechat_config($params)['mode'] ?? null) ? $this->getPartnerUri($rocket) : $this->getUri($rocket); - - return str_starts_with($url, 'http') ? $url : (get_wechat_base_uri($params).$url); - } - - protected function getHeaders(): array - { - return [ - 'Accept' => 'application/json, text/plain, application/x-gzip', - 'User-Agent' => 'yansongda/pay-v3', - 'Content-Type' => 'application/json; charset=utf-8', - ]; - } - - protected function getConfigKey(array $params): string - { - $key = ($params['_type'] ?? 'mp').'_app_id'; - - if ('app_app_id' === $key) { - $key = 'app_id'; - } - - return $key; - } - - abstract protected function doSomething(Rocket $rocket): void; - - abstract protected function getUri(Rocket $rocket): string; - - protected function getPartnerUri(Rocket $rocket): string - { - return $this->getUri($rocket); - } -} diff --git a/src/Plugin/Wechat/GeneralV2Plugin.php b/src/Plugin/Wechat/GeneralV2Plugin.php deleted file mode 100644 index ce6713d..0000000 --- a/src/Plugin/Wechat/GeneralV2Plugin.php +++ /dev/null @@ -1,42 +0,0 @@ - 'application/xml', - 'User-Agent' => 'yansongda/pay-v3', - ]; - } - - /** - * @throws ContainerException - * @throws ServiceNotFoundException - */ - protected function doSomething(Rocket $rocket): void - { - $config = get_wechat_config($rocket->getParams()); - $configKey = $this->getConfigKey($rocket->getParams()); - - $rocket->setPacker(XmlPacker::class)->mergeParams(['_version' => 'v2']); - - $rocket->mergePayload([ - 'appid' => $config[$configKey] ?? '', - 'mch_id' => $config['mch_id'] ?? '', - ]); - } - - abstract protected function getUri(Rocket $rocket): string; -} diff --git a/src/Plugin/Wechat/Marketing/Coupon/CreatePlugin.php b/src/Plugin/Wechat/Marketing/Coupon/CreatePlugin.php index d5bc8c2..db1b0f9 100644 --- a/src/Plugin/Wechat/Marketing/Coupon/CreatePlugin.php +++ b/src/Plugin/Wechat/Marketing/Coupon/CreatePlugin.php @@ -4,34 +4,42 @@ declare(strict_types=1); namespace Yansongda\Pay\Plugin\Wechat\Marketing\Coupon; +use Closure; +use Yansongda\Pay\Contract\PluginInterface; use Yansongda\Pay\Exception\ContainerException; use Yansongda\Pay\Exception\ServiceNotFoundException; -use Yansongda\Pay\Plugin\Wechat\GeneralPlugin; +use Yansongda\Pay\Logger; use Yansongda\Pay\Rocket; use function Yansongda\Pay\get_wechat_config; /** - * @see https://pay.weixin.qq.com/wiki/doc/apiv3/apis/chapter9_1_1.shtml + * @see https://pay.weixin.qq.com/docs/merchant/apis/cash-coupons/stock/create-coupon-stock.html + * @see https://pay.weixin.qq.com/docs/partner/apis/cash-coupons/stock/create-coupon-stock.html */ -class CreatePlugin extends GeneralPlugin +class CreatePlugin implements PluginInterface { /** * @throws ContainerException * @throws ServiceNotFoundException */ - protected function doSomething(Rocket $rocket): void + public function assembly(Rocket $rocket, Closure $next): Rocket { - $config = get_wechat_config($rocket->getParams()); - $payload = $rocket->getPayload(); + Logger::debug('[Wechat][Marketing][Coupon][CreatePlugin] 插件开始装载', ['rocket' => $rocket]); - if (!$payload->has('belong_merchant')) { - $rocket->mergePayload(['belong_merchant' => $config['mch_id']]); - } - } + $params = $rocket->getParams(); + $config = get_wechat_config($params); + $belongMerchant = $rocket->getPayload()?->get('belong_merchant') ?? $config['mch_id']; - protected function getUri(Rocket $rocket): string - { - return 'v3/marketing/favor/coupon-stocks'; + $rocket->mergePayload([ + '_method' => 'POST', + '_url' => 'v3/marketing/favor/coupon-stocks', + '_service_url' => 'v3/marketing/favor/coupon-stocks', + 'belong_merchant' => $belongMerchant, + ]); + + Logger::info('[Wechat][Marketing][Coupon][CreatePlugin] 插件装载完毕', ['rocket' => $rocket]); + + return $next($rocket); } } diff --git a/src/Plugin/Wechat/Marketing/Coupon/PausePlugin.php b/src/Plugin/Wechat/Marketing/Coupon/PausePlugin.php index 1ae99ae..6fca687 100644 --- a/src/Plugin/Wechat/Marketing/Coupon/PausePlugin.php +++ b/src/Plugin/Wechat/Marketing/Coupon/PausePlugin.php @@ -4,47 +4,51 @@ declare(strict_types=1); namespace Yansongda\Pay\Plugin\Wechat\Marketing\Coupon; +use Closure; +use Yansongda\Pay\Contract\PluginInterface; use Yansongda\Pay\Exception\ContainerException; use Yansongda\Pay\Exception\Exception; use Yansongda\Pay\Exception\InvalidParamsException; use Yansongda\Pay\Exception\ServiceNotFoundException; -use Yansongda\Pay\Plugin\Wechat\GeneralPlugin; +use Yansongda\Pay\Logger; use Yansongda\Pay\Rocket; use function Yansongda\Pay\get_wechat_config; /** - * @see https://pay.weixin.qq.com/wiki/doc/apiv3/apis/chapter9_1_13.shtml + * @see https://pay.weixin.qq.com/docs/merchant/apis/cash-coupons/stock/pause-stock.html + * @see https://pay.weixin.qq.com/docs/partner/apis/cash-coupons/stock/pause-stock.html */ -class PausePlugin extends GeneralPlugin +class PausePlugin implements PluginInterface { /** * @throws ContainerException + * @throws InvalidParamsException * @throws ServiceNotFoundException */ - protected function doSomething(Rocket $rocket): void + public function assembly(Rocket $rocket, Closure $next): Rocket { - $config = get_wechat_config($rocket->getParams()); - $payload = $rocket->getPayload(); + Logger::debug('[Wechat][Marketing][Coupon][PausePlugin] 插件开始装载', ['rocket' => $rocket]); - if (!$payload->has('stock_creator_mchid')) { - $rocket->mergePayload(['stock_creator_mchid' => $config['mch_id']]); + $params = $rocket->getParams(); + $config = get_wechat_config($params); + $payload = $rocket->getPayload(); + $stockId = $payload?->get('stock_id') ?? null; + $stockCreatorMchId = $payload?->get('stock_creator_mchid') ?? $config['mch_id'] ?? ''; + + if (empty($stockId)) { + throw new InvalidParamsException(Exception::PARAMS_NECESSARY_PARAMS_MISSING, '参数异常: 暂停代金券批次,参数缺少 `stock_id`'); } - $rocket->getPayload()->forget('stock_id'); - } + $rocket->setPayload([ + '_method' => 'POST', + '_url' => 'v3/marketing/favor/stocks/'.$stockId.'/pause', + '_service_url' => 'v3/marketing/favor/stocks/'.$stockId.'/pause', + 'stock_creator_mchid' => $stockCreatorMchId, + ]); - /** - * @throws InvalidParamsException - */ - protected function getUri(Rocket $rocket): string - { - $payload = $rocket->getPayload(); + Logger::info('[Wechat][Marketing][Coupon][PausePlugin] 插件装载完毕', ['rocket' => $rocket]); - if (!$payload->has('stock_id')) { - throw new InvalidParamsException(Exception::PARAMS_NECESSARY_PARAMS_MISSING); - } - - return 'v3/marketing/favor/stocks/'.$payload->get('stock_id').'/pause'; + return $next($rocket); } } diff --git a/src/Plugin/Wechat/Marketing/Coupon/QueryCallbackPlugin.php b/src/Plugin/Wechat/Marketing/Coupon/QueryCallbackPlugin.php new file mode 100644 index 0000000..df2146e --- /dev/null +++ b/src/Plugin/Wechat/Marketing/Coupon/QueryCallbackPlugin.php @@ -0,0 +1,44 @@ + $rocket]); + + $params = $rocket->getParams(); + $config = get_wechat_config($params); + $mchId = $rocket->getPayload()?->get('mchid') ?? $config['mch_id'] ?? 'null'; + + $rocket->setPayload([ + '_method' => 'GET', + '_url' => 'v3/marketing/favor/callbacks?mchid='.$mchId, + '_service_url' => 'v3/marketing/favor/callbacks?mchid='.$mchId, + ]); + + Logger::info('[Wechat][Marketing][Coupon][QueryCallbackPlugin] 插件装载完毕', ['rocket' => $rocket]); + + return $next($rocket); + } +} diff --git a/src/Plugin/Wechat/Marketing/Coupon/QueryCouponDetailPlugin.php b/src/Plugin/Wechat/Marketing/Coupon/QueryCouponDetailPlugin.php index ebce159..3f189e3 100644 --- a/src/Plugin/Wechat/Marketing/Coupon/QueryCouponDetailPlugin.php +++ b/src/Plugin/Wechat/Marketing/Coupon/QueryCouponDetailPlugin.php @@ -4,48 +4,52 @@ declare(strict_types=1); namespace Yansongda\Pay\Plugin\Wechat\Marketing\Coupon; +use Closure; +use Yansongda\Pay\Contract\PluginInterface; use Yansongda\Pay\Exception\ContainerException; use Yansongda\Pay\Exception\Exception; use Yansongda\Pay\Exception\InvalidParamsException; use Yansongda\Pay\Exception\ServiceNotFoundException; -use Yansongda\Pay\Plugin\Wechat\GeneralPlugin; +use Yansongda\Pay\Logger; use Yansongda\Pay\Rocket; use function Yansongda\Pay\get_wechat_config; +use function Yansongda\Pay\get_wechat_type_key; /** - * @see https://pay.weixin.qq.com/wiki/doc/apiv3/apis/chapter9_1_6.shtml + * @see https://pay.weixin.qq.com/docs/merchant/apis/cash-coupons/coupon/query-coupon.html + * @see https://pay.weixin.qq.com/docs/partner/apis/cash-coupons/coupon/query-coupon.html */ -class QueryCouponDetailPlugin extends GeneralPlugin +class QueryCouponDetailPlugin implements PluginInterface { - protected function getMethod(): string - { - return 'GET'; - } - - protected function doSomething(Rocket $rocket): void - { - $rocket->setPayload(null); - } - /** - * @throws ContainerException * @throws InvalidParamsException + * @throws ContainerException * @throws ServiceNotFoundException */ - protected function getUri(Rocket $rocket): string + public function assembly(Rocket $rocket, Closure $next): Rocket { - $payload = $rocket->getPayload(); + Logger::debug('[Wechat][Marketing][Coupon][QueryCouponDetailPlugin] 插件开始装载', ['rocket' => $rocket]); + $params = $rocket->getParams(); $config = get_wechat_config($params); + $payload = $rocket->getPayload(); + $openId = $payload?->get('openid') ?? null; + $couponId = $payload?->get('coupon_id') ?? null; + $appId = $payload?->get('appid') ?? $config[get_wechat_type_key($params)] ?? 'null'; - if (!$payload->has('coupon_id') || !$payload->has('openid')) { - throw new InvalidParamsException(Exception::PARAMS_NECESSARY_PARAMS_MISSING); + if (empty($openId) || empty($couponId)) { + throw new InvalidParamsException(Exception::PARAMS_NECESSARY_PARAMS_MISSING, '参数异常: 查询代金券详情,参数缺少 `openid` 或 `coupon_id`'); } - return 'v3/marketing/favor/users/'. - $payload->get('openid'). - '/coupons/'.$payload->get('coupon_id'). - '?appid='.$payload->get('appid', $config[$this->getConfigKey($params)] ?? ''); + $rocket->setPayload([ + '_method' => 'GET', + '_url' => 'v3/marketing/favor/users/'.$openId.'/coupons/'.$couponId.'?appid='.$appId, + '_service_url' => 'v3/marketing/favor/users/'.$openId.'/coupons/'.$couponId.'?appid='.$appId, + ]); + + Logger::info('[Wechat][Marketing][Coupon][QueryCouponDetailPlugin] 插件装载完毕', ['rocket' => $rocket]); + + return $next($rocket); } } diff --git a/src/Plugin/Wechat/Marketing/Coupon/QueryStockDetailPlugin.php b/src/Plugin/Wechat/Marketing/Coupon/QueryStockDetailPlugin.php index dfc0a19..d770dc8 100644 --- a/src/Plugin/Wechat/Marketing/Coupon/QueryStockDetailPlugin.php +++ b/src/Plugin/Wechat/Marketing/Coupon/QueryStockDetailPlugin.php @@ -4,47 +4,50 @@ declare(strict_types=1); namespace Yansongda\Pay\Plugin\Wechat\Marketing\Coupon; +use Closure; +use Yansongda\Pay\Contract\PluginInterface; use Yansongda\Pay\Exception\ContainerException; use Yansongda\Pay\Exception\Exception; use Yansongda\Pay\Exception\InvalidParamsException; use Yansongda\Pay\Exception\ServiceNotFoundException; -use Yansongda\Pay\Plugin\Wechat\GeneralPlugin; +use Yansongda\Pay\Logger; use Yansongda\Pay\Rocket; use function Yansongda\Pay\get_wechat_config; /** - * @see https://pay.weixin.qq.com/wiki/doc/apiv3/apis/chapter9_1_5.shtml + * @see https://pay.weixin.qq.com/docs/merchant/apis/cash-coupons/stock/query-stock.html + * @see https://pay.weixin.qq.com/docs/partner/apis/cash-coupons/stock/query-stock.html */ -class QueryStockDetailPlugin extends GeneralPlugin +class QueryStockDetailPlugin implements PluginInterface { - protected function getMethod(): string - { - return 'GET'; - } - - protected function doSomething(Rocket $rocket): void - { - $rocket->setPayload(null); - } - /** - * @throws InvalidParamsException * @throws ContainerException + * @throws InvalidParamsException * @throws ServiceNotFoundException */ - protected function getUri(Rocket $rocket): string + public function assembly(Rocket $rocket, Closure $next): Rocket { - $payload = $rocket->getPayload(); + Logger::debug('[Wechat][Marketing][Coupon][QueryStockDetailPlugin] 插件开始装载', ['rocket' => $rocket]); + $params = $rocket->getParams(); $config = get_wechat_config($params); + $payload = $rocket->getPayload(); + $stockId = $payload?->get('stock_id') ?? null; + $mchId = $payload?->get('stock_creator_mchid') ?? $config['mch_id'] ?? 'null'; - if (!$payload->has('stock_id')) { - throw new InvalidParamsException(Exception::PARAMS_NECESSARY_PARAMS_MISSING); + if (empty($stockId)) { + throw new InvalidParamsException(Exception::PARAMS_NECESSARY_PARAMS_MISSING, '参数异常: 查询代金券批次详情,参数缺少 `stock_id`'); } - return 'v3/marketing/favor/stocks/'. - $payload->get('stock_id'). - '?stock_creator_mchid='.$payload->get('stock_creator_mchid', $config['mch_id'] ?? ''); + $rocket->setPayload([ + '_method' => 'GET', + '_url' => 'v3/marketing/favor/stocks/'.$stockId.'?stock_creator_mchid='.$mchId, + '_service_url' => 'v3/marketing/favor/stocks/'.$stockId.'?stock_creator_mchid='.$mchId, + ]); + + Logger::info('[Wechat][Marketing][Coupon][QueryStockDetailPlugin] 插件装载完毕', ['rocket' => $rocket]); + + return $next($rocket); } } diff --git a/src/Plugin/Wechat/Marketing/Coupon/QueryStockItemsPlugin.php b/src/Plugin/Wechat/Marketing/Coupon/QueryStockItemsPlugin.php index 9b0309a..fd6b7a0 100644 --- a/src/Plugin/Wechat/Marketing/Coupon/QueryStockItemsPlugin.php +++ b/src/Plugin/Wechat/Marketing/Coupon/QueryStockItemsPlugin.php @@ -4,55 +4,61 @@ declare(strict_types=1); namespace Yansongda\Pay\Plugin\Wechat\Marketing\Coupon; +use Closure; +use Yansongda\Pay\Contract\PluginInterface; use Yansongda\Pay\Exception\ContainerException; use Yansongda\Pay\Exception\Exception; use Yansongda\Pay\Exception\InvalidParamsException; use Yansongda\Pay\Exception\ServiceNotFoundException; -use Yansongda\Pay\Plugin\Wechat\GeneralPlugin; +use Yansongda\Pay\Logger; use Yansongda\Pay\Rocket; +use Yansongda\Supports\Collection; use function Yansongda\Pay\get_wechat_config; /** - * @see https://pay.weixin.qq.com/wiki/doc/apiv3/apis/chapter9_1_8.shtml + * @see https://pay.weixin.qq.com/docs/merchant/apis/cash-coupons/stock/list-available-singleitems.html + * @see https://pay.weixin.qq.com/docs/partner/apis/cash-coupons/stock/list-available-singleitems.html */ -class QueryStockItemsPlugin extends GeneralPlugin +class QueryStockItemsPlugin implements PluginInterface { - protected function getMethod(): string - { - return 'GET'; - } - - protected function doSomething(Rocket $rocket): void - { - $rocket->setPayload(null); - } - /** - * @throws InvalidParamsException * @throws ContainerException + * @throws InvalidParamsException * @throws ServiceNotFoundException */ - protected function getUri(Rocket $rocket): string + public function assembly(Rocket $rocket, Closure $next): Rocket { - $payload = $rocket->getPayload(); + Logger::debug('[Wechat][Marketing][Coupon][QueryStockItemsPlugin] 插件开始装载', ['rocket' => $rocket]); + $params = $rocket->getParams(); $config = get_wechat_config($params); + $payload = $rocket->getPayload(); + $stockId = $payload?->get('stock_id') ?? null; - if (!$payload->has('stock_id')) { - throw new InvalidParamsException(Exception::PARAMS_NECESSARY_PARAMS_MISSING); + if (empty($stockId)) { + throw new InvalidParamsException(Exception::PARAMS_NECESSARY_PARAMS_MISSING, '参数异常: 查询代金券可用单品,参数缺少 `stock_id`'); } - if (!$payload->has('stock_creator_mchid')) { - $rocket->mergePayload(['stock_creator_mchid' => $config['mch_id']]); + $rocket->setPayload([ + '_method' => 'GET', + '_url' => 'v3/marketing/favor/stocks/'.$stockId.'/items?'.$this->normal($payload, $config), + '_service_url' => 'v3/marketing/favor/stocks/'.$stockId.'/items?'.$this->normal($payload, $config), + ]); + + Logger::info('[Wechat][Marketing][Coupon][QueryStockItemsPlugin] 插件装载完毕', ['rocket' => $rocket]); + + return $next($rocket); + } + + public function normal(Collection $payload, array $config): string + { + $stockCreatorMchId = $payload->get('stock_creator_mchid'); + + if (is_null($stockCreatorMchId)) { + $payload->set('stock_creator_mchid', $config['mch_id'] ?? ''); } - $query = $rocket->getPayload()->all(); - - unset($query['stock_id']); - - return 'v3/marketing/favor/stocks/'. - $payload->get('stock_id'). - '/items?'.http_build_query($query); + return $payload->except('stock_id')->query(); } } diff --git a/src/Plugin/Wechat/Marketing/Coupon/QueryStockMerchantsPlugin.php b/src/Plugin/Wechat/Marketing/Coupon/QueryStockMerchantsPlugin.php index 48bf26c..0e1dfb5 100644 --- a/src/Plugin/Wechat/Marketing/Coupon/QueryStockMerchantsPlugin.php +++ b/src/Plugin/Wechat/Marketing/Coupon/QueryStockMerchantsPlugin.php @@ -4,55 +4,61 @@ declare(strict_types=1); namespace Yansongda\Pay\Plugin\Wechat\Marketing\Coupon; +use Closure; +use Yansongda\Pay\Contract\PluginInterface; use Yansongda\Pay\Exception\ContainerException; use Yansongda\Pay\Exception\Exception; use Yansongda\Pay\Exception\InvalidParamsException; use Yansongda\Pay\Exception\ServiceNotFoundException; -use Yansongda\Pay\Plugin\Wechat\GeneralPlugin; +use Yansongda\Pay\Logger; use Yansongda\Pay\Rocket; +use Yansongda\Supports\Collection; use function Yansongda\Pay\get_wechat_config; /** - * @see https://pay.weixin.qq.com/wiki/doc/apiv3/apis/chapter9_1_7.shtml + * @see https://pay.weixin.qq.com/docs/merchant/apis/cash-coupons/stock/list-available-merchants.html + * @see https://pay.weixin.qq.com/docs/partner/apis/cash-coupons/stock/list-available-merchants.html */ -class QueryStockMerchantsPlugin extends GeneralPlugin +class QueryStockMerchantsPlugin implements PluginInterface { - protected function getMethod(): string - { - return 'GET'; - } - - protected function doSomething(Rocket $rocket): void - { - $rocket->setPayload(null); - } - /** - * @throws InvalidParamsException * @throws ContainerException + * @throws InvalidParamsException * @throws ServiceNotFoundException */ - protected function getUri(Rocket $rocket): string + public function assembly(Rocket $rocket, Closure $next): Rocket { - $payload = $rocket->getPayload(); + Logger::debug('[Wechat][Marketing][Coupon][QueryStockMerchantsPlugin] 插件开始装载', ['rocket' => $rocket]); + $params = $rocket->getParams(); $config = get_wechat_config($params); + $payload = $rocket->getPayload(); + $stockId = $payload?->get('stock_id') ?? null; - if (!$payload->has('stock_creator_mchid')) { - $rocket->mergePayload(['stock_creator_mchid' => $config['mch_id']]); + if (empty($stockId)) { + throw new InvalidParamsException(Exception::PARAMS_NECESSARY_PARAMS_MISSING, '参数异常: 查询代金券可用商户,参数缺少 `stock_id`'); } - if (!$payload->has('stock_id')) { - throw new InvalidParamsException(Exception::PARAMS_NECESSARY_PARAMS_MISSING); + $rocket->setPayload([ + '_method' => 'GET', + '_url' => 'v3/marketing/favor/stocks/'.$stockId.'/merchants?'.$this->normal($payload, $config), + '_service_url' => 'v3/marketing/favor/stocks/'.$stockId.'/merchants?'.$this->normal($payload, $config), + ]); + + Logger::info('[Wechat][Marketing][Coupon][QueryStockMerchantsPlugin] 插件装载完毕', ['rocket' => $rocket]); + + return $next($rocket); + } + + public function normal(Collection $payload, array $config): string + { + $stockCreatorMchId = $payload->get('stock_creator_mchid'); + + if (is_null($stockCreatorMchId)) { + $payload->set('stock_creator_mchid', $config['mch_id'] ?? ''); } - $query = $rocket->getPayload()->all(); - - unset($query['stock_id']); - - return 'v3/marketing/favor/stocks/'. - $payload->get('stock_id'). - '/merchants?'.http_build_query($query); + return $payload->except('stock_id')->query(); } } diff --git a/src/Plugin/Wechat/Marketing/Coupon/QueryStockRefundFlowPlugin.php b/src/Plugin/Wechat/Marketing/Coupon/QueryStockRefundFlowPlugin.php index b9f059a..2e1e5ad 100644 --- a/src/Plugin/Wechat/Marketing/Coupon/QueryStockRefundFlowPlugin.php +++ b/src/Plugin/Wechat/Marketing/Coupon/QueryStockRefundFlowPlugin.php @@ -4,39 +4,40 @@ declare(strict_types=1); namespace Yansongda\Pay\Plugin\Wechat\Marketing\Coupon; +use Closure; +use Yansongda\Pay\Contract\PluginInterface; use Yansongda\Pay\Exception\Exception; use Yansongda\Pay\Exception\InvalidParamsException; -use Yansongda\Pay\Plugin\Wechat\GeneralPlugin; +use Yansongda\Pay\Logger; use Yansongda\Pay\Rocket; /** - * @see https://pay.weixin.qq.com/wiki/doc/apiv3/apis/chapter9_1_11.shtml + * @see https://pay.weixin.qq.com/docs/merchant/apis/cash-coupons/stock/refund-flow.html + * @see https://pay.weixin.qq.com/docs/partner/apis/cash-coupons/stock/refund-flow.html */ -class QueryStockRefundFlowPlugin extends GeneralPlugin +class QueryStockRefundFlowPlugin implements PluginInterface { - protected function getMethod(): string - { - return 'GET'; - } - - protected function doSomething(Rocket $rocket): void - { - $rocket->setPayload(null); - } - /** * @throws InvalidParamsException */ - protected function getUri(Rocket $rocket): string + public function assembly(Rocket $rocket, Closure $next): Rocket { - $payload = $rocket->getPayload(); + Logger::debug('[Wechat][Marketing][Coupon][QueryStockRefundFlowPlugin] 插件开始装载', ['rocket' => $rocket]); - if (!$payload->has('stock_id')) { - throw new InvalidParamsException(Exception::PARAMS_NECESSARY_PARAMS_MISSING); + $stockId = $rocket->getPayload()?->get('stock_id') ?? null; + + if (empty($stockId)) { + throw new InvalidParamsException(Exception::PARAMS_NECESSARY_PARAMS_MISSING, '参数异常: 下载批次退款明细,参数缺少 `stock_id`'); } - return 'v3/marketing/favor/stocks/'. - $payload->get('stock_id'). - '/refund-flow'; + $rocket->setPayload([ + '_method' => 'GET', + '_url' => 'v3/marketing/favor/stocks/'.$stockId.'/refund-flow', + '_service_url' => 'v3/marketing/favor/stocks/'.$stockId.'/refund-flow', + ]); + + Logger::info('[Wechat][Marketing][Coupon][QueryStockRefundFlowPlugin] 插件装载完毕', ['rocket' => $rocket]); + + return $next($rocket); } } diff --git a/src/Plugin/Wechat/Marketing/Coupon/QueryStockUseFlowPlugin.php b/src/Plugin/Wechat/Marketing/Coupon/QueryStockUseFlowPlugin.php index c7ccb53..d279464 100644 --- a/src/Plugin/Wechat/Marketing/Coupon/QueryStockUseFlowPlugin.php +++ b/src/Plugin/Wechat/Marketing/Coupon/QueryStockUseFlowPlugin.php @@ -4,39 +4,40 @@ declare(strict_types=1); namespace Yansongda\Pay\Plugin\Wechat\Marketing\Coupon; +use Closure; +use Yansongda\Pay\Contract\PluginInterface; use Yansongda\Pay\Exception\Exception; use Yansongda\Pay\Exception\InvalidParamsException; -use Yansongda\Pay\Plugin\Wechat\GeneralPlugin; +use Yansongda\Pay\Logger; use Yansongda\Pay\Rocket; /** - * @see https://pay.weixin.qq.com/wiki/doc/apiv3/apis/chapter9_1_10.shtml + * @see https://pay.weixin.qq.com/docs/merchant/apis/cash-coupons/stock/use-flow.html + * @see https://pay.weixin.qq.com/docs/partner/apis/cash-coupons/stock/use-flow.html */ -class QueryStockUseFlowPlugin extends GeneralPlugin +class QueryStockUseFlowPlugin implements PluginInterface { - protected function getMethod(): string - { - return 'GET'; - } - - protected function doSomething(Rocket $rocket): void - { - $rocket->setPayload(null); - } - /** * @throws InvalidParamsException */ - protected function getUri(Rocket $rocket): string + public function assembly(Rocket $rocket, Closure $next): Rocket { - $payload = $rocket->getPayload(); + Logger::debug('[Wechat][Marketing][Coupon][QueryStockUseFlowPlugin] 插件开始装载', ['rocket' => $rocket]); - if (!$payload->has('stock_id')) { - throw new InvalidParamsException(Exception::PARAMS_NECESSARY_PARAMS_MISSING); + $stockId = $rocket->getPayload()?->get('stock_id') ?? null; + + if (empty($stockId)) { + throw new InvalidParamsException(Exception::PARAMS_NECESSARY_PARAMS_MISSING, '参数异常: 下载批次核销明细,参数缺少 `stock_id`'); } - return 'v3/marketing/favor/stocks/'. - $payload->get('stock_id'). - '/use-flow'; + $rocket->setPayload([ + '_method' => 'GET', + '_url' => 'v3/marketing/favor/stocks/'.$stockId.'/use-flow', + '_service_url' => 'v3/marketing/favor/stocks/'.$stockId.'/use-flow', + ]); + + Logger::info('[Wechat][Marketing][Coupon][QueryStockUseFlowPlugin] 插件装载完毕', ['rocket' => $rocket]); + + return $next($rocket); } } diff --git a/src/Plugin/Wechat/Marketing/Coupon/QueryStocksPlugin.php b/src/Plugin/Wechat/Marketing/Coupon/QueryStocksPlugin.php index 700c9a4..313fddb 100644 --- a/src/Plugin/Wechat/Marketing/Coupon/QueryStocksPlugin.php +++ b/src/Plugin/Wechat/Marketing/Coupon/QueryStocksPlugin.php @@ -4,41 +4,60 @@ declare(strict_types=1); namespace Yansongda\Pay\Plugin\Wechat\Marketing\Coupon; +use Closure; +use Yansongda\Pay\Contract\PluginInterface; use Yansongda\Pay\Exception\ContainerException; +use Yansongda\Pay\Exception\Exception; +use Yansongda\Pay\Exception\InvalidParamsException; use Yansongda\Pay\Exception\ServiceNotFoundException; -use Yansongda\Pay\Plugin\Wechat\GeneralPlugin; +use Yansongda\Pay\Logger; use Yansongda\Pay\Rocket; +use Yansongda\Supports\Collection; use function Yansongda\Pay\get_wechat_config; /** - * @see https://pay.weixin.qq.com/wiki/doc/apiv3/apis/chapter9_1_4.shtml + * @see https://pay.weixin.qq.com/docs/merchant/apis/cash-coupons/stock/list-stocks.html + * @see https://pay.weixin.qq.com/docs/partner/apis/cash-coupons/stock/list-stocks.html */ -class QueryStocksPlugin extends GeneralPlugin +class QueryStocksPlugin implements PluginInterface { - protected function getMethod(): string - { - return 'GET'; - } - - protected function doSomething(Rocket $rocket): void - { - $rocket->setPayload(null); - } - /** * @throws ContainerException + * @throws InvalidParamsException * @throws ServiceNotFoundException */ - protected function getUri(Rocket $rocket): string + public function assembly(Rocket $rocket, Closure $next): Rocket { + Logger::debug('[Wechat][Marketing][Coupon][QueryStocksPlugin] 插件开始装载', ['rocket' => $rocket]); + $params = $rocket->getParams(); $config = get_wechat_config($params); + $payload = $rocket->getPayload(); - if (!$rocket->getPayload()->has('stock_creator_mchid')) { - $rocket->mergePayload(['stock_creator_mchid' => $config['mch_id']]); + if (is_null($payload)) { + throw new InvalidParamsException(Exception::PARAMS_NECESSARY_PARAMS_MISSING, '参数异常: 缺少代金券相关参数'); } - return 'v3/marketing/favor/stocks?'.$rocket->getPayload()->query(); + $rocket->setPayload([ + '_method' => 'GET', + '_url' => 'v3/marketing/favor/stocks?'.$this->normal($payload, $config), + '_service_url' => 'v3/marketing/favor/stocks?'.$this->normal($payload, $config), + ]); + + Logger::info('[Wechat][Marketing][Coupon][QueryStocksPlugin] 插件装载完毕', ['rocket' => $rocket]); + + return $next($rocket); + } + + public function normal(Collection $payload, array $config): string + { + $stockCreatorMchId = $payload->get('stock_creator_mchid'); + + if (is_null($stockCreatorMchId)) { + $payload->set('stock_creator_mchid', $config['mch_id'] ?? ''); + } + + return $payload->query(); } } diff --git a/src/Plugin/Wechat/Marketing/Coupon/QueryUserCouponsPlugin.php b/src/Plugin/Wechat/Marketing/Coupon/QueryUserCouponsPlugin.php index 2e7f792..590580d 100644 --- a/src/Plugin/Wechat/Marketing/Coupon/QueryUserCouponsPlugin.php +++ b/src/Plugin/Wechat/Marketing/Coupon/QueryUserCouponsPlugin.php @@ -4,59 +4,62 @@ declare(strict_types=1); namespace Yansongda\Pay\Plugin\Wechat\Marketing\Coupon; +use Closure; +use Yansongda\Pay\Contract\PluginInterface; use Yansongda\Pay\Exception\ContainerException; use Yansongda\Pay\Exception\Exception; use Yansongda\Pay\Exception\InvalidParamsException; use Yansongda\Pay\Exception\ServiceNotFoundException; -use Yansongda\Pay\Plugin\Wechat\GeneralPlugin; +use Yansongda\Pay\Logger; use Yansongda\Pay\Rocket; +use Yansongda\Supports\Collection; use function Yansongda\Pay\get_wechat_config; +use function Yansongda\Pay\get_wechat_type_key; /** - * @see https://pay.weixin.qq.com/wiki/doc/apiv3/apis/chapter9_1_9.shtml + * @see https://pay.weixin.qq.com/docs/merchant/apis/cash-coupons/coupon/list-coupons-by-filter.html + * @see https://pay.weixin.qq.com/docs/partner/apis/cash-coupons/coupon/list-coupons-by-filter.html */ -class QueryUserCouponsPlugin extends GeneralPlugin +class QueryUserCouponsPlugin implements PluginInterface { - protected function getMethod(): string - { - return 'GET'; - } - - protected function doSomething(Rocket $rocket): void - { - $rocket->setPayload(null); - } - /** * @throws InvalidParamsException * @throws ContainerException * @throws ServiceNotFoundException */ - protected function getUri(Rocket $rocket): string + public function assembly(Rocket $rocket, Closure $next): Rocket { - $payload = $rocket->getPayload(); + Logger::debug('[Wechat][Marketing][Coupon][QueryUserCouponsPlugin] 插件开始装载', ['rocket' => $rocket]); + $params = $rocket->getParams(); $config = get_wechat_config($params); + $payload = $rocket->getPayload(); + $openId = $payload?->get('openid') ?? null; - if (!$payload->has('openid')) { - throw new InvalidParamsException(Exception::PARAMS_NECESSARY_PARAMS_MISSING); + if (empty($openId)) { + throw new InvalidParamsException(Exception::PARAMS_NECESSARY_PARAMS_MISSING, '参数异常: 根据商户号查用户的券,参数缺少 `openid`'); } - if (!$payload->has('appid')) { - $rocket->mergePayload(['appid' => $config[$this->getConfigKey($params)] ?? '']); + $rocket->setPayload([ + '_method' => 'GET', + '_url' => 'v3/marketing/favor/users/'.$openId.'/coupons?'.$this->normal($payload, $params, $config), + '_service_url' => 'v3/marketing/favor/users/'.$openId.'/coupons?'.$this->normal($payload, $params, $config), + ]); + + Logger::info('[Wechat][Marketing][Coupon][QueryUserCouponsPlugin] 插件装载完毕', ['rocket' => $rocket]); + + return $next($rocket); + } + + protected function normal(Collection $payload, array $params, array $config): string + { + $appId = $payload->get('appid'); + + if (is_null($appId)) { + $payload->set('appid', $config[get_wechat_type_key($params)] ?? ''); } - if (!$payload->has('creator_mchid')) { - $rocket->mergePayload(['creator_mchid' => $config['mch_id']]); - } - - $query = $rocket->getPayload()->all(); - - unset($query['openid']); - - return 'v3/marketing/favor/users/'. - $payload->get('openid'). - '/coupons?'.http_build_query($query); + return $payload->except('openid')->query(); } } diff --git a/src/Plugin/Wechat/Marketing/Coupon/RestartPlugin.php b/src/Plugin/Wechat/Marketing/Coupon/RestartPlugin.php index d175a66..a31e8fc 100644 --- a/src/Plugin/Wechat/Marketing/Coupon/RestartPlugin.php +++ b/src/Plugin/Wechat/Marketing/Coupon/RestartPlugin.php @@ -4,48 +4,51 @@ declare(strict_types=1); namespace Yansongda\Pay\Plugin\Wechat\Marketing\Coupon; +use Closure; +use Yansongda\Pay\Contract\PluginInterface; use Yansongda\Pay\Exception\ContainerException; use Yansongda\Pay\Exception\Exception; use Yansongda\Pay\Exception\InvalidParamsException; use Yansongda\Pay\Exception\ServiceNotFoundException; -use Yansongda\Pay\Plugin\Wechat\GeneralPlugin; +use Yansongda\Pay\Logger; use Yansongda\Pay\Rocket; use function Yansongda\Pay\get_wechat_config; /** - * @see https://pay.weixin.qq.com/wiki/doc/apiv3/apis/chapter9_1_14.shtml + * @see https://pay.weixin.qq.com/docs/merchant/apis/cash-coupons/stock/restart-stock.html + * @see https://pay.weixin.qq.com/docs/partner/apis/cash-coupons/stock/restart-stock.html */ -class RestartPlugin extends GeneralPlugin +class RestartPlugin implements PluginInterface { /** * @throws ContainerException + * @throws InvalidParamsException * @throws ServiceNotFoundException */ - protected function doSomething(Rocket $rocket): void + public function assembly(Rocket $rocket, Closure $next): Rocket { - $payload = $rocket->getPayload(); + Logger::debug('[Wechat][Marketing][Coupon][RestartPlugin] 插件开始装载', ['rocket' => $rocket]); + $params = $rocket->getParams(); $config = get_wechat_config($params); - - if (!$payload->has('stock_creator_mchid')) { - $rocket->mergePayload(['stock_creator_mchid' => $config['mch_id']]); - } - - $rocket->getPayload()->forget('stock_id'); - } - - /** - * @throws InvalidParamsException - */ - protected function getUri(Rocket $rocket): string - { $payload = $rocket->getPayload(); + $stockId = $payload?->get('stock_id') ?? null; + $stockCreatorMchId = $payload?->get('stock_creator_mchid') ?? $config['mch_id'] ?? ''; - if (!$payload->has('stock_id')) { - throw new InvalidParamsException(Exception::PARAMS_NECESSARY_PARAMS_MISSING); + if (empty($stockId)) { + throw new InvalidParamsException(Exception::PARAMS_NECESSARY_PARAMS_MISSING, '参数异常: 激活代金券,参数缺少 `stock_id`'); } - return 'v3/marketing/favor/stocks/'.$payload->get('stock_id').'/restart'; + $rocket->setPayload([ + '_method' => 'POST', + '_url' => 'v3/marketing/favor/stocks/'.$stockId.'/restart', + '_service_url' => 'v3/marketing/favor/stocks/'.$stockId.'/restart', + 'stock_creator_mchid' => $stockCreatorMchId, + ]); + + Logger::info('[Wechat][Marketing][Coupon][RestartPlugin] 插件装载完毕', ['rocket' => $rocket]); + + return $next($rocket); } } diff --git a/src/Plugin/Wechat/Marketing/Coupon/SendPlugin.php b/src/Plugin/Wechat/Marketing/Coupon/SendPlugin.php index ba01695..196337c 100644 --- a/src/Plugin/Wechat/Marketing/Coupon/SendPlugin.php +++ b/src/Plugin/Wechat/Marketing/Coupon/SendPlugin.php @@ -4,51 +4,67 @@ declare(strict_types=1); namespace Yansongda\Pay\Plugin\Wechat\Marketing\Coupon; +use Closure; +use Yansongda\Pay\Contract\PluginInterface; use Yansongda\Pay\Exception\ContainerException; use Yansongda\Pay\Exception\Exception; use Yansongda\Pay\Exception\InvalidParamsException; use Yansongda\Pay\Exception\ServiceNotFoundException; -use Yansongda\Pay\Plugin\Wechat\GeneralPlugin; +use Yansongda\Pay\Logger; use Yansongda\Pay\Rocket; +use Yansongda\Supports\Collection; use function Yansongda\Pay\get_wechat_config; +use function Yansongda\Pay\get_wechat_type_key; /** - * @see https://pay.weixin.qq.com/wiki/doc/apiv3/apis/chapter9_1_2.shtml + * @see https://pay.weixin.qq.com/docs/merchant/apis/cash-coupons/coupon/send-coupon.html + * @see https://pay.weixin.qq.com/docs/partner/apis/cash-coupons/coupon/send-coupon.html */ -class SendPlugin extends GeneralPlugin +class SendPlugin implements PluginInterface { /** + * @throws InvalidParamsException * @throws ContainerException * @throws ServiceNotFoundException */ - protected function doSomething(Rocket $rocket): void + public function assembly(Rocket $rocket, Closure $next): Rocket { + Logger::debug('[Wechat][Marketing][Coupon][SendPlugin] 插件开始装载', ['rocket' => $rocket]); + $params = $rocket->getParams(); $config = get_wechat_config($params); + $payload = $rocket->getPayload(); + $openId = $payload?->get('openid') ?? null; - if (!$rocket->getPayload()->has('appid')) { - $rocket->mergePayload(['appid' => $config[$this->getConfigKey($params)] ?? '']); + if (empty($openId)) { + throw new InvalidParamsException(Exception::PARAMS_NECESSARY_PARAMS_MISSING, '参数异常: 发放指定批次的代金券,参数缺少 `openid`'); } - if (!$rocket->getPayload()->has('stock_creator_mchid')) { - $rocket->mergePayload(['stock_creator_mchid' => $config['mch_id']]); - } + $rocket->setPayload(array_merge( + [ + '_method' => 'POST', + '_url' => 'v3/marketing/favor/users/'.$openId.'/coupons', + '_service_url' => 'v3/marketing/favor/users/'.$openId.'/coupons', + ], + $this->normal($payload, $params, $config), + )); - $rocket->getPayload()->forget('openid'); + Logger::info('[Wechat][Marketing][Coupon][SendPlugin] 插件装载完毕', ['rocket' => $rocket]); + + return $next($rocket); } - /** - * @throws InvalidParamsException - */ - protected function getUri(Rocket $rocket): string + protected function normal(Collection $payload, array $params, array $config): array { - $payload = $rocket->getPayload(); - - if (!$payload->has('openid')) { - throw new InvalidParamsException(Exception::PARAMS_NECESSARY_PARAMS_MISSING); + if (empty($payload->get('appid'))) { + $payload->set('appid', $config[get_wechat_type_key($params)] ?? ''); } - return 'v3/marketing/favor/users/'.$payload->get('openid').'/coupons'; + if (empty($payload->get('stock_creator_mchid'))) { + $payload->set('stock_creator_mchid', $config['mch_id'] ?? ''); + } + + return $payload->except('openid')->all(); } } diff --git a/src/Plugin/Wechat/Marketing/Coupon/SetCallbackPlugin.php b/src/Plugin/Wechat/Marketing/Coupon/SetCallbackPlugin.php index e620c1d..69807b1 100644 --- a/src/Plugin/Wechat/Marketing/Coupon/SetCallbackPlugin.php +++ b/src/Plugin/Wechat/Marketing/Coupon/SetCallbackPlugin.php @@ -4,33 +4,45 @@ declare(strict_types=1); namespace Yansongda\Pay\Plugin\Wechat\Marketing\Coupon; +use Closure; +use Yansongda\Pay\Contract\PluginInterface; use Yansongda\Pay\Exception\ContainerException; use Yansongda\Pay\Exception\ServiceNotFoundException; -use Yansongda\Pay\Plugin\Wechat\GeneralPlugin; +use Yansongda\Pay\Logger; use Yansongda\Pay\Rocket; use function Yansongda\Pay\get_wechat_config; /** - * @see https://pay.weixin.qq.com/wiki/doc/apiv3/apis/chapter9_1_12.shtml + * @see https://pay.weixin.qq.com/docs/merchant/apis/cash-coupons/call-back-url/set-callback.html + * @see https://pay.weixin.qq.com/docs/partner/apis/cash-coupons/call-back-url/set-callback.html */ -class SetCallbackPlugin extends GeneralPlugin +class SetCallbackPlugin implements PluginInterface { /** * @throws ContainerException * @throws ServiceNotFoundException */ - protected function doSomething(Rocket $rocket): void + public function assembly(Rocket $rocket, Closure $next): Rocket { - $config = get_wechat_config($rocket->getParams()); + Logger::debug('[Wechat][Marketing][Coupon][SetCallbackPlugin] 插件开始装载', ['rocket' => $rocket]); - $rocket->mergePayload([ - 'mchid' => $config['mch_id'] ?? '', - ]); - } + $params = $rocket->getParams(); + $config = get_wechat_config($params); + $payload = $rocket->getPayload(); - protected function getUri(Rocket $rocket): string - { - return 'v3/marketing/favor/callbacks'; + $rocket->mergePayload(array_merge( + [ + '_method' => 'POST', + '_url' => 'v3/marketing/favor/callbacks', + '_service_url' => 'v3/marketing/favor/callbacks', + 'mchid' => $payload?->get('mchid') ?? $config['mch_id'] ?? '', + 'notify_url' => $payload?->get('notify_url') ?? $config['notify_url'] ?? '', + ], + )); + + Logger::info('[Wechat][Marketing][Coupon][SetCallbackPlugin] 插件装载完毕', ['rocket' => $rocket]); + + return $next($rocket); } } diff --git a/src/Plugin/Wechat/Marketing/Coupon/StartPlugin.php b/src/Plugin/Wechat/Marketing/Coupon/StartPlugin.php index ac22059..24f67ac 100644 --- a/src/Plugin/Wechat/Marketing/Coupon/StartPlugin.php +++ b/src/Plugin/Wechat/Marketing/Coupon/StartPlugin.php @@ -4,47 +4,50 @@ declare(strict_types=1); namespace Yansongda\Pay\Plugin\Wechat\Marketing\Coupon; +use Closure; +use Yansongda\Pay\Contract\PluginInterface; use Yansongda\Pay\Exception\ContainerException; use Yansongda\Pay\Exception\Exception; use Yansongda\Pay\Exception\InvalidParamsException; use Yansongda\Pay\Exception\ServiceNotFoundException; -use Yansongda\Pay\Plugin\Wechat\GeneralPlugin; +use Yansongda\Pay\Logger; use Yansongda\Pay\Rocket; use function Yansongda\Pay\get_wechat_config; /** - * @see https://pay.weixin.qq.com/wiki/doc/apiv3/apis/chapter9_1_3.shtml + * @see https://pay.weixin.qq.com/docs/merchant/apis/cash-coupons/stock/start-stock.html + * @see https://pay.weixin.qq.com/docs/partner/apis/cash-coupons/stock/start-stock.html */ -class StartPlugin extends GeneralPlugin +class StartPlugin implements PluginInterface { /** * @throws ContainerException + * @throws InvalidParamsException * @throws ServiceNotFoundException */ - protected function doSomething(Rocket $rocket): void + public function assembly(Rocket $rocket, Closure $next): Rocket { + Logger::debug('[Wechat][Marketing][Coupon][StartPlugin] 插件开始装载', ['rocket' => $rocket]); + $params = $rocket->getParams(); $config = get_wechat_config($params); - - if (!$rocket->getPayload()->has('stock_creator_mchid')) { - $rocket->mergePayload(['stock_creator_mchid' => $config['mch_id']]); - } - - $rocket->getPayload()->forget('stock_id'); - } - - /** - * @throws InvalidParamsException - */ - protected function getUri(Rocket $rocket): string - { $payload = $rocket->getPayload(); + $stockId = $payload?->get('stock_id') ?? null; - if (!$payload->has('stock_id')) { - throw new InvalidParamsException(Exception::PARAMS_NECESSARY_PARAMS_MISSING); + if (empty($stockId)) { + throw new InvalidParamsException(Exception::PARAMS_NECESSARY_PARAMS_MISSING, '参数异常: 激活代金券,参数缺少 `stock_id`'); } - return 'v3/marketing/favor/stocks/'.$payload->get('stock_id').'/start'; + $rocket->setPayload([ + '_method' => 'POST', + '_url' => 'v3/marketing/favor/stocks/'.$stockId.'/start', + '_service_url' => 'v3/marketing/favor/stocks/'.$stockId.'/start', + 'stock_creator_mchid' => $payload->get('stock_creator_mchid') ?? $config['mch_id'] ?? '', + ]); + + Logger::info('[Wechat][Marketing][Coupon][StartPlugin] 插件装载完毕', ['rocket' => $rocket]); + + return $next($rocket); } } diff --git a/src/Plugin/Wechat/Marketing/ECommerceBalance/QueryDayEndPlugin.php b/src/Plugin/Wechat/Marketing/ECommerceBalance/QueryDayEndPlugin.php new file mode 100644 index 0000000..9bfc4d1 --- /dev/null +++ b/src/Plugin/Wechat/Marketing/ECommerceBalance/QueryDayEndPlugin.php @@ -0,0 +1,66 @@ + $rocket]); + + $config = get_wechat_config($rocket->getParams()); + $payload = $rocket->getPayload(); + $accountType = $payload?->get('account_type') ?? null; + + if (Pay::MODE_NORMAL === ($config['mode'] ?? Pay::MODE_NORMAL)) { + throw new InvalidParamsException(Exception::PARAMS_PLUGIN_ONLY_SUPPORT_SERVICE_MODE, '参数异常: 查询电商平台账户日终余额,只支持服务商模式,当前配置为普通商户模式'); + } + + if (empty($accountType)) { + throw new InvalidParamsException(Exception::PARAMS_NECESSARY_PARAMS_MISSING, '参数异常: 查询电商平台账户日终余额,参数缺少 `account_type`'); + } + + $rocket->setPayload([ + '_method' => 'GET', + '_service_url' => 'v3/merchant/fund/dayendbalance/'.$accountType.$this->service($payload), + ]); + + Logger::info('[Wechat][Marketing][ECommerceBalance][QueryDayEndPlugin] 插件装载完毕', ['rocket' => $rocket]); + + return $next($rocket); + } + + protected function service(Collection $payload): string + { + $query = $payload->except('account_type'); + + if ($query->isEmpty()) { + return ''; + } + + return '?'.$query->query(); + } +} diff --git a/src/Plugin/Wechat/Marketing/ECommerceBalance/QueryPlugin.php b/src/Plugin/Wechat/Marketing/ECommerceBalance/QueryPlugin.php new file mode 100644 index 0000000..2b2e8ce --- /dev/null +++ b/src/Plugin/Wechat/Marketing/ECommerceBalance/QueryPlugin.php @@ -0,0 +1,53 @@ + $rocket]); + + $config = get_wechat_config($rocket->getParams()); + $accountType = $rocket->getPayload()?->get('account_type') ?? null; + + if (Pay::MODE_NORMAL === ($config['mode'] ?? Pay::MODE_NORMAL)) { + throw new InvalidParamsException(Exception::PARAMS_PLUGIN_ONLY_SUPPORT_SERVICE_MODE, '参数异常: 查询电商平台账户实时余额,只支持服务商模式,当前配置为普通商户模式'); + } + + if (empty($accountType)) { + throw new InvalidParamsException(Exception::PARAMS_NECESSARY_PARAMS_MISSING, '参数异常: 查询电商平台账户实时余额,参数缺少 `account_type`'); + } + + $rocket->setPayload([ + '_method' => 'GET', + '_service_url' => 'v3/merchant/fund/balance/'.$accountType, + ]); + + Logger::info('[Wechat][Marketing][ECommerceBalance][QueryPlugin] 插件装载完毕', ['rocket' => $rocket]); + + return $next($rocket); + } +} diff --git a/src/Plugin/Wechat/Marketing/ECommerceRefund/ApplyPlugin.php b/src/Plugin/Wechat/Marketing/ECommerceRefund/ApplyPlugin.php new file mode 100644 index 0000000..395ea63 --- /dev/null +++ b/src/Plugin/Wechat/Marketing/ECommerceRefund/ApplyPlugin.php @@ -0,0 +1,60 @@ + $rocket]); + + $params = $rocket->getParams(); + $payload = $rocket->getPayload(); + $config = get_wechat_config($params); + $subMchId = $payload?->get('sub_mchid') ?? $config['sub_mch_id'] ?? ''; + $spAppId = $payload?->get('sp_appid') ?? $config[get_wechat_type_key($params)] ?? ''; + + if (Pay::MODE_NORMAL === ($config['mode'] ?? Pay::MODE_NORMAL)) { + throw new InvalidParamsException(Exception::PARAMS_PLUGIN_ONLY_SUPPORT_SERVICE_MODE, '参数异常: 平台收付通(退款)-申请退款,只支持服务商模式,当前配置为普通商户模式'); + } + + if (is_null($payload)) { + throw new InvalidParamsException(Exception::PARAMS_NECESSARY_PARAMS_MISSING, '参数异常: 平台收付通(退款)-申请退款,缺少必要参数'); + } + + $rocket->mergePayload([ + '_method' => 'POST', + '_service_url' => 'v3/ecommerce/refunds/apply', + 'sub_mchid' => $subMchId, + 'sp_appid' => $spAppId, + 'notify_url' => $payload->get('notify_url', $config['notify_url'] ?? null), + ]); + + Logger::info('[Wechat][Marketing][ECommerceRefund][ApplyPlugin] 插件装载完毕', ['rocket' => $rocket]); + + return $next($rocket); + } +} diff --git a/src/Plugin/Wechat/Marketing/ECommerceRefund/QueryByWxPlugin.php b/src/Plugin/Wechat/Marketing/ECommerceRefund/QueryByWxPlugin.php new file mode 100644 index 0000000..934a2fa --- /dev/null +++ b/src/Plugin/Wechat/Marketing/ECommerceRefund/QueryByWxPlugin.php @@ -0,0 +1,55 @@ + $rocket]); + + $params = $rocket->getParams(); + $payload = $rocket->getPayload(); + $config = get_wechat_config($params); + $refundId = $payload?->get('refund_id') ?? null; + + if (Pay::MODE_NORMAL === ($config['mode'] ?? Pay::MODE_NORMAL)) { + throw new InvalidParamsException(Exception::PARAMS_PLUGIN_ONLY_SUPPORT_SERVICE_MODE, '参数异常: 平台收付通(退款)-查询单笔退款(按微信支付退款单号),只支持服务商模式,当前配置为普通商户模式'); + } + + if (is_null($refundId)) { + throw new InvalidParamsException(Exception::PARAMS_NECESSARY_PARAMS_MISSING, '参数异常: 平台收付通(退款)-查询单笔退款(按微信支付退款单号),缺少必要参数 `refund_id`'); + } + + $rocket->setPayload([ + '_method' => 'GET', + '_service_url' => 'v3/ecommerce/refunds/id/'.$refundId.'?sub_mchid='.$payload->get('sub_mchid', $config['sub_mch_id'] ?? 'null'), + ]); + + Logger::info('[Wechat][Marketing][ECommerceRefund][QueryBatchByWxPlugin] 插件装载完毕', ['rocket' => $rocket]); + + return $next($rocket); + } +} diff --git a/src/Plugin/Wechat/Marketing/ECommerceRefund/QueryPlugin.php b/src/Plugin/Wechat/Marketing/ECommerceRefund/QueryPlugin.php new file mode 100644 index 0000000..edc83b3 --- /dev/null +++ b/src/Plugin/Wechat/Marketing/ECommerceRefund/QueryPlugin.php @@ -0,0 +1,55 @@ + $rocket]); + + $params = $rocket->getParams(); + $payload = $rocket->getPayload(); + $config = get_wechat_config($params); + $outRefundNo = $payload?->get('out_refund_no') ?? null; + + if (Pay::MODE_NORMAL === ($config['mode'] ?? Pay::MODE_NORMAL)) { + throw new InvalidParamsException(Exception::PARAMS_PLUGIN_ONLY_SUPPORT_SERVICE_MODE, '参数异常: 平台收付通(退款)-查询单笔退款(按商户退款单号),只支持服务商模式,当前配置为普通商户模式'); + } + + if (is_null($outRefundNo)) { + throw new InvalidParamsException(Exception::PARAMS_NECESSARY_PARAMS_MISSING, '参数异常: 平台收付通(退款)-查询单笔退款(按商户退款单号),缺少必要参数 `out_refund_no`'); + } + + $rocket->setPayload([ + '_method' => 'GET', + '_service_url' => 'v3/ecommerce/refunds/out-refund-no/'.$outRefundNo.'?sub_mchid='.$payload->get('sub_mchid', $config['sub_mch_id'] ?? 'null'), + ]); + + Logger::info('[Wechat][Marketing][ECommerceRefund][QueryPlugin] 插件装载完毕', ['rocket' => $rocket]); + + return $next($rocket); + } +} diff --git a/src/Plugin/Wechat/Marketing/ECommerceRefund/QueryReturnAdvancePlugin.php b/src/Plugin/Wechat/Marketing/ECommerceRefund/QueryReturnAdvancePlugin.php new file mode 100644 index 0000000..952029f --- /dev/null +++ b/src/Plugin/Wechat/Marketing/ECommerceRefund/QueryReturnAdvancePlugin.php @@ -0,0 +1,55 @@ + $rocket]); + + $params = $rocket->getParams(); + $payload = $rocket->getPayload(); + $config = get_wechat_config($params); + $refundId = $payload?->get('refund_id') ?? null; + + if (Pay::MODE_NORMAL === ($config['mode'] ?? Pay::MODE_NORMAL)) { + throw new InvalidParamsException(Exception::PARAMS_PLUGIN_ONLY_SUPPORT_SERVICE_MODE, '参数异常: 平台收付通(退款)-查询垫付回补结果,只支持服务商模式,当前配置为普通商户模式'); + } + + if (is_null($refundId)) { + throw new InvalidParamsException(Exception::PARAMS_NECESSARY_PARAMS_MISSING, '参数异常: 平台收付通(退款)-查询垫付回补结果,缺少必要参数 `refund_id`'); + } + + $rocket->setPayload([ + '_method' => 'GET', + '_service_url' => 'v3/ecommerce/refunds/'.$refundId.'/return-advance?sub_mchid='.$payload->get('sub_mchid', $config['sub_mch_id']), + ]); + + Logger::info('[Wechat][Marketing][ECommerceRefund][QueryReturnAdvancePlugin] 插件装载完毕', ['rocket' => $rocket]); + + return $next($rocket); + } +} diff --git a/src/Plugin/Wechat/Marketing/ECommerceRefund/ReturnAdvancePlugin.php b/src/Plugin/Wechat/Marketing/ECommerceRefund/ReturnAdvancePlugin.php new file mode 100644 index 0000000..3fa52f8 --- /dev/null +++ b/src/Plugin/Wechat/Marketing/ECommerceRefund/ReturnAdvancePlugin.php @@ -0,0 +1,56 @@ + $rocket]); + + $params = $rocket->getParams(); + $payload = $rocket->getPayload(); + $config = get_wechat_config($params); + $refundId = $payload?->get('refund_id') ?? null; + + if (Pay::MODE_NORMAL === ($config['mode'] ?? Pay::MODE_NORMAL)) { + throw new InvalidParamsException(Exception::PARAMS_PLUGIN_ONLY_SUPPORT_SERVICE_MODE, '参数异常: 平台收付通(退款)-垫付退款回补,只支持服务商模式,当前配置为普通商户模式'); + } + + if (is_null($refundId)) { + throw new InvalidParamsException(Exception::PARAMS_NECESSARY_PARAMS_MISSING, '参数异常: 平台收付通(退款)-垫付退款回补,缺少必要参数 `refund_id`'); + } + + $rocket->setPayload([ + '_method' => 'POST', + '_service_url' => 'v3/ecommerce/refunds/'.$refundId.'/return-advance', + 'sub_mchid' => $payload->get('sub_mchid', $config['sub_mch_id'] ?? ''), + ]); + + Logger::info('[Wechat][Marketing][ECommerceRefund][ReturnAdvancePlugin] 插件装载完毕', ['rocket' => $rocket]); + + return $next($rocket); + } +} diff --git a/src/Plugin/Wechat/Marketing/Transfer/CreatePlugin.php b/src/Plugin/Wechat/Marketing/Transfer/CreatePlugin.php new file mode 100644 index 0000000..de13894 --- /dev/null +++ b/src/Plugin/Wechat/Marketing/Transfer/CreatePlugin.php @@ -0,0 +1,104 @@ + $rocket]); + + $params = $rocket->getParams(); + $payload = $rocket->getPayload(); + $config = get_wechat_config($params); + + if (Pay::MODE_SERVICE === ($config['mode'] ?? Pay::MODE_NORMAL)) { + throw new InvalidParamsException(Exception::PARAMS_PLUGIN_ONLY_SUPPORT_NORMAL_MODE, '参数异常: 发起商家转账,只支持普通商户模式,当前配置为服务商模式'); + } + + if (is_null($payload) || $payload->isEmpty()) { + throw new InvalidParamsException(Exception::PARAMS_NECESSARY_PARAMS_MISSING, '参数异常: 发起商家转账参数,参数缺失'); + } + + $rocket->mergePayload(array_merge( + [ + '_method' => 'POST', + '_url' => 'v3/transfer/batches', + 'appid' => $payload->get('appid', $config[get_wechat_type_key($params)] ?? ''), + ], + $this->normal($params, $config, $payload) + )); + + Logger::info('[Wechat][Marketing][Transfer][CreatePlugin] 插件装载完毕', ['rocket' => $rocket]); + + return $next($rocket); + } + + /** + * @throws ContainerException + * @throws InvalidParamsException + * @throws ServiceNotFoundException + * @throws DecryptException + * @throws InvalidConfigException + */ + protected function normal(array $params, array $config, Collection $payload): array + { + if (!$payload->has('transfer_detail_list.0.user_name')) { + return []; + } + + return $this->encryptSensitiveData($params, $config, $payload); + } + + /** + * @throws ContainerException + * @throws DecryptException + * @throws InvalidConfigException + * @throws InvalidParamsException + * @throws ServiceNotFoundException + */ + protected function encryptSensitiveData(array $params, array $config, Collection $payload): array + { + $data['_serial_no'] = get_wechat_serial_no($params); + $publicKey = get_wechat_public_key($config, $data['_serial_no']); + + foreach ($payload->get('transfer_detail_list', []) as $key => $list) { + if (!empty($list['user_name'])) { + $data['transfer_detail_list'][$key]['user_name'] = encrypt_wechat_contents($list['user_name'], $publicKey); + } + } + + return $data; + } +} diff --git a/src/Plugin/Wechat/Marketing/Transfer/CreateReceiptDetailPlugin.php b/src/Plugin/Wechat/Marketing/Transfer/CreateReceiptDetailPlugin.php new file mode 100644 index 0000000..65b568e --- /dev/null +++ b/src/Plugin/Wechat/Marketing/Transfer/CreateReceiptDetailPlugin.php @@ -0,0 +1,48 @@ + $rocket]); + + $config = get_wechat_config($rocket->getParams()); + + if (Pay::MODE_SERVICE === ($config['mode'] ?? Pay::MODE_NORMAL)) { + throw new InvalidParamsException(Exception::PARAMS_PLUGIN_ONLY_SUPPORT_NORMAL_MODE, '参数异常: 受理转账明细电子回单,只支持普通商户模式,当前配置为服务商模式'); + } + + $rocket->mergePayload([ + '_method' => 'POST', + '_url' => 'v3/transfer-detail/electronic-receipts', + ]); + + Logger::info('[Wechat][Marketing][Transfer][CreateReceiptDetailPlugin] 插件装载完毕', ['rocket' => $rocket]); + + return $next($rocket); + } +} diff --git a/src/Plugin/Wechat/Marketing/Transfer/CreateReceiptPlugin.php b/src/Plugin/Wechat/Marketing/Transfer/CreateReceiptPlugin.php new file mode 100644 index 0000000..3173acc --- /dev/null +++ b/src/Plugin/Wechat/Marketing/Transfer/CreateReceiptPlugin.php @@ -0,0 +1,48 @@ + $rocket]); + + $config = get_wechat_config($rocket->getParams()); + + if (Pay::MODE_SERVICE === ($config['mode'] ?? Pay::MODE_NORMAL)) { + throw new InvalidParamsException(Exception::PARAMS_PLUGIN_ONLY_SUPPORT_NORMAL_MODE, '参数异常: 转账账单电子回单申请受理接口,只支持普通商户模式,当前配置为服务商模式'); + } + + $rocket->mergePayload([ + '_method' => 'POST', + '_url' => 'v3/transfer/bill-receipt', + ]); + + Logger::info('[Wechat][Marketing][Transfer][CreateReceiptPlugin] 插件装载完毕', ['rocket' => $rocket]); + + return $next($rocket); + } +} diff --git a/src/Plugin/Wechat/Marketing/Transfer/DownloadReceiptPlugin.php b/src/Plugin/Wechat/Marketing/Transfer/DownloadReceiptPlugin.php new file mode 100644 index 0000000..9c292d0 --- /dev/null +++ b/src/Plugin/Wechat/Marketing/Transfer/DownloadReceiptPlugin.php @@ -0,0 +1,53 @@ + $rocket]); + + $downloadUrl = $rocket->getPayload()?->get('download_url') ?? null; + $config = get_wechat_config($rocket->getParams()); + + if (Pay::MODE_SERVICE === ($config['mode'] ?? Pay::MODE_NORMAL)) { + throw new InvalidParamsException(Exception::PARAMS_PLUGIN_ONLY_SUPPORT_NORMAL_MODE, '参数异常: 下载电子回单,只支持普通商户模式,当前配置为服务商模式'); + } + + if (empty($downloadUrl)) { + throw new InvalidParamsException(Exception::PARAMS_NECESSARY_PARAMS_MISSING, '参数异常: 下载电子回单,参数缺少 `download_url`'); + } + + $rocket->setPayload([ + '_method' => 'GET', + '_url' => $downloadUrl, + ]); + + Logger::info('[Wechat][Marketing][Transfer][DownloadReceiptPlugin] 插件装载完毕', ['rocket' => $rocket]); + + return $next($rocket); + } +} diff --git a/src/Plugin/Wechat/Marketing/Transfer/QueryBatchByWxPlugin.php b/src/Plugin/Wechat/Marketing/Transfer/QueryBatchByWxPlugin.php new file mode 100644 index 0000000..dd8e8ca --- /dev/null +++ b/src/Plugin/Wechat/Marketing/Transfer/QueryBatchByWxPlugin.php @@ -0,0 +1,54 @@ + $rocket]); + + $config = get_wechat_config($rocket->getParams()); + $payload = $rocket->getPayload(); + $batchId = $payload?->get('batch_id') ?? null; + + if (Pay::MODE_SERVICE === ($config['mode'] ?? Pay::MODE_NORMAL)) { + throw new InvalidParamsException(Exception::PARAMS_PLUGIN_ONLY_SUPPORT_NORMAL_MODE, '参数异常: 通过微信批次单号查询批次单,只支持普通商户模式,当前配置为服务商模式'); + } + + if (empty($batchId)) { + throw new InvalidParamsException(Exception::PARAMS_NECESSARY_PARAMS_MISSING, '参数异常: 通过微信批次单号查询批次单,参数缺少 `batch_id`'); + } + + $rocket->setPayload([ + '_method' => 'GET', + '_url' => 'v3/transfer/batches/batch-id/'.$batchId.'?'.$payload->except('batch_id')->query(), + ]); + + Logger::info('[Wechat][Marketing][Transfer][QueryBatchByWxPlugin] 插件装载完毕', ['rocket' => $rocket]); + + return $next($rocket); + } +} diff --git a/src/Plugin/Wechat/Marketing/Transfer/QueryBatchPlugin.php b/src/Plugin/Wechat/Marketing/Transfer/QueryBatchPlugin.php new file mode 100644 index 0000000..415991d --- /dev/null +++ b/src/Plugin/Wechat/Marketing/Transfer/QueryBatchPlugin.php @@ -0,0 +1,54 @@ + $rocket]); + + $config = get_wechat_config($rocket->getParams()); + $payload = $rocket->getPayload(); + $outBatchNo = $payload?->get('out_batch_no') ?? null; + + if (Pay::MODE_SERVICE === ($config['mode'] ?? Pay::MODE_NORMAL)) { + throw new InvalidParamsException(Exception::PARAMS_PLUGIN_ONLY_SUPPORT_NORMAL_MODE, '参数异常: 通过商家批次单号查询批次单,只支持普通商户模式,当前配置为服务商模式'); + } + + if (empty($outBatchNo)) { + throw new InvalidParamsException(Exception::PARAMS_NECESSARY_PARAMS_MISSING, '参数异常: 通过商家批次单号查询批次单,参数缺少 `out_batch_no`'); + } + + $rocket->setPayload([ + '_method' => 'GET', + '_url' => 'v3/transfer/batches/out-batch-no/'.$outBatchNo.'?'.$payload->except('out_batch_no')->query(), + ]); + + Logger::info('[Wechat][Marketing][Transfer][QueryBatchPlugin] 插件装载完毕', ['rocket' => $rocket]); + + return $next($rocket); + } +} diff --git a/src/Plugin/Wechat/Marketing/Transfer/QueryDetailByWxPlugin.php b/src/Plugin/Wechat/Marketing/Transfer/QueryDetailByWxPlugin.php new file mode 100644 index 0000000..35571f9 --- /dev/null +++ b/src/Plugin/Wechat/Marketing/Transfer/QueryDetailByWxPlugin.php @@ -0,0 +1,55 @@ + $rocket]); + + $config = get_wechat_config($rocket->getParams()); + $payload = $rocket->getPayload(); + $batchId = $payload?->get('batch_id') ?? null; + $detailId = $payload?->get('detail_id') ?? null; + + if (Pay::MODE_SERVICE === ($config['mode'] ?? Pay::MODE_NORMAL)) { + throw new InvalidParamsException(Exception::PARAMS_PLUGIN_ONLY_SUPPORT_NORMAL_MODE, '参数异常: 通过微信明细单号查询明细单,只支持普通商户模式,当前配置为服务商模式'); + } + + if (empty($batchId) || empty($detailId)) { + throw new InvalidParamsException(Exception::PARAMS_NECESSARY_PARAMS_MISSING, '参数异常: 通过微信明细单号查询明细单,参数缺少 `batch_id` 或 `detail_id`'); + } + + $rocket->setPayload([ + '_method' => 'GET', + '_url' => 'v3/transfer/batches/batch-id/'.$batchId.'/details/detail-id/'.$detailId, + ]); + + Logger::info('[Wechat][Marketing][Transfer][QueryDetailByWxPlugin] 插件装载完毕', ['rocket' => $rocket]); + + return $next($rocket); + } +} diff --git a/src/Plugin/Wechat/Marketing/Transfer/QueryDetailPlugin.php b/src/Plugin/Wechat/Marketing/Transfer/QueryDetailPlugin.php new file mode 100644 index 0000000..7675301 --- /dev/null +++ b/src/Plugin/Wechat/Marketing/Transfer/QueryDetailPlugin.php @@ -0,0 +1,55 @@ + $rocket]); + + $config = get_wechat_config($rocket->getParams()); + $payload = $rocket->getPayload(); + $outBatchNo = $payload?->get('out_batch_no') ?? null; + $outDetailNo = $payload?->get('out_detail_no') ?? null; + + if (Pay::MODE_SERVICE === ($config['mode'] ?? Pay::MODE_NORMAL)) { + throw new InvalidParamsException(Exception::PARAMS_PLUGIN_ONLY_SUPPORT_NORMAL_MODE, '参数异常: 通过商家明细单号查询明细单,只支持普通商户模式,当前配置为服务商模式'); + } + + if (empty($outBatchNo) || empty($outDetailNo)) { + throw new InvalidParamsException(Exception::PARAMS_NECESSARY_PARAMS_MISSING, '参数异常: 通过商家明细单号查询明细单,参数缺少 `out_batch_no` 或 `out_detail_no`'); + } + + $rocket->setPayload([ + '_method' => 'GET', + '_url' => 'v3/transfer/batches/out-batch-no/'.$outBatchNo.'/details/out-detail-no/'.$outDetailNo, + ]); + + Logger::info('[Wechat][Marketing][Transfer][QueryDetailPlugin] 插件装载完毕', ['rocket' => $rocket]); + + return $next($rocket); + } +} diff --git a/src/Plugin/Wechat/Marketing/Transfer/QueryReceiptDetailPlugin.php b/src/Plugin/Wechat/Marketing/Transfer/QueryReceiptDetailPlugin.php new file mode 100644 index 0000000..ec05be2 --- /dev/null +++ b/src/Plugin/Wechat/Marketing/Transfer/QueryReceiptDetailPlugin.php @@ -0,0 +1,53 @@ + $rocket]); + + $payload = $rocket->getPayload(); + $config = get_wechat_config($rocket->getParams()); + + if (Pay::MODE_SERVICE === ($config['mode'] ?? Pay::MODE_NORMAL)) { + throw new InvalidParamsException(Exception::PARAMS_PLUGIN_ONLY_SUPPORT_NORMAL_MODE, '参数异常: 查询转账明细电子回单受理结果API,只支持普通商户模式,当前配置为服务商模式'); + } + + if (is_null($payload)) { + throw new InvalidParamsException(Exception::PARAMS_NECESSARY_PARAMS_MISSING, '参数异常: 查询转账明细电子回单受理结果API,参数为空'); + } + + $rocket->setPayload([ + '_method' => 'GET', + '_url' => 'v3/transfer-detail/electronic-receipts?'.$payload->query(), + ]); + + Logger::info('[Wechat][Marketing][Transfer][QueryReceiptDetailPlugin] 插件装载完毕', ['rocket' => $rocket]); + + return $next($rocket); + } +} diff --git a/src/Plugin/Wechat/Marketing/Transfer/QueryReceiptPlugin.php b/src/Plugin/Wechat/Marketing/Transfer/QueryReceiptPlugin.php new file mode 100644 index 0000000..d517441 --- /dev/null +++ b/src/Plugin/Wechat/Marketing/Transfer/QueryReceiptPlugin.php @@ -0,0 +1,53 @@ + $rocket]); + + $outBatchNo = $rocket->getPayload()?->get('out_batch_no') ?? null; + $config = get_wechat_config($rocket->getParams()); + + if (Pay::MODE_SERVICE === ($config['mode'] ?? Pay::MODE_NORMAL)) { + throw new InvalidParamsException(Exception::PARAMS_PLUGIN_ONLY_SUPPORT_NORMAL_MODE, '参数异常: 查询转账账单电子回单接口,只支持普通商户模式,当前配置为服务商模式'); + } + + if (empty($outBatchNo)) { + throw new InvalidParamsException(Exception::PARAMS_NECESSARY_PARAMS_MISSING, '参数异常: 查询转账账单电子回单接口,参数缺少 `out_batch_no`'); + } + + $rocket->setPayload([ + '_method' => 'GET', + '_url' => 'v3/transfer/bill-receipt/'.$outBatchNo, + ]); + + Logger::info('[Wechat][Marketing][Transfer][QueryReceiptPlugin] 插件装载完毕', ['rocket' => $rocket]); + + return $next($rocket); + } +} diff --git a/src/Plugin/Wechat/Papay/ApplyPlugin.php b/src/Plugin/Wechat/Papay/ApplyPlugin.php deleted file mode 100644 index 5443b00..0000000 --- a/src/Plugin/Wechat/Papay/ApplyPlugin.php +++ /dev/null @@ -1,21 +0,0 @@ -getParams()); - $wechatId = $this->getWechatId($config, $rocket->getParams()); - - if (!$rocket->getPayload()->has('notify_url')) { - $wechatId['notify_url'] = $config['notify_url'] ?? ''; - } - - $rocket->mergePayload($wechatId); - $rocket->mergePayload([ - 'sign' => get_wechat_sign_v2($rocket->getParams(), $rocket->getPayload()->all()), - ]); - - $rocket->setDestination($rocket->getPayload()); - $rocket->setDirection(NoHttpRequestDirection::class); - - return $next($rocket); - } - - protected function getWechatId(array $config, array $params): array - { - $configKey = $this->getConfigKey($params); - - return [ - 'appid' => $config[$configKey] ?? '', - 'mch_id' => $config['mch_id'] ?? '', - ]; - } - - protected function getConfigKey(array $params): string - { - $key = ($params['_type'] ?? 'mp').'_app_id'; - - if ('app_app_id' === $key) { - $key = 'app_id'; - } - - return $key; - } -} diff --git a/src/Plugin/Wechat/Pay/App/ClosePlugin.php b/src/Plugin/Wechat/Pay/App/ClosePlugin.php index 9e82e5f..de196c1 100644 --- a/src/Plugin/Wechat/Pay/App/ClosePlugin.php +++ b/src/Plugin/Wechat/Pay/App/ClosePlugin.php @@ -4,7 +4,73 @@ declare(strict_types=1); namespace Yansongda\Pay\Plugin\Wechat\Pay\App; +use Closure; +use Yansongda\Pay\Contract\PluginInterface; +use Yansongda\Pay\Exception\ContainerException; +use Yansongda\Pay\Exception\Exception; +use Yansongda\Pay\Exception\InvalidParamsException; +use Yansongda\Pay\Exception\ServiceNotFoundException; +use Yansongda\Pay\Logger; +use Yansongda\Pay\Pay; +use Yansongda\Pay\Rocket; +use Yansongda\Supports\Collection; + +use function Yansongda\Pay\get_wechat_config; + /** - * @see https://pay.weixin.qq.com/wiki/doc/apiv3/apis/chapter3_2_3.shtml + * @see https://pay.weixin.qq.com/docs/merchant/apis/in-app-payment/close-order.html + * @see https://pay.weixin.qq.com/docs/partner/apis/partner-in-app-payment/close-order.html */ -class ClosePlugin extends \Yansongda\Pay\Plugin\Wechat\Pay\Common\ClosePlugin {} +class ClosePlugin implements PluginInterface +{ + /** + * @throws ContainerException + * @throws InvalidParamsException + * @throws ServiceNotFoundException + */ + public function assembly(Rocket $rocket, Closure $next): Rocket + { + Logger::debug('[Wechat][Pay][App][ClosePlugin] 插件开始装载', ['rocket' => $rocket]); + + $params = $rocket->getParams(); + $config = get_wechat_config($params); + $payload = $rocket->getPayload(); + $outTradeNo = $payload?->get('out_trade_no') ?? null; + + if (empty($outTradeNo)) { + throw new InvalidParamsException(Exception::PARAMS_NECESSARY_PARAMS_MISSING, '参数异常: App 关闭订单,参数缺少 `out_trade_no`'); + } + + if (Pay::MODE_SERVICE === ($config['mode'] ?? Pay::MODE_NORMAL)) { + $data = $this->service($payload, $config); + } + + $rocket->setPayload(array_merge( + [ + '_method' => 'POST', + '_url' => 'v3/pay/transactions/out-trade-no/'.$outTradeNo.'/close', + '_service_url' => 'v3/pay/partner/transactions/out-trade-no/'.$outTradeNo.'/close', + ], + $data ?? $this->normal($config) + )); + + Logger::info('[Wechat][Pay][App][ClosePlugin] 插件装载完毕', ['rocket' => $rocket]); + + return $next($rocket); + } + + protected function normal(array $config): array + { + return [ + 'mchid' => $config['mch_id'] ?? '', + ]; + } + + protected function service(Collection $payload, array $config): array + { + return [ + 'sp_mchid' => $config['mch_id'] ?? '', + 'sub_mchid' => $payload->get('sub_mchid', $config['sub_mch_id'] ?? ''), + ]; + } +} diff --git a/src/Plugin/Wechat/Pay/App/DownloadBillPlugin.php b/src/Plugin/Wechat/Pay/App/DownloadBillPlugin.php index 34d4bbd..c6451d4 100644 --- a/src/Plugin/Wechat/Pay/App/DownloadBillPlugin.php +++ b/src/Plugin/Wechat/Pay/App/DownloadBillPlugin.php @@ -4,7 +4,40 @@ declare(strict_types=1); namespace Yansongda\Pay\Plugin\Wechat\Pay\App; +use Closure; +use Yansongda\Pay\Contract\PluginInterface; +use Yansongda\Pay\Exception\Exception; +use Yansongda\Pay\Exception\InvalidParamsException; +use Yansongda\Pay\Logger; +use Yansongda\Pay\Rocket; + /** - * @see https://pay.weixin.qq.com/wiki/doc/apiv3/apis/chapter3_2_8.shtml + * @see https://pay.weixin.qq.com/docs/merchant/apis/in-app-payment/download-bill.html + * @see https://pay.weixin.qq.com/docs/partner/apis/partner-in-app-payment/download-bill.html */ -class DownloadBillPlugin extends \Yansongda\Pay\Plugin\Wechat\Pay\Common\DownloadBillPlugin {} +class DownloadBillPlugin implements PluginInterface +{ + /** + * @throws InvalidParamsException + */ + public function assembly(Rocket $rocket, Closure $next): Rocket + { + Logger::debug('[Wechat][Pay][App][DownloadBillPlugin] 插件开始装载', ['rocket' => $rocket]); + + $downloadUrl = $rocket->getPayload()?->get('download_url') ?? null; + + if (empty($downloadUrl)) { + throw new InvalidParamsException(Exception::PARAMS_NECESSARY_PARAMS_MISSING, '参数异常: App 下载交易对账单,参数缺少 `download_url`'); + } + + $rocket->setPayload([ + '_method' => 'GET', + '_url' => $downloadUrl, + '_service_url' => $downloadUrl, + ]); + + Logger::info('[Wechat][Pay][App][DownloadBillPlugin] 插件装载完毕', ['rocket' => $rocket]); + + return $next($rocket); + } +} diff --git a/src/Plugin/Wechat/Pay/App/GetFlowBillPlugin.php b/src/Plugin/Wechat/Pay/App/GetFlowBillPlugin.php deleted file mode 100644 index 85e6c4b..0000000 --- a/src/Plugin/Wechat/Pay/App/GetFlowBillPlugin.php +++ /dev/null @@ -1,10 +0,0 @@ - $rocket]); + + $payload = $rocket->getPayload(); + + if (is_null($payload)) { + throw new InvalidParamsException(Exception::PARAMS_NECESSARY_PARAMS_MISSING, '参数异常: App 申请资金账单,参数为空'); + } + + $query = $payload->query(); + + $rocket->setPayload([ + '_method' => 'GET', + '_url' => 'v3/bill/fundflowbill?'.$query, + '_service_url' => 'v3/bill/fundflowbill?'.$query, + ]); + + Logger::info('[Wechat][Pay][App][GetFundBillPlugin] 插件装载完毕', ['rocket' => $rocket]); + + return $next($rocket); + } +} diff --git a/src/Plugin/Wechat/Pay/App/GetTradeBillPlugin.php b/src/Plugin/Wechat/Pay/App/GetTradeBillPlugin.php index 90026ea..73ba922 100644 --- a/src/Plugin/Wechat/Pay/App/GetTradeBillPlugin.php +++ b/src/Plugin/Wechat/Pay/App/GetTradeBillPlugin.php @@ -4,7 +4,42 @@ declare(strict_types=1); namespace Yansongda\Pay\Plugin\Wechat\Pay\App; +use Closure; +use Yansongda\Pay\Contract\PluginInterface; +use Yansongda\Pay\Exception\Exception; +use Yansongda\Pay\Exception\InvalidParamsException; +use Yansongda\Pay\Logger; +use Yansongda\Pay\Rocket; + /** - * @see https://pay.weixin.qq.com/wiki/doc/apiv3/apis/chapter3_2_6.shtml + * @see https://pay.weixin.qq.com/docs/merchant/apis/in-app-payment/get-trade-bill.html + * @see https://pay.weixin.qq.com/docs/partner/apis/partner-in-app-payment/get-trade-bill.html */ -class GetTradeBillPlugin extends \Yansongda\Pay\Plugin\Wechat\Pay\Common\GetTradeBillPlugin {} +class GetTradeBillPlugin implements PluginInterface +{ + /** + * @throws InvalidParamsException + */ + public function assembly(Rocket $rocket, Closure $next): Rocket + { + Logger::debug('[Wechat][Pay][App][GetTradeBillPlugin] 插件开始装载', ['rocket' => $rocket]); + + $payload = $rocket->getPayload(); + + if (is_null($payload)) { + throw new InvalidParamsException(Exception::PARAMS_NECESSARY_PARAMS_MISSING, '参数异常: App 申请交易账单,参数为空'); + } + + $query = $payload->query(); + + $rocket->setPayload([ + '_method' => 'GET', + '_url' => 'v3/bill/tradebill?'.$query, + '_service_url' => 'v3/bill/tradebill?'.$query, + ]); + + Logger::info('[Wechat][Pay][App][GetTradeBillPlugin] 插件装载完毕', ['rocket' => $rocket]); + + return $next($rocket); + } +} diff --git a/src/Plugin/Wechat/Pay/App/InvokePlugin.php b/src/Plugin/Wechat/Pay/App/InvokePlugin.php new file mode 100644 index 0000000..b42351a --- /dev/null +++ b/src/Plugin/Wechat/Pay/App/InvokePlugin.php @@ -0,0 +1,111 @@ + $rocket]); + + $destination = $rocket->getDestination(); + $prepayId = $destination?->get('prepay_id'); + + if (is_null($prepayId)) { + Logger::error('[Wechat][Pay][App][InvokePlugin] 预下单失败:响应缺少 `prepay_id` 参数,请自行检查参数是否符合微信要求', $destination?->all() ?? null); + + throw new InvalidResponseException(Exception::RESPONSE_MISSING_NECESSARY_PARAMS, $destination?->get('message') ?? '预下单失败:响应缺少 `prepay_id` 参数,请自行检查参数是否符合微信要求', $destination?->all() ?? null); + } + + $params = $rocket->getParams(); + $config = get_wechat_config($params); + $payload = $rocket->getPayload(); + + $rocket->setDestination($this->getInvokeConfig($payload, $config, $prepayId)); + + Logger::info('[Wechat][Pay][App][InvokePlugin] 插件装载完毕', ['rocket' => $rocket]); + + return $rocket; + } + + /** + * @throws InvalidConfigException + * @throws Throwable 生成随机串失败 + */ + protected function getInvokeConfig(?Collection $payload, array $config, string $prepayId): Config + { + $invokeConfig = new Config([ + 'appid' => $this->getAppId($payload, $config), + 'partnerid' => $this->getPartnerId($payload, $config), + 'prepayid' => $prepayId, + 'package' => 'Sign=WXPay', + 'noncestr' => Str::random(32), + 'timestamp' => time().'', + ]); + + $invokeConfig->set('sign', $this->getSign($invokeConfig, $config)); + + return $invokeConfig; + } + + /** + * @throws InvalidConfigException + */ + protected function getSign(Collection $invokeConfig, array $config): string + { + $contents = $invokeConfig->get('appid', '')."\n". + $invokeConfig->get('timestamp', '')."\n". + $invokeConfig->get('noncestr', '')."\n". + $invokeConfig->get('prepayid', '')."\n"; + + return get_wechat_sign($config, $contents); + } + + protected function getAppId(?Collection $payload, array $config): string + { + if (Pay::MODE_SERVICE === ($config['mode'] ?? Pay::MODE_NORMAL)) { + return $payload?->get('_invoke_appid') ?? $config['sub_app_id'] ?? ''; + } + + return $payload?->get('_invoke_appid') ?? $config['app_id'] ?? ''; + } + + protected function getPartnerId(?Collection $payload, array $config): string + { + return $payload?->get('_invoke_partnerid') ?? $config['mch_id'] ?? ''; + } +} diff --git a/src/Plugin/Wechat/Pay/App/InvokePrepayPlugin.php b/src/Plugin/Wechat/Pay/App/InvokePrepayPlugin.php deleted file mode 100644 index 834641c..0000000 --- a/src/Plugin/Wechat/Pay/App/InvokePrepayPlugin.php +++ /dev/null @@ -1,64 +0,0 @@ - $this->getAppId($rocket), - 'partnerid' => get_wechat_config($rocket->getParams())['mch_id'] ?? null, - 'prepayid' => $prepayId, - 'package' => 'Sign=WXPay', - 'noncestr' => Str::random(32), - 'timestamp' => time().'', - ]); - - $config->set('sign', $this->getSign($config, $rocket->getParams())); - - return $config; - } - - /** - * @throws ContainerException - * @throws InvalidConfigException - * @throws ServiceNotFoundException - */ - protected function getSign(Collection $invokeConfig, array $params): string - { - $contents = $invokeConfig->get('appid', '')."\n". - $invokeConfig->get('timestamp', '')."\n". - $invokeConfig->get('noncestr', '')."\n". - $invokeConfig->get('prepayid', '')."\n"; - - return get_wechat_sign($params, $contents); - } - - protected function getConfigKey(): string - { - return 'app_id'; - } -} diff --git a/src/Plugin/Wechat/Pay/App/InvokePrepayV2Plugin.php b/src/Plugin/Wechat/Pay/App/InvokePrepayV2Plugin.php deleted file mode 100644 index 8ec4ba9..0000000 --- a/src/Plugin/Wechat/Pay/App/InvokePrepayV2Plugin.php +++ /dev/null @@ -1,49 +0,0 @@ -getParams(); - - $config = new Config([ - 'appId' => $this->getAppId($rocket), - 'partnerId' => get_wechat_config($params)['mch_id'] ?? null, - 'prepayId' => $prepayId, - 'package' => 'Sign=WXPay', - 'nonceStr' => Str::random(32), - 'timeStamp' => time().'', - ]); - - $config->set('sign', get_wechat_sign_v2($params, $config->all())); - - return $config; - } - - protected function getConfigKey(): string - { - return 'app_id'; - } -} diff --git a/src/Plugin/Wechat/Pay/App/PayPlugin.php b/src/Plugin/Wechat/Pay/App/PayPlugin.php new file mode 100644 index 0000000..e04a722 --- /dev/null +++ b/src/Plugin/Wechat/Pay/App/PayPlugin.php @@ -0,0 +1,78 @@ + $rocket]); + + $payload = $rocket->getPayload(); + $params = $rocket->getParams(); + $config = get_wechat_config($params); + + if (is_null($payload)) { + throw new InvalidParamsException(Exception::PARAMS_NECESSARY_PARAMS_MISSING, '参数异常: APP下单,参数为空'); + } + + if (Pay::MODE_SERVICE === ($config['mode'] ?? Pay::MODE_NORMAL)) { + $data = $this->service($payload, $config); + } + + $rocket->mergePayload(array_merge( + [ + '_method' => 'POST', + '_url' => 'v3/pay/transactions/app', + '_service_url' => 'v3/pay/partner/transactions/app', + 'notify_url' => $payload->get('notify_url', $config['notify_url'] ?? ''), + ], + $data ?? $this->normal($config) + )); + + Logger::info('[Wechat][Pay][App][PayPlugin] 插件装载完毕', ['rocket' => $rocket]); + + return $next($rocket); + } + + protected function normal(array $config): array + { + return [ + 'appid' => $config['app_id'] ?? '', + 'mchid' => $config['mch_id'] ?? '', + ]; + } + + protected function service(Collection $payload, array $config): array + { + return [ + 'sp_appid' => $config['app_id'] ?? '', + 'sp_mchid' => $config['mch_id'] ?? '', + 'sub_mchid' => $payload->get('sub_mchid', $config['sub_mch_id'] ?? ''), + ]; + } +} diff --git a/src/Plugin/Wechat/Pay/App/PrepayPlugin.php b/src/Plugin/Wechat/Pay/App/PrepayPlugin.php deleted file mode 100644 index 12df20e..0000000 --- a/src/Plugin/Wechat/Pay/App/PrepayPlugin.php +++ /dev/null @@ -1,28 +0,0 @@ - $rocket]); + + $params = $rocket->getParams(); + $config = get_wechat_config($params); + $payload = $rocket->getPayload(); + $transactionId = $payload?->get('transaction_id') ?? null; + + if (empty($transactionId)) { + throw new InvalidParamsException(Exception::PARAMS_NECESSARY_PARAMS_MISSING, '参数异常: App 通过微信订单号查询订单,参数缺少 `transaction_id`'); + } + + $rocket->setPayload([ + '_method' => 'GET', + '_url' => 'v3/pay/transactions/id/'.$transactionId.'?'.$this->normal($config), + '_service_url' => 'v3/pay/partner/transactions/id/'.$transactionId.'?'.$this->service($payload, $config), + ]); + + Logger::info('[Wechat][Pay][App][QueryByWxPlugin] 插件装载完毕', ['rocket' => $rocket]); + + return $next($rocket); + } + + protected function normal(array $config): string + { + return http_build_query([ + 'mchid' => $config['mch_id'] ?? 'null', + ]); + } + + protected function service(Collection $payload, array $config): string + { + return http_build_query([ + 'sp_mchid' => $config['mch_id'] ?? 'null', + 'sub_mchid' => $payload->get('sub_mchid', $config['sub_mch_id'] ?? 'null'), + ]); + } +} diff --git a/src/Plugin/Wechat/Pay/App/QueryPlugin.php b/src/Plugin/Wechat/Pay/App/QueryPlugin.php index eb9d770..db89c2d 100644 --- a/src/Plugin/Wechat/Pay/App/QueryPlugin.php +++ b/src/Plugin/Wechat/Pay/App/QueryPlugin.php @@ -4,7 +4,65 @@ declare(strict_types=1); namespace Yansongda\Pay\Plugin\Wechat\Pay\App; +use Closure; +use Yansongda\Pay\Contract\PluginInterface; +use Yansongda\Pay\Exception\ContainerException; +use Yansongda\Pay\Exception\Exception; +use Yansongda\Pay\Exception\InvalidParamsException; +use Yansongda\Pay\Exception\ServiceNotFoundException; +use Yansongda\Pay\Logger; +use Yansongda\Pay\Rocket; +use Yansongda\Supports\Collection; + +use function Yansongda\Pay\get_wechat_config; + /** - * @see https://pay.weixin.qq.com/wiki/doc/apiv3/apis/chapter3_2_2.shtml + * @see https://pay.weixin.qq.com/docs/merchant/apis/in-app-payment/query-by-out-trade-no.html + * @see https://pay.weixin.qq.com/docs/partner/apis/partner-in-app-payment/query-by-out-trade-no.html */ -class QueryPlugin extends \Yansongda\Pay\Plugin\Wechat\Pay\Common\QueryPlugin {} +class QueryPlugin implements PluginInterface +{ + /** + * @throws InvalidParamsException + * @throws ContainerException + * @throws ServiceNotFoundException + */ + public function assembly(Rocket $rocket, Closure $next): Rocket + { + Logger::debug('[Wechat][Pay][App][QueryPlugin] 插件开始装载', ['rocket' => $rocket]); + + $params = $rocket->getParams(); + $config = get_wechat_config($params); + $payload = $rocket->getPayload(); + $outTradeNo = $payload?->get('out_trade_no') ?? null; + + if (empty($outTradeNo)) { + throw new InvalidParamsException(Exception::PARAMS_NECESSARY_PARAMS_MISSING, '参数异常: App 通过商户订单号查询订单,参数缺少 `out_trade_no`'); + } + + $rocket->setPayload([ + '_method' => 'GET', + '_url' => 'v3/pay/transactions/out-trade-no/'.$outTradeNo.'?'.$this->normal($config), + '_service_url' => 'v3/pay/partner/transactions/out-trade-no/'.$outTradeNo.'?'.$this->service($payload, $config), + ]); + + Logger::info('[Wechat][Pay][App][QueryPlugin] 插件装载完毕', ['rocket' => $rocket]); + + return $next($rocket); + } + + protected function normal(array $config): string + { + return http_build_query([ + 'mchid' => $config['mch_id'] ?? '', + ]); + } + + protected function service(Collection $payload, array $config): string + { + return http_build_query([ + 'sp_mchid' => $config['mch_id'] ?? '', + 'sub_mchid' => $payload->get('sub_mchid', $config['sub_mch_id'] ?? ''), + ]); + } +} diff --git a/src/Plugin/Wechat/Pay/App/QueryRefundPlugin.php b/src/Plugin/Wechat/Pay/App/QueryRefundPlugin.php index 50fe384..5dabbba 100644 --- a/src/Plugin/Wechat/Pay/App/QueryRefundPlugin.php +++ b/src/Plugin/Wechat/Pay/App/QueryRefundPlugin.php @@ -4,7 +4,51 @@ declare(strict_types=1); namespace Yansongda\Pay\Plugin\Wechat\Pay\App; +use Closure; +use Yansongda\Pay\Contract\PluginInterface; +use Yansongda\Pay\Exception\ContainerException; +use Yansongda\Pay\Exception\Exception; +use Yansongda\Pay\Exception\InvalidParamsException; +use Yansongda\Pay\Exception\ServiceNotFoundException; +use Yansongda\Pay\Logger; +use Yansongda\Pay\Rocket; + +use function Yansongda\Pay\get_wechat_config; + /** - * @see https://pay.weixin.qq.com/wiki/doc/apiv3/apis/chapter3_2_10.shtml + * @see https://pay.weixin.qq.com/docs/merchant/apis/in-app-payment/query-by-out-refund-no.html + * @see https://pay.weixin.qq.com/docs/partner/apis/partner-in-app-payment/query-by-out-refund-no.html */ -class QueryRefundPlugin extends \Yansongda\Pay\Plugin\Wechat\Pay\Common\QueryRefundPlugin {} +class QueryRefundPlugin implements PluginInterface +{ + /** + * @throws InvalidParamsException + * @throws ContainerException + * @throws ServiceNotFoundException + */ + public function assembly(Rocket $rocket, Closure $next): Rocket + { + Logger::debug('[Wechat][Pay][App][QueryRefundPlugin] 插件开始装载', ['rocket' => $rocket]); + + $params = $rocket->getParams(); + $config = get_wechat_config($params); + $payload = $rocket->getPayload(); + $outRefundNo = $payload?->get('out_refund_no') ?? null; + + if (empty($outRefundNo)) { + throw new InvalidParamsException(Exception::PARAMS_NECESSARY_PARAMS_MISSING, '参数异常: App 查询退款订单,参数缺少 `out_refund_no`'); + } + + $subMchId = $payload->get('sub_mchid', $config['sub_mch_id'] ?? ''); + + $rocket->setPayload([ + '_method' => 'GET', + '_url' => 'v3/refund/domestic/refunds/'.$outRefundNo, + '_service_url' => 'v3/refund/domestic/refunds/'.$outRefundNo.'?sub_mchid='.$subMchId, + ]); + + Logger::info('[Wechat][Pay][App][QueryRefundPlugin] 插件装载完毕', ['rocket' => $rocket]); + + return $next($rocket); + } +} diff --git a/src/Plugin/Wechat/Pay/App/RefundPlugin.php b/src/Plugin/Wechat/Pay/App/RefundPlugin.php index 5fe9d7f..ffe4075 100644 --- a/src/Plugin/Wechat/Pay/App/RefundPlugin.php +++ b/src/Plugin/Wechat/Pay/App/RefundPlugin.php @@ -4,7 +4,70 @@ declare(strict_types=1); namespace Yansongda\Pay\Plugin\Wechat\Pay\App; +use Closure; +use Yansongda\Pay\Contract\PluginInterface; +use Yansongda\Pay\Exception\ContainerException; +use Yansongda\Pay\Exception\Exception; +use Yansongda\Pay\Exception\InvalidParamsException; +use Yansongda\Pay\Exception\ServiceNotFoundException; +use Yansongda\Pay\Logger; +use Yansongda\Pay\Pay; +use Yansongda\Pay\Rocket; +use Yansongda\Supports\Collection; + +use function Yansongda\Pay\get_wechat_config; + /** - * @see https://pay.weixin.qq.com/wiki/doc/apiv3/apis/chapter3_2_9.shtml + * @see https://pay.weixin.qq.com/docs/merchant/apis/in-app-payment/create.html + * @see https://pay.weixin.qq.com/docs/partner/apis/partner-in-app-payment/create.html */ -class RefundPlugin extends \Yansongda\Pay\Plugin\Wechat\Pay\Common\RefundPlugin {} +class RefundPlugin implements PluginInterface +{ + /** + * @throws ContainerException + * @throws InvalidParamsException + * @throws ServiceNotFoundException + */ + public function assembly(Rocket $rocket, Closure $next): Rocket + { + Logger::debug('[Wechat][Pay][App][RefundPlugin] 插件开始装载', ['rocket' => $rocket]); + + $params = $rocket->getParams(); + $config = get_wechat_config($params); + $payload = $rocket->getPayload(); + + if (is_null($payload)) { + throw new InvalidParamsException(Exception::PARAMS_NECESSARY_PARAMS_MISSING, '参数异常: App 退款申请,参数为空'); + } + + if (Pay::MODE_SERVICE === $config['mode']) { + $data = $this->service($payload, $config); + } + + $rocket->mergePayload(array_merge( + [ + '_method' => 'POST', + '_url' => 'v3/refund/domestic/refunds', + '_service_url' => 'v3/refund/domestic/refunds', + 'notify_url' => $payload->get('notify_url', $config['notify_url'] ?? null), + ], + $data ?? $this->normal() + )); + + Logger::info('[Wechat][Pay][App][RefundPlugin] 插件装载完毕', ['rocket' => $rocket]); + + return $next($rocket); + } + + protected function normal(): array + { + return []; + } + + protected function service(Collection $payload, array $config): array + { + return [ + 'sub_mchid' => $payload->get('sub_mchid', $config['sub_mch_id'] ?? ''), + ]; + } +} diff --git a/src/Plugin/Wechat/Pay/Combine/AppInvokePlugin.php b/src/Plugin/Wechat/Pay/Combine/AppInvokePlugin.php new file mode 100644 index 0000000..ae6d8d4 --- /dev/null +++ b/src/Plugin/Wechat/Pay/Combine/AppInvokePlugin.php @@ -0,0 +1,111 @@ + $rocket]); + + $destination = $rocket->getDestination(); + $prepayId = $destination?->get('prepay_id'); + + if (is_null($prepayId)) { + Logger::error('[Wechat][Pay][Combine][AppInvokePlugin] 预下单失败:响应缺少 `prepay_id` 参数,请自行检查参数是否符合微信要求', $destination?->all() ?? null); + + throw new InvalidResponseException(Exception::RESPONSE_MISSING_NECESSARY_PARAMS, $destination?->get('message') ?? '预下单失败:响应缺少 `prepay_id` 参数,请自行检查参数是否符合微信要求', $destination?->all() ?? null); + } + + $params = $rocket->getParams(); + $config = get_wechat_config($params); + $payload = $rocket->getPayload(); + + $rocket->setDestination($this->getInvokeConfig($payload, $config, $prepayId)); + + Logger::info('[Wechat][Pay][Combine][AppInvokePlugin] 插件装载完毕', ['rocket' => $rocket]); + + return $rocket; + } + + /** + * @throws InvalidConfigException + * @throws Throwable 生成随机串失败 + */ + protected function getInvokeConfig(?Collection $payload, array $config, string $prepayId): Config + { + $invokeConfig = new Config([ + 'appid' => $this->getAppId($payload, $config), + 'partnerid' => $this->getPartnerId($payload, $config), + 'prepayid' => $prepayId, + 'package' => 'Sign=WXPay', + 'noncestr' => Str::random(32), + 'timestamp' => time().'', + ]); + + $invokeConfig->set('sign', $this->getSign($invokeConfig, $config)); + + return $invokeConfig; + } + + /** + * @throws InvalidConfigException + */ + protected function getSign(Collection $invokeConfig, array $config): string + { + $contents = $invokeConfig->get('appid', '')."\n". + $invokeConfig->get('timestamp', '')."\n". + $invokeConfig->get('noncestr', '')."\n". + $invokeConfig->get('prepayid', '')."\n"; + + return get_wechat_sign($config, $contents); + } + + protected function getAppId(?Collection $payload, array $config): string + { + if (Pay::MODE_SERVICE === ($config['mode'] ?? Pay::MODE_NORMAL)) { + return $payload?->get('_invoke_appid') ?? $config['sub_app_id'] ?? ''; + } + + return $payload?->get('_invoke_appid') ?? $config['app_id'] ?? ''; + } + + protected function getPartnerId(?Collection $payload, array $config): string + { + return $payload?->get('_invoke_partnerid') ?? $config['mch_id'] ?? ''; + } +} diff --git a/src/Plugin/Wechat/Pay/Combine/AppPayPlugin.php b/src/Plugin/Wechat/Pay/Combine/AppPayPlugin.php new file mode 100644 index 0000000..e58887b --- /dev/null +++ b/src/Plugin/Wechat/Pay/Combine/AppPayPlugin.php @@ -0,0 +1,54 @@ + $rocket]); + + $params = $rocket->getParams(); + $config = get_wechat_config($params); + $payload = $rocket->getPayload(); + + if (is_null($payload)) { + throw new InvalidParamsException(Exception::PARAMS_NECESSARY_PARAMS_MISSING, '参数异常: APP合单 下单,参数为空'); + } + + $rocket->mergePayload([ + '_method' => 'POST', + '_url' => 'v3/combine-transactions/app', + '_service_url' => 'v3/combine-transactions/app', + 'notify_url' => $payload->get('notify_url', $config['notify_url'] ?? ''), + 'combine_appid' => $payload->get('combine_appid', $config['app_id'] ?? ''), + 'combine_mchid' => $payload->get('combine_mchid', $config['mch_id'] ?? ''), + ]); + + Logger::info('[Wechat][Pay][Combine][AppPayPlugin] 插件装载完毕', ['rocket' => $rocket]); + + return $next($rocket); + } +} diff --git a/src/Plugin/Wechat/Pay/Combine/AppPrepayPlugin.php b/src/Plugin/Wechat/Pay/Combine/AppPrepayPlugin.php deleted file mode 100644 index 80b4cd2..0000000 --- a/src/Plugin/Wechat/Pay/Combine/AppPrepayPlugin.php +++ /dev/null @@ -1,19 +0,0 @@ -getPayload(); - - if (!$payload->has('combine_out_trade_no') && !$payload->has('out_trade_no')) { - throw new InvalidParamsException(Exception::PARAMS_NECESSARY_PARAMS_MISSING); - } - - return 'v3/combine-transactions/out-trade-no/'. - $payload->get('combine_out_trade_no', $payload->get('out_trade_no')). - '/close'; - } - /** * @throws ContainerException + * @throws InvalidParamsException * @throws ServiceNotFoundException */ - protected function doSomething(Rocket $rocket): void + public function assembly(Rocket $rocket, Closure $next): Rocket { - $config = get_wechat_config($rocket->getParams()); + Logger::debug('[Wechat][Pay][Combine][ClosePlugin] 插件开始装载', ['rocket' => $rocket]); - $rocket->setPayload(new Collection([ - 'combine_appid' => $config['combine_appid'] ?? '', - 'sub_orders' => $rocket->getParams()['sub_orders'] ?? [], - ])); + $params = $rocket->getParams(); + $config = get_wechat_config($params); + $payload = $rocket->getPayload(); + $combineOutTradeNo = $payload?->get('combine_out_trade_no') ?? null; + + if (empty($combineOutTradeNo)) { + throw new InvalidParamsException(Exception::PARAMS_NECESSARY_PARAMS_MISSING, '参数异常: 合单关单,参数缺少 `combine_out_trade_no`'); + } + + $rocket->mergePayload([ + '_method' => 'POST', + '_url' => 'v3/combine-transactions/out-trade-no/'.$combineOutTradeNo.'/close', + '_service_url' => 'v3/combine-transactions/out-trade-no/'.$combineOutTradeNo.'/close', + 'combine_appid' => $payload->get('combine_appid', $config[get_wechat_type_key($params)] ?? ''), + ])->exceptPayload('combine_out_trade_no'); + + Logger::info('[Wechat][Pay][Combine][ClosePlugin] 插件装载完毕', ['rocket' => $rocket]); + + return $next($rocket); } } diff --git a/src/Plugin/Wechat/Pay/Combine/DownloadBillPlugin.php b/src/Plugin/Wechat/Pay/Combine/DownloadBillPlugin.php index 3e43aea..5b9e33e 100644 --- a/src/Plugin/Wechat/Pay/Combine/DownloadBillPlugin.php +++ b/src/Plugin/Wechat/Pay/Combine/DownloadBillPlugin.php @@ -4,7 +4,40 @@ declare(strict_types=1); namespace Yansongda\Pay\Plugin\Wechat\Pay\Combine; +use Closure; +use Yansongda\Pay\Contract\PluginInterface; +use Yansongda\Pay\Exception\Exception; +use Yansongda\Pay\Exception\InvalidParamsException; +use Yansongda\Pay\Logger; +use Yansongda\Pay\Rocket; + /** - * @see https://pay.weixin.qq.com/wiki/doc/apiv3/apis/chapter5_1_19.shtml + * @see https://pay.weixin.qq.com/docs/merchant/apis/combine-payment/bill-download/download-bill.html + * @see https://pay.weixin.qq.com/docs/partner/apis/combine-payment/bill-download/download-bill.html */ -class DownloadBillPlugin extends \Yansongda\Pay\Plugin\Wechat\Pay\Common\DownloadBillPlugin {} +class DownloadBillPlugin implements PluginInterface +{ + /** + * @throws InvalidParamsException + */ + public function assembly(Rocket $rocket, Closure $next): Rocket + { + Logger::debug('[Wechat][Pay][Combine][DownloadBillPlugin] 插件开始装载', ['rocket' => $rocket]); + + $downloadUrl = $rocket->getPayload()?->get('download_url') ?? null; + + if (empty($downloadUrl)) { + throw new InvalidParamsException(Exception::PARAMS_NECESSARY_PARAMS_MISSING, '参数异常: 合单 下载交易对账单,参数缺少 `download_url`'); + } + + $rocket->setPayload([ + '_method' => 'GET', + '_url' => $downloadUrl, + '_service_url' => $downloadUrl, + ]); + + Logger::info('[Wechat][Pay][Combine][DownloadBillPlugin] 插件装载完毕', ['rocket' => $rocket]); + + return $next($rocket); + } +} diff --git a/src/Plugin/Wechat/Pay/Combine/GetFlowBillPlugin.php b/src/Plugin/Wechat/Pay/Combine/GetFlowBillPlugin.php deleted file mode 100644 index 4a3a81b..0000000 --- a/src/Plugin/Wechat/Pay/Combine/GetFlowBillPlugin.php +++ /dev/null @@ -1,10 +0,0 @@ - $rocket]); + + $payload = $rocket->getPayload(); + + if (is_null($payload)) { + throw new InvalidParamsException(Exception::PARAMS_NECESSARY_PARAMS_MISSING, '参数异常: 合单 申请资金账单,参数为空'); + } + + $query = $payload->query(); + + $rocket->setPayload([ + '_method' => 'GET', + '_url' => 'v3/bill/fundflowbill?'.$query, + '_service_url' => 'v3/bill/fundflowbill?'.$query, + ]); + + Logger::info('[Wechat][Pay][Combine][GetFundBillPlugin] 插件装载完毕', ['rocket' => $rocket]); + + return $next($rocket); + } +} diff --git a/src/Plugin/Wechat/Pay/Combine/GetTradeBillPlugin.php b/src/Plugin/Wechat/Pay/Combine/GetTradeBillPlugin.php index c28d528..9db115c 100644 --- a/src/Plugin/Wechat/Pay/Combine/GetTradeBillPlugin.php +++ b/src/Plugin/Wechat/Pay/Combine/GetTradeBillPlugin.php @@ -4,7 +4,42 @@ declare(strict_types=1); namespace Yansongda\Pay\Plugin\Wechat\Pay\Combine; +use Closure; +use Yansongda\Pay\Contract\PluginInterface; +use Yansongda\Pay\Exception\Exception; +use Yansongda\Pay\Exception\InvalidParamsException; +use Yansongda\Pay\Logger; +use Yansongda\Pay\Rocket; + /** - * @see https://pay.weixin.qq.com/wiki/doc/apiv3/apis/chapter5_1_17.shtml + * @see https://pay.weixin.qq.com/docs/merchant/apis/combine-payment/bill-download/get-trade-bill.html + * @see https://pay.weixin.qq.com/docs/partner/apis/combine-payment/bill-download/get-trade-bill.html */ -class GetTradeBillPlugin extends \Yansongda\Pay\Plugin\Wechat\Pay\Common\GetTradeBillPlugin {} +class GetTradeBillPlugin implements PluginInterface +{ + /** + * @throws InvalidParamsException + */ + public function assembly(Rocket $rocket, Closure $next): Rocket + { + Logger::debug('[Wechat][Pay][Combine][GetTradeBillPlugin] 插件开始装载', ['rocket' => $rocket]); + + $payload = $rocket->getPayload(); + + if (is_null($payload)) { + throw new InvalidParamsException(Exception::PARAMS_NECESSARY_PARAMS_MISSING, '参数异常: 合单 申请交易账单,参数为空'); + } + + $query = $payload->query(); + + $rocket->setPayload([ + '_method' => 'GET', + '_url' => 'v3/bill/tradebill?'.$query, + '_service_url' => 'v3/bill/tradebill?'.$query, + ]); + + Logger::info('[Wechat][Pay][Combine][GetTradeBillPlugin] 插件装载完毕', ['rocket' => $rocket]); + + return $next($rocket); + } +} diff --git a/src/Plugin/Wechat/Pay/Combine/H5PayPlugin.php b/src/Plugin/Wechat/Pay/Combine/H5PayPlugin.php new file mode 100644 index 0000000..b4c3f0b --- /dev/null +++ b/src/Plugin/Wechat/Pay/Combine/H5PayPlugin.php @@ -0,0 +1,55 @@ + $rocket]); + + $params = $rocket->getParams(); + $config = get_wechat_config($params); + $payload = $rocket->getPayload(); + + if (is_null($payload)) { + throw new InvalidParamsException(Exception::PARAMS_NECESSARY_PARAMS_MISSING, '参数异常: H5合单 下单,参数为空'); + } + + $rocket->mergePayload([ + '_method' => 'POST', + '_url' => 'v3/combine-transactions/h5', + '_service_url' => 'v3/combine-transactions/h5', + 'notify_url' => $payload->get('notify_url', $config['notify_url'] ?? ''), + 'combine_appid' => $payload->get('combine_appid', $config[get_wechat_type_key($params)] ?? ''), + 'combine_mchid' => $payload->get('combine_mchid', $config['mch_id'] ?? ''), + ]); + + Logger::info('[Wechat][Pay][Combine][H5PayPlugin] 插件装载完毕', ['rocket' => $rocket]); + + return $next($rocket); + } +} diff --git a/src/Plugin/Wechat/Pay/Combine/H5PrepayPlugin.php b/src/Plugin/Wechat/Pay/Combine/H5PrepayPlugin.php deleted file mode 100644 index a080e17..0000000 --- a/src/Plugin/Wechat/Pay/Combine/H5PrepayPlugin.php +++ /dev/null @@ -1,19 +0,0 @@ - $rocket]); + + $destination = $rocket->getDestination(); + $prepayId = $destination?->get('prepay_id'); + + if (is_null($prepayId)) { + Logger::error('[Wechat][Pay][Combine][JsapiInvokePlugin] 预下单失败:响应缺少 `prepay_id` 参数,请自行检查参数是否符合微信要求', $destination?->all() ?? null); + + throw new InvalidResponseException(Exception::RESPONSE_MISSING_NECESSARY_PARAMS, $destination?->get('message') ?? '预下单失败:响应缺少 `prepay_id` 参数,请自行检查参数是否符合微信要求', $destination?->all() ?? null); + } + + $params = $rocket->getParams(); + $config = get_wechat_config($params); + $payload = $rocket->getPayload(); + + $rocket->setDestination($this->getInvokeConfig($payload, $params, $config, $prepayId)); + + Logger::info('[Wechat][Pay][Combine][JsapiInvokePlugin] 插件装载完毕', ['rocket' => $rocket]); + + return $rocket; + } + + /** + * @throws InvalidConfigException + * @throws Throwable 生成随机串失败 + */ + protected function getInvokeConfig(?Collection $payload, array $params, array $config, string $prepayId): Config + { + $invokeConfig = new Config([ + 'appId' => $this->getAppId($payload, $config, $params), + 'timeStamp' => time().'', + 'nonceStr' => Str::random(32), + 'package' => 'prepay_id='.$prepayId, + 'signType' => 'RSA', + ]); + + $invokeConfig->set('paySign', $this->getSign($invokeConfig, $config)); + + return $invokeConfig; + } + + /** + * @throws InvalidConfigException + */ + protected function getSign(Collection $invokeConfig, array $config): string + { + $contents = $invokeConfig->get('appId', '')."\n". + $invokeConfig->get('timeStamp', '')."\n". + $invokeConfig->get('nonceStr', '')."\n". + $invokeConfig->get('package', '')."\n"; + + return get_wechat_sign($config, $contents); + } + + protected function getAppId(?Collection $payload, array $config, array $params): string + { + if (Pay::MODE_SERVICE === ($config['mode'] ?? Pay::MODE_NORMAL)) { + return $payload?->get('_invoke_appid') ?? $config['sub_'.get_wechat_type_key($params)] ?? ''; + } + + return $payload?->get('_invoke_appid') ?? $config[get_wechat_type_key($params)] ?? ''; + } +} diff --git a/src/Plugin/Wechat/Pay/Combine/JsapiPayPlugin.php b/src/Plugin/Wechat/Pay/Combine/JsapiPayPlugin.php new file mode 100644 index 0000000..c5bba72 --- /dev/null +++ b/src/Plugin/Wechat/Pay/Combine/JsapiPayPlugin.php @@ -0,0 +1,55 @@ + $rocket]); + + $params = $rocket->getParams(); + $config = get_wechat_config($params); + $payload = $rocket->getPayload(); + + if (is_null($payload)) { + throw new InvalidParamsException(Exception::PARAMS_NECESSARY_PARAMS_MISSING, '参数异常: Jsapi合单 下单,参数为空'); + } + + $rocket->mergePayload([ + '_method' => 'POST', + '_url' => 'v3/combine-transactions/jsapi', + '_service_url' => 'v3/combine-transactions/jsapi', + 'notify_url' => $payload->get('notify_url', $config['notify_url'] ?? ''), + 'combine_appid' => $payload->get('combine_appid', $config[get_wechat_type_key($params)] ?? ''), + 'combine_mchid' => $payload->get('combine_mchid', $config['mch_id'] ?? ''), + ]); + + Logger::info('[Wechat][Pay][Combine][JsapiPayPlugin] 插件装载完毕', ['rocket' => $rocket]); + + return $next($rocket); + } +} diff --git a/src/Plugin/Wechat/Pay/Combine/JsapiPrepayPlugin.php b/src/Plugin/Wechat/Pay/Combine/JsapiPrepayPlugin.php deleted file mode 100644 index a9454d9..0000000 --- a/src/Plugin/Wechat/Pay/Combine/JsapiPrepayPlugin.php +++ /dev/null @@ -1,12 +0,0 @@ - $rocket]); + + $destination = $rocket->getDestination(); + $prepayId = $destination?->get('prepay_id'); + + if (is_null($prepayId)) { + Logger::error('[Wechat][Pay][Combine][MiniInvokePlugin] 预下单失败:响应缺少 `prepay_id` 参数,请自行检查参数是否符合微信要求', $destination?->all() ?? null); + + throw new InvalidResponseException(Exception::RESPONSE_MISSING_NECESSARY_PARAMS, $destination?->get('message') ?? '预下单失败:响应缺少 `prepay_id` 参数,请自行检查参数是否符合微信要求', $destination?->all() ?? null); + } + + $params = $rocket->getParams(); + $config = get_wechat_config($params); + $payload = $rocket->getPayload(); + + $rocket->setDestination($this->getInvokeConfig($payload, $config, $prepayId)); + + Logger::info('[Wechat][Pay][Combine][MiniInvokePlugin] 插件装载完毕', ['rocket' => $rocket]); + + return $rocket; + } + + /** + * @throws InvalidConfigException + * @throws Throwable 生成随机串失败 + */ + protected function getInvokeConfig(?Collection $payload, array $config, string $prepayId): Config + { + $invokeConfig = new Config([ + 'appId' => $this->getAppId($payload, $config), + 'timeStamp' => time().'', + 'nonceStr' => Str::random(32), + 'package' => 'prepay_id='.$prepayId, + 'signType' => 'RSA', + ]); + + $invokeConfig->set('paySign', $this->getSign($invokeConfig, $config)); + + return $invokeConfig; + } + + /** + * @throws InvalidConfigException + */ + protected function getSign(Collection $invokeConfig, array $config): string + { + $contents = $invokeConfig->get('appId', '')."\n". + $invokeConfig->get('timeStamp', '')."\n". + $invokeConfig->get('nonceStr', '')."\n". + $invokeConfig->get('package', '')."\n"; + + return get_wechat_sign($config, $contents); + } + + protected function getAppId(?Collection $payload, array $config): string + { + if (Pay::MODE_SERVICE === ($config['mode'] ?? Pay::MODE_NORMAL)) { + return $payload?->get('_invoke_appid') ?? $config['sub_mini_app_id'] ?? ''; + } + + return $payload?->get('_invoke_appid') ?? $config['mini_app_id'] ?? ''; + } +} diff --git a/src/Plugin/Wechat/Pay/Combine/MiniPayPlugin.php b/src/Plugin/Wechat/Pay/Combine/MiniPayPlugin.php new file mode 100644 index 0000000..e8d83bc --- /dev/null +++ b/src/Plugin/Wechat/Pay/Combine/MiniPayPlugin.php @@ -0,0 +1,54 @@ + $rocket]); + + $params = $rocket->getParams(); + $config = get_wechat_config($params); + $payload = $rocket->getPayload(); + + if (is_null($payload)) { + throw new InvalidParamsException(Exception::PARAMS_NECESSARY_PARAMS_MISSING, '参数异常: Mini合单 下单,参数为空'); + } + + $rocket->mergePayload([ + '_method' => 'POST', + '_url' => 'v3/combine-transactions/jsapi', + '_service_url' => 'v3/combine-transactions/jsapi', + 'notify_url' => $payload->get('notify_url', $config['notify_url'] ?? ''), + 'combine_appid' => $payload->get('combine_appid', $config['mini_app_id'] ?? ''), + 'combine_mchid' => $payload->get('combine_mchid', $config['mch_id'] ?? ''), + ]); + + Logger::info('[Wechat][Pay][Combine][MiniPayPlugin] 插件装载完毕', ['rocket' => $rocket]); + + return $next($rocket); + } +} diff --git a/src/Plugin/Wechat/Pay/Combine/MiniPrepayPlugin.php b/src/Plugin/Wechat/Pay/Combine/MiniPrepayPlugin.php deleted file mode 100644 index 20dcc14..0000000 --- a/src/Plugin/Wechat/Pay/Combine/MiniPrepayPlugin.php +++ /dev/null @@ -1,12 +0,0 @@ - $rocket]); + + $params = $rocket->getParams(); + $config = get_wechat_config($params); + $payload = $rocket->getPayload(); + + if (is_null($payload)) { + throw new InvalidParamsException(Exception::PARAMS_NECESSARY_PARAMS_MISSING, '参数异常: Native合单 下单,参数为空'); + } + + $rocket->mergePayload([ + '_method' => 'POST', + '_url' => 'v3/combine-transactions/native', + '_service_url' => 'v3/combine-transactions/native', + 'notify_url' => $payload->get('notify_url', $config['notify_url'] ?? ''), + 'combine_appid' => $payload->get('combine_appid', $config[get_wechat_type_key($params)] ?? ''), + 'combine_mchid' => $payload->get('combine_mchid', $config['mch_id'] ?? ''), + ]); + + Logger::info('[Wechat][Pay][Combine][NativePayPlugin] 插件装载完毕', ['rocket' => $rocket]); + + return $next($rocket); + } +} diff --git a/src/Plugin/Wechat/Pay/Combine/NativePrepayPlugin.php b/src/Plugin/Wechat/Pay/Combine/NativePrepayPlugin.php deleted file mode 100644 index d9317cf..0000000 --- a/src/Plugin/Wechat/Pay/Combine/NativePrepayPlugin.php +++ /dev/null @@ -1,19 +0,0 @@ -getPayload(); + Logger::debug('[Wechat][Pay][Combine][QueryPlugin] 插件开始装载', ['rocket' => $rocket]); - if (!$payload->has('combine_out_trade_no') && !$payload->has('transaction_id')) { - throw new InvalidParamsException(Exception::PARAMS_NECESSARY_PARAMS_MISSING); + $combineOutTradeNo = $rocket->getPayload()?->get('combine_out_trade_no') ?? null; + + if (empty($combineOutTradeNo)) { + throw new InvalidParamsException(Exception::PARAMS_NECESSARY_PARAMS_MISSING, '参数异常: 合单查询,参数缺少 `combine_out_trade_no`'); } - return 'v3/combine-transactions/out-trade-no/'. - $payload->get('combine_out_trade_no', $payload->get('transaction_id')); + $rocket->setPayload([ + '_method' => 'GET', + '_url' => 'v3/combine-transactions/out-trade-no/'.$combineOutTradeNo, + '_service_url' => 'v3/combine-transactions/out-trade-no/'.$combineOutTradeNo, + ]); + + Logger::info('[Wechat][Pay][Combine][QueryPlugin] 插件装载完毕', ['rocket' => $rocket]); + + return $next($rocket); } } diff --git a/src/Plugin/Wechat/Pay/Combine/QueryRefundPlugin.php b/src/Plugin/Wechat/Pay/Combine/QueryRefundPlugin.php index b0385bb..232f20a 100644 --- a/src/Plugin/Wechat/Pay/Combine/QueryRefundPlugin.php +++ b/src/Plugin/Wechat/Pay/Combine/QueryRefundPlugin.php @@ -4,7 +4,51 @@ declare(strict_types=1); namespace Yansongda\Pay\Plugin\Wechat\Pay\Combine; +use Closure; +use Yansongda\Pay\Contract\PluginInterface; +use Yansongda\Pay\Exception\ContainerException; +use Yansongda\Pay\Exception\Exception; +use Yansongda\Pay\Exception\InvalidParamsException; +use Yansongda\Pay\Exception\ServiceNotFoundException; +use Yansongda\Pay\Logger; +use Yansongda\Pay\Rocket; + +use function Yansongda\Pay\get_wechat_config; + /** - * @see https://pay.weixin.qq.com/wiki/doc/apiv3/apis/chapter5_1_15.shtml + * @see https://pay.weixin.qq.com/docs/merchant/apis/combine-payment/refunds/query-by-out-refund-no.html + * @see https://pay.weixin.qq.com/docs/partner/apis/combine-payment/refunds/query-by-out-refund-no.html */ -class QueryRefundPlugin extends \Yansongda\Pay\Plugin\Wechat\Pay\Common\QueryRefundPlugin {} +class QueryRefundPlugin implements PluginInterface +{ + /** + * @throws InvalidParamsException + * @throws ContainerException + * @throws ServiceNotFoundException + */ + public function assembly(Rocket $rocket, Closure $next): Rocket + { + Logger::debug('[Wechat][Pay][Combine][QueryRefundPlugin] 插件开始装载', ['rocket' => $rocket]); + + $params = $rocket->getParams(); + $config = get_wechat_config($params); + $payload = $rocket->getPayload(); + $outRefundNo = $payload?->get('out_refund_no') ?? null; + + if (empty($outRefundNo)) { + throw new InvalidParamsException(Exception::PARAMS_NECESSARY_PARAMS_MISSING, '参数异常: 合单查询退款订单,参数缺少 `out_refund_no`'); + } + + $subMchId = $payload->get('sub_mchid', $config['sub_mch_id'] ?? ''); + + $rocket->setPayload([ + '_method' => 'GET', + '_url' => 'v3/refund/domestic/refunds/'.$outRefundNo, + '_service_url' => 'v3/refund/domestic/refunds/'.$outRefundNo.'?sub_mchid='.$subMchId, + ]); + + Logger::info('[Wechat][Pay][Combine][QueryRefundPlugin] 插件装载完毕', ['rocket' => $rocket]); + + return $next($rocket); + } +} diff --git a/src/Plugin/Wechat/Pay/Combine/RefundPlugin.php b/src/Plugin/Wechat/Pay/Combine/RefundPlugin.php index c7ce097..a2bc441 100644 --- a/src/Plugin/Wechat/Pay/Combine/RefundPlugin.php +++ b/src/Plugin/Wechat/Pay/Combine/RefundPlugin.php @@ -4,7 +4,70 @@ declare(strict_types=1); namespace Yansongda\Pay\Plugin\Wechat\Pay\Combine; +use Closure; +use Yansongda\Pay\Contract\PluginInterface; +use Yansongda\Pay\Exception\ContainerException; +use Yansongda\Pay\Exception\Exception; +use Yansongda\Pay\Exception\InvalidParamsException; +use Yansongda\Pay\Exception\ServiceNotFoundException; +use Yansongda\Pay\Logger; +use Yansongda\Pay\Pay; +use Yansongda\Pay\Rocket; +use Yansongda\Supports\Collection; + +use function Yansongda\Pay\get_wechat_config; + /** - * @see https://pay.weixin.qq.com/wiki/doc/apiv3/apis/chapter5_1_14.shtml + * @see https://pay.weixin.qq.com/docs/merchant/apis/combine-payment/refunds/create.html + * @see https://pay.weixin.qq.com/docs/partner/apis/combine-payment/refunds/create.html */ -class RefundPlugin extends \Yansongda\Pay\Plugin\Wechat\Pay\Common\RefundPlugin {} +class RefundPlugin implements PluginInterface +{ + /** + * @throws ContainerException + * @throws InvalidParamsException + * @throws ServiceNotFoundException + */ + public function assembly(Rocket $rocket, Closure $next): Rocket + { + Logger::debug('[Wechat][Pay][Combine][RefundPlugin] 插件开始装载', ['rocket' => $rocket]); + + $params = $rocket->getParams(); + $config = get_wechat_config($params); + $payload = $rocket->getPayload(); + + if (is_null($payload)) { + throw new InvalidParamsException(Exception::PARAMS_NECESSARY_PARAMS_MISSING, '参数异常: 合单 退款申请,参数为空'); + } + + if (Pay::MODE_SERVICE === $config['mode']) { + $data = $this->service($payload, $config); + } + + $rocket->mergePayload(array_merge( + [ + '_method' => 'POST', + '_url' => 'v3/refund/domestic/refunds', + '_service_url' => 'v3/refund/domestic/refunds', + 'notify_url' => $payload->get('notify_url', $config['notify_url'] ?? null), + ], + $data ?? $this->normal() + )); + + Logger::info('[Wechat][Pay][Combine][RefundPlugin] 插件装载完毕', ['rocket' => $rocket]); + + return $next($rocket); + } + + protected function normal(): array + { + return []; + } + + protected function service(Collection $payload, array $config): array + { + return [ + 'sub_mchid' => $payload->get('sub_mchid', $config['sub_mch_id'] ?? ''), + ]; + } +} diff --git a/src/Plugin/Wechat/Pay/Common/ClosePlugin.php b/src/Plugin/Wechat/Pay/Common/ClosePlugin.php deleted file mode 100644 index b53182f..0000000 --- a/src/Plugin/Wechat/Pay/Common/ClosePlugin.php +++ /dev/null @@ -1,76 +0,0 @@ -getPayload(); - - if (!$payload->has('out_trade_no')) { - throw new InvalidParamsException(Exception::PARAMS_NECESSARY_PARAMS_MISSING); - } - - return 'v3/pay/transactions/out-trade-no/'. - $payload->get('out_trade_no'). - '/close'; - } - - /** - * @throws InvalidParamsException - */ - protected function getPartnerUri(Rocket $rocket): string - { - $payload = $rocket->getPayload(); - - if (!$payload->has('out_trade_no')) { - throw new InvalidParamsException(Exception::PARAMS_NECESSARY_PARAMS_MISSING); - } - - return 'v3/pay/partner/transactions/out-trade-no/'. - $payload->get('out_trade_no'). - '/close'; - } - - /** - * @throws ContainerException - * @throws ServiceNotFoundException - */ - protected function doSomething(Rocket $rocket): void - { - $rocket->setDirection(OriginResponseDirection::class); - - $config = get_wechat_config($rocket->getParams()); - - $body = [ - 'mchid' => $config['mch_id'] ?? '', - ]; - - if (Pay::MODE_SERVICE == ($config['mode'] ?? null)) { - $body = [ - 'sp_mchid' => $config['mch_id'] ?? '', - 'sub_mchid' => $rocket->getPayload()->get('sub_mchid', $config['sub_mch_id'] ?? ''), - ]; - } - - $rocket->setPayload(new Collection($body)); - } -} diff --git a/src/Plugin/Wechat/Pay/Common/CombinePrepayPlugin.php b/src/Plugin/Wechat/Pay/Common/CombinePrepayPlugin.php deleted file mode 100644 index 24363da..0000000 --- a/src/Plugin/Wechat/Pay/Common/CombinePrepayPlugin.php +++ /dev/null @@ -1,50 +0,0 @@ -getParams()); - $collection = $rocket->getPayload(); - - $payload = $this->getWechatId($config); - - if (!$collection->has('notify_url')) { - $payload['notify_url'] = $config['notify_url'] ?? ''; - } - - if (!$collection->has('combine_out_trade_no')) { - $payload['combine_out_trade_no'] = $rocket->getParams()['out_trade_no']; - } - - $rocket->mergePayload($payload); - } - - protected function getWechatId(array $config): array - { - return [ - 'combine_appid' => $config['combine_app_id'] ?? '', - 'combine_mchid' => $config['combine_mch_id'] ?? '', - ]; - } -} diff --git a/src/Plugin/Wechat/Pay/Common/DownloadBillPlugin.php b/src/Plugin/Wechat/Pay/Common/DownloadBillPlugin.php deleted file mode 100644 index f71cc99..0000000 --- a/src/Plugin/Wechat/Pay/Common/DownloadBillPlugin.php +++ /dev/null @@ -1,40 +0,0 @@ -getPayload(); - - if (!$payload->has('download_url')) { - throw new InvalidParamsException(Exception::PARAMS_NECESSARY_PARAMS_MISSING); - } - - return $payload->get('download_url'); - } - - protected function getMethod(): string - { - return 'GET'; - } - - protected function doSomething(Rocket $rocket): void - { - $rocket->setDirection(OriginResponseDirection::class); - - $rocket->setPayload(null); - } -} diff --git a/src/Plugin/Wechat/Pay/Common/GetFlowBillPlugin.php b/src/Plugin/Wechat/Pay/Common/GetFlowBillPlugin.php deleted file mode 100644 index a170038..0000000 --- a/src/Plugin/Wechat/Pay/Common/GetFlowBillPlugin.php +++ /dev/null @@ -1,26 +0,0 @@ -getParams()); - } - - protected function getMethod(): string - { - return 'GET'; - } - - protected function doSomething(Rocket $rocket): void - { - $rocket->setPayload(null); - } -} diff --git a/src/Plugin/Wechat/Pay/Common/GetTradeBillPlugin.php b/src/Plugin/Wechat/Pay/Common/GetTradeBillPlugin.php deleted file mode 100644 index 692e2cf..0000000 --- a/src/Plugin/Wechat/Pay/Common/GetTradeBillPlugin.php +++ /dev/null @@ -1,26 +0,0 @@ -getParams()); - } - - protected function getMethod(): string - { - return 'GET'; - } - - protected function doSomething(Rocket $rocket): void - { - $rocket->setPayload(null); - } -} diff --git a/src/Plugin/Wechat/Pay/Common/InvokePrepayPlugin.php b/src/Plugin/Wechat/Pay/Common/InvokePrepayPlugin.php deleted file mode 100644 index e1f2247..0000000 --- a/src/Plugin/Wechat/Pay/Common/InvokePrepayPlugin.php +++ /dev/null @@ -1,112 +0,0 @@ - $rocket]); - - $destination = $rocket->getDestination(); - - $prepayId = $destination->get('prepay_id'); - - if (is_null($prepayId)) { - Logger::error('[wechat][InvokePrepayPlugin] 预下单失败:响应缺少 prepay_id 参数,请自行检查参数是否符合微信要求', $destination->all()); - - throw new InvalidResponseException(Exception::RESPONSE_MISSING_NECESSARY_PARAMS, $destination->get('message', '预下单失败:响应缺少 prepay_id 参数,请自行检查参数是否符合微信要求'), $destination->all()); - } - - $config = $this->getInvokeConfig($rocket, $prepayId); - - $rocket->setDestination($config); - - Logger::info('[wechat][InvokePrepayPlugin] 插件装载完毕', ['rocket' => $rocket]); - - return $rocket; - } - - /** - * @throws ContainerException - * @throws ServiceNotFoundException - * @throws \Exception - */ - protected function getInvokeConfig(Rocket $rocket, string $prepayId): Config - { - $config = new Config([ - 'appId' => $this->getAppId($rocket), - 'timeStamp' => time().'', - 'nonceStr' => Str::random(32), - 'package' => 'prepay_id='.$prepayId, - 'signType' => 'RSA', - ]); - - $config->set('paySign', $this->getSign($config, $rocket->getParams())); - - return $config; - } - - /** - * @throws ContainerException - * @throws InvalidConfigException - * @throws ServiceNotFoundException - */ - protected function getSign(Collection $invokeConfig, array $params): string - { - $contents = $invokeConfig->get('appId', '')."\n". - $invokeConfig->get('timeStamp', '')."\n". - $invokeConfig->get('nonceStr', '')."\n". - $invokeConfig->get('package', '')."\n"; - - return get_wechat_sign($params, $contents); - } - - /** - * @throws ContainerException - * @throws ServiceNotFoundException - */ - protected function getAppId(Rocket $rocket): string - { - $config = get_wechat_config($rocket->getParams()); - $payload = $rocket->getPayload(); - - if (Pay::MODE_SERVICE === ($config['mode'] ?? null) && $payload->has('sub_appid')) { - return $payload->get('sub_appid', ''); - } - - return $config[$this->getConfigKey()] ?? ''; - } - - protected function getConfigKey(): string - { - return 'mp_app_id'; - } -} diff --git a/src/Plugin/Wechat/Pay/Common/InvokePrepayV2Plugin.php b/src/Plugin/Wechat/Pay/Common/InvokePrepayV2Plugin.php deleted file mode 100644 index 1c4313c..0000000 --- a/src/Plugin/Wechat/Pay/Common/InvokePrepayV2Plugin.php +++ /dev/null @@ -1,40 +0,0 @@ - $this->getAppId($rocket), - 'timeStamp' => time().'', - 'nonceStr' => Str::random(32), - 'package' => 'prepay_id='.$prepayId, - 'signType' => 'MD5', - ]); - - $config->set('paySign', get_wechat_sign_v2($rocket->getParams(), $config->toArray())); - - return $config; - } -} diff --git a/src/Plugin/Wechat/Pay/Common/PrepayPlugin.php b/src/Plugin/Wechat/Pay/Common/PrepayPlugin.php deleted file mode 100644 index 5ffaa2a..0000000 --- a/src/Plugin/Wechat/Pay/Common/PrepayPlugin.php +++ /dev/null @@ -1,70 +0,0 @@ -getParams()); - - $wechatId = $this->getWechatId($config, $rocket); - - if (!$rocket->getPayload()->has('notify_url')) { - $wechatId['notify_url'] = $config['notify_url'] ?? null; - } - - $rocket->mergePayload($wechatId); - } - - protected function getWechatId(array $config, Rocket $rocket): array - { - $payload = $rocket->getPayload(); - $configKey = $this->getConfigKey($rocket->getParams()); - - $result = [ - 'appid' => $config[$configKey] ?? '', - 'mchid' => $config['mch_id'] ?? '', - ]; - - if (Pay::MODE_SERVICE === ($config['mode'] ?? null)) { - $result = [ - 'sp_appid' => $config[$configKey] ?? '', - 'sp_mchid' => $config['mch_id'] ?? '', - 'sub_mchid' => $payload->get('sub_mchid', $config['sub_mch_id'] ?? null), - ]; - - $subAppId = $payload->get('sub_appid', $config['sub_'.$configKey] ?? null); - - if (!empty($subAppId)) { - $result['sub_appid'] = $subAppId; - } - } - - return $result; - } -} diff --git a/src/Plugin/Wechat/Pay/Common/QueryPlugin.php b/src/Plugin/Wechat/Pay/Common/QueryPlugin.php deleted file mode 100644 index f52beee..0000000 --- a/src/Plugin/Wechat/Pay/Common/QueryPlugin.php +++ /dev/null @@ -1,79 +0,0 @@ -getParams()); - $payload = $rocket->getPayload(); - - if ($payload->has('transaction_id')) { - return 'v3/pay/transactions/id/'. - $payload->get('transaction_id'). - '?mchid='.($config['mch_id'] ?? ''); - } - - if ($payload->has('out_trade_no')) { - return 'v3/pay/transactions/out-trade-no/'. - $payload->get('out_trade_no'). - '?mchid='.($config['mch_id'] ?? ''); - } - - throw new InvalidParamsException(Exception::PARAMS_NECESSARY_PARAMS_MISSING); - } - - /** - * @throws ContainerException - * @throws ServiceNotFoundException - * @throws InvalidParamsException - */ - protected function getPartnerUri(Rocket $rocket): string - { - $config = get_wechat_config($rocket->getParams()); - $payload = $rocket->getPayload(); - - if ($payload->has('transaction_id')) { - return 'v3/pay/partner/transactions/id/'. - $payload->get('transaction_id'). - '?sp_mchid='.($config['mch_id'] ?? ''). - '&sub_mchid='.$payload->get('sub_mchid', $config['sub_mch_id'] ?? null); - } - - if ($payload->has('out_trade_no')) { - return 'v3/pay/partner/transactions/out-trade-no/'. - $payload->get('out_trade_no'). - '?sp_mchid='.($config['mch_id'] ?? ''). - '&sub_mchid='.$payload->get('sub_mchid', $config['sub_mch_id'] ?? null); - } - - throw new InvalidParamsException(Exception::PARAMS_NECESSARY_PARAMS_MISSING); - } - - protected function getMethod(): string - { - return 'GET'; - } - - protected function doSomething(Rocket $rocket): void - { - $rocket->setPayload(null); - } -} diff --git a/src/Plugin/Wechat/Pay/Common/QueryRefundPlugin.php b/src/Plugin/Wechat/Pay/Common/QueryRefundPlugin.php deleted file mode 100644 index 2daf8f7..0000000 --- a/src/Plugin/Wechat/Pay/Common/QueryRefundPlugin.php +++ /dev/null @@ -1,53 +0,0 @@ -getPayload(); - - if (!$payload->has('out_refund_no')) { - throw new InvalidParamsException(Exception::PARAMS_NECESSARY_PARAMS_MISSING); - } - - return 'v3/refund/domestic/refunds/'.$payload->get('out_refund_no'); - } - - /** - * @throws ContainerException - * @throws ServiceNotFoundException - */ - protected function getPartnerUri(Rocket $rocket): string - { - $config = get_wechat_config($rocket->getParams()); - $url = parent::getPartnerUri($rocket); - - return $url.'?sub_mchid='.$rocket->getPayload()->get('sub_mchid', $config['sub_mch_id'] ?? ''); - } - - protected function getMethod(): string - { - return 'GET'; - } - - protected function doSomething(Rocket $rocket): void - { - $rocket->setPayload(null); - } -} diff --git a/src/Plugin/Wechat/Pay/Common/RefundPlugin.php b/src/Plugin/Wechat/Pay/Common/RefundPlugin.php deleted file mode 100644 index 3be79d0..0000000 --- a/src/Plugin/Wechat/Pay/Common/RefundPlugin.php +++ /dev/null @@ -1,41 +0,0 @@ -getParams()); - $payload = $rocket->getPayload(); - - if (empty($payload->get('notify_url')) && !empty($config['notify_url'])) { - $merge['notify_url'] = $config['notify_url']; - } - - if (Pay::MODE_SERVICE === ($config['mode'] ?? null)) { - $merge['sub_mchid'] = $payload->get('sub_mchid', $config['sub_mch_id'] ?? null); - } - - $rocket->mergePayload($merge ?? []); - } -} diff --git a/src/Plugin/Wechat/Pay/H5/ClosePlugin.php b/src/Plugin/Wechat/Pay/H5/ClosePlugin.php index 9db2e10..51c3f3f 100644 --- a/src/Plugin/Wechat/Pay/H5/ClosePlugin.php +++ b/src/Plugin/Wechat/Pay/H5/ClosePlugin.php @@ -4,7 +4,73 @@ declare(strict_types=1); namespace Yansongda\Pay\Plugin\Wechat\Pay\H5; +use Closure; +use Yansongda\Pay\Contract\PluginInterface; +use Yansongda\Pay\Exception\ContainerException; +use Yansongda\Pay\Exception\Exception; +use Yansongda\Pay\Exception\InvalidParamsException; +use Yansongda\Pay\Exception\ServiceNotFoundException; +use Yansongda\Pay\Logger; +use Yansongda\Pay\Pay; +use Yansongda\Pay\Rocket; +use Yansongda\Supports\Collection; + +use function Yansongda\Pay\get_wechat_config; + /** - * @see https://pay.weixin.qq.com/wiki/doc/apiv3/apis/chapter3_3_3.shtml + * @see https://pay.weixin.qq.com/docs/merchant/apis/h5-payment/close-order.html + * @see https://pay.weixin.qq.com/docs/partner/apis/partner-h5-payment/close-order.html */ -class ClosePlugin extends \Yansongda\Pay\Plugin\Wechat\Pay\Common\ClosePlugin {} +class ClosePlugin implements PluginInterface +{ + /** + * @throws ContainerException + * @throws InvalidParamsException + * @throws ServiceNotFoundException + */ + public function assembly(Rocket $rocket, Closure $next): Rocket + { + Logger::debug('[Wechat][Pay][H5][ClosePlugin] 插件开始装载', ['rocket' => $rocket]); + + $params = $rocket->getParams(); + $config = get_wechat_config($params); + $payload = $rocket->getPayload(); + $outTradeNo = $payload?->get('out_trade_no') ?? null; + + if (empty($outTradeNo)) { + throw new InvalidParamsException(Exception::PARAMS_NECESSARY_PARAMS_MISSING, '参数异常: H5 关闭订单,参数缺少 `out_trade_no`'); + } + + if (Pay::MODE_SERVICE === ($config['mode'] ?? Pay::MODE_NORMAL)) { + $data = $this->service($payload, $config); + } + + $rocket->setPayload(array_merge( + [ + '_method' => 'POST', + '_url' => 'v3/pay/transactions/out-trade-no/'.$outTradeNo.'/close', + '_service_url' => 'v3/pay/partner/transactions/out-trade-no/'.$outTradeNo.'/close', + ], + $data ?? $this->normal($config) + )); + + Logger::info('[Wechat][Pay][H5][ClosePlugin] 插件装载完毕', ['rocket' => $rocket]); + + return $next($rocket); + } + + protected function normal(array $config): array + { + return [ + 'mchid' => $config['mch_id'] ?? '', + ]; + } + + protected function service(Collection $payload, array $config): array + { + return [ + 'sp_mchid' => $config['mch_id'] ?? '', + 'sub_mchid' => $payload->get('sub_mchid', $config['sub_mch_id'] ?? ''), + ]; + } +} diff --git a/src/Plugin/Wechat/Pay/H5/DownloadBillPlugin.php b/src/Plugin/Wechat/Pay/H5/DownloadBillPlugin.php index f1f316b..ccd666c 100644 --- a/src/Plugin/Wechat/Pay/H5/DownloadBillPlugin.php +++ b/src/Plugin/Wechat/Pay/H5/DownloadBillPlugin.php @@ -4,7 +4,40 @@ declare(strict_types=1); namespace Yansongda\Pay\Plugin\Wechat\Pay\H5; +use Closure; +use Yansongda\Pay\Contract\PluginInterface; +use Yansongda\Pay\Exception\Exception; +use Yansongda\Pay\Exception\InvalidParamsException; +use Yansongda\Pay\Logger; +use Yansongda\Pay\Rocket; + /** - * @see https://pay.weixin.qq.com/wiki/doc/apiv3/apis/chapter3_3_8.shtml + * @see https://pay.weixin.qq.com/docs/merchant/apis/h5-payment/download-bill.html + * @see https://pay.weixin.qq.com/docs/partner/apis/partner-h5-payment/download-bill.html */ -class DownloadBillPlugin extends \Yansongda\Pay\Plugin\Wechat\Pay\Common\DownloadBillPlugin {} +class DownloadBillPlugin implements PluginInterface +{ + /** + * @throws InvalidParamsException + */ + public function assembly(Rocket $rocket, Closure $next): Rocket + { + Logger::debug('[Wechat][Pay][H5][DownloadBillPlugin] 插件开始装载', ['rocket' => $rocket]); + + $downloadUrl = $rocket->getPayload()?->get('download_url') ?? null; + + if (empty($downloadUrl)) { + throw new InvalidParamsException(Exception::PARAMS_NECESSARY_PARAMS_MISSING, '参数异常: H5 下载交易对账单,参数缺少 `download_url`'); + } + + $rocket->setPayload([ + '_method' => 'GET', + '_url' => $downloadUrl, + '_service_url' => $downloadUrl, + ]); + + Logger::info('[Wechat][Pay][H5][DownloadBillPlugin] 插件装载完毕', ['rocket' => $rocket]); + + return $next($rocket); + } +} diff --git a/src/Plugin/Wechat/Pay/H5/GetFlowBillPlugin.php b/src/Plugin/Wechat/Pay/H5/GetFlowBillPlugin.php deleted file mode 100644 index 3d9413c..0000000 --- a/src/Plugin/Wechat/Pay/H5/GetFlowBillPlugin.php +++ /dev/null @@ -1,10 +0,0 @@ - $rocket]); + + $payload = $rocket->getPayload(); + + if (is_null($payload)) { + throw new InvalidParamsException(Exception::PARAMS_NECESSARY_PARAMS_MISSING, '参数异常: H5 申请资金账单,参数为空'); + } + + $query = $payload->query(); + + $rocket->setPayload([ + '_method' => 'GET', + '_url' => 'v3/bill/fundflowbill?'.$query, + '_service_url' => 'v3/bill/fundflowbill?'.$query, + ]); + + Logger::info('[Wechat][Pay][H5][GetFundBillPlugin] 插件装载完毕', ['rocket' => $rocket]); + + return $next($rocket); + } +} diff --git a/src/Plugin/Wechat/Pay/H5/GetTradeBillPlugin.php b/src/Plugin/Wechat/Pay/H5/GetTradeBillPlugin.php index 3fac0e9..f849519 100644 --- a/src/Plugin/Wechat/Pay/H5/GetTradeBillPlugin.php +++ b/src/Plugin/Wechat/Pay/H5/GetTradeBillPlugin.php @@ -4,7 +4,42 @@ declare(strict_types=1); namespace Yansongda\Pay\Plugin\Wechat\Pay\H5; +use Closure; +use Yansongda\Pay\Contract\PluginInterface; +use Yansongda\Pay\Exception\Exception; +use Yansongda\Pay\Exception\InvalidParamsException; +use Yansongda\Pay\Logger; +use Yansongda\Pay\Rocket; + /** - * @see https://pay.weixin.qq.com/wiki/doc/apiv3/apis/chapter3_3_6.shtml + * @see https://pay.weixin.qq.com/docs/merchant/apis/h5-payment/get-trade-bill.html + * @see https://pay.weixin.qq.com/docs/partner/apis/partner-h5-payment/get-trade-bill.html */ -class GetTradeBillPlugin extends \Yansongda\Pay\Plugin\Wechat\Pay\Common\GetTradeBillPlugin {} +class GetTradeBillPlugin implements PluginInterface +{ + /** + * @throws InvalidParamsException + */ + public function assembly(Rocket $rocket, Closure $next): Rocket + { + Logger::debug('[Wechat][Pay][H5][GetTradeBillPlugin] 插件开始装载', ['rocket' => $rocket]); + + $payload = $rocket->getPayload(); + + if (is_null($payload)) { + throw new InvalidParamsException(Exception::PARAMS_NECESSARY_PARAMS_MISSING, '参数异常: H5 申请交易账单,参数为空'); + } + + $query = $payload->query(); + + $rocket->setPayload([ + '_method' => 'GET', + '_url' => 'v3/bill/tradebill?'.$query, + '_service_url' => 'v3/bill/tradebill?'.$query, + ]); + + Logger::info('[Wechat][Pay][H5][GetTradeBillPlugin] 插件装载完毕', ['rocket' => $rocket]); + + return $next($rocket); + } +} diff --git a/src/Plugin/Wechat/Pay/H5/PayPlugin.php b/src/Plugin/Wechat/Pay/H5/PayPlugin.php new file mode 100644 index 0000000..7c8b2b8 --- /dev/null +++ b/src/Plugin/Wechat/Pay/H5/PayPlugin.php @@ -0,0 +1,81 @@ + $rocket]); + + $payload = $rocket->getPayload(); + $params = $rocket->getParams(); + $config = get_wechat_config($params); + + if (is_null($payload)) { + throw new InvalidParamsException(Exception::PARAMS_NECESSARY_PARAMS_MISSING, '参数异常: H5 下单,参数为空'); + } + + if (Pay::MODE_SERVICE === ($config['mode'] ?? Pay::MODE_NORMAL)) { + $data = $this->service($payload, $params, $config); + } + + $rocket->mergePayload(array_merge( + [ + '_method' => 'POST', + '_url' => 'v3/pay/transactions/h5', + '_service_url' => 'v3/pay/partner/transactions/h5', + 'notify_url' => $payload->get('notify_url', $config['notify_url'] ?? ''), + ], + $data ?? $this->normal($params, $config) + )); + + Logger::info('[Wechat][Pay][H5][PayPlugin] 插件装载完毕', ['rocket' => $rocket]); + + return $next($rocket); + } + + protected function normal(array $params, array $config): array + { + return [ + 'appid' => $config[get_wechat_type_key($params)] ?? '', + 'mchid' => $config['mch_id'] ?? '', + ]; + } + + protected function service(Collection $payload, array $params, array $config): array + { + $configKey = get_wechat_type_key($params); + + return [ + 'sp_appid' => $config[$configKey] ?? '', + 'sp_mchid' => $config['mch_id'] ?? '', + 'sub_mchid' => $payload->get('sub_mchid', $config['sub_mch_id'] ?? ''), + ]; + } +} diff --git a/src/Plugin/Wechat/Pay/H5/PrepayPlugin.php b/src/Plugin/Wechat/Pay/H5/PrepayPlugin.php deleted file mode 100644 index b45f933..0000000 --- a/src/Plugin/Wechat/Pay/H5/PrepayPlugin.php +++ /dev/null @@ -1,23 +0,0 @@ - $rocket]); + + $params = $rocket->getParams(); + $config = get_wechat_config($params); + $payload = $rocket->getPayload(); + $transactionId = $payload?->get('transaction_id') ?? null; + + if (empty($transactionId)) { + throw new InvalidParamsException(Exception::PARAMS_NECESSARY_PARAMS_MISSING, '参数异常: H5 通过微信订单号查询订单,参数缺少 `transaction_id`'); + } + + $rocket->setPayload([ + '_method' => 'GET', + '_url' => 'v3/pay/transactions/id/'.$transactionId.'?'.$this->normal($config), + '_service_url' => 'v3/pay/partner/transactions/id/'.$transactionId.'?'.$this->service($payload, $config), + ]); + + Logger::info('[Wechat][Pay][H5][QueryByWxPlugin] 插件装载完毕', ['rocket' => $rocket]); + + return $next($rocket); + } + + protected function normal(array $config): string + { + return http_build_query([ + 'mchid' => $config['mch_id'] ?? 'null', + ]); + } + + protected function service(Collection $payload, array $config): string + { + return http_build_query([ + 'sp_mchid' => $config['mch_id'] ?? 'null', + 'sub_mchid' => $payload->get('sub_mchid', $config['sub_mch_id'] ?? 'null'), + ]); + } +} diff --git a/src/Plugin/Wechat/Pay/H5/QueryPlugin.php b/src/Plugin/Wechat/Pay/H5/QueryPlugin.php index 6eeb5fb..c569b3a 100644 --- a/src/Plugin/Wechat/Pay/H5/QueryPlugin.php +++ b/src/Plugin/Wechat/Pay/H5/QueryPlugin.php @@ -4,7 +4,65 @@ declare(strict_types=1); namespace Yansongda\Pay\Plugin\Wechat\Pay\H5; +use Closure; +use Yansongda\Pay\Contract\PluginInterface; +use Yansongda\Pay\Exception\ContainerException; +use Yansongda\Pay\Exception\Exception; +use Yansongda\Pay\Exception\InvalidParamsException; +use Yansongda\Pay\Exception\ServiceNotFoundException; +use Yansongda\Pay\Logger; +use Yansongda\Pay\Rocket; +use Yansongda\Supports\Collection; + +use function Yansongda\Pay\get_wechat_config; + /** - * @see https://pay.weixin.qq.com/wiki/doc/apiv3/apis/chapter3_3_2.shtml + * @see https://pay.weixin.qq.com/docs/merchant/apis/h5-payment/query-by-out-trade-no.html + * @see https://pay.weixin.qq.com/docs/partner/apis/partner-h5-payment/query-by-out-trade-no.html */ -class QueryPlugin extends \Yansongda\Pay\Plugin\Wechat\Pay\Common\QueryPlugin {} +class QueryPlugin implements PluginInterface +{ + /** + * @throws InvalidParamsException + * @throws ContainerException + * @throws ServiceNotFoundException + */ + public function assembly(Rocket $rocket, Closure $next): Rocket + { + Logger::debug('[Wechat][Pay][H5][QueryPlugin] 插件开始装载', ['rocket' => $rocket]); + + $params = $rocket->getParams(); + $config = get_wechat_config($params); + $payload = $rocket->getPayload(); + $outTradeNo = $payload?->get('out_trade_no') ?? null; + + if (empty($outTradeNo)) { + throw new InvalidParamsException(Exception::PARAMS_NECESSARY_PARAMS_MISSING, '参数异常: H5 通过商户订单号查询订单,参数缺少 `out_trade_no`'); + } + + $rocket->setPayload([ + '_method' => 'GET', + '_url' => 'v3/pay/transactions/out-trade-no/'.$outTradeNo.'?'.$this->normal($config), + '_service_url' => 'v3/pay/partner/transactions/out-trade-no/'.$outTradeNo.'?'.$this->service($payload, $config), + ]); + + Logger::info('[Wechat][Pay][H5][QueryPlugin] 插件装载完毕', ['rocket' => $rocket]); + + return $next($rocket); + } + + protected function normal(array $config): string + { + return http_build_query([ + 'mchid' => $config['mch_id'] ?? '', + ]); + } + + protected function service(Collection $payload, array $config): string + { + return http_build_query([ + 'sp_mchid' => $config['mch_id'] ?? '', + 'sub_mchid' => $payload->get('sub_mchid', $config['sub_mch_id'] ?? ''), + ]); + } +} diff --git a/src/Plugin/Wechat/Pay/H5/QueryRefundPlugin.php b/src/Plugin/Wechat/Pay/H5/QueryRefundPlugin.php index e03d729..78df1b9 100644 --- a/src/Plugin/Wechat/Pay/H5/QueryRefundPlugin.php +++ b/src/Plugin/Wechat/Pay/H5/QueryRefundPlugin.php @@ -4,7 +4,51 @@ declare(strict_types=1); namespace Yansongda\Pay\Plugin\Wechat\Pay\H5; +use Closure; +use Yansongda\Pay\Contract\PluginInterface; +use Yansongda\Pay\Exception\ContainerException; +use Yansongda\Pay\Exception\Exception; +use Yansongda\Pay\Exception\InvalidParamsException; +use Yansongda\Pay\Exception\ServiceNotFoundException; +use Yansongda\Pay\Logger; +use Yansongda\Pay\Rocket; + +use function Yansongda\Pay\get_wechat_config; + /** - * @see https://pay.weixin.qq.com/wiki/doc/apiv3/apis/chapter3_3_10.shtml + * @see https://pay.weixin.qq.com/docs/merchant/apis/h5-payment/query-by-out-refund-no.html + * @see https://pay.weixin.qq.com/docs/partner/apis/partner-h5-payment/query-by-out-refund-no.html */ -class QueryRefundPlugin extends \Yansongda\Pay\Plugin\Wechat\Pay\Common\QueryRefundPlugin {} +class QueryRefundPlugin implements PluginInterface +{ + /** + * @throws InvalidParamsException + * @throws ContainerException + * @throws ServiceNotFoundException + */ + public function assembly(Rocket $rocket, Closure $next): Rocket + { + Logger::debug('[Wechat][Pay][H5][QueryRefundPlugin] 插件开始装载', ['rocket' => $rocket]); + + $params = $rocket->getParams(); + $config = get_wechat_config($params); + $payload = $rocket->getPayload(); + $outRefundNo = $payload?->get('out_refund_no') ?? null; + + if (empty($outRefundNo)) { + throw new InvalidParamsException(Exception::PARAMS_NECESSARY_PARAMS_MISSING, '参数异常: H5 查询退款订单,参数缺少 `out_refund_no`'); + } + + $subMchId = $payload->get('sub_mchid', $config['sub_mch_id'] ?? ''); + + $rocket->setPayload([ + '_method' => 'GET', + '_url' => 'v3/refund/domestic/refunds/'.$outRefundNo, + '_service_url' => 'v3/refund/domestic/refunds/'.$outRefundNo.'?sub_mchid='.$subMchId, + ]); + + Logger::info('[Wechat][Pay][H5][QueryRefundPlugin] 插件装载完毕', ['rocket' => $rocket]); + + return $next($rocket); + } +} diff --git a/src/Plugin/Wechat/Pay/H5/RefundPlugin.php b/src/Plugin/Wechat/Pay/H5/RefundPlugin.php index fe475e8..abe2e18 100644 --- a/src/Plugin/Wechat/Pay/H5/RefundPlugin.php +++ b/src/Plugin/Wechat/Pay/H5/RefundPlugin.php @@ -4,7 +4,70 @@ declare(strict_types=1); namespace Yansongda\Pay\Plugin\Wechat\Pay\H5; +use Closure; +use Yansongda\Pay\Contract\PluginInterface; +use Yansongda\Pay\Exception\ContainerException; +use Yansongda\Pay\Exception\Exception; +use Yansongda\Pay\Exception\InvalidParamsException; +use Yansongda\Pay\Exception\ServiceNotFoundException; +use Yansongda\Pay\Logger; +use Yansongda\Pay\Pay; +use Yansongda\Pay\Rocket; +use Yansongda\Supports\Collection; + +use function Yansongda\Pay\get_wechat_config; + /** - * @see https://pay.weixin.qq.com/wiki/doc/apiv3/apis/chapter3_3_9.shtml + * @see https://pay.weixin.qq.com/docs/merchant/apis/h5-payment/create.html + * @see https://pay.weixin.qq.com/docs/partner/apis/partner-h5-payment/create.html */ -class RefundPlugin extends \Yansongda\Pay\Plugin\Wechat\Pay\Common\RefundPlugin {} +class RefundPlugin implements PluginInterface +{ + /** + * @throws ContainerException + * @throws InvalidParamsException + * @throws ServiceNotFoundException + */ + public function assembly(Rocket $rocket, Closure $next): Rocket + { + Logger::debug('[Wechat][Pay][H5][RefundPlugin] 插件开始装载', ['rocket' => $rocket]); + + $params = $rocket->getParams(); + $config = get_wechat_config($params); + $payload = $rocket->getPayload(); + + if (is_null($payload)) { + throw new InvalidParamsException(Exception::PARAMS_NECESSARY_PARAMS_MISSING, '参数异常: H5 退款申请,参数为空'); + } + + if (Pay::MODE_SERVICE === $config['mode']) { + $data = $this->service($payload, $config); + } + + $rocket->mergePayload(array_merge( + [ + '_method' => 'POST', + '_url' => 'v3/refund/domestic/refunds', + '_service_url' => 'v3/refund/domestic/refunds', + 'notify_url' => $payload->get('notify_url', $config['notify_url'] ?? null), + ], + $data ?? $this->normal() + )); + + Logger::info('[Wechat][Pay][H5][RefundPlugin] 插件装载完毕', ['rocket' => $rocket]); + + return $next($rocket); + } + + protected function normal(): array + { + return []; + } + + protected function service(Collection $payload, array $config): array + { + return [ + 'sub_mchid' => $payload->get('sub_mchid', $config['sub_mch_id'] ?? ''), + ]; + } +} diff --git a/src/Plugin/Wechat/Pay/Jsapi/ClosePlugin.php b/src/Plugin/Wechat/Pay/Jsapi/ClosePlugin.php index 660b2ee..3f159fa 100644 --- a/src/Plugin/Wechat/Pay/Jsapi/ClosePlugin.php +++ b/src/Plugin/Wechat/Pay/Jsapi/ClosePlugin.php @@ -4,7 +4,73 @@ declare(strict_types=1); namespace Yansongda\Pay\Plugin\Wechat\Pay\Jsapi; +use Closure; +use Yansongda\Pay\Contract\PluginInterface; +use Yansongda\Pay\Exception\ContainerException; +use Yansongda\Pay\Exception\Exception; +use Yansongda\Pay\Exception\InvalidParamsException; +use Yansongda\Pay\Exception\ServiceNotFoundException; +use Yansongda\Pay\Logger; +use Yansongda\Pay\Pay; +use Yansongda\Pay\Rocket; +use Yansongda\Supports\Collection; + +use function Yansongda\Pay\get_wechat_config; + /** - * @see https://pay.weixin.qq.com/wiki/doc/apiv3/apis/chapter3_1_3.shtml + * @see https://pay.weixin.qq.com/docs/merchant/apis/jsapi-payment/close-order.html + * @see https://pay.weixin.qq.com/docs/partner/apis/partner-jsapi-payment/close-order.html */ -class ClosePlugin extends \Yansongda\Pay\Plugin\Wechat\Pay\Common\ClosePlugin {} +class ClosePlugin implements PluginInterface +{ + /** + * @throws ContainerException + * @throws InvalidParamsException + * @throws ServiceNotFoundException + */ + public function assembly(Rocket $rocket, Closure $next): Rocket + { + Logger::debug('[Wechat][Pay][Jsapi][ClosePlugin] 插件开始装载', ['rocket' => $rocket]); + + $params = $rocket->getParams(); + $config = get_wechat_config($params); + $payload = $rocket->getPayload(); + $outTradeNo = $payload?->get('out_trade_no') ?? null; + + if (empty($outTradeNo)) { + throw new InvalidParamsException(Exception::PARAMS_NECESSARY_PARAMS_MISSING, '参数异常: Jsapi 关闭订单,参数缺少 `out_trade_no`'); + } + + if (Pay::MODE_SERVICE === ($config['mode'] ?? Pay::MODE_NORMAL)) { + $data = $this->service($payload, $config); + } + + $rocket->setPayload(array_merge( + [ + '_method' => 'POST', + '_url' => 'v3/pay/transactions/out-trade-no/'.$outTradeNo.'/close', + '_service_url' => 'v3/pay/partner/transactions/out-trade-no/'.$outTradeNo.'/close', + ], + $data ?? $this->normal($config) + )); + + Logger::info('[Wechat][Pay][Jsapi][ClosePlugin] 插件装载完毕', ['rocket' => $rocket]); + + return $next($rocket); + } + + protected function normal(array $config): array + { + return [ + 'mchid' => $config['mch_id'] ?? '', + ]; + } + + protected function service(Collection $payload, array $config): array + { + return [ + 'sp_mchid' => $config['mch_id'] ?? '', + 'sub_mchid' => $payload->get('sub_mchid', $config['sub_mch_id'] ?? ''), + ]; + } +} diff --git a/src/Plugin/Wechat/Pay/Jsapi/DownloadBillPlugin.php b/src/Plugin/Wechat/Pay/Jsapi/DownloadBillPlugin.php index 9c21e70..efc79dd 100644 --- a/src/Plugin/Wechat/Pay/Jsapi/DownloadBillPlugin.php +++ b/src/Plugin/Wechat/Pay/Jsapi/DownloadBillPlugin.php @@ -4,7 +4,40 @@ declare(strict_types=1); namespace Yansongda\Pay\Plugin\Wechat\Pay\Jsapi; +use Closure; +use Yansongda\Pay\Contract\PluginInterface; +use Yansongda\Pay\Exception\Exception; +use Yansongda\Pay\Exception\InvalidParamsException; +use Yansongda\Pay\Logger; +use Yansongda\Pay\Rocket; + /** - * @see https://pay.weixin.qq.com/wiki/doc/apiv3/apis/chapter3_1_8.shtml + * @see https://pay.weixin.qq.com/docs/merchant/apis/jsapi-payment/download-bill.html + * @see https://pay.weixin.qq.com/docs/partner/apis/partner-jsapi-payment/download-bill.html */ -class DownloadBillPlugin extends \Yansongda\Pay\Plugin\Wechat\Pay\Common\DownloadBillPlugin {} +class DownloadBillPlugin implements PluginInterface +{ + /** + * @throws InvalidParamsException + */ + public function assembly(Rocket $rocket, Closure $next): Rocket + { + Logger::debug('[Wechat][Pay][Jsapi][DownloadBillPlugin] 插件开始装载', ['rocket' => $rocket]); + + $downloadUrl = $rocket->getPayload()?->get('download_url') ?? null; + + if (empty($downloadUrl)) { + throw new InvalidParamsException(Exception::PARAMS_NECESSARY_PARAMS_MISSING, '参数异常: Jsapi 下载交易对账单,参数缺少 `download_url`'); + } + + $rocket->setPayload([ + '_method' => 'GET', + '_url' => $downloadUrl, + '_service_url' => $downloadUrl, + ]); + + Logger::info('[Wechat][Pay][Jsapi][DownloadBillPlugin] 插件装载完毕', ['rocket' => $rocket]); + + return $next($rocket); + } +} diff --git a/src/Plugin/Wechat/Pay/Jsapi/GetFlowBillPlugin.php b/src/Plugin/Wechat/Pay/Jsapi/GetFlowBillPlugin.php deleted file mode 100644 index 8be6641..0000000 --- a/src/Plugin/Wechat/Pay/Jsapi/GetFlowBillPlugin.php +++ /dev/null @@ -1,10 +0,0 @@ - $rocket]); + + $payload = $rocket->getPayload(); + + if (is_null($payload)) { + throw new InvalidParamsException(Exception::PARAMS_NECESSARY_PARAMS_MISSING, '参数异常: Jsapi 申请资金账单,参数为空'); + } + + $query = $payload->query(); + + $rocket->setPayload([ + '_method' => 'GET', + '_url' => 'v3/bill/fundflowbill?'.$query, + '_service_url' => 'v3/bill/fundflowbill?'.$query, + ]); + + Logger::info('[Wechat][Pay][Jsapi][GetFundBillPlugin] 插件装载完毕', ['rocket' => $rocket]); + + return $next($rocket); + } +} diff --git a/src/Plugin/Wechat/Pay/Jsapi/GetTradeBillPlugin.php b/src/Plugin/Wechat/Pay/Jsapi/GetTradeBillPlugin.php index 7dea200..5e13448 100644 --- a/src/Plugin/Wechat/Pay/Jsapi/GetTradeBillPlugin.php +++ b/src/Plugin/Wechat/Pay/Jsapi/GetTradeBillPlugin.php @@ -4,7 +4,42 @@ declare(strict_types=1); namespace Yansongda\Pay\Plugin\Wechat\Pay\Jsapi; +use Closure; +use Yansongda\Pay\Contract\PluginInterface; +use Yansongda\Pay\Exception\Exception; +use Yansongda\Pay\Exception\InvalidParamsException; +use Yansongda\Pay\Logger; +use Yansongda\Pay\Rocket; + /** - * @see https://pay.weixin.qq.com/wiki/doc/apiv3/apis/chapter3_1_6.shtml + * @see https://pay.weixin.qq.com/docs/merchant/apis/jsapi-payment/get-trade-bill.html + * @see https://pay.weixin.qq.com/docs/partner/apis/partner-jsapi-payment/get-trade-bill.html */ -class GetTradeBillPlugin extends \Yansongda\Pay\Plugin\Wechat\Pay\Common\GetTradeBillPlugin {} +class GetTradeBillPlugin implements PluginInterface +{ + /** + * @throws InvalidParamsException + */ + public function assembly(Rocket $rocket, Closure $next): Rocket + { + Logger::debug('[Wechat][Pay][Jsapi][GetTradeBillPlugin] 插件开始装载', ['rocket' => $rocket]); + + $payload = $rocket->getPayload(); + + if (is_null($payload)) { + throw new InvalidParamsException(Exception::PARAMS_NECESSARY_PARAMS_MISSING, '参数异常: Jsapi 申请交易账单,参数为空'); + } + + $query = $payload->query(); + + $rocket->setPayload([ + '_method' => 'GET', + '_url' => 'v3/bill/tradebill?'.$query, + '_service_url' => 'v3/bill/tradebill?'.$query, + ]); + + Logger::info('[Wechat][Pay][Jsapi][GetTradeBillPlugin] 插件装载完毕', ['rocket' => $rocket]); + + return $next($rocket); + } +} diff --git a/src/Plugin/Wechat/Pay/Jsapi/InvokePlugin.php b/src/Plugin/Wechat/Pay/Jsapi/InvokePlugin.php new file mode 100644 index 0000000..7c1dbfc --- /dev/null +++ b/src/Plugin/Wechat/Pay/Jsapi/InvokePlugin.php @@ -0,0 +1,106 @@ + $rocket]); + + $destination = $rocket->getDestination(); + $prepayId = $destination?->get('prepay_id'); + + if (is_null($prepayId)) { + Logger::error('[Wechat][Pay][Jsapi][InvokePlugin] 预下单失败:响应缺少 `prepay_id` 参数,请自行检查参数是否符合微信要求', $destination?->all() ?? null); + + throw new InvalidResponseException(Exception::RESPONSE_MISSING_NECESSARY_PARAMS, $destination?->get('message') ?? '预下单失败:响应缺少 `prepay_id` 参数,请自行检查参数是否符合微信要求', $destination?->all() ?? null); + } + + $params = $rocket->getParams(); + $config = get_wechat_config($params); + $payload = $rocket->getPayload(); + + $rocket->setDestination($this->getInvokeConfig($payload, $params, $config, $prepayId)); + + Logger::info('[Wechat][Pay][Jsapi][InvokePlugin] 插件装载完毕', ['rocket' => $rocket]); + + return $rocket; + } + + /** + * @throws InvalidConfigException + * @throws Throwable 生成随机串失败 + */ + protected function getInvokeConfig(?Collection $payload, array $params, array $config, string $prepayId): Config + { + $invokeConfig = new Config([ + 'appId' => $this->getAppId($payload, $config, $params), + 'timeStamp' => time().'', + 'nonceStr' => Str::random(32), + 'package' => 'prepay_id='.$prepayId, + 'signType' => 'RSA', + ]); + + $invokeConfig->set('paySign', $this->getSign($invokeConfig, $config)); + + return $invokeConfig; + } + + /** + * @throws InvalidConfigException + */ + protected function getSign(Collection $invokeConfig, array $config): string + { + $contents = $invokeConfig->get('appId', '')."\n". + $invokeConfig->get('timeStamp', '')."\n". + $invokeConfig->get('nonceStr', '')."\n". + $invokeConfig->get('package', '')."\n"; + + return get_wechat_sign($config, $contents); + } + + protected function getAppId(?Collection $payload, array $config, array $params): string + { + if (Pay::MODE_SERVICE === ($config['mode'] ?? Pay::MODE_NORMAL)) { + return $payload?->get('_invoke_appid') ?? $config['sub_'.get_wechat_type_key($params)] ?? ''; + } + + return $payload?->get('_invoke_appid') ?? $config[get_wechat_type_key($params)] ?? ''; + } +} diff --git a/src/Plugin/Wechat/Pay/Jsapi/InvokePrepayPlugin.php b/src/Plugin/Wechat/Pay/Jsapi/InvokePrepayPlugin.php deleted file mode 100644 index 7ff2011..0000000 --- a/src/Plugin/Wechat/Pay/Jsapi/InvokePrepayPlugin.php +++ /dev/null @@ -1,10 +0,0 @@ - $rocket]); + + $payload = $rocket->getPayload(); + $params = $rocket->getParams(); + $config = get_wechat_config($params); + + if (is_null($payload)) { + throw new InvalidParamsException(Exception::PARAMS_NECESSARY_PARAMS_MISSING, '参数异常: Jsapi 下单,参数为空'); + } + + if (Pay::MODE_SERVICE === ($config['mode'] ?? Pay::MODE_NORMAL)) { + $data = $this->service($payload, $config, $params); + } + + $rocket->mergePayload(array_merge( + [ + '_method' => 'POST', + '_url' => 'v3/pay/transactions/jsapi', + '_service_url' => 'v3/pay/partner/transactions/jsapi', + 'notify_url' => $payload->get('notify_url', $config['notify_url'] ?? ''), + ], + $data ?? $this->normal($config, $params) + )); + + Logger::info('[Wechat][Pay][Jsapi][PayPlugin] 插件装载完毕', ['rocket' => $rocket]); + + return $next($rocket); + } + + protected function normal(array $config, array $params): array + { + return [ + 'appid' => $config[get_wechat_type_key($params)] ?? '', + 'mchid' => $config['mch_id'] ?? '', + ]; + } + + protected function service(Collection $payload, array $config, array $params): array + { + $wechatTypeKey = get_wechat_type_key($params); + + $data = [ + 'sp_appid' => $config[$wechatTypeKey] ?? '', + 'sp_mchid' => $config['mch_id'] ?? '', + 'sub_mchid' => $payload->get('sub_mchid', $config['sub_mch_id'] ?? ''), + ]; + + if ($payload->has('payer.sub_openid')) { + $data['sub_appid'] = $config['sub_'.$wechatTypeKey] ?? ''; + } + + return $data; + } +} diff --git a/src/Plugin/Wechat/Pay/Jsapi/PrepayPlugin.php b/src/Plugin/Wechat/Pay/Jsapi/PrepayPlugin.php deleted file mode 100644 index d333a32..0000000 --- a/src/Plugin/Wechat/Pay/Jsapi/PrepayPlugin.php +++ /dev/null @@ -1,10 +0,0 @@ - $rocket]); + + $params = $rocket->getParams(); + $config = get_wechat_config($params); + $payload = $rocket->getPayload(); + $transactionId = $payload?->get('transaction_id') ?? null; + + if (empty($transactionId)) { + throw new InvalidParamsException(Exception::PARAMS_NECESSARY_PARAMS_MISSING, '参数异常: Jsapi 通过微信订单号查询订单,参数缺少 `transaction_id`'); + } + + $rocket->setPayload([ + '_method' => 'GET', + '_url' => 'v3/pay/transactions/id/'.$transactionId.'?'.$this->normal($config), + '_service_url' => 'v3/pay/partner/transactions/id/'.$transactionId.'?'.$this->service($payload, $config), + ]); + + Logger::info('[Wechat][Pay][Jsapi][QueryByWxPlugin] 插件装载完毕', ['rocket' => $rocket]); + + return $next($rocket); + } + + protected function normal(array $config): string + { + return http_build_query([ + 'mchid' => $config['mch_id'] ?? 'null', + ]); + } + + protected function service(Collection $payload, array $config): string + { + return http_build_query([ + 'sp_mchid' => $config['mch_id'] ?? 'null', + 'sub_mchid' => $payload->get('sub_mchid', $config['sub_mch_id'] ?? 'null'), + ]); + } +} diff --git a/src/Plugin/Wechat/Pay/Jsapi/QueryPlugin.php b/src/Plugin/Wechat/Pay/Jsapi/QueryPlugin.php index d7558ef..896bf70 100644 --- a/src/Plugin/Wechat/Pay/Jsapi/QueryPlugin.php +++ b/src/Plugin/Wechat/Pay/Jsapi/QueryPlugin.php @@ -4,7 +4,65 @@ declare(strict_types=1); namespace Yansongda\Pay\Plugin\Wechat\Pay\Jsapi; +use Closure; +use Yansongda\Pay\Contract\PluginInterface; +use Yansongda\Pay\Exception\ContainerException; +use Yansongda\Pay\Exception\Exception; +use Yansongda\Pay\Exception\InvalidParamsException; +use Yansongda\Pay\Exception\ServiceNotFoundException; +use Yansongda\Pay\Logger; +use Yansongda\Pay\Rocket; +use Yansongda\Supports\Collection; + +use function Yansongda\Pay\get_wechat_config; + /** - * @see https://pay.weixin.qq.com/wiki/doc/apiv3/apis/chapter3_1_2.shtml + * @see https://pay.weixin.qq.com/docs/merchant/apis/jsapi-payment/query-by-out-trade-no.html + * @see https://pay.weixin.qq.com/docs/partner/apis/partner-jsapi-payment/query-by-out-trade-no.html */ -class QueryPlugin extends \Yansongda\Pay\Plugin\Wechat\Pay\Common\QueryPlugin {} +class QueryPlugin implements PluginInterface +{ + /** + * @throws InvalidParamsException + * @throws ContainerException + * @throws ServiceNotFoundException + */ + public function assembly(Rocket $rocket, Closure $next): Rocket + { + Logger::debug('[Wechat][Pay][Jsapi][QueryPlugin] 插件开始装载', ['rocket' => $rocket]); + + $params = $rocket->getParams(); + $config = get_wechat_config($params); + $payload = $rocket->getPayload(); + $outTradeNo = $payload?->get('out_trade_no') ?? null; + + if (empty($outTradeNo)) { + throw new InvalidParamsException(Exception::PARAMS_NECESSARY_PARAMS_MISSING, '参数异常: Jsapi 通过商户订单号查询订单,参数缺少 `out_trade_no`'); + } + + $rocket->setPayload([ + '_method' => 'GET', + '_url' => 'v3/pay/transactions/out-trade-no/'.$outTradeNo.'?'.$this->normal($config), + '_service_url' => 'v3/pay/partner/transactions/out-trade-no/'.$outTradeNo.'?'.$this->service($payload, $config), + ]); + + Logger::info('[Wechat][Pay][Jsapi][QueryPlugin] 插件装载完毕', ['rocket' => $rocket]); + + return $next($rocket); + } + + protected function normal(array $config): string + { + return http_build_query([ + 'mchid' => $config['mch_id'] ?? '', + ]); + } + + protected function service(Collection $payload, array $config): string + { + return http_build_query([ + 'sp_mchid' => $config['mch_id'] ?? '', + 'sub_mchid' => $payload->get('sub_mchid', $config['sub_mch_id'] ?? ''), + ]); + } +} diff --git a/src/Plugin/Wechat/Pay/Jsapi/QueryRefundPlugin.php b/src/Plugin/Wechat/Pay/Jsapi/QueryRefundPlugin.php index 61d1459..3771f7b 100644 --- a/src/Plugin/Wechat/Pay/Jsapi/QueryRefundPlugin.php +++ b/src/Plugin/Wechat/Pay/Jsapi/QueryRefundPlugin.php @@ -4,7 +4,51 @@ declare(strict_types=1); namespace Yansongda\Pay\Plugin\Wechat\Pay\Jsapi; +use Closure; +use Yansongda\Pay\Contract\PluginInterface; +use Yansongda\Pay\Exception\ContainerException; +use Yansongda\Pay\Exception\Exception; +use Yansongda\Pay\Exception\InvalidParamsException; +use Yansongda\Pay\Exception\ServiceNotFoundException; +use Yansongda\Pay\Logger; +use Yansongda\Pay\Rocket; + +use function Yansongda\Pay\get_wechat_config; + /** - * @see https://pay.weixin.qq.com/wiki/doc/apiv3/apis/chapter3_1_10.shtml + * @see https://pay.weixin.qq.com/docs/merchant/apis/jsapi-payment/query-by-out-refund-no.html + * @see https://pay.weixin.qq.com/docs/partner/apis/partner-jsapi-payment/query-by-out-refund-no.html */ -class QueryRefundPlugin extends \Yansongda\Pay\Plugin\Wechat\Pay\Common\QueryRefundPlugin {} +class QueryRefundPlugin implements PluginInterface +{ + /** + * @throws InvalidParamsException + * @throws ContainerException + * @throws ServiceNotFoundException + */ + public function assembly(Rocket $rocket, Closure $next): Rocket + { + Logger::debug('[Wechat][Pay][Jsapi][QueryRefundPlugin] 插件开始装载', ['rocket' => $rocket]); + + $params = $rocket->getParams(); + $config = get_wechat_config($params); + $payload = $rocket->getPayload(); + $outRefundNo = $payload?->get('out_refund_no') ?? null; + + if (empty($outRefundNo)) { + throw new InvalidParamsException(Exception::PARAMS_NECESSARY_PARAMS_MISSING, '参数异常: Jsapi 查询退款订单,参数缺少 `out_refund_no`'); + } + + $subMchId = $payload->get('sub_mchid', $config['sub_mch_id'] ?? ''); + + $rocket->setPayload([ + '_method' => 'GET', + '_url' => 'v3/refund/domestic/refunds/'.$outRefundNo, + '_service_url' => 'v3/refund/domestic/refunds/'.$outRefundNo.'?sub_mchid='.$subMchId, + ]); + + Logger::info('[Wechat][Pay][Jsapi][QueryRefundPlugin] 插件装载完毕', ['rocket' => $rocket]); + + return $next($rocket); + } +} diff --git a/src/Plugin/Wechat/Pay/Jsapi/RefundPlugin.php b/src/Plugin/Wechat/Pay/Jsapi/RefundPlugin.php index 2de06b1..05c309e 100644 --- a/src/Plugin/Wechat/Pay/Jsapi/RefundPlugin.php +++ b/src/Plugin/Wechat/Pay/Jsapi/RefundPlugin.php @@ -4,7 +4,70 @@ declare(strict_types=1); namespace Yansongda\Pay\Plugin\Wechat\Pay\Jsapi; +use Closure; +use Yansongda\Pay\Contract\PluginInterface; +use Yansongda\Pay\Exception\ContainerException; +use Yansongda\Pay\Exception\Exception; +use Yansongda\Pay\Exception\InvalidParamsException; +use Yansongda\Pay\Exception\ServiceNotFoundException; +use Yansongda\Pay\Logger; +use Yansongda\Pay\Pay; +use Yansongda\Pay\Rocket; +use Yansongda\Supports\Collection; + +use function Yansongda\Pay\get_wechat_config; + /** - * @see https://pay.weixin.qq.com/wiki/doc/apiv3/apis/chapter3_1_9.shtml + * @see https://pay.weixin.qq.com/docs/merchant/apis/jsapi-payment/create.html + * @see https://pay.weixin.qq.com/docs/partner/apis/partner-jsapi-payment/create.html */ -class RefundPlugin extends \Yansongda\Pay\Plugin\Wechat\Pay\Common\RefundPlugin {} +class RefundPlugin implements PluginInterface +{ + /** + * @throws ContainerException + * @throws InvalidParamsException + * @throws ServiceNotFoundException + */ + public function assembly(Rocket $rocket, Closure $next): Rocket + { + Logger::debug('[Wechat][Pay][Jsapi][RefundPlugin] 插件开始装载', ['rocket' => $rocket]); + + $params = $rocket->getParams(); + $config = get_wechat_config($params); + $payload = $rocket->getPayload(); + + if (is_null($payload)) { + throw new InvalidParamsException(Exception::PARAMS_NECESSARY_PARAMS_MISSING, '参数异常: Jsapi 退款申请,参数为空'); + } + + if (Pay::MODE_SERVICE === $config['mode']) { + $data = $this->service($payload, $config); + } + + $rocket->mergePayload(array_merge( + [ + '_method' => 'POST', + '_url' => 'v3/refund/domestic/refunds', + '_service_url' => 'v3/refund/domestic/refunds', + 'notify_url' => $payload->get('notify_url', $config['notify_url'] ?? null), + ], + $data ?? $this->normal() + )); + + Logger::info('[Wechat][Pay][Jsapi][RefundPlugin] 插件装载完毕', ['rocket' => $rocket]); + + return $next($rocket); + } + + protected function normal(): array + { + return []; + } + + protected function service(Collection $payload, array $config): array + { + return [ + 'sub_mchid' => $payload->get('sub_mchid', $config['sub_mch_id'] ?? ''), + ]; + } +} diff --git a/src/Plugin/Wechat/Pay/Mini/ClosePlugin.php b/src/Plugin/Wechat/Pay/Mini/ClosePlugin.php index f007014..aad9deb 100644 --- a/src/Plugin/Wechat/Pay/Mini/ClosePlugin.php +++ b/src/Plugin/Wechat/Pay/Mini/ClosePlugin.php @@ -4,7 +4,73 @@ declare(strict_types=1); namespace Yansongda\Pay\Plugin\Wechat\Pay\Mini; +use Closure; +use Yansongda\Pay\Contract\PluginInterface; +use Yansongda\Pay\Exception\ContainerException; +use Yansongda\Pay\Exception\Exception; +use Yansongda\Pay\Exception\InvalidParamsException; +use Yansongda\Pay\Exception\ServiceNotFoundException; +use Yansongda\Pay\Logger; +use Yansongda\Pay\Pay; +use Yansongda\Pay\Rocket; +use Yansongda\Supports\Collection; + +use function Yansongda\Pay\get_wechat_config; + /** - * @see https://pay.weixin.qq.com/wiki/doc/apiv3/apis/chapter3_5_3.shtml + * @see https://pay.weixin.qq.com/docs/merchant/apis/mini-program-payment/close-order.html + * @see https://pay.weixin.qq.com/docs/partner/apis/partner-mini-program-payment/close-order.html */ -class ClosePlugin extends \Yansongda\Pay\Plugin\Wechat\Pay\Common\ClosePlugin {} +class ClosePlugin implements PluginInterface +{ + /** + * @throws ContainerException + * @throws InvalidParamsException + * @throws ServiceNotFoundException + */ + public function assembly(Rocket $rocket, Closure $next): Rocket + { + Logger::debug('[Wechat][Pay][Mini][ClosePlugin] 插件开始装载', ['rocket' => $rocket]); + + $params = $rocket->getParams(); + $config = get_wechat_config($params); + $payload = $rocket->getPayload(); + $outTradeNo = $payload?->get('out_trade_no') ?? null; + + if (empty($outTradeNo)) { + throw new InvalidParamsException(Exception::PARAMS_NECESSARY_PARAMS_MISSING, '参数异常: Mini 关闭订单,参数缺少 `out_trade_no`'); + } + + if (Pay::MODE_SERVICE === ($config['mode'] ?? Pay::MODE_NORMAL)) { + $data = $this->service($payload, $config); + } + + $rocket->setPayload(array_merge( + [ + '_method' => 'POST', + '_url' => 'v3/pay/transactions/out-trade-no/'.$outTradeNo.'/close', + '_service_url' => 'v3/pay/partner/transactions/out-trade-no/'.$outTradeNo.'/close', + ], + $data ?? $this->normal($config) + )); + + Logger::info('[Wechat][Pay][Mini][ClosePlugin] 插件装载完毕', ['rocket' => $rocket]); + + return $next($rocket); + } + + protected function normal(array $config): array + { + return [ + 'mchid' => $config['mch_id'] ?? '', + ]; + } + + protected function service(Collection $payload, array $config): array + { + return [ + 'sp_mchid' => $config['mch_id'] ?? '', + 'sub_mchid' => $payload->get('sub_mchid', $config['sub_mch_id'] ?? ''), + ]; + } +} diff --git a/src/Plugin/Wechat/Pay/Mini/DownloadBillPlugin.php b/src/Plugin/Wechat/Pay/Mini/DownloadBillPlugin.php index ec8d3f8..dcff9d3 100644 --- a/src/Plugin/Wechat/Pay/Mini/DownloadBillPlugin.php +++ b/src/Plugin/Wechat/Pay/Mini/DownloadBillPlugin.php @@ -4,7 +4,40 @@ declare(strict_types=1); namespace Yansongda\Pay\Plugin\Wechat\Pay\Mini; +use Closure; +use Yansongda\Pay\Contract\PluginInterface; +use Yansongda\Pay\Exception\Exception; +use Yansongda\Pay\Exception\InvalidParamsException; +use Yansongda\Pay\Logger; +use Yansongda\Pay\Rocket; + /** - * @see https://pay.weixin.qq.com/wiki/doc/apiv3/apis/chapter3_5_8.shtml + * @see https://pay.weixin.qq.com/docs/merchant/apis/mini-program-payment/download-bill.html + * @see https://pay.weixin.qq.com/docs/partner/apis/partner-mini-program-payment/download-bill.html */ -class DownloadBillPlugin extends \Yansongda\Pay\Plugin\Wechat\Pay\Common\DownloadBillPlugin {} +class DownloadBillPlugin implements PluginInterface +{ + /** + * @throws InvalidParamsException + */ + public function assembly(Rocket $rocket, Closure $next): Rocket + { + Logger::debug('[Wechat][Pay][Mini][DownloadBillPlugin] 插件开始装载', ['rocket' => $rocket]); + + $downloadUrl = $rocket->getPayload()?->get('download_url') ?? null; + + if (empty($downloadUrl)) { + throw new InvalidParamsException(Exception::PARAMS_NECESSARY_PARAMS_MISSING, '参数异常: Mini 下载交易对账单,参数缺少 `download_url`'); + } + + $rocket->setPayload([ + '_method' => 'GET', + '_url' => $downloadUrl, + '_service_url' => $downloadUrl, + ]); + + Logger::info('[Wechat][Pay][Mini][DownloadBillPlugin] 插件装载完毕', ['rocket' => $rocket]); + + return $next($rocket); + } +} diff --git a/src/Plugin/Wechat/Pay/Mini/GetFlowBillPlugin.php b/src/Plugin/Wechat/Pay/Mini/GetFlowBillPlugin.php deleted file mode 100644 index f089983..0000000 --- a/src/Plugin/Wechat/Pay/Mini/GetFlowBillPlugin.php +++ /dev/null @@ -1,10 +0,0 @@ - $rocket]); + + $payload = $rocket->getPayload(); + + if (is_null($payload)) { + throw new InvalidParamsException(Exception::PARAMS_NECESSARY_PARAMS_MISSING, '参数异常: Mini 申请资金账单,参数为空'); + } + + $query = $payload->query(); + + $rocket->setPayload([ + '_method' => 'GET', + '_url' => 'v3/bill/fundflowbill?'.$query, + '_service_url' => 'v3/bill/fundflowbill?'.$query, + ]); + + Logger::info('[Wechat][Pay][Mini][GetFundBillPlugin] 插件装载完毕', ['rocket' => $rocket]); + + return $next($rocket); + } +} diff --git a/src/Plugin/Wechat/Pay/Mini/GetTradeBillPlugin.php b/src/Plugin/Wechat/Pay/Mini/GetTradeBillPlugin.php index 161ecce..1e5ca6c 100644 --- a/src/Plugin/Wechat/Pay/Mini/GetTradeBillPlugin.php +++ b/src/Plugin/Wechat/Pay/Mini/GetTradeBillPlugin.php @@ -4,7 +4,42 @@ declare(strict_types=1); namespace Yansongda\Pay\Plugin\Wechat\Pay\Mini; +use Closure; +use Yansongda\Pay\Contract\PluginInterface; +use Yansongda\Pay\Exception\Exception; +use Yansongda\Pay\Exception\InvalidParamsException; +use Yansongda\Pay\Logger; +use Yansongda\Pay\Rocket; + /** - * @see https://pay.weixin.qq.com/wiki/doc/apiv3/apis/chapter3_5_6.shtml + * @see https://pay.weixin.qq.com/docs/merchant/apis/mini-program-payment/get-trade-bill.html + * @see https://pay.weixin.qq.com/docs/partner/apis/partner-mini-program-payment/get-trade-bill.html */ -class GetTradeBillPlugin extends \Yansongda\Pay\Plugin\Wechat\Pay\Common\GetTradeBillPlugin {} +class GetTradeBillPlugin implements PluginInterface +{ + /** + * @throws InvalidParamsException + */ + public function assembly(Rocket $rocket, Closure $next): Rocket + { + Logger::debug('[Wechat][Pay][Mini][GetTradeBillPlugin] 插件开始装载', ['rocket' => $rocket]); + + $payload = $rocket->getPayload(); + + if (is_null($payload)) { + throw new InvalidParamsException(Exception::PARAMS_NECESSARY_PARAMS_MISSING, '参数异常: Mini 申请交易账单,参数为空'); + } + + $query = $payload->query(); + + $rocket->setPayload([ + '_method' => 'GET', + '_url' => 'v3/bill/tradebill?'.$query, + '_service_url' => 'v3/bill/tradebill?'.$query, + ]); + + Logger::info('[Wechat][Pay][Mini][GetTradeBillPlugin] 插件装载完毕', ['rocket' => $rocket]); + + return $next($rocket); + } +} diff --git a/src/Plugin/Wechat/Pay/Mini/InvokePlugin.php b/src/Plugin/Wechat/Pay/Mini/InvokePlugin.php new file mode 100644 index 0000000..e325e05 --- /dev/null +++ b/src/Plugin/Wechat/Pay/Mini/InvokePlugin.php @@ -0,0 +1,105 @@ + $rocket]); + + $destination = $rocket->getDestination(); + $prepayId = $destination?->get('prepay_id'); + + if (is_null($prepayId)) { + Logger::error('[Wechat][Pay][Mini][InvokePlugin] 预下单失败:响应缺少 `prepay_id` 参数,请自行检查参数是否符合微信要求', $destination?->all() ?? null); + + throw new InvalidResponseException(Exception::RESPONSE_MISSING_NECESSARY_PARAMS, $destination?->get('message') ?? '预下单失败:响应缺少 `prepay_id` 参数,请自行检查参数是否符合微信要求', $destination?->all() ?? null); + } + + $params = $rocket->getParams(); + $config = get_wechat_config($params); + $payload = $rocket->getPayload(); + + $rocket->setDestination($this->getInvokeConfig($payload, $config, $prepayId)); + + Logger::info('[Wechat][Pay][Mini][InvokePlugin] 插件装载完毕', ['rocket' => $rocket]); + + return $rocket; + } + + /** + * @throws InvalidConfigException + * @throws Throwable 生成随机串失败 + */ + protected function getInvokeConfig(?Collection $payload, array $config, string $prepayId): Config + { + $invokeConfig = new Config([ + 'appId' => $this->getAppId($payload, $config), + 'timeStamp' => time().'', + 'nonceStr' => Str::random(32), + 'package' => 'prepay_id='.$prepayId, + 'signType' => 'RSA', + ]); + + $invokeConfig->set('paySign', $this->getSign($invokeConfig, $config)); + + return $invokeConfig; + } + + /** + * @throws InvalidConfigException + */ + protected function getSign(Collection $invokeConfig, array $config): string + { + $contents = $invokeConfig->get('appId', '')."\n". + $invokeConfig->get('timeStamp', '')."\n". + $invokeConfig->get('nonceStr', '')."\n". + $invokeConfig->get('package', '')."\n"; + + return get_wechat_sign($config, $contents); + } + + protected function getAppId(?Collection $payload, array $config): string + { + if (Pay::MODE_SERVICE === ($config['mode'] ?? Pay::MODE_NORMAL)) { + return $payload?->get('_invoke_appid') ?? $config['sub_mini_app_id'] ?? ''; + } + + return $payload?->get('_invoke_appid') ?? $config['mini_app_id'] ?? ''; + } +} diff --git a/src/Plugin/Wechat/Pay/Mini/InvokePrepayPlugin.php b/src/Plugin/Wechat/Pay/Mini/InvokePrepayPlugin.php deleted file mode 100644 index 195d1ff..0000000 --- a/src/Plugin/Wechat/Pay/Mini/InvokePrepayPlugin.php +++ /dev/null @@ -1,16 +0,0 @@ - $rocket]); + + $payload = $rocket->getPayload(); + $params = $rocket->getParams(); + $config = get_wechat_config($params); + + if (is_null($payload)) { + throw new InvalidParamsException(Exception::PARAMS_NECESSARY_PARAMS_MISSING, '参数异常: Mini 下单,参数为空'); + } + + if (Pay::MODE_SERVICE === ($config['mode'] ?? Pay::MODE_NORMAL)) { + $data = $this->service($payload, $config); + } + + $rocket->mergePayload(array_merge( + [ + '_method' => 'POST', + '_url' => 'v3/pay/transactions/jsapi', + '_service_url' => 'v3/pay/partner/transactions/jsapi', + 'notify_url' => $payload->get('notify_url', $config['notify_url'] ?? ''), + ], + $data ?? $this->normal($config) + )); + + Logger::info('[Wechat][Pay][Mini][PayPlugin] 插件装载完毕', ['rocket' => $rocket]); + + return $next($rocket); + } + + protected function normal(array $config): array + { + return [ + 'appid' => $config['mini_app_id'] ?? '', + 'mchid' => $config['mch_id'] ?? '', + ]; + } + + protected function service(Collection $payload, array $config): array + { + $data = [ + 'sp_appid' => $config['mini_app_id'] ?? '', + 'sp_mchid' => $config['mch_id'] ?? '', + 'sub_mchid' => $payload->get('sub_mchid', $config['sub_mch_id'] ?? ''), + ]; + + if ($payload->has('payer.sub_openid')) { + $data['sub_appid'] = $config['sub_mini_app_id'] ?? ''; + } + + return $data; + } +} diff --git a/src/Plugin/Wechat/Pay/Mini/PrepayPlugin.php b/src/Plugin/Wechat/Pay/Mini/PrepayPlugin.php deleted file mode 100644 index 7ea8e29..0000000 --- a/src/Plugin/Wechat/Pay/Mini/PrepayPlugin.php +++ /dev/null @@ -1,31 +0,0 @@ - $rocket]); + + $params = $rocket->getParams(); + $config = get_wechat_config($params); + $payload = $rocket->getPayload(); + $transactionId = $payload?->get('transaction_id') ?? null; + + if (empty($transactionId)) { + throw new InvalidParamsException(Exception::PARAMS_NECESSARY_PARAMS_MISSING, '参数异常: Mini 通过微信订单号查询订单,参数缺少 `transaction_id`'); + } + + $rocket->setPayload([ + '_method' => 'GET', + '_url' => 'v3/pay/transactions/id/'.$transactionId.'?'.$this->normal($config), + '_service_url' => 'v3/pay/partner/transactions/id/'.$transactionId.'?'.$this->service($payload, $config), + ]); + + Logger::info('[Wechat][Pay][Mini][QueryByWxPlugin] 插件装载完毕', ['rocket' => $rocket]); + + return $next($rocket); + } + + protected function normal(array $config): string + { + return http_build_query([ + 'mchid' => $config['mch_id'] ?? 'null', + ]); + } + + protected function service(Collection $payload, array $config): string + { + return http_build_query([ + 'sp_mchid' => $config['mch_id'] ?? 'null', + 'sub_mchid' => $payload->get('sub_mchid', $config['sub_mch_id'] ?? 'null'), + ]); + } +} diff --git a/src/Plugin/Wechat/Pay/Mini/QueryPlugin.php b/src/Plugin/Wechat/Pay/Mini/QueryPlugin.php index 7611cdc..b150f89 100644 --- a/src/Plugin/Wechat/Pay/Mini/QueryPlugin.php +++ b/src/Plugin/Wechat/Pay/Mini/QueryPlugin.php @@ -4,7 +4,65 @@ declare(strict_types=1); namespace Yansongda\Pay\Plugin\Wechat\Pay\Mini; +use Closure; +use Yansongda\Pay\Contract\PluginInterface; +use Yansongda\Pay\Exception\ContainerException; +use Yansongda\Pay\Exception\Exception; +use Yansongda\Pay\Exception\InvalidParamsException; +use Yansongda\Pay\Exception\ServiceNotFoundException; +use Yansongda\Pay\Logger; +use Yansongda\Pay\Rocket; +use Yansongda\Supports\Collection; + +use function Yansongda\Pay\get_wechat_config; + /** - * @see https://pay.weixin.qq.com/wiki/doc/apiv3/apis/chapter3_5_2.shtml + * @see https://pay.weixin.qq.com/docs/merchant/apis/mini-program-payment/query-by-out-trade-no.html + * @see https://pay.weixin.qq.com/docs/partner/apis/partner-mini-program-payment/query-by-out-trade-no.html */ -class QueryPlugin extends \Yansongda\Pay\Plugin\Wechat\Pay\Common\QueryPlugin {} +class QueryPlugin implements PluginInterface +{ + /** + * @throws InvalidParamsException + * @throws ContainerException + * @throws ServiceNotFoundException + */ + public function assembly(Rocket $rocket, Closure $next): Rocket + { + Logger::debug('[Wechat][Pay][Mini][QueryPlugin] 插件开始装载', ['rocket' => $rocket]); + + $params = $rocket->getParams(); + $config = get_wechat_config($params); + $payload = $rocket->getPayload(); + $outTradeNo = $payload?->get('out_trade_no') ?? null; + + if (empty($outTradeNo)) { + throw new InvalidParamsException(Exception::PARAMS_NECESSARY_PARAMS_MISSING, '参数异常: Mini 通过商户订单号查询订单,参数缺少 `out_trade_no`'); + } + + $rocket->setPayload([ + '_method' => 'GET', + '_url' => 'v3/pay/transactions/out-trade-no/'.$outTradeNo.'?'.$this->normal($config), + '_service_url' => 'v3/pay/partner/transactions/out-trade-no/'.$outTradeNo.'?'.$this->service($payload, $config), + ]); + + Logger::info('[Wechat][Pay][Mini][QueryPlugin] 插件装载完毕', ['rocket' => $rocket]); + + return $next($rocket); + } + + protected function normal(array $config): string + { + return http_build_query([ + 'mchid' => $config['mch_id'] ?? '', + ]); + } + + protected function service(Collection $payload, array $config): string + { + return http_build_query([ + 'sp_mchid' => $config['mch_id'] ?? '', + 'sub_mchid' => $payload->get('sub_mchid', $config['sub_mch_id'] ?? ''), + ]); + } +} diff --git a/src/Plugin/Wechat/Pay/Mini/QueryRefundPlugin.php b/src/Plugin/Wechat/Pay/Mini/QueryRefundPlugin.php index f066794..15b0538 100644 --- a/src/Plugin/Wechat/Pay/Mini/QueryRefundPlugin.php +++ b/src/Plugin/Wechat/Pay/Mini/QueryRefundPlugin.php @@ -4,7 +4,51 @@ declare(strict_types=1); namespace Yansongda\Pay\Plugin\Wechat\Pay\Mini; +use Closure; +use Yansongda\Pay\Contract\PluginInterface; +use Yansongda\Pay\Exception\ContainerException; +use Yansongda\Pay\Exception\Exception; +use Yansongda\Pay\Exception\InvalidParamsException; +use Yansongda\Pay\Exception\ServiceNotFoundException; +use Yansongda\Pay\Logger; +use Yansongda\Pay\Rocket; + +use function Yansongda\Pay\get_wechat_config; + /** - * @see https://pay.weixin.qq.com/wiki/doc/apiv3/apis/chapter3_5_10.shtml + * @see https://pay.weixin.qq.com/docs/merchant/apis/mini-program-payment/query-by-out-refund-no.html + * @see https://pay.weixin.qq.com/docs/partner/apis/partner-mini-program-payment/query-by-out-refund-no.html */ -class QueryRefundPlugin extends \Yansongda\Pay\Plugin\Wechat\Pay\Common\QueryRefundPlugin {} +class QueryRefundPlugin implements PluginInterface +{ + /** + * @throws InvalidParamsException + * @throws ContainerException + * @throws ServiceNotFoundException + */ + public function assembly(Rocket $rocket, Closure $next): Rocket + { + Logger::debug('[Wechat][Pay][Mini][QueryRefundPlugin] 插件开始装载', ['rocket' => $rocket]); + + $params = $rocket->getParams(); + $config = get_wechat_config($params); + $payload = $rocket->getPayload(); + $outRefundNo = $payload?->get('out_refund_no') ?? null; + + if (empty($outRefundNo)) { + throw new InvalidParamsException(Exception::PARAMS_NECESSARY_PARAMS_MISSING, '参数异常: Mini 查询退款订单,参数缺少 `out_refund_no`'); + } + + $subMchId = $payload->get('sub_mchid', $config['sub_mch_id'] ?? ''); + + $rocket->setPayload([ + '_method' => 'GET', + '_url' => 'v3/refund/domestic/refunds/'.$outRefundNo, + '_service_url' => 'v3/refund/domestic/refunds/'.$outRefundNo.'?sub_mchid='.$subMchId, + ]); + + Logger::info('[Wechat][Pay][Mini][QueryRefundPlugin] 插件装载完毕', ['rocket' => $rocket]); + + return $next($rocket); + } +} diff --git a/src/Plugin/Wechat/Pay/Mini/RefundPlugin.php b/src/Plugin/Wechat/Pay/Mini/RefundPlugin.php index 7335e14..3b4a685 100644 --- a/src/Plugin/Wechat/Pay/Mini/RefundPlugin.php +++ b/src/Plugin/Wechat/Pay/Mini/RefundPlugin.php @@ -4,7 +4,70 @@ declare(strict_types=1); namespace Yansongda\Pay\Plugin\Wechat\Pay\Mini; +use Closure; +use Yansongda\Pay\Contract\PluginInterface; +use Yansongda\Pay\Exception\ContainerException; +use Yansongda\Pay\Exception\Exception; +use Yansongda\Pay\Exception\InvalidParamsException; +use Yansongda\Pay\Exception\ServiceNotFoundException; +use Yansongda\Pay\Logger; +use Yansongda\Pay\Pay; +use Yansongda\Pay\Rocket; +use Yansongda\Supports\Collection; + +use function Yansongda\Pay\get_wechat_config; + /** - * @see https://pay.weixin.qq.com/wiki/doc/apiv3/apis/chapter3_5_9.shtml + * @see https://pay.weixin.qq.com/docs/merchant/apis/mini-program-payment/create.html + * @see https://pay.weixin.qq.com/docs/partner/apis/partner-mini-program-payment/create.html */ -class RefundPlugin extends \Yansongda\Pay\Plugin\Wechat\Pay\Common\RefundPlugin {} +class RefundPlugin implements PluginInterface +{ + /** + * @throws ContainerException + * @throws InvalidParamsException + * @throws ServiceNotFoundException + */ + public function assembly(Rocket $rocket, Closure $next): Rocket + { + Logger::debug('[Wechat][Pay][Mini][RefundPlugin] 插件开始装载', ['rocket' => $rocket]); + + $params = $rocket->getParams(); + $config = get_wechat_config($params); + $payload = $rocket->getPayload(); + + if (is_null($payload)) { + throw new InvalidParamsException(Exception::PARAMS_NECESSARY_PARAMS_MISSING, '参数异常: Mini 退款申请,参数为空'); + } + + if (Pay::MODE_SERVICE === $config['mode']) { + $data = $this->service($payload, $config); + } + + $rocket->mergePayload(array_merge( + [ + '_method' => 'POST', + '_url' => 'v3/refund/domestic/refunds', + '_service_url' => 'v3/refund/domestic/refunds', + 'notify_url' => $payload->get('notify_url', $config['notify_url'] ?? null), + ], + $data ?? $this->normal() + )); + + Logger::info('[Wechat][Pay][Mini][RefundPlugin] 插件装载完毕', ['rocket' => $rocket]); + + return $next($rocket); + } + + protected function normal(): array + { + return []; + } + + protected function service(Collection $payload, array $config): array + { + return [ + 'sub_mchid' => $payload->get('sub_mchid', $config['sub_mch_id'] ?? ''), + ]; + } +} diff --git a/src/Plugin/Wechat/Pay/Native/ClosePlugin.php b/src/Plugin/Wechat/Pay/Native/ClosePlugin.php index d61e81d..4cb5c08 100644 --- a/src/Plugin/Wechat/Pay/Native/ClosePlugin.php +++ b/src/Plugin/Wechat/Pay/Native/ClosePlugin.php @@ -4,7 +4,73 @@ declare(strict_types=1); namespace Yansongda\Pay\Plugin\Wechat\Pay\Native; +use Closure; +use Yansongda\Pay\Contract\PluginInterface; +use Yansongda\Pay\Exception\ContainerException; +use Yansongda\Pay\Exception\Exception; +use Yansongda\Pay\Exception\InvalidParamsException; +use Yansongda\Pay\Exception\ServiceNotFoundException; +use Yansongda\Pay\Logger; +use Yansongda\Pay\Pay; +use Yansongda\Pay\Rocket; +use Yansongda\Supports\Collection; + +use function Yansongda\Pay\get_wechat_config; + /** - * @see https://pay.weixin.qq.com/wiki/doc/apiv3/apis/chapter3_4_3.shtml + * @see https://pay.weixin.qq.com/docs/merchant/apis/native-payment/close-order.html + * @see https://pay.weixin.qq.com/docs/partner/apis/partner-native-payment/close-order.html */ -class ClosePlugin extends \Yansongda\Pay\Plugin\Wechat\Pay\Common\ClosePlugin {} +class ClosePlugin implements PluginInterface +{ + /** + * @throws ContainerException + * @throws InvalidParamsException + * @throws ServiceNotFoundException + */ + public function assembly(Rocket $rocket, Closure $next): Rocket + { + Logger::debug('[Wechat][Pay][Native][ClosePlugin] 插件开始装载', ['rocket' => $rocket]); + + $params = $rocket->getParams(); + $config = get_wechat_config($params); + $payload = $rocket->getPayload(); + $outTradeNo = $payload?->get('out_trade_no') ?? null; + + if (empty($outTradeNo)) { + throw new InvalidParamsException(Exception::PARAMS_NECESSARY_PARAMS_MISSING, '参数异常: Native 关闭订单,参数缺少 `out_trade_no`'); + } + + if (Pay::MODE_SERVICE === ($config['mode'] ?? Pay::MODE_NORMAL)) { + $data = $this->service($payload, $config); + } + + $rocket->setPayload(array_merge( + [ + '_method' => 'POST', + '_url' => 'v3/pay/transactions/out-trade-no/'.$outTradeNo.'/close', + '_service_url' => 'v3/pay/partner/transactions/out-trade-no/'.$outTradeNo.'/close', + ], + $data ?? $this->normal($config) + )); + + Logger::info('[Wechat][Pay][Native][ClosePlugin] 插件装载完毕', ['rocket' => $rocket]); + + return $next($rocket); + } + + protected function normal(array $config): array + { + return [ + 'mchid' => $config['mch_id'] ?? '', + ]; + } + + protected function service(Collection $payload, array $config): array + { + return [ + 'sp_mchid' => $config['mch_id'] ?? '', + 'sub_mchid' => $payload->get('sub_mchid', $config['sub_mch_id'] ?? ''), + ]; + } +} diff --git a/src/Plugin/Wechat/Pay/Native/DownloadBillPlugin.php b/src/Plugin/Wechat/Pay/Native/DownloadBillPlugin.php index 9c168bb..df5a9f9 100644 --- a/src/Plugin/Wechat/Pay/Native/DownloadBillPlugin.php +++ b/src/Plugin/Wechat/Pay/Native/DownloadBillPlugin.php @@ -4,7 +4,40 @@ declare(strict_types=1); namespace Yansongda\Pay\Plugin\Wechat\Pay\Native; +use Closure; +use Yansongda\Pay\Contract\PluginInterface; +use Yansongda\Pay\Exception\Exception; +use Yansongda\Pay\Exception\InvalidParamsException; +use Yansongda\Pay\Logger; +use Yansongda\Pay\Rocket; + /** - * @see https://pay.weixin.qq.com/wiki/doc/apiv3/apis/chapter3_4_8.shtml + * @see https://pay.weixin.qq.com/docs/merchant/apis/native-payment/download-bill.html + * @see https://pay.weixin.qq.com/docs/partner/apis/partner-native-payment/download-bill.html */ -class DownloadBillPlugin extends \Yansongda\Pay\Plugin\Wechat\Pay\Common\DownloadBillPlugin {} +class DownloadBillPlugin implements PluginInterface +{ + /** + * @throws InvalidParamsException + */ + public function assembly(Rocket $rocket, Closure $next): Rocket + { + Logger::debug('[Wechat][Pay][Native][DownloadBillPlugin] 插件开始装载', ['rocket' => $rocket]); + + $downloadUrl = $rocket->getPayload()?->get('download_url') ?? null; + + if (empty($downloadUrl)) { + throw new InvalidParamsException(Exception::PARAMS_NECESSARY_PARAMS_MISSING, '参数异常: Native 下载交易对账单,参数缺少 `download_url`'); + } + + $rocket->setPayload([ + '_method' => 'GET', + '_url' => $downloadUrl, + '_service_url' => $downloadUrl, + ]); + + Logger::info('[Wechat][Pay][Native][DownloadBillPlugin] 插件装载完毕', ['rocket' => $rocket]); + + return $next($rocket); + } +} diff --git a/src/Plugin/Wechat/Pay/Native/GetFlowBillPlugin.php b/src/Plugin/Wechat/Pay/Native/GetFlowBillPlugin.php deleted file mode 100644 index f4e87aa..0000000 --- a/src/Plugin/Wechat/Pay/Native/GetFlowBillPlugin.php +++ /dev/null @@ -1,10 +0,0 @@ - $rocket]); + + $payload = $rocket->getPayload(); + + if (is_null($payload)) { + throw new InvalidParamsException(Exception::PARAMS_NECESSARY_PARAMS_MISSING, '参数异常: Native 申请资金账单,参数为空'); + } + + $query = $payload->query(); + + $rocket->setPayload([ + '_method' => 'GET', + '_url' => 'v3/bill/fundflowbill?'.$query, + '_service_url' => 'v3/bill/fundflowbill?'.$query, + ]); + + Logger::info('[Wechat][Pay][Native][GetFundBillPlugin] 插件装载完毕', ['rocket' => $rocket]); + + return $next($rocket); + } +} diff --git a/src/Plugin/Wechat/Pay/Native/GetTradeBillPlugin.php b/src/Plugin/Wechat/Pay/Native/GetTradeBillPlugin.php index 7fc64cb..f42a9a0 100644 --- a/src/Plugin/Wechat/Pay/Native/GetTradeBillPlugin.php +++ b/src/Plugin/Wechat/Pay/Native/GetTradeBillPlugin.php @@ -4,7 +4,42 @@ declare(strict_types=1); namespace Yansongda\Pay\Plugin\Wechat\Pay\Native; +use Closure; +use Yansongda\Pay\Contract\PluginInterface; +use Yansongda\Pay\Exception\Exception; +use Yansongda\Pay\Exception\InvalidParamsException; +use Yansongda\Pay\Logger; +use Yansongda\Pay\Rocket; + /** - * @see https://pay.weixin.qq.com/wiki/doc/apiv3/apis/chapter3_4_6.shtml + * @see https://pay.weixin.qq.com/docs/merchant/apis/native-payment/get-trade-bill.html + * @see https://pay.weixin.qq.com/docs/partner/apis/partner-native-payment/get-trade-bill.html */ -class GetTradeBillPlugin extends \Yansongda\Pay\Plugin\Wechat\Pay\Common\GetTradeBillPlugin {} +class GetTradeBillPlugin implements PluginInterface +{ + /** + * @throws InvalidParamsException + */ + public function assembly(Rocket $rocket, Closure $next): Rocket + { + Logger::debug('[Wechat][Pay][Native][GetTradeBillPlugin] 插件开始装载', ['rocket' => $rocket]); + + $payload = $rocket->getPayload(); + + if (is_null($payload)) { + throw new InvalidParamsException(Exception::PARAMS_NECESSARY_PARAMS_MISSING, '参数异常: Native 申请交易账单,参数为空'); + } + + $query = $payload->query(); + + $rocket->setPayload([ + '_method' => 'GET', + '_url' => 'v3/bill/tradebill?'.$query, + '_service_url' => 'v3/bill/tradebill?'.$query, + ]); + + Logger::info('[Wechat][Pay][Native][GetTradeBillPlugin] 插件装载完毕', ['rocket' => $rocket]); + + return $next($rocket); + } +} diff --git a/src/Plugin/Wechat/Pay/Native/PayPlugin.php b/src/Plugin/Wechat/Pay/Native/PayPlugin.php new file mode 100644 index 0000000..5f8858b --- /dev/null +++ b/src/Plugin/Wechat/Pay/Native/PayPlugin.php @@ -0,0 +1,81 @@ + $rocket]); + + $payload = $rocket->getPayload(); + $params = $rocket->getParams(); + $config = get_wechat_config($params); + + if (is_null($payload)) { + throw new InvalidParamsException(Exception::PARAMS_NECESSARY_PARAMS_MISSING, '参数异常: Native 下单,参数为空'); + } + + if (Pay::MODE_SERVICE === ($config['mode'] ?? Pay::MODE_NORMAL)) { + $data = $this->service($payload, $params, $config); + } + + $rocket->mergePayload(array_merge( + [ + '_method' => 'POST', + '_url' => 'v3/pay/transactions/native', + '_service_url' => 'v3/pay/partner/transactions/native', + 'notify_url' => $payload->get('notify_url', $config['notify_url'] ?? ''), + ], + $data ?? $this->normal($params, $config) + )); + + Logger::info('[Wechat][Pay][Native][PayPlugin] 插件装载完毕', ['rocket' => $rocket]); + + return $next($rocket); + } + + protected function normal(array $params, array $config): array + { + return [ + 'appid' => $config[get_wechat_type_key($params)] ?? '', + 'mchid' => $config['mch_id'] ?? '', + ]; + } + + protected function service(Collection $payload, array $params, array $config): array + { + $configKey = get_wechat_type_key($params); + + return [ + 'sp_appid' => $config[$configKey] ?? '', + 'sp_mchid' => $config['mch_id'] ?? '', + 'sub_mchid' => $payload->get('sub_mchid', $config['sub_mch_id'] ?? ''), + ]; + } +} diff --git a/src/Plugin/Wechat/Pay/Native/PrepayPlugin.php b/src/Plugin/Wechat/Pay/Native/PrepayPlugin.php deleted file mode 100644 index 48f09fa..0000000 --- a/src/Plugin/Wechat/Pay/Native/PrepayPlugin.php +++ /dev/null @@ -1,23 +0,0 @@ - $rocket]); + + $params = $rocket->getParams(); + $config = get_wechat_config($params); + $payload = $rocket->getPayload(); + $transactionId = $payload?->get('transaction_id') ?? null; + + if (empty($transactionId)) { + throw new InvalidParamsException(Exception::PARAMS_NECESSARY_PARAMS_MISSING, '参数异常: Native 通过微信订单号查询订单,参数缺少 `transaction_id`'); + } + + $rocket->setPayload([ + '_method' => 'GET', + '_url' => 'v3/pay/transactions/id/'.$transactionId.'?'.$this->normal($config), + '_service_url' => 'v3/pay/partner/transactions/id/'.$transactionId.'?'.$this->service($payload, $config), + ]); + + Logger::info('[Wechat][Pay][Native][QueryBatchByWxPlugin] 插件装载完毕', ['rocket' => $rocket]); + + return $next($rocket); + } + + protected function normal(array $config): string + { + return http_build_query([ + 'mchid' => $config['mch_id'] ?? 'null', + ]); + } + + protected function service(Collection $payload, array $config): string + { + return http_build_query([ + 'sp_mchid' => $config['mch_id'] ?? 'null', + 'sub_mchid' => $payload->get('sub_mchid', $config['sub_mch_id'] ?? 'null'), + ]); + } +} diff --git a/src/Plugin/Wechat/Pay/Native/QueryPlugin.php b/src/Plugin/Wechat/Pay/Native/QueryPlugin.php index 9935bbf..7e7b483 100644 --- a/src/Plugin/Wechat/Pay/Native/QueryPlugin.php +++ b/src/Plugin/Wechat/Pay/Native/QueryPlugin.php @@ -4,7 +4,65 @@ declare(strict_types=1); namespace Yansongda\Pay\Plugin\Wechat\Pay\Native; +use Closure; +use Yansongda\Pay\Contract\PluginInterface; +use Yansongda\Pay\Exception\ContainerException; +use Yansongda\Pay\Exception\Exception; +use Yansongda\Pay\Exception\InvalidParamsException; +use Yansongda\Pay\Exception\ServiceNotFoundException; +use Yansongda\Pay\Logger; +use Yansongda\Pay\Rocket; +use Yansongda\Supports\Collection; + +use function Yansongda\Pay\get_wechat_config; + /** - * @see https://pay.weixin.qq.com/wiki/doc/apiv3/apis/chapter3_4_2.shtml + * @see https://pay.weixin.qq.com/docs/merchant/apis/native-payment/query-by-out-trade-no.html + * @see https://pay.weixin.qq.com/docs/partner/apis/partner-native-payment/query-by-out-trade-no.html */ -class QueryPlugin extends \Yansongda\Pay\Plugin\Wechat\Pay\Common\QueryPlugin {} +class QueryPlugin implements PluginInterface +{ + /** + * @throws InvalidParamsException + * @throws ContainerException + * @throws ServiceNotFoundException + */ + public function assembly(Rocket $rocket, Closure $next): Rocket + { + Logger::debug('[Wechat][Pay][Native][QueryPlugin] 插件开始装载', ['rocket' => $rocket]); + + $params = $rocket->getParams(); + $config = get_wechat_config($params); + $payload = $rocket->getPayload(); + $outTradeNo = $payload?->get('out_trade_no') ?? null; + + if (empty($outTradeNo)) { + throw new InvalidParamsException(Exception::PARAMS_NECESSARY_PARAMS_MISSING, '参数异常: Native 通过商户订单号查询订单,参数缺少 `out_trade_no`'); + } + + $rocket->setPayload([ + '_method' => 'GET', + '_url' => 'v3/pay/transactions/out-trade-no/'.$outTradeNo.'?'.$this->normal($config), + '_service_url' => 'v3/pay/partner/transactions/out-trade-no/'.$outTradeNo.'?'.$this->service($payload, $config), + ]); + + Logger::info('[Wechat][Pay][Native][QueryPlugin] 插件装载完毕', ['rocket' => $rocket]); + + return $next($rocket); + } + + protected function normal(array $config): string + { + return http_build_query([ + 'mchid' => $config['mch_id'] ?? '', + ]); + } + + protected function service(Collection $payload, array $config): string + { + return http_build_query([ + 'sp_mchid' => $config['mch_id'] ?? '', + 'sub_mchid' => $payload->get('sub_mchid', $config['sub_mch_id'] ?? ''), + ]); + } +} diff --git a/src/Plugin/Wechat/Pay/Native/QueryRefundPlugin.php b/src/Plugin/Wechat/Pay/Native/QueryRefundPlugin.php index 036a887..8e5312a 100644 --- a/src/Plugin/Wechat/Pay/Native/QueryRefundPlugin.php +++ b/src/Plugin/Wechat/Pay/Native/QueryRefundPlugin.php @@ -4,7 +4,51 @@ declare(strict_types=1); namespace Yansongda\Pay\Plugin\Wechat\Pay\Native; +use Closure; +use Yansongda\Pay\Contract\PluginInterface; +use Yansongda\Pay\Exception\ContainerException; +use Yansongda\Pay\Exception\Exception; +use Yansongda\Pay\Exception\InvalidParamsException; +use Yansongda\Pay\Exception\ServiceNotFoundException; +use Yansongda\Pay\Logger; +use Yansongda\Pay\Rocket; + +use function Yansongda\Pay\get_wechat_config; + /** - * @see https://pay.weixin.qq.com/wiki/doc/apiv3/apis/chapter3_4_10.shtml + * @see https://pay.weixin.qq.com/docs/merchant/apis/native-payment/query-by-out-refund-no.html + * @see https://pay.weixin.qq.com/docs/partner/apis/partner-native-payment/query-by-out-refund-no.html */ -class QueryRefundPlugin extends \Yansongda\Pay\Plugin\Wechat\Pay\Common\QueryRefundPlugin {} +class QueryRefundPlugin implements PluginInterface +{ + /** + * @throws InvalidParamsException + * @throws ContainerException + * @throws ServiceNotFoundException + */ + public function assembly(Rocket $rocket, Closure $next): Rocket + { + Logger::debug('[Wechat][Pay][Native][QueryRefundPlugin] 插件开始装载', ['rocket' => $rocket]); + + $params = $rocket->getParams(); + $config = get_wechat_config($params); + $payload = $rocket->getPayload(); + $outRefundNo = $payload?->get('out_refund_no') ?? null; + + if (empty($outRefundNo)) { + throw new InvalidParamsException(Exception::PARAMS_NECESSARY_PARAMS_MISSING, '参数异常: Native 查询退款订单,参数缺少 `out_refund_no`'); + } + + $subMchId = $payload->get('sub_mchid', $config['sub_mch_id'] ?? ''); + + $rocket->setPayload([ + '_method' => 'GET', + '_url' => 'v3/refund/domestic/refunds/'.$outRefundNo, + '_service_url' => 'v3/refund/domestic/refunds/'.$outRefundNo.'?sub_mchid='.$subMchId, + ]); + + Logger::info('[Wechat][Pay][Native][QueryRefundPlugin] 插件装载完毕', ['rocket' => $rocket]); + + return $next($rocket); + } +} diff --git a/src/Plugin/Wechat/Pay/Native/RefundPlugin.php b/src/Plugin/Wechat/Pay/Native/RefundPlugin.php index 7ebdb75..45aab56 100644 --- a/src/Plugin/Wechat/Pay/Native/RefundPlugin.php +++ b/src/Plugin/Wechat/Pay/Native/RefundPlugin.php @@ -4,7 +4,70 @@ declare(strict_types=1); namespace Yansongda\Pay\Plugin\Wechat\Pay\Native; +use Closure; +use Yansongda\Pay\Contract\PluginInterface; +use Yansongda\Pay\Exception\ContainerException; +use Yansongda\Pay\Exception\Exception; +use Yansongda\Pay\Exception\InvalidParamsException; +use Yansongda\Pay\Exception\ServiceNotFoundException; +use Yansongda\Pay\Logger; +use Yansongda\Pay\Pay; +use Yansongda\Pay\Rocket; +use Yansongda\Supports\Collection; + +use function Yansongda\Pay\get_wechat_config; + /** - * @see https://pay.weixin.qq.com/wiki/doc/apiv3/apis/chapter3_4_9.shtml + * @see https://pay.weixin.qq.com/docs/merchant/apis/native-payment/create.html + * @see https://pay.weixin.qq.com/docs/partner/apis/partner-native-payment/create.html */ -class RefundPlugin extends \Yansongda\Pay\Plugin\Wechat\Pay\Common\RefundPlugin {} +class RefundPlugin implements PluginInterface +{ + /** + * @throws ContainerException + * @throws InvalidParamsException + * @throws ServiceNotFoundException + */ + public function assembly(Rocket $rocket, Closure $next): Rocket + { + Logger::debug('[Wechat][Pay][Native][RefundPlugin] 插件开始装载', ['rocket' => $rocket]); + + $params = $rocket->getParams(); + $config = get_wechat_config($params); + $payload = $rocket->getPayload(); + + if (is_null($payload)) { + throw new InvalidParamsException(Exception::PARAMS_NECESSARY_PARAMS_MISSING, '参数异常: Native 退款申请,参数为空'); + } + + if (Pay::MODE_SERVICE === $config['mode']) { + $data = $this->service($payload, $config); + } + + $rocket->mergePayload(array_merge( + [ + '_method' => 'POST', + '_url' => 'v3/refund/domestic/refunds', + '_service_url' => 'v3/refund/domestic/refunds', + 'notify_url' => $payload->get('notify_url', $config['notify_url'] ?? null), + ], + $data ?? $this->normal() + )); + + Logger::info('[Wechat][Pay][Native][RefundPlugin] 插件装载完毕', ['rocket' => $rocket]); + + return $next($rocket); + } + + protected function normal(): array + { + return []; + } + + protected function service(Collection $payload, array $config): array + { + return [ + 'sub_mchid' => $payload->get('sub_mchid', $config['sub_mch_id'] ?? ''), + ]; + } +} diff --git a/src/Plugin/Wechat/Pay/Pos/PayPlugin.php b/src/Plugin/Wechat/Pay/Pos/PayPlugin.php deleted file mode 100644 index bc0098f..0000000 --- a/src/Plugin/Wechat/Pay/Pos/PayPlugin.php +++ /dev/null @@ -1,19 +0,0 @@ - $rocket]); + + $params = $rocket->getParams(); + $payload = $rocket->getPayload(); + $config = get_wechat_config($params); + $refundId = $payload?->get('refund_id') ?? null; + + if (empty($refundId)) { + throw new InvalidParamsException(Exception::PARAMS_NECESSARY_PARAMS_MISSING, '参数异常: 发起异常退款,参数缺少 `refund_id`'); + } + + if (Pay::MODE_SERVICE === ($config['mode'] ?? Pay::MODE_NORMAL)) { + $data = $this->service($params, $config, $payload); + } + + $rocket->mergePayload(array_merge( + [ + '_method' => 'POST', + '_url' => 'v3/refund/domestic/refunds/'.$refundId.'/apply-abnormal-refund', + '_service_url' => 'v3/refund/domestic/refunds/'.$refundId.'/apply-abnormal-refund', + ], + $data ?? $this->normal($params, $config, $payload) + ))->exceptPayload('refund_id'); + + Logger::info('[Wechat][Pay][Refund][RefundAbnormalPlugin] 插件装载完毕', ['rocket' => $rocket]); + + return $next($rocket); + } + + /** + * @throws ContainerException + * @throws InvalidParamsException + * @throws ServiceNotFoundException + * @throws DecryptException + * @throws InvalidConfigException + */ + protected function normal(array $params, array $config, Collection $payload): array + { + return $this->encryptSensitiveData($params, $config, $payload); + } + + /** + * @throws ContainerException + * @throws DecryptException + * @throws InvalidConfigException + * @throws InvalidParamsException + * @throws ServiceNotFoundException + */ + protected function service(array $params, array $config, Collection $payload): array + { + $data = [ + 'sub_mchid' => $payload->get('sub_mchid', $config['sub_mch_id'] ?? ''), + ]; + + return array_merge($data, $this->encryptSensitiveData($params, $config, $payload)); + } + + /** + * @throws ContainerException + * @throws DecryptException + * @throws InvalidConfigException + * @throws InvalidParamsException + * @throws ServiceNotFoundException + */ + protected function encryptSensitiveData(array $params, array $config, Collection $payload): array + { + if ($payload->has('bank_account') && $payload->has('real_name')) { + $data['_serial_no'] = get_wechat_serial_no($params); + $publicKey = get_wechat_public_key($config, $data['_serial_no']); + + $data['real_name'] = encrypt_wechat_contents($payload->get('real_name'), $publicKey); + $data['bank_account'] = encrypt_wechat_contents($payload->get('bank_account'), $publicKey); + } + + return $data ?? []; + } +} diff --git a/src/Plugin/Wechat/PreparePlugin.php b/src/Plugin/Wechat/PreparePlugin.php deleted file mode 100644 index 7cc9a4e..0000000 --- a/src/Plugin/Wechat/PreparePlugin.php +++ /dev/null @@ -1,30 +0,0 @@ - $rocket]); - - $rocket->mergePayload($this->getPayload($rocket->getParams())); - - Logger::info('[wechat][StartPlugin] 插件装载完毕', ['rocket' => $rocket]); - - return $next($rocket); - } - - protected function getPayload(array $params): array - { - return array_filter($params, fn ($v, $k) => !Str::startsWith(strval($k), '_'), ARRAY_FILTER_USE_BOTH); - } -} diff --git a/src/Plugin/Wechat/RadarSignPlugin.php b/src/Plugin/Wechat/RadarSignPlugin.php deleted file mode 100644 index fe91d54..0000000 --- a/src/Plugin/Wechat/RadarSignPlugin.php +++ /dev/null @@ -1,163 +0,0 @@ -jsonPacker = $jsonPacker ?? new JsonPacker(); - $this->xmlPacker = $xmlPacker ?? new XmlPacker(); - } - - /** - * @throws ContainerException - * @throws InvalidConfigException - * @throws InvalidParamsException - * @throws ServiceNotFoundException - */ - public function assembly(Rocket $rocket, Closure $next): Rocket - { - Logger::debug('[wechat][AddRadarPlugin] 插件开始装载', ['rocket' => $rocket]); - - $radar = match ($rocket->getParams()['_version'] ?? 'default') { - 'v2' => $this->v2($rocket), - default => $this->v3($rocket), - }; - - $rocket->setRadar($radar); - - Logger::info('[wechat][AddRadarPlugin] 插件装载完毕', ['rocket' => $rocket]); - - return $next($rocket); - } - - /** - * @throws ContainerException - * @throws ServiceNotFoundException - * @throws InvalidConfigException - * @throws \Exception - */ - protected function v2(Rocket $rocket): RequestInterface - { - $rocket->mergePayload(['nonce_str' => Str::random(32)]); - $rocket->mergePayload([ - 'sign' => get_wechat_sign_v2($rocket->getParams(), $rocket->getPayload()->all()), - ]); - - return $rocket->getRadar()->withBody( - Utils::streamFor($this->xmlPacker->pack($rocket->getPayload()->all())) - ); - } - - /** - * @throws ContainerException - * @throws InvalidConfigException - * @throws InvalidParamsException - * @throws ServiceNotFoundException - * @throws \Exception - */ - protected function v3(Rocket $rocket): RequestInterface - { - $timestamp = time(); - $random = Str::random(32); - $body = $this->v3PayloadToString($rocket->getPayload()); - $contents = $this->v3GetContents($rocket, $timestamp, $random); - $authorization = $this->v3GetWechatAuthorization($rocket->getParams(), $timestamp, $random, $contents); - $radar = $rocket->getRadar()->withHeader('Authorization', $authorization); - - if (!empty($rocket->getParams()['_serial_no'])) { - $radar = $radar->withHeader('Wechatpay-Serial', $rocket->getParams()['_serial_no']); - } - - if (!empty($body)) { - $radar = $radar->withBody(Utils::streamFor($body)); - } - - return $radar; - } - - /** - * @throws ContainerException - * @throws InvalidConfigException - * @throws ServiceNotFoundException - */ - protected function v3GetWechatAuthorization(array $params, int $timestamp, string $random, string $contents): string - { - $config = get_wechat_config($params); - $mchPublicCertPath = $config['mch_public_cert_path'] ?? null; - - if (empty($mchPublicCertPath)) { - throw new InvalidConfigException(Exception::CONFIG_WECHAT_INVALID, 'Missing Wechat Config -- [mch_public_cert_path]'); - } - - $ssl = openssl_x509_parse(get_public_cert($mchPublicCertPath)); - - if (empty($ssl['serialNumberHex'])) { - throw new InvalidConfigException(Exception::CONFIG_WECHAT_INVALID, 'Parse [mch_public_cert_path] Serial Number Error'); - } - - $auth = sprintf( - 'mchid="%s",nonce_str="%s",timestamp="%d",serial_no="%s",signature="%s"', - $config['mch_id'] ?? '', - $random, - $timestamp, - $ssl['serialNumberHex'], - get_wechat_sign($params, $contents), - ); - - return 'WECHATPAY2-SHA256-RSA2048 '.$auth; - } - - /** - * @throws InvalidParamsException - */ - protected function v3GetContents(Rocket $rocket, int $timestamp, string $random): string - { - $request = $rocket->getRadar(); - - if (is_null($request)) { - throw new InvalidParamsException(Exception::PARAMS_REQUEST_EMPTY); - } - - $uri = $request->getUri(); - - return $request->getMethod()."\n". - $uri->getPath().(empty($uri->getQuery()) ? '' : '?'.$uri->getQuery())."\n". - $timestamp."\n". - $random."\n". - $this->v3PayloadToString($rocket->getPayload())."\n"; - } - - protected function v3PayloadToString(?Collection $payload): string - { - return (is_null($payload) || 0 === $payload->count()) ? '' : $this->jsonPacker->pack($payload->all()); - } -} diff --git a/src/Plugin/Wechat/LaunchPlugin.php b/src/Plugin/Wechat/ResponsePlugin.php similarity index 56% rename from src/Plugin/Wechat/LaunchPlugin.php rename to src/Plugin/Wechat/ResponsePlugin.php index e4c2425..0e96db2 100644 --- a/src/Plugin/Wechat/LaunchPlugin.php +++ b/src/Plugin/Wechat/ResponsePlugin.php @@ -8,42 +8,27 @@ use Closure; use Psr\Http\Message\MessageInterface; use Psr\Http\Message\ResponseInterface; use Yansongda\Pay\Contract\PluginInterface; -use Yansongda\Pay\Exception\ContainerException; use Yansongda\Pay\Exception\Exception; -use Yansongda\Pay\Exception\InvalidConfigException; -use Yansongda\Pay\Exception\InvalidParamsException; use Yansongda\Pay\Exception\InvalidResponseException; -use Yansongda\Pay\Exception\ServiceNotFoundException; use Yansongda\Pay\Logger; use Yansongda\Pay\Rocket; use Yansongda\Supports\Collection; -use function Yansongda\Pay\should_do_http_request; -use function Yansongda\Pay\verify_wechat_sign; - -class LaunchPlugin implements PluginInterface +class ResponsePlugin implements PluginInterface { /** - * @throws ContainerException - * @throws InvalidConfigException * @throws InvalidResponseException - * @throws ServiceNotFoundException - * @throws InvalidParamsException */ public function assembly(Rocket $rocket, Closure $next): Rocket { /* @var Rocket $rocket */ $rocket = $next($rocket); - Logger::debug('[wechat][ResponsePlugin] 插件开始装载', ['rocket' => $rocket]); + Logger::debug('[Wechat][ResponsePlugin] 插件开始装载', ['rocket' => $rocket]); - if (should_do_http_request($rocket->getDirection()) && !is_null($rocket->getDestinationOrigin())) { - verify_wechat_sign($rocket->getDestinationOrigin(), $rocket->getParams()); + $rocket->setDestination($this->validateResponse($rocket)); - $rocket->setDestination($this->validateResponse($rocket)); - } - - Logger::info('[wechat][ResponsePlugin] 插件装载完毕', ['rocket' => $rocket]); + Logger::info('[Wechat][ResponsePlugin] 插件装载完毕', ['rocket' => $rocket]); return $rocket; } diff --git a/src/Plugin/Wechat/Risk/Complaints/CompleteComplaintPlugin.php b/src/Plugin/Wechat/Risk/Complaints/CompleteComplaintPlugin.php deleted file mode 100644 index c5e39a2..0000000 --- a/src/Plugin/Wechat/Risk/Complaints/CompleteComplaintPlugin.php +++ /dev/null @@ -1,54 +0,0 @@ -setDirection(OriginResponseDirection::class); - - $payload = $rocket->getPayload(); - $config = get_wechat_config($rocket->getParams()); - - $rocket->setPayload(new Collection([ - 'complainted_mchid' => $payload->get('complainted_mchid', $config['mch_id'] ?? ''), - ])); - } - - /** - * @throws InvalidParamsException - */ - protected function getUri(Rocket $rocket): string - { - $payload = $rocket->getPayload(); - - if (!$payload->has('complaint_id')) { - throw new InvalidParamsException(Exception::PARAMS_NECESSARY_PARAMS_MISSING); - } - - return 'v3/merchant-service/complaints-v2/'. - $payload->get('complaint_id'). - '/complete'; - } -} diff --git a/src/Plugin/Wechat/Risk/Complaints/DeleteCallbackPlugin.php b/src/Plugin/Wechat/Risk/Complaints/DeleteCallbackPlugin.php deleted file mode 100644 index 326854a..0000000 --- a/src/Plugin/Wechat/Risk/Complaints/DeleteCallbackPlugin.php +++ /dev/null @@ -1,32 +0,0 @@ -setDirection(OriginResponseDirection::class); - - $rocket->setPayload(null); - } - - protected function getUri(Rocket $rocket): string - { - return 'v3/merchant-service/complaint-notifications'; - } -} diff --git a/src/Plugin/Wechat/Risk/Complaints/DownloadMediaPlugin.php b/src/Plugin/Wechat/Risk/Complaints/DownloadMediaPlugin.php deleted file mode 100644 index 6ac844a..0000000 --- a/src/Plugin/Wechat/Risk/Complaints/DownloadMediaPlugin.php +++ /dev/null @@ -1,43 +0,0 @@ -getPayload(); - - if (!$payload->has('media_url')) { - throw new InvalidParamsException(Exception::PARAMS_NECESSARY_PARAMS_MISSING); - } - - return $payload->get('media_url'); - } - - protected function getMethod(): string - { - return 'GET'; - } - - protected function doSomething(Rocket $rocket): void - { - $rocket->setDirection(OriginResponseDirection::class); - - $rocket->setPayload(null); - } -} diff --git a/src/Plugin/Wechat/Risk/Complaints/QueryCallbackPlugin.php b/src/Plugin/Wechat/Risk/Complaints/QueryCallbackPlugin.php deleted file mode 100644 index 30857d6..0000000 --- a/src/Plugin/Wechat/Risk/Complaints/QueryCallbackPlugin.php +++ /dev/null @@ -1,29 +0,0 @@ -setPayload(null); - } - - protected function getUri(Rocket $rocket): string - { - return 'v3/merchant-service/complaint-notifications'; - } -} diff --git a/src/Plugin/Wechat/Risk/Complaints/QueryComplaintDetailPlugin.php b/src/Plugin/Wechat/Risk/Complaints/QueryComplaintDetailPlugin.php deleted file mode 100644 index a730685..0000000 --- a/src/Plugin/Wechat/Risk/Complaints/QueryComplaintDetailPlugin.php +++ /dev/null @@ -1,40 +0,0 @@ -setPayload(null); - } - - /** - * @throws InvalidParamsException - */ - protected function getUri(Rocket $rocket): string - { - $payload = $rocket->getPayload(); - - if (!$payload->has('complaint_id')) { - throw new InvalidParamsException(Exception::PARAMS_NECESSARY_PARAMS_MISSING); - } - - return 'v3/merchant-service/complaints-v2/'.$payload->get('complaint_id'); - } -} diff --git a/src/Plugin/Wechat/Risk/Complaints/QueryComplaintNegotiationPlugin.php b/src/Plugin/Wechat/Risk/Complaints/QueryComplaintNegotiationPlugin.php deleted file mode 100644 index b3f1d69..0000000 --- a/src/Plugin/Wechat/Risk/Complaints/QueryComplaintNegotiationPlugin.php +++ /dev/null @@ -1,45 +0,0 @@ -setPayload(null); - } - - /** - * @throws InvalidParamsException - */ - protected function getUri(Rocket $rocket): string - { - $payload = $rocket->getPayload(); - $complaintId = $payload->get('complaint_id'); - - if (is_null($complaintId)) { - throw new InvalidParamsException(Exception::PARAMS_NECESSARY_PARAMS_MISSING); - } - - $payload->forget('complaint_id'); - - return 'v3/merchant-service/complaints-v2/'. - $complaintId. - '/negotiation-historys?'.$payload->query(); - } -} diff --git a/src/Plugin/Wechat/Risk/Complaints/QueryComplaintsPlugin.php b/src/Plugin/Wechat/Risk/Complaints/QueryComplaintsPlugin.php deleted file mode 100644 index aadc6a1..0000000 --- a/src/Plugin/Wechat/Risk/Complaints/QueryComplaintsPlugin.php +++ /dev/null @@ -1,29 +0,0 @@ -setPayload(null); - } - - protected function getUri(Rocket $rocket): string - { - return 'v3/merchant-service/complaints-v2?'.$rocket->getPayload()->query(); - } -} diff --git a/src/Plugin/Wechat/Risk/Complaints/ResponseComplaintPlugin.php b/src/Plugin/Wechat/Risk/Complaints/ResponseComplaintPlugin.php deleted file mode 100644 index c0e713c..0000000 --- a/src/Plugin/Wechat/Risk/Complaints/ResponseComplaintPlugin.php +++ /dev/null @@ -1,57 +0,0 @@ -setDirection(OriginResponseDirection::class); - - $config = get_wechat_config($rocket->getParams()); - $payload = $rocket->getPayload(); - - $payload->forget('complaint_id'); - - if (!$payload->has('complainted_mchid')) { - $rocket->mergePayload([ - 'complainted_mchid' => $config['mch_id'] ?? '', - ]); - } - } - - /** - * @throws InvalidParamsException - */ - protected function getUri(Rocket $rocket): string - { - $payload = $rocket->getPayload(); - - if (!$payload->has('complaint_id')) { - throw new InvalidParamsException(Exception::PARAMS_NECESSARY_PARAMS_MISSING); - } - - return 'v3/merchant-service/complaints-v2/'. - $payload->get('complaint_id'). - '/response'; - } -} diff --git a/src/Plugin/Wechat/Risk/Complaints/SetCallbackPlugin.php b/src/Plugin/Wechat/Risk/Complaints/SetCallbackPlugin.php deleted file mode 100644 index de08301..0000000 --- a/src/Plugin/Wechat/Risk/Complaints/SetCallbackPlugin.php +++ /dev/null @@ -1,21 +0,0 @@ -getPayload()->forget('complaint_id'); - } - - /** - * @throws InvalidParamsException - */ - protected function getUri(Rocket $rocket): string - { - $payload = $rocket->getPayload(); - - if (!$payload->has('complaint_id')) { - throw new InvalidParamsException(Exception::PARAMS_NECESSARY_PARAMS_MISSING); - } - - return 'v3/merchant-service/complaints-v2/'. - $payload->get('complaint_id'). - '/update-refund-progress'; - } -} diff --git a/src/Plugin/Wechat/StartPlugin.php b/src/Plugin/Wechat/StartPlugin.php new file mode 100644 index 0000000..328ab67 --- /dev/null +++ b/src/Plugin/Wechat/StartPlugin.php @@ -0,0 +1,24 @@ + $rocket]); + + $rocket->mergePayload($rocket->getParams()); + + Logger::info('[Wechat][StartPlugin] 插件装载完毕', ['rocket' => $rocket]); + + return $next($rocket); + } +} diff --git a/src/Plugin/Wechat/VerifySignaturePlugin.php b/src/Plugin/Wechat/VerifySignaturePlugin.php new file mode 100644 index 0000000..7d32f14 --- /dev/null +++ b/src/Plugin/Wechat/VerifySignaturePlugin.php @@ -0,0 +1,48 @@ + $rocket]); + + if (!should_do_http_request($rocket->getDirection()) || is_null($rocket->getDestinationOrigin())) { + return $rocket; + } + + verify_wechat_sign($rocket->getDestinationOrigin(), $rocket->getParams()); + + Logger::info('[Wechat][VerifySignaturePlugin] 插件装载完毕', ['rocket' => $rocket]); + + return $rocket; + } +} diff --git a/src/Plugin/Wechat/WechatPublicCertsPlugin.php b/src/Plugin/Wechat/WechatPublicCertsPlugin.php index 132e2ff..9f0eeec 100644 --- a/src/Plugin/Wechat/WechatPublicCertsPlugin.php +++ b/src/Plugin/Wechat/WechatPublicCertsPlugin.php @@ -4,22 +4,24 @@ declare(strict_types=1); namespace Yansongda\Pay\Plugin\Wechat; +use Closure; +use Yansongda\Pay\Contract\PluginInterface; +use Yansongda\Pay\Logger; use Yansongda\Pay\Rocket; -class WechatPublicCertsPlugin extends GeneralPlugin +class WechatPublicCertsPlugin implements PluginInterface { - protected function getMethod(): string + public function assembly(Rocket $rocket, Closure $next): Rocket { - return 'GET'; - } + Logger::debug('[Wechat][WechatPublicCertsPlugin] 插件开始装载', ['rocket' => $rocket]); - protected function doSomething(Rocket $rocket): void - { - $rocket->setPayload(null); - } + $rocket->setPayload([ + '_method' => 'GET', + '_url' => 'v3/certificates', + ]); - protected function getUri(Rocket $rocket): string - { - return 'v3/certificates'; + Logger::info('[Wechat][WechatPublicCertsPlugin] 插件装载完毕', ['rocket' => $rocket]); + + return $next($rocket); } } diff --git a/src/Provider/AbstractProvider.php b/src/Provider/AbstractProvider.php index 5fbfef1..7d0545c 100644 --- a/src/Provider/AbstractProvider.php +++ b/src/Provider/AbstractProvider.php @@ -33,10 +33,10 @@ abstract class AbstractProvider implements ProviderInterface * @throws InvalidParamsException * @throws ServiceNotFoundException */ - public function call(string $plugin, array $params = []): null|Collection|MessageInterface + public function call(string $plugin, array $params = []): null|Collection|MessageInterface|Rocket { if (!class_exists($plugin) || !in_array(ShortcutInterface::class, class_implements($plugin))) { - throw new InvalidParamsException(Exception::PARAMS_SHORTCUT_NOT_FOUND, "[{$plugin}] is not incompatible"); + throw new InvalidParamsException(Exception::PARAMS_SHORTCUT_NOT_FOUND, "参数异常: [{$plugin}] 未实现 `ShortcutInterface`"); } /* @var ShortcutInterface $shortcut */ @@ -49,7 +49,7 @@ abstract class AbstractProvider implements ProviderInterface * @throws ContainerException * @throws InvalidParamsException */ - public function pay(array $plugins, array $params): null|Collection|MessageInterface + public function pay(array $plugins, array $params): null|Collection|MessageInterface|Rocket { Logger::info('[AbstractProvider] 即将进行 pay 操作', func_get_args()); @@ -69,6 +69,10 @@ abstract class AbstractProvider implements ProviderInterface Event::dispatch(new Event\PayFinish($rocket)); + if (!empty($params['_return_rocket'])) { + return $rocket; + } + return $rocket->getDestination(); } @@ -88,7 +92,7 @@ abstract class AbstractProvider implements ProviderInterface $http = Pay::get(HttpClientInterface::class); if (!$http instanceof ClientInterface) { - throw new InvalidConfigException(Exception::CONFIG_HTTP_CLIENT_INVALID); + throw new InvalidConfigException(Exception::CONFIG_HTTP_CLIENT_INVALID, '配置异常: 配置的 ClientInterface 不符合 PSR 规范'); } Logger::info('[AbstractProvider] 准备请求支付服务商 API', $rocket->toArray()); @@ -99,14 +103,14 @@ abstract class AbstractProvider implements ProviderInterface $response = $http->sendRequest($rocket->getRadar()); $rocket->setDestination(clone $response) - ->setDestinationOrigin($response); + ->setDestinationOrigin(clone $response); } catch (Throwable $e) { Logger::error('[AbstractProvider] 请求支付服务商 API 出错', ['message' => $e->getMessage(), 'rocket' => $rocket->toArray(), 'trace' => $e->getTrace()]); - throw new InvalidResponseException(Exception::REQUEST_RESPONSE_ERROR, $e->getMessage(), [], $e); + throw new InvalidResponseException(Exception::REQUEST_RESPONSE_ERROR, '响应异常: 请求支付服务商 API 出错 - '.$e->getMessage(), [], $e); } - Logger::info('[AbstractProvider] 请求支付服务商 API 成功', ['response' => $response, 'rocket' => $rocket->toArray()]); + Logger::info('[AbstractProvider] 请求支付服务商 API 成功', ['response' => ['status' => $response->getStatusCode(), 'headers' => $response->getHeaders(), 'body' => (string) $response->getBody()], 'rocket' => $rocket->toArray()]); Event::dispatch(new Event\ApiRequested($rocket)); @@ -131,7 +135,7 @@ abstract class AbstractProvider implements ProviderInterface continue; } - throw new InvalidParamsException(Exception::PARAMS_PLUGIN_INCOMPATIBLE, "[{$plugin}] is not incompatible"); + throw new InvalidParamsException(Exception::PARAMS_PLUGIN_INCOMPATIBLE, "参数异常: [{$plugin}] 插件未实现 `PluginInterface`"); } } } diff --git a/src/Provider/Alipay.php b/src/Provider/Alipay.php index 7415d7d..58ce36d 100644 --- a/src/Provider/Alipay.php +++ b/src/Provider/Alipay.php @@ -14,25 +14,26 @@ use Yansongda\Pay\Exception\ContainerException; use Yansongda\Pay\Exception\InvalidParamsException; use Yansongda\Pay\Exception\ServiceNotFoundException; use Yansongda\Pay\Pay; +use Yansongda\Pay\Plugin\Alipay\AddPayloadSignaturePlugin; use Yansongda\Pay\Plugin\Alipay\AddRadarPlugin; -use Yansongda\Pay\Plugin\Alipay\AddSignaturePlugin; use Yansongda\Pay\Plugin\Alipay\CallbackPlugin; -use Yansongda\Pay\Plugin\Alipay\FormatBizContentPlugin; +use Yansongda\Pay\Plugin\Alipay\FormatPayloadBizContentPlugin; use Yansongda\Pay\Plugin\Alipay\ResponsePlugin; use Yansongda\Pay\Plugin\Alipay\StartPlugin; use Yansongda\Pay\Plugin\Alipay\VerifySignaturePlugin; use Yansongda\Pay\Plugin\ParserPlugin; +use Yansongda\Pay\Rocket; use Yansongda\Supports\Collection; use Yansongda\Supports\Str; /** - * @method ResponseInterface app(array $order) APP 支付 - * @method Collection pos(array $order) 刷卡支付 - * @method Collection scan(array $order) 扫码支付 - * @method Collection transfer(array $order) 帐户转账 - * @method ResponseInterface wap(array $order) 手机网站支付 - * @method ResponseInterface web(array $order) 电脑支付 - * @method Collection mini(array $order) 小程序支付 + * @method ResponseInterface|Rocket app(array $order) APP 支付 + * @method Collection|Rocket pos(array $order) 刷卡支付 + * @method Collection|Rocket scan(array $order) 扫码支付 + * @method Collection|Rocket transfer(array $order) 帐户转账 + * @method ResponseInterface|Rocket wap(array $order) 手机网站支付 + * @method ResponseInterface|Rocket web(array $order) 电脑支付 + * @method Collection|Rocket mini(array $order) 小程序支付 */ class Alipay extends AbstractProvider { @@ -47,7 +48,7 @@ class Alipay extends AbstractProvider * @throws InvalidParamsException * @throws ServiceNotFoundException */ - public function __call(string $shortcut, array $params): null|Collection|MessageInterface + public function __call(string $shortcut, array $params): null|Collection|MessageInterface|Rocket { $plugin = '\\Yansongda\\Pay\\Shortcut\\Alipay\\'.Str::studly($shortcut).'Shortcut'; @@ -59,7 +60,7 @@ class Alipay extends AbstractProvider * @throws InvalidParamsException * @throws ServiceNotFoundException */ - public function query(array $order): array|Collection + public function query(array $order): Collection|Rocket { Event::dispatch(new Event\MethodCalled('alipay', __METHOD__, $order, null)); @@ -71,7 +72,7 @@ class Alipay extends AbstractProvider * @throws InvalidParamsException * @throws ServiceNotFoundException */ - public function cancel(array $order): null|array|Collection + public function cancel(array $order): Collection|Rocket { Event::dispatch(new Event\MethodCalled('alipay', __METHOD__, $order, null)); @@ -83,7 +84,7 @@ class Alipay extends AbstractProvider * @throws InvalidParamsException * @throws ServiceNotFoundException */ - public function close(array $order): null|array|Collection + public function close(array $order): Collection|Rocket { Event::dispatch(new Event\MethodCalled('alipay', __METHOD__, $order, null)); @@ -95,7 +96,7 @@ class Alipay extends AbstractProvider * @throws InvalidParamsException * @throws ServiceNotFoundException */ - public function refund(array $order): array|Collection + public function refund(array $order): Collection|Rocket { Event::dispatch(new Event\MethodCalled('alipay', __METHOD__, $order, null)); @@ -125,7 +126,7 @@ class Alipay extends AbstractProvider return array_merge( [StartPlugin::class], $plugins, - [FormatBizContentPlugin::class, AddSignaturePlugin::class, AddRadarPlugin::class, VerifySignaturePlugin::class, ResponsePlugin::class, ParserPlugin::class], + [FormatPayloadBizContentPlugin::class, AddPayloadSignaturePlugin::class, AddRadarPlugin::class, VerifySignaturePlugin::class, ResponsePlugin::class, ParserPlugin::class], ); } diff --git a/src/Provider/Unipay.php b/src/Provider/Unipay.php index 01521fa..e5be12d 100644 --- a/src/Provider/Unipay.php +++ b/src/Provider/Unipay.php @@ -20,6 +20,7 @@ use Yansongda\Pay\Plugin\Unipay\CallbackPlugin; use Yansongda\Pay\Plugin\Unipay\LaunchPlugin; use Yansongda\Pay\Plugin\Unipay\PreparePlugin; use Yansongda\Pay\Plugin\Unipay\RadarSignPlugin; +use Yansongda\Pay\Rocket; use Yansongda\Supports\Collection; use Yansongda\Supports\Str; @@ -39,7 +40,7 @@ class Unipay extends AbstractProvider * @throws InvalidParamsException * @throws ServiceNotFoundException */ - public function __call(string $shortcut, array $params): null|Collection|MessageInterface + public function __call(string $shortcut, array $params): null|Collection|MessageInterface|Rocket { $plugin = '\\Yansongda\\Pay\\Shortcut\\Unipay\\'.Str::studly($shortcut).'Shortcut'; @@ -51,7 +52,7 @@ class Unipay extends AbstractProvider * @throws InvalidParamsException * @throws ServiceNotFoundException */ - public function query(array $order): array|Collection + public function query(array $order): Collection|Rocket { Event::dispatch(new Event\MethodCalled('unipay', __METHOD__, $order, null)); @@ -63,7 +64,7 @@ class Unipay extends AbstractProvider * @throws InvalidParamsException * @throws ServiceNotFoundException */ - public function cancel(array $order): null|array|Collection + public function cancel(array $order): Collection|Rocket { Event::dispatch(new Event\MethodCalled('unipay', __METHOD__, $order, null)); @@ -73,9 +74,9 @@ class Unipay extends AbstractProvider /** * @throws InvalidParamsException */ - public function close(array $order): null|array|Collection + public function close(array $order): Collection|Rocket { - throw new InvalidParamsException(Exception::PARAMS_METHOD_NOT_SUPPORTED, 'Unipay does not support close api'); + throw new InvalidParamsException(Exception::PARAMS_METHOD_NOT_SUPPORTED, '参数异常: 银联不支持 close API'); } /** @@ -83,7 +84,7 @@ class Unipay extends AbstractProvider * @throws InvalidParamsException * @throws ServiceNotFoundException */ - public function refund(array $order): array|Collection + public function refund(array $order): Collection|Rocket { Event::dispatch(new Event\MethodCalled('unipay', __METHOD__, $order, null)); @@ -94,7 +95,7 @@ class Unipay extends AbstractProvider * @throws ContainerException * @throws InvalidParamsException */ - public function callback(null|array|ServerRequestInterface $contents = null, ?array $params = null): Collection + public function callback(null|array|ServerRequestInterface $contents = null, ?array $params = null): Collection|Rocket { $request = $this->getCallbackParams($contents); diff --git a/src/Provider/Wechat.php b/src/Provider/Wechat.php index 5bca033..fc2658f 100644 --- a/src/Provider/Wechat.php +++ b/src/Provider/Wechat.php @@ -16,10 +16,14 @@ use Yansongda\Pay\Exception\InvalidParamsException; use Yansongda\Pay\Exception\ServiceNotFoundException; use Yansongda\Pay\Pay; use Yansongda\Pay\Plugin\ParserPlugin; +use Yansongda\Pay\Plugin\Wechat\AddPayloadBodyPlugin; +use Yansongda\Pay\Plugin\Wechat\AddPayloadSignaturePlugin; +use Yansongda\Pay\Plugin\Wechat\AddRadarPlugin; use Yansongda\Pay\Plugin\Wechat\CallbackPlugin; -use Yansongda\Pay\Plugin\Wechat\LaunchPlugin; -use Yansongda\Pay\Plugin\Wechat\PreparePlugin; -use Yansongda\Pay\Plugin\Wechat\RadarSignPlugin; +use Yansongda\Pay\Plugin\Wechat\ResponsePlugin; +use Yansongda\Pay\Plugin\Wechat\StartPlugin; +use Yansongda\Pay\Plugin\Wechat\VerifySignaturePlugin; +use Yansongda\Pay\Rocket; use Yansongda\Supports\Collection; use Yansongda\Supports\Str; @@ -63,7 +67,7 @@ class Wechat extends AbstractProvider * @throws InvalidParamsException * @throws ServiceNotFoundException */ - public function query(array $order): array|Collection + public function query(array $order): Collection|Rocket { Event::dispatch(new Event\MethodCalled('wechat', __METHOD__, $order, null)); @@ -73,9 +77,9 @@ class Wechat extends AbstractProvider /** * @throws InvalidParamsException */ - public function cancel(array $order): null|array|Collection + public function cancel(array $order): Collection|Rocket { - throw new InvalidParamsException(Exception::PARAMS_METHOD_NOT_SUPPORTED, 'Wechat does not support cancel api'); + throw new InvalidParamsException(Exception::PARAMS_METHOD_NOT_SUPPORTED, '参数异常: 微信不支持 cancel API'); } /** @@ -83,13 +87,13 @@ class Wechat extends AbstractProvider * @throws InvalidParamsException * @throws ServiceNotFoundException */ - public function close(array $order): null|array|Collection + public function close(array $order): Collection|Rocket { Event::dispatch(new Event\MethodCalled('wechat', __METHOD__, $order, null)); $this->__call('close', [$order]); - return null; + return new Collection(); } /** @@ -97,7 +101,7 @@ class Wechat extends AbstractProvider * @throws InvalidParamsException * @throws ServiceNotFoundException */ - public function refund(array $order): array|Collection + public function refund(array $order): Collection|Rocket { Event::dispatch(new Event\MethodCalled('wechat', __METHOD__, $order, null)); @@ -108,7 +112,7 @@ class Wechat extends AbstractProvider * @throws ContainerException * @throws InvalidParamsException */ - public function callback(null|array|ServerRequestInterface $contents = null, ?array $params = null): Collection + public function callback(null|array|ServerRequestInterface $contents = null, ?array $params = null): Collection|Rocket { $request = $this->getCallbackParams($contents); @@ -116,7 +120,7 @@ class Wechat extends AbstractProvider return $this->pay( [CallbackPlugin::class], - ['request' => $request, 'params' => $params] + ['_request' => $request, '_params' => $params] ); } @@ -132,10 +136,9 @@ class Wechat extends AbstractProvider public function mergeCommonPlugins(array $plugins): array { return array_merge( - [PreparePlugin::class], + [StartPlugin::class], $plugins, - [RadarSignPlugin::class], - [LaunchPlugin::class, ParserPlugin::class], + [AddPayloadBodyPlugin::class, AddPayloadSignaturePlugin::class, AddRadarPlugin::class, ResponsePlugin::class, VerifySignaturePlugin::class, ParserPlugin::class], ); } diff --git a/src/Rocket.php b/src/Rocket.php index 6ecc367..c0743e4 100644 --- a/src/Rocket.php +++ b/src/Rocket.php @@ -72,8 +72,12 @@ class Rocket implements JsonSerializableInterface, ArrayAccess return $this->payload; } - public function setPayload(?Collection $payload): Rocket + public function setPayload(null|array|Collection $payload): Rocket { + if (is_array($payload)) { + $payload = new Collection($payload); + } + $this->payload = $payload; return $this; @@ -90,6 +94,17 @@ class Rocket implements JsonSerializableInterface, ArrayAccess return $this; } + public function exceptPayload(mixed $key): Rocket + { + if (empty($this->payload)) { + return $this; + } + + $this->payload = $this->payload->except($key); + + return $this; + } + public function getPacker(): string { return $this->packer; diff --git a/src/Service/ContainerServiceProvider.php b/src/Service/ContainerServiceProvider.php index dd3471c..d207d28 100644 --- a/src/Service/ContainerServiceProvider.php +++ b/src/Service/ContainerServiceProvider.php @@ -95,7 +95,7 @@ class ContainerServiceProvider implements ServiceProviderInterface protected function defaultApplication(): void { if (!class_exists(DefaultContainer::class)) { - throw new ContainerNotFoundException('Init failed! Maybe you should install `hyperf/pimple` first', Exception::CONTAINER_NOT_FOUND); + throw new ContainerNotFoundException('容器未找到: Init failed! Maybe you should install `hyperf/pimple` first', Exception::CONTAINER_NOT_FOUND); } $container = (new DefaultContainer())(); diff --git a/src/Shortcut/Alipay/AppShortcut.php b/src/Shortcut/Alipay/AppShortcut.php index 6be2ebf..506f385 100644 --- a/src/Shortcut/Alipay/AppShortcut.php +++ b/src/Shortcut/Alipay/AppShortcut.php @@ -5,8 +5,8 @@ declare(strict_types=1); namespace Yansongda\Pay\Shortcut\Alipay; use Yansongda\Pay\Contract\ShortcutInterface; -use Yansongda\Pay\Plugin\Alipay\AddSignaturePlugin; -use Yansongda\Pay\Plugin\Alipay\FormatBizContentPlugin; +use Yansongda\Pay\Plugin\Alipay\AddPayloadSignaturePlugin; +use Yansongda\Pay\Plugin\Alipay\FormatPayloadBizContentPlugin; use Yansongda\Pay\Plugin\Alipay\Pay\App\PayPlugin; use Yansongda\Pay\Plugin\Alipay\ResponseInvokeStringPlugin; use Yansongda\Pay\Plugin\Alipay\StartPlugin; @@ -19,8 +19,8 @@ class AppShortcut implements ShortcutInterface return [ StartPlugin::class, PayPlugin::class, - FormatBizContentPlugin::class, - AddSignaturePlugin::class, + FormatPayloadBizContentPlugin::class, + AddPayloadSignaturePlugin::class, ResponseInvokeStringPlugin::class, ParserPlugin::class, ]; diff --git a/src/Shortcut/Alipay/CancelShortcut.php b/src/Shortcut/Alipay/CancelShortcut.php index 44889b5..77ab681 100644 --- a/src/Shortcut/Alipay/CancelShortcut.php +++ b/src/Shortcut/Alipay/CancelShortcut.php @@ -7,9 +7,9 @@ namespace Yansongda\Pay\Shortcut\Alipay; use Yansongda\Pay\Contract\ShortcutInterface; use Yansongda\Pay\Exception\Exception; use Yansongda\Pay\Exception\InvalidParamsException; +use Yansongda\Pay\Plugin\Alipay\AddPayloadSignaturePlugin; use Yansongda\Pay\Plugin\Alipay\AddRadarPlugin; -use Yansongda\Pay\Plugin\Alipay\AddSignaturePlugin; -use Yansongda\Pay\Plugin\Alipay\FormatBizContentPlugin; +use Yansongda\Pay\Plugin\Alipay\FormatPayloadBizContentPlugin; use Yansongda\Pay\Plugin\Alipay\Pay\Agreement\CancelPlugin as AgreementCancelPlugin; use Yansongda\Pay\Plugin\Alipay\Pay\Authorization\CancelPlugin as AuthorizationCancelPlugin; use Yansongda\Pay\Plugin\Alipay\Pay\Mini\CancelPlugin as MiniCancelPlugin; @@ -39,16 +39,7 @@ class CancelShortcut implements ShortcutInterface protected function defaultPlugins(): array { - return [ - StartPlugin::class, - PosCancelPlugin::class, - FormatBizContentPlugin::class, - AddSignaturePlugin::class, - AddRadarPlugin::class, - VerifySignaturePlugin::class, - ResponsePlugin::class, - ParserPlugin::class, - ]; + return $this->posPlugins(); } protected function agreementPlugins(): array @@ -56,8 +47,8 @@ class CancelShortcut implements ShortcutInterface return [ StartPlugin::class, AgreementCancelPlugin::class, - FormatBizContentPlugin::class, - AddSignaturePlugin::class, + FormatPayloadBizContentPlugin::class, + AddPayloadSignaturePlugin::class, AddRadarPlugin::class, VerifySignaturePlugin::class, ResponsePlugin::class, @@ -70,8 +61,8 @@ class CancelShortcut implements ShortcutInterface return [ StartPlugin::class, AuthorizationCancelPlugin::class, - FormatBizContentPlugin::class, - AddSignaturePlugin::class, + FormatPayloadBizContentPlugin::class, + AddPayloadSignaturePlugin::class, AddRadarPlugin::class, VerifySignaturePlugin::class, ResponsePlugin::class, @@ -84,8 +75,8 @@ class CancelShortcut implements ShortcutInterface return [ StartPlugin::class, MiniCancelPlugin::class, - FormatBizContentPlugin::class, - AddSignaturePlugin::class, + FormatPayloadBizContentPlugin::class, + AddPayloadSignaturePlugin::class, AddRadarPlugin::class, VerifySignaturePlugin::class, ResponsePlugin::class, @@ -98,8 +89,8 @@ class CancelShortcut implements ShortcutInterface return [ StartPlugin::class, PosCancelPlugin::class, - FormatBizContentPlugin::class, - AddSignaturePlugin::class, + FormatPayloadBizContentPlugin::class, + AddPayloadSignaturePlugin::class, AddRadarPlugin::class, VerifySignaturePlugin::class, ResponsePlugin::class, @@ -112,8 +103,8 @@ class CancelShortcut implements ShortcutInterface return [ StartPlugin::class, ScanCancelPlugin::class, - FormatBizContentPlugin::class, - AddSignaturePlugin::class, + FormatPayloadBizContentPlugin::class, + AddPayloadSignaturePlugin::class, AddRadarPlugin::class, VerifySignaturePlugin::class, ResponsePlugin::class, diff --git a/src/Shortcut/Alipay/CloseShortcut.php b/src/Shortcut/Alipay/CloseShortcut.php index 0cf53d7..7c2d046 100644 --- a/src/Shortcut/Alipay/CloseShortcut.php +++ b/src/Shortcut/Alipay/CloseShortcut.php @@ -7,16 +7,16 @@ namespace Yansongda\Pay\Shortcut\Alipay; use Yansongda\Pay\Contract\ShortcutInterface; use Yansongda\Pay\Exception\Exception; use Yansongda\Pay\Exception\InvalidParamsException; +use Yansongda\Pay\Plugin\Alipay\AddPayloadSignaturePlugin; use Yansongda\Pay\Plugin\Alipay\AddRadarPlugin; -use Yansongda\Pay\Plugin\Alipay\AddSignaturePlugin; -use Yansongda\Pay\Plugin\Alipay\FormatBizContentPlugin; +use Yansongda\Pay\Plugin\Alipay\FormatPayloadBizContentPlugin; use Yansongda\Pay\Plugin\Alipay\Pay\Agreement\ClosePlugin as AgreementClosePlugin; use Yansongda\Pay\Plugin\Alipay\Pay\App\ClosePlugin as AppClosePlugin; use Yansongda\Pay\Plugin\Alipay\Pay\Authorization\ClosePlugin as AuthorizationClosePlugin; +use Yansongda\Pay\Plugin\Alipay\Pay\H5\ClosePlugin as WapClosePlugin; use Yansongda\Pay\Plugin\Alipay\Pay\Mini\ClosePlugin as MiniClosePlugin; use Yansongda\Pay\Plugin\Alipay\Pay\Pos\ClosePlugin as PosClosePlugin; use Yansongda\Pay\Plugin\Alipay\Pay\Scan\ClosePlugin as ScanClosePlugin; -use Yansongda\Pay\Plugin\Alipay\Pay\Wap\ClosePlugin as WapClosePlugin; use Yansongda\Pay\Plugin\Alipay\Pay\Web\ClosePlugin as WebClosePlugin; use Yansongda\Pay\Plugin\Alipay\ResponsePlugin; use Yansongda\Pay\Plugin\Alipay\StartPlugin; @@ -42,16 +42,7 @@ class CloseShortcut implements ShortcutInterface protected function defaultPlugins(): array { - return [ - StartPlugin::class, - WebClosePlugin::class, - FormatBizContentPlugin::class, - AddSignaturePlugin::class, - AddRadarPlugin::class, - VerifySignaturePlugin::class, - ResponsePlugin::class, - ParserPlugin::class, - ]; + return $this->webPlugins(); } protected function agreementPlugins(): array @@ -59,8 +50,8 @@ class CloseShortcut implements ShortcutInterface return [ StartPlugin::class, AgreementClosePlugin::class, - FormatBizContentPlugin::class, - AddSignaturePlugin::class, + FormatPayloadBizContentPlugin::class, + AddPayloadSignaturePlugin::class, AddRadarPlugin::class, VerifySignaturePlugin::class, ResponsePlugin::class, @@ -73,8 +64,8 @@ class CloseShortcut implements ShortcutInterface return [ StartPlugin::class, AppClosePlugin::class, - FormatBizContentPlugin::class, - AddSignaturePlugin::class, + FormatPayloadBizContentPlugin::class, + AddPayloadSignaturePlugin::class, AddRadarPlugin::class, VerifySignaturePlugin::class, ResponsePlugin::class, @@ -87,8 +78,8 @@ class CloseShortcut implements ShortcutInterface return [ StartPlugin::class, AuthorizationClosePlugin::class, - FormatBizContentPlugin::class, - AddSignaturePlugin::class, + FormatPayloadBizContentPlugin::class, + AddPayloadSignaturePlugin::class, AddRadarPlugin::class, VerifySignaturePlugin::class, ResponsePlugin::class, @@ -101,8 +92,8 @@ class CloseShortcut implements ShortcutInterface return [ StartPlugin::class, MiniClosePlugin::class, - FormatBizContentPlugin::class, - AddSignaturePlugin::class, + FormatPayloadBizContentPlugin::class, + AddPayloadSignaturePlugin::class, AddRadarPlugin::class, VerifySignaturePlugin::class, ResponsePlugin::class, @@ -115,8 +106,8 @@ class CloseShortcut implements ShortcutInterface return [ StartPlugin::class, PosClosePlugin::class, - FormatBizContentPlugin::class, - AddSignaturePlugin::class, + FormatPayloadBizContentPlugin::class, + AddPayloadSignaturePlugin::class, AddRadarPlugin::class, VerifySignaturePlugin::class, ResponsePlugin::class, @@ -129,8 +120,8 @@ class CloseShortcut implements ShortcutInterface return [ StartPlugin::class, ScanClosePlugin::class, - FormatBizContentPlugin::class, - AddSignaturePlugin::class, + FormatPayloadBizContentPlugin::class, + AddPayloadSignaturePlugin::class, AddRadarPlugin::class, VerifySignaturePlugin::class, ResponsePlugin::class, @@ -143,8 +134,8 @@ class CloseShortcut implements ShortcutInterface return [ StartPlugin::class, WapClosePlugin::class, - FormatBizContentPlugin::class, - AddSignaturePlugin::class, + FormatPayloadBizContentPlugin::class, + AddPayloadSignaturePlugin::class, AddRadarPlugin::class, VerifySignaturePlugin::class, ResponsePlugin::class, @@ -157,8 +148,8 @@ class CloseShortcut implements ShortcutInterface return [ StartPlugin::class, WebClosePlugin::class, - FormatBizContentPlugin::class, - AddSignaturePlugin::class, + FormatPayloadBizContentPlugin::class, + AddPayloadSignaturePlugin::class, AddRadarPlugin::class, VerifySignaturePlugin::class, ResponsePlugin::class, diff --git a/src/Shortcut/Alipay/MiniShortcut.php b/src/Shortcut/Alipay/MiniShortcut.php index 3caca04..7795492 100644 --- a/src/Shortcut/Alipay/MiniShortcut.php +++ b/src/Shortcut/Alipay/MiniShortcut.php @@ -5,9 +5,9 @@ declare(strict_types=1); namespace Yansongda\Pay\Shortcut\Alipay; use Yansongda\Pay\Contract\ShortcutInterface; +use Yansongda\Pay\Plugin\Alipay\AddPayloadSignaturePlugin; use Yansongda\Pay\Plugin\Alipay\AddRadarPlugin; -use Yansongda\Pay\Plugin\Alipay\AddSignaturePlugin; -use Yansongda\Pay\Plugin\Alipay\FormatBizContentPlugin; +use Yansongda\Pay\Plugin\Alipay\FormatPayloadBizContentPlugin; use Yansongda\Pay\Plugin\Alipay\Pay\Mini\PayPlugin; use Yansongda\Pay\Plugin\Alipay\ResponsePlugin; use Yansongda\Pay\Plugin\Alipay\StartPlugin; @@ -21,8 +21,8 @@ class MiniShortcut implements ShortcutInterface return [ StartPlugin::class, PayPlugin::class, - FormatBizContentPlugin::class, - AddSignaturePlugin::class, + FormatPayloadBizContentPlugin::class, + AddPayloadSignaturePlugin::class, AddRadarPlugin::class, VerifySignaturePlugin::class, ResponsePlugin::class, diff --git a/src/Shortcut/Alipay/PosShortcut.php b/src/Shortcut/Alipay/PosShortcut.php index 36162d7..38683f2 100644 --- a/src/Shortcut/Alipay/PosShortcut.php +++ b/src/Shortcut/Alipay/PosShortcut.php @@ -5,14 +5,14 @@ declare(strict_types=1); namespace Yansongda\Pay\Shortcut\Alipay; use Yansongda\Pay\Contract\ShortcutInterface; +use Yansongda\Pay\Plugin\Alipay\AddPayloadSignaturePlugin; use Yansongda\Pay\Plugin\Alipay\AddRadarPlugin; -use Yansongda\Pay\Plugin\Alipay\AddSignaturePlugin; -use Yansongda\Pay\Plugin\Alipay\FormatBizContentPlugin; +use Yansongda\Pay\Plugin\Alipay\FormatPayloadBizContentPlugin; +use Yansongda\Pay\Plugin\Alipay\Pay\Pos\PayPlugin; use Yansongda\Pay\Plugin\Alipay\ResponsePlugin; use Yansongda\Pay\Plugin\Alipay\StartPlugin; use Yansongda\Pay\Plugin\Alipay\VerifySignaturePlugin; use Yansongda\Pay\Plugin\ParserPlugin; -use Yansongda\Pay\Plugin\Wechat\Pay\Pos\PayPlugin; class PosShortcut implements ShortcutInterface { @@ -21,8 +21,8 @@ class PosShortcut implements ShortcutInterface return [ StartPlugin::class, PayPlugin::class, - FormatBizContentPlugin::class, - AddSignaturePlugin::class, + FormatPayloadBizContentPlugin::class, + AddPayloadSignaturePlugin::class, AddRadarPlugin::class, VerifySignaturePlugin::class, ResponsePlugin::class, diff --git a/src/Shortcut/Alipay/QueryShortcut.php b/src/Shortcut/Alipay/QueryShortcut.php index 80f677e..a3a66ac 100644 --- a/src/Shortcut/Alipay/QueryShortcut.php +++ b/src/Shortcut/Alipay/QueryShortcut.php @@ -7,9 +7,9 @@ namespace Yansongda\Pay\Shortcut\Alipay; use Yansongda\Pay\Contract\ShortcutInterface; use Yansongda\Pay\Exception\Exception; use Yansongda\Pay\Exception\InvalidParamsException; +use Yansongda\Pay\Plugin\Alipay\AddPayloadSignaturePlugin; use Yansongda\Pay\Plugin\Alipay\AddRadarPlugin; -use Yansongda\Pay\Plugin\Alipay\AddSignaturePlugin; -use Yansongda\Pay\Plugin\Alipay\FormatBizContentPlugin; +use Yansongda\Pay\Plugin\Alipay\FormatPayloadBizContentPlugin; use Yansongda\Pay\Plugin\Alipay\Fund\Transfer\QueryPlugin as TransferQueryPlugin; use Yansongda\Pay\Plugin\Alipay\Pay\Agreement\QueryPlugin as AgreementQueryPlugin; use Yansongda\Pay\Plugin\Alipay\Pay\App\QueryPlugin as AppQueryPlugin; @@ -17,14 +17,14 @@ use Yansongda\Pay\Plugin\Alipay\Pay\App\QueryRefundPlugin as AppQueryRefundPlugi use Yansongda\Pay\Plugin\Alipay\Pay\Authorization\QueryPlugin as AuthorizationQueryPlugin; use Yansongda\Pay\Plugin\Alipay\Pay\Authorization\QueryRefundPlugin as AuthorizationQueryRefundPlugin; use Yansongda\Pay\Plugin\Alipay\Pay\Face\QueryPlugin as FaceQueryPlugin; +use Yansongda\Pay\Plugin\Alipay\Pay\H5\QueryPlugin as WapQueryPlugin; +use Yansongda\Pay\Plugin\Alipay\Pay\H5\QueryRefundPlugin as WapQueryRefundPlugin; use Yansongda\Pay\Plugin\Alipay\Pay\Mini\QueryPlugin as MiniQueryPlugin; use Yansongda\Pay\Plugin\Alipay\Pay\Mini\QueryRefundPlugin as MiniQueryRefundPlugin; use Yansongda\Pay\Plugin\Alipay\Pay\Pos\QueryPlugin as PosQueryPlugin; use Yansongda\Pay\Plugin\Alipay\Pay\Pos\QueryRefundPlugin as PosQueryRefundPlugin; use Yansongda\Pay\Plugin\Alipay\Pay\Scan\QueryPlugin as ScanQueryPlugin; use Yansongda\Pay\Plugin\Alipay\Pay\Scan\QueryRefundPlugin as ScanQueryRefundPlugin; -use Yansongda\Pay\Plugin\Alipay\Pay\Wap\QueryPlugin as WapQueryPlugin; -use Yansongda\Pay\Plugin\Alipay\Pay\Wap\QueryRefundPlugin as WapQueryRefundPlugin; use Yansongda\Pay\Plugin\Alipay\Pay\Web\QueryPlugin as WebQueryPlugin; use Yansongda\Pay\Plugin\Alipay\Pay\Web\QueryRefundPlugin as WebQueryRefundPlugin; use Yansongda\Pay\Plugin\Alipay\ResponsePlugin; @@ -55,16 +55,7 @@ class QueryShortcut implements ShortcutInterface protected function defaultPlugins(): array { - return [ - StartPlugin::class, - WebQueryPlugin::class, - FormatBizContentPlugin::class, - AddSignaturePlugin::class, - AddRadarPlugin::class, - VerifySignaturePlugin::class, - ResponsePlugin::class, - ParserPlugin::class, - ]; + return $this->webPlugins(); } protected function agreementPlugins(): array @@ -72,8 +63,8 @@ class QueryShortcut implements ShortcutInterface return [ StartPlugin::class, AgreementQueryPlugin::class, - FormatBizContentPlugin::class, - AddSignaturePlugin::class, + FormatPayloadBizContentPlugin::class, + AddPayloadSignaturePlugin::class, AddRadarPlugin::class, VerifySignaturePlugin::class, ResponsePlugin::class, @@ -86,8 +77,8 @@ class QueryShortcut implements ShortcutInterface return [ StartPlugin::class, AppQueryPlugin::class, - FormatBizContentPlugin::class, - AddSignaturePlugin::class, + FormatPayloadBizContentPlugin::class, + AddPayloadSignaturePlugin::class, AddRadarPlugin::class, VerifySignaturePlugin::class, ResponsePlugin::class, @@ -100,8 +91,8 @@ class QueryShortcut implements ShortcutInterface return [ StartPlugin::class, AuthorizationQueryPlugin::class, - FormatBizContentPlugin::class, - AddSignaturePlugin::class, + FormatPayloadBizContentPlugin::class, + AddPayloadSignaturePlugin::class, AddRadarPlugin::class, VerifySignaturePlugin::class, ResponsePlugin::class, @@ -114,8 +105,8 @@ class QueryShortcut implements ShortcutInterface return [ StartPlugin::class, FaceQueryPlugin::class, - FormatBizContentPlugin::class, - AddSignaturePlugin::class, + FormatPayloadBizContentPlugin::class, + AddPayloadSignaturePlugin::class, AddRadarPlugin::class, VerifySignaturePlugin::class, ResponsePlugin::class, @@ -128,8 +119,8 @@ class QueryShortcut implements ShortcutInterface return [ StartPlugin::class, MiniQueryPlugin::class, - FormatBizContentPlugin::class, - AddSignaturePlugin::class, + FormatPayloadBizContentPlugin::class, + AddPayloadSignaturePlugin::class, AddRadarPlugin::class, VerifySignaturePlugin::class, ResponsePlugin::class, @@ -142,8 +133,8 @@ class QueryShortcut implements ShortcutInterface return [ StartPlugin::class, PosQueryPlugin::class, - FormatBizContentPlugin::class, - AddSignaturePlugin::class, + FormatPayloadBizContentPlugin::class, + AddPayloadSignaturePlugin::class, AddRadarPlugin::class, VerifySignaturePlugin::class, ResponsePlugin::class, @@ -156,8 +147,8 @@ class QueryShortcut implements ShortcutInterface return [ StartPlugin::class, ScanQueryPlugin::class, - FormatBizContentPlugin::class, - AddSignaturePlugin::class, + FormatPayloadBizContentPlugin::class, + AddPayloadSignaturePlugin::class, AddRadarPlugin::class, VerifySignaturePlugin::class, ResponsePlugin::class, @@ -170,8 +161,8 @@ class QueryShortcut implements ShortcutInterface return [ StartPlugin::class, WapQueryPlugin::class, - FormatBizContentPlugin::class, - AddSignaturePlugin::class, + FormatPayloadBizContentPlugin::class, + AddPayloadSignaturePlugin::class, AddRadarPlugin::class, VerifySignaturePlugin::class, ResponsePlugin::class, @@ -184,8 +175,8 @@ class QueryShortcut implements ShortcutInterface return [ StartPlugin::class, WebQueryPlugin::class, - FormatBizContentPlugin::class, - AddSignaturePlugin::class, + FormatPayloadBizContentPlugin::class, + AddPayloadSignaturePlugin::class, AddRadarPlugin::class, VerifySignaturePlugin::class, ResponsePlugin::class, @@ -198,8 +189,8 @@ class QueryShortcut implements ShortcutInterface return [ StartPlugin::class, TransferQueryPlugin::class, - FormatBizContentPlugin::class, - AddSignaturePlugin::class, + FormatPayloadBizContentPlugin::class, + AddPayloadSignaturePlugin::class, AddRadarPlugin::class, VerifySignaturePlugin::class, ResponsePlugin::class, @@ -212,8 +203,8 @@ class QueryShortcut implements ShortcutInterface return [ StartPlugin::class, WebQueryRefundPlugin::class, - FormatBizContentPlugin::class, - AddSignaturePlugin::class, + FormatPayloadBizContentPlugin::class, + AddPayloadSignaturePlugin::class, AddRadarPlugin::class, VerifySignaturePlugin::class, ResponsePlugin::class, @@ -226,8 +217,8 @@ class QueryShortcut implements ShortcutInterface return [ StartPlugin::class, AppQueryRefundPlugin::class, - FormatBizContentPlugin::class, - AddSignaturePlugin::class, + FormatPayloadBizContentPlugin::class, + AddPayloadSignaturePlugin::class, AddRadarPlugin::class, VerifySignaturePlugin::class, ResponsePlugin::class, @@ -240,8 +231,8 @@ class QueryShortcut implements ShortcutInterface return [ StartPlugin::class, AuthorizationQueryRefundPlugin::class, - FormatBizContentPlugin::class, - AddSignaturePlugin::class, + FormatPayloadBizContentPlugin::class, + AddPayloadSignaturePlugin::class, AddRadarPlugin::class, VerifySignaturePlugin::class, ResponsePlugin::class, @@ -254,8 +245,8 @@ class QueryShortcut implements ShortcutInterface return [ StartPlugin::class, MiniQueryRefundPlugin::class, - FormatBizContentPlugin::class, - AddSignaturePlugin::class, + FormatPayloadBizContentPlugin::class, + AddPayloadSignaturePlugin::class, AddRadarPlugin::class, VerifySignaturePlugin::class, ResponsePlugin::class, @@ -268,8 +259,8 @@ class QueryShortcut implements ShortcutInterface return [ StartPlugin::class, PosQueryRefundPlugin::class, - FormatBizContentPlugin::class, - AddSignaturePlugin::class, + FormatPayloadBizContentPlugin::class, + AddPayloadSignaturePlugin::class, AddRadarPlugin::class, VerifySignaturePlugin::class, ResponsePlugin::class, @@ -282,8 +273,8 @@ class QueryShortcut implements ShortcutInterface return [ StartPlugin::class, ScanQueryRefundPlugin::class, - FormatBizContentPlugin::class, - AddSignaturePlugin::class, + FormatPayloadBizContentPlugin::class, + AddPayloadSignaturePlugin::class, AddRadarPlugin::class, VerifySignaturePlugin::class, ResponsePlugin::class, @@ -296,8 +287,8 @@ class QueryShortcut implements ShortcutInterface return [ StartPlugin::class, WapQueryRefundPlugin::class, - FormatBizContentPlugin::class, - AddSignaturePlugin::class, + FormatPayloadBizContentPlugin::class, + AddPayloadSignaturePlugin::class, AddRadarPlugin::class, VerifySignaturePlugin::class, ResponsePlugin::class, @@ -310,8 +301,8 @@ class QueryShortcut implements ShortcutInterface return [ StartPlugin::class, WebQueryRefundPlugin::class, - FormatBizContentPlugin::class, - AddSignaturePlugin::class, + FormatPayloadBizContentPlugin::class, + AddPayloadSignaturePlugin::class, AddRadarPlugin::class, VerifySignaturePlugin::class, ResponsePlugin::class, diff --git a/src/Shortcut/Alipay/RefundShortcut.php b/src/Shortcut/Alipay/RefundShortcut.php index f7466cf..588b3a5 100644 --- a/src/Shortcut/Alipay/RefundShortcut.php +++ b/src/Shortcut/Alipay/RefundShortcut.php @@ -7,17 +7,17 @@ namespace Yansongda\Pay\Shortcut\Alipay; use Yansongda\Pay\Contract\ShortcutInterface; use Yansongda\Pay\Exception\Exception; use Yansongda\Pay\Exception\InvalidParamsException; +use Yansongda\Pay\Plugin\Alipay\AddPayloadSignaturePlugin; use Yansongda\Pay\Plugin\Alipay\AddRadarPlugin; -use Yansongda\Pay\Plugin\Alipay\AddSignaturePlugin; -use Yansongda\Pay\Plugin\Alipay\FormatBizContentPlugin; +use Yansongda\Pay\Plugin\Alipay\FormatPayloadBizContentPlugin; use Yansongda\Pay\Plugin\Alipay\Fund\Transfer\RefundPlugin as FundTransferRefundPlugin; use Yansongda\Pay\Plugin\Alipay\Pay\Agreement\RefundPlugin as AgreementRefundPlugin; use Yansongda\Pay\Plugin\Alipay\Pay\App\RefundPlugin as AppRefundPlugin; use Yansongda\Pay\Plugin\Alipay\Pay\Authorization\RefundPlugin as AuthorizationRefundPlugin; +use Yansongda\Pay\Plugin\Alipay\Pay\H5\RefundPlugin as WapRefundPlugin; use Yansongda\Pay\Plugin\Alipay\Pay\Mini\RefundPlugin as MiniRefundPlugin; use Yansongda\Pay\Plugin\Alipay\Pay\Pos\RefundPlugin as PosRefundPlugin; use Yansongda\Pay\Plugin\Alipay\Pay\Scan\RefundPlugin as ScanRefundPlugin; -use Yansongda\Pay\Plugin\Alipay\Pay\Wap\RefundPlugin as WapRefundPlugin; use Yansongda\Pay\Plugin\Alipay\Pay\Web\RefundPlugin as WebRefundPlugin; use Yansongda\Pay\Plugin\Alipay\ResponsePlugin; use Yansongda\Pay\Plugin\Alipay\StartPlugin; @@ -43,16 +43,7 @@ class RefundShortcut implements ShortcutInterface protected function defaultPlugins(): array { - return [ - StartPlugin::class, - WebRefundPlugin::class, - FormatBizContentPlugin::class, - AddSignaturePlugin::class, - AddRadarPlugin::class, - VerifySignaturePlugin::class, - ResponsePlugin::class, - ParserPlugin::class, - ]; + return $this->webPlugins(); } protected function agreementPlugins(): array @@ -60,8 +51,8 @@ class RefundShortcut implements ShortcutInterface return [ StartPlugin::class, AgreementRefundPlugin::class, - FormatBizContentPlugin::class, - AddSignaturePlugin::class, + FormatPayloadBizContentPlugin::class, + AddPayloadSignaturePlugin::class, AddRadarPlugin::class, VerifySignaturePlugin::class, ResponsePlugin::class, @@ -74,8 +65,8 @@ class RefundShortcut implements ShortcutInterface return [ StartPlugin::class, AppRefundPlugin::class, - FormatBizContentPlugin::class, - AddSignaturePlugin::class, + FormatPayloadBizContentPlugin::class, + AddPayloadSignaturePlugin::class, AddRadarPlugin::class, VerifySignaturePlugin::class, ResponsePlugin::class, @@ -88,8 +79,8 @@ class RefundShortcut implements ShortcutInterface return [ StartPlugin::class, AuthorizationRefundPlugin::class, - FormatBizContentPlugin::class, - AddSignaturePlugin::class, + FormatPayloadBizContentPlugin::class, + AddPayloadSignaturePlugin::class, AddRadarPlugin::class, VerifySignaturePlugin::class, ResponsePlugin::class, @@ -102,8 +93,8 @@ class RefundShortcut implements ShortcutInterface return [ StartPlugin::class, MiniRefundPlugin::class, - FormatBizContentPlugin::class, - AddSignaturePlugin::class, + FormatPayloadBizContentPlugin::class, + AddPayloadSignaturePlugin::class, AddRadarPlugin::class, VerifySignaturePlugin::class, ResponsePlugin::class, @@ -116,8 +107,8 @@ class RefundShortcut implements ShortcutInterface return [ StartPlugin::class, PosRefundPlugin::class, - FormatBizContentPlugin::class, - AddSignaturePlugin::class, + FormatPayloadBizContentPlugin::class, + AddPayloadSignaturePlugin::class, AddRadarPlugin::class, VerifySignaturePlugin::class, ResponsePlugin::class, @@ -130,8 +121,8 @@ class RefundShortcut implements ShortcutInterface return [ StartPlugin::class, ScanRefundPlugin::class, - FormatBizContentPlugin::class, - AddSignaturePlugin::class, + FormatPayloadBizContentPlugin::class, + AddPayloadSignaturePlugin::class, AddRadarPlugin::class, VerifySignaturePlugin::class, ResponsePlugin::class, @@ -144,8 +135,8 @@ class RefundShortcut implements ShortcutInterface return [ StartPlugin::class, WapRefundPlugin::class, - FormatBizContentPlugin::class, - AddSignaturePlugin::class, + FormatPayloadBizContentPlugin::class, + AddPayloadSignaturePlugin::class, AddRadarPlugin::class, VerifySignaturePlugin::class, ResponsePlugin::class, @@ -158,8 +149,8 @@ class RefundShortcut implements ShortcutInterface return [ StartPlugin::class, WebRefundPlugin::class, - FormatBizContentPlugin::class, - AddSignaturePlugin::class, + FormatPayloadBizContentPlugin::class, + AddPayloadSignaturePlugin::class, AddRadarPlugin::class, VerifySignaturePlugin::class, ResponsePlugin::class, @@ -172,8 +163,8 @@ class RefundShortcut implements ShortcutInterface return [ StartPlugin::class, FundTransferRefundPlugin::class, - FormatBizContentPlugin::class, - AddSignaturePlugin::class, + FormatPayloadBizContentPlugin::class, + AddPayloadSignaturePlugin::class, AddRadarPlugin::class, VerifySignaturePlugin::class, ResponsePlugin::class, diff --git a/src/Shortcut/Alipay/ScanShortcut.php b/src/Shortcut/Alipay/ScanShortcut.php index 8dfd62d..16f8442 100644 --- a/src/Shortcut/Alipay/ScanShortcut.php +++ b/src/Shortcut/Alipay/ScanShortcut.php @@ -5,9 +5,9 @@ declare(strict_types=1); namespace Yansongda\Pay\Shortcut\Alipay; use Yansongda\Pay\Contract\ShortcutInterface; +use Yansongda\Pay\Plugin\Alipay\AddPayloadSignaturePlugin; use Yansongda\Pay\Plugin\Alipay\AddRadarPlugin; -use Yansongda\Pay\Plugin\Alipay\AddSignaturePlugin; -use Yansongda\Pay\Plugin\Alipay\FormatBizContentPlugin; +use Yansongda\Pay\Plugin\Alipay\FormatPayloadBizContentPlugin; use Yansongda\Pay\Plugin\Alipay\Pay\Scan\PayPlugin; use Yansongda\Pay\Plugin\Alipay\ResponsePlugin; use Yansongda\Pay\Plugin\Alipay\StartPlugin; @@ -21,8 +21,8 @@ class ScanShortcut implements ShortcutInterface return [ StartPlugin::class, PayPlugin::class, - FormatBizContentPlugin::class, - AddSignaturePlugin::class, + FormatPayloadBizContentPlugin::class, + AddPayloadSignaturePlugin::class, AddRadarPlugin::class, VerifySignaturePlugin::class, ResponsePlugin::class, diff --git a/src/Shortcut/Alipay/TransferShortcut.php b/src/Shortcut/Alipay/TransferShortcut.php index 00ec5ef..bd22fe9 100644 --- a/src/Shortcut/Alipay/TransferShortcut.php +++ b/src/Shortcut/Alipay/TransferShortcut.php @@ -5,9 +5,9 @@ declare(strict_types=1); namespace Yansongda\Pay\Shortcut\Alipay; use Yansongda\Pay\Contract\ShortcutInterface; +use Yansongda\Pay\Plugin\Alipay\AddPayloadSignaturePlugin; use Yansongda\Pay\Plugin\Alipay\AddRadarPlugin; -use Yansongda\Pay\Plugin\Alipay\AddSignaturePlugin; -use Yansongda\Pay\Plugin\Alipay\FormatBizContentPlugin; +use Yansongda\Pay\Plugin\Alipay\FormatPayloadBizContentPlugin; use Yansongda\Pay\Plugin\Alipay\Fund\Transfer\TransferPlugin; use Yansongda\Pay\Plugin\Alipay\ResponsePlugin; use Yansongda\Pay\Plugin\Alipay\StartPlugin; @@ -21,8 +21,8 @@ class TransferShortcut implements ShortcutInterface return [ StartPlugin::class, TransferPlugin::class, - FormatBizContentPlugin::class, - AddSignaturePlugin::class, + FormatPayloadBizContentPlugin::class, + AddPayloadSignaturePlugin::class, AddRadarPlugin::class, VerifySignaturePlugin::class, ResponsePlugin::class, diff --git a/src/Shortcut/Alipay/WapShortcut.php b/src/Shortcut/Alipay/WapShortcut.php index abf302e..87893c7 100644 --- a/src/Shortcut/Alipay/WapShortcut.php +++ b/src/Shortcut/Alipay/WapShortcut.php @@ -5,9 +5,9 @@ declare(strict_types=1); namespace Yansongda\Pay\Shortcut\Alipay; use Yansongda\Pay\Contract\ShortcutInterface; -use Yansongda\Pay\Plugin\Alipay\AddSignaturePlugin; -use Yansongda\Pay\Plugin\Alipay\FormatBizContentPlugin; -use Yansongda\Pay\Plugin\Alipay\Pay\Wap\PayPlugin; +use Yansongda\Pay\Plugin\Alipay\AddPayloadSignaturePlugin; +use Yansongda\Pay\Plugin\Alipay\FormatPayloadBizContentPlugin; +use Yansongda\Pay\Plugin\Alipay\Pay\H5\PayPlugin; use Yansongda\Pay\Plugin\Alipay\ResponseHtmlPlugin; use Yansongda\Pay\Plugin\Alipay\StartPlugin; use Yansongda\Pay\Plugin\ParserPlugin; @@ -19,8 +19,8 @@ class WapShortcut implements ShortcutInterface return [ StartPlugin::class, PayPlugin::class, - FormatBizContentPlugin::class, - AddSignaturePlugin::class, + FormatPayloadBizContentPlugin::class, + AddPayloadSignaturePlugin::class, ResponseHtmlPlugin::class, ParserPlugin::class, ]; diff --git a/src/Shortcut/Alipay/WebShortcut.php b/src/Shortcut/Alipay/WebShortcut.php index 339c5df..cbb05fd 100644 --- a/src/Shortcut/Alipay/WebShortcut.php +++ b/src/Shortcut/Alipay/WebShortcut.php @@ -5,9 +5,9 @@ declare(strict_types=1); namespace Yansongda\Pay\Shortcut\Alipay; use Yansongda\Pay\Contract\ShortcutInterface; +use Yansongda\Pay\Plugin\Alipay\AddPayloadSignaturePlugin; use Yansongda\Pay\Plugin\Alipay\AddRadarPlugin; -use Yansongda\Pay\Plugin\Alipay\AddSignaturePlugin; -use Yansongda\Pay\Plugin\Alipay\FormatBizContentPlugin; +use Yansongda\Pay\Plugin\Alipay\FormatPayloadBizContentPlugin; use Yansongda\Pay\Plugin\Alipay\Pay\Web\PayPlugin; use Yansongda\Pay\Plugin\Alipay\ResponseHtmlPlugin; use Yansongda\Pay\Plugin\Alipay\StartPlugin; @@ -20,8 +20,8 @@ class WebShortcut implements ShortcutInterface return [ StartPlugin::class, PayPlugin::class, - FormatBizContentPlugin::class, - AddSignaturePlugin::class, + FormatPayloadBizContentPlugin::class, + AddPayloadSignaturePlugin::class, AddRadarPlugin::class, ResponseHtmlPlugin::class, ParserPlugin::class, diff --git a/src/Shortcut/Wechat/AppShortcut.php b/src/Shortcut/Wechat/AppShortcut.php index 7ad8449..d2fdd6c 100644 --- a/src/Shortcut/Wechat/AppShortcut.php +++ b/src/Shortcut/Wechat/AppShortcut.php @@ -5,23 +5,29 @@ declare(strict_types=1); namespace Yansongda\Pay\Shortcut\Wechat; use Yansongda\Pay\Contract\ShortcutInterface; +use Yansongda\Pay\Plugin\Alipay\Pay\App\PayPlugin; use Yansongda\Pay\Plugin\ParserPlugin; -use Yansongda\Pay\Plugin\Wechat\LaunchPlugin; -use Yansongda\Pay\Plugin\Wechat\Pay\App\InvokePrepayPlugin; -use Yansongda\Pay\Plugin\Wechat\Pay\App\PrepayPlugin; -use Yansongda\Pay\Plugin\Wechat\PreparePlugin; -use Yansongda\Pay\Plugin\Wechat\RadarSignPlugin; +use Yansongda\Pay\Plugin\Wechat\AddPayloadBodyPlugin; +use Yansongda\Pay\Plugin\Wechat\AddPayloadSignaturePlugin; +use Yansongda\Pay\Plugin\Wechat\AddRadarPlugin; +use Yansongda\Pay\Plugin\Wechat\Pay\App\InvokePlugin; +use Yansongda\Pay\Plugin\Wechat\ResponsePlugin; +use Yansongda\Pay\Plugin\Wechat\StartPlugin; +use Yansongda\Pay\Plugin\Wechat\VerifySignaturePlugin; class AppShortcut implements ShortcutInterface { public function getPlugins(array $params): array { return [ - PreparePlugin::class, - PrepayPlugin::class, - InvokePrepayPlugin::class, - RadarSignPlugin::class, - LaunchPlugin::class, + StartPlugin::class, + PayPlugin::class, + AddPayloadBodyPlugin::class, + AddPayloadSignaturePlugin::class, + AddRadarPlugin::class, + InvokePlugin::class, + ResponsePlugin::class, + VerifySignaturePlugin::class, ParserPlugin::class, ]; } diff --git a/src/Shortcut/Wechat/CloseShortcut.php b/src/Shortcut/Wechat/CloseShortcut.php index ad066b0..09c37d8 100644 --- a/src/Shortcut/Wechat/CloseShortcut.php +++ b/src/Shortcut/Wechat/CloseShortcut.php @@ -8,10 +8,18 @@ use Yansongda\Pay\Contract\ShortcutInterface; use Yansongda\Pay\Exception\Exception; use Yansongda\Pay\Exception\InvalidParamsException; use Yansongda\Pay\Plugin\ParserPlugin; -use Yansongda\Pay\Plugin\Wechat\LaunchPlugin; -use Yansongda\Pay\Plugin\Wechat\Pay\Common\ClosePlugin; -use Yansongda\Pay\Plugin\Wechat\PreparePlugin; -use Yansongda\Pay\Plugin\Wechat\RadarSignPlugin; +use Yansongda\Pay\Plugin\Wechat\AddPayloadBodyPlugin; +use Yansongda\Pay\Plugin\Wechat\AddPayloadSignaturePlugin; +use Yansongda\Pay\Plugin\Wechat\AddRadarPlugin; +use Yansongda\Pay\Plugin\Wechat\Pay\App\ClosePlugin as AppClosePlugin; +use Yansongda\Pay\Plugin\Wechat\Pay\Combine\ClosePlugin as CombineClosePlugin; +use Yansongda\Pay\Plugin\Wechat\Pay\H5\ClosePlugin as H5ClosePlugin; +use Yansongda\Pay\Plugin\Wechat\Pay\Jsapi\ClosePlugin as JsapiClosePlugin; +use Yansongda\Pay\Plugin\Wechat\Pay\Mini\ClosePlugin as MiniClosePlugin; +use Yansongda\Pay\Plugin\Wechat\Pay\Native\ClosePlugin as NativeClosePlugin; +use Yansongda\Pay\Plugin\Wechat\ResponsePlugin; +use Yansongda\Pay\Plugin\Wechat\StartPlugin; +use Yansongda\Pay\Plugin\Wechat\VerifySignaturePlugin; use Yansongda\Supports\Str; class CloseShortcut implements ShortcutInterface @@ -25,22 +33,86 @@ class CloseShortcut implements ShortcutInterface return $this->combinePlugins(); } - $typeMethod = Str::camel($params['_action'] ?? 'default').'Plugins'; + $action = Str::camel($params['_action'] ?? 'default').'Plugins'; - if (method_exists($this, $typeMethod)) { - return $this->{$typeMethod}(); + if (method_exists($this, $action)) { + return $this->{$action}(); } - throw new InvalidParamsException(Exception::PARAMS_SHORTCUT_ACTION_INVALID, "Query action [{$typeMethod}] not supported"); + throw new InvalidParamsException(Exception::PARAMS_SHORTCUT_ACTION_INVALID, "Close action [{$action}] not supported"); } protected function defaultPlugins(): array + { + return $this->jsapiPlugins(); + } + + protected function appPlugins(): array { return [ - PreparePlugin::class, - ClosePlugin::class, - RadarSignPlugin::class, - LaunchPlugin::class, + StartPlugin::class, + AppClosePlugin::class, + AddPayloadBodyPlugin::class, + AddPayloadSignaturePlugin::class, + AddRadarPlugin::class, + ResponsePlugin::class, + VerifySignaturePlugin::class, + ParserPlugin::class, + ]; + } + + protected function H5Plugins(): array + { + return [ + StartPlugin::class, + H5ClosePlugin::class, + AddPayloadBodyPlugin::class, + AddPayloadSignaturePlugin::class, + AddRadarPlugin::class, + ResponsePlugin::class, + VerifySignaturePlugin::class, + ParserPlugin::class, + ]; + } + + protected function jsapiPlugins(): array + { + return [ + StartPlugin::class, + JsapiClosePlugin::class, + AddPayloadBodyPlugin::class, + AddPayloadSignaturePlugin::class, + AddRadarPlugin::class, + ResponsePlugin::class, + VerifySignaturePlugin::class, + ParserPlugin::class, + ]; + } + + protected function miniPlugins(): array + { + return [ + StartPlugin::class, + MiniClosePlugin::class, + AddPayloadBodyPlugin::class, + AddPayloadSignaturePlugin::class, + AddRadarPlugin::class, + ResponsePlugin::class, + VerifySignaturePlugin::class, + ParserPlugin::class, + ]; + } + + protected function nativePlugins(): array + { + return [ + StartPlugin::class, + NativeClosePlugin::class, + AddPayloadBodyPlugin::class, + AddPayloadSignaturePlugin::class, + AddRadarPlugin::class, + ResponsePlugin::class, + VerifySignaturePlugin::class, ParserPlugin::class, ]; } @@ -48,10 +120,13 @@ class CloseShortcut implements ShortcutInterface protected function combinePlugins(): array { return [ - PreparePlugin::class, - \Yansongda\Pay\Plugin\Wechat\Pay\Combine\ClosePlugin::class, - RadarSignPlugin::class, - LaunchPlugin::class, + StartPlugin::class, + CombineClosePlugin::class, + AddPayloadBodyPlugin::class, + AddPayloadSignaturePlugin::class, + AddRadarPlugin::class, + ResponsePlugin::class, + VerifySignaturePlugin::class, ParserPlugin::class, ]; } diff --git a/src/Shortcut/Wechat/MiniShortcut.php b/src/Shortcut/Wechat/MiniShortcut.php index ee8419b..46dcb5e 100644 --- a/src/Shortcut/Wechat/MiniShortcut.php +++ b/src/Shortcut/Wechat/MiniShortcut.php @@ -6,22 +6,26 @@ namespace Yansongda\Pay\Shortcut\Wechat; use Yansongda\Pay\Contract\ShortcutInterface; use Yansongda\Pay\Plugin\ParserPlugin; -use Yansongda\Pay\Plugin\Wechat\LaunchPlugin; -use Yansongda\Pay\Plugin\Wechat\Pay\Mini\InvokePrepayPlugin; -use Yansongda\Pay\Plugin\Wechat\Pay\Mini\PrepayPlugin; -use Yansongda\Pay\Plugin\Wechat\PreparePlugin; -use Yansongda\Pay\Plugin\Wechat\RadarSignPlugin; +use Yansongda\Pay\Plugin\Wechat\AddPayloadBodyPlugin; +use Yansongda\Pay\Plugin\Wechat\AddPayloadSignaturePlugin; +use Yansongda\Pay\Plugin\Wechat\AddRadarPlugin; +use Yansongda\Pay\Plugin\Wechat\Pay\Mini\PayPlugin; +use Yansongda\Pay\Plugin\Wechat\ResponsePlugin; +use Yansongda\Pay\Plugin\Wechat\StartPlugin; +use Yansongda\Pay\Plugin\Wechat\VerifySignaturePlugin; class MiniShortcut implements ShortcutInterface { public function getPlugins(array $params): array { return [ - PreparePlugin::class, - PrepayPlugin::class, - InvokePrepayPlugin::class, - RadarSignPlugin::class, - LaunchPlugin::class, + StartPlugin::class, + PayPlugin::class, + AddPayloadBodyPlugin::class, + AddPayloadSignaturePlugin::class, + AddRadarPlugin::class, + ResponsePlugin::class, + VerifySignaturePlugin::class, ParserPlugin::class, ]; } diff --git a/src/Shortcut/Wechat/MpShortcut.php b/src/Shortcut/Wechat/MpShortcut.php index 0f0c980..4659125 100644 --- a/src/Shortcut/Wechat/MpShortcut.php +++ b/src/Shortcut/Wechat/MpShortcut.php @@ -6,22 +6,26 @@ namespace Yansongda\Pay\Shortcut\Wechat; use Yansongda\Pay\Contract\ShortcutInterface; use Yansongda\Pay\Plugin\ParserPlugin; -use Yansongda\Pay\Plugin\Wechat\LaunchPlugin; -use Yansongda\Pay\Plugin\Wechat\Pay\Jsapi\InvokePrepayPlugin; -use Yansongda\Pay\Plugin\Wechat\Pay\Jsapi\PrepayPlugin; -use Yansongda\Pay\Plugin\Wechat\PreparePlugin; -use Yansongda\Pay\Plugin\Wechat\RadarSignPlugin; +use Yansongda\Pay\Plugin\Wechat\AddPayloadBodyPlugin; +use Yansongda\Pay\Plugin\Wechat\AddPayloadSignaturePlugin; +use Yansongda\Pay\Plugin\Wechat\AddRadarPlugin; +use Yansongda\Pay\Plugin\Wechat\Pay\Jsapi\PayPlugin; +use Yansongda\Pay\Plugin\Wechat\ResponsePlugin; +use Yansongda\Pay\Plugin\Wechat\StartPlugin; +use Yansongda\Pay\Plugin\Wechat\VerifySignaturePlugin; class MpShortcut implements ShortcutInterface { public function getPlugins(array $params): array { return [ - PreparePlugin::class, - PrepayPlugin::class, - InvokePrepayPlugin::class, - RadarSignPlugin::class, - LaunchPlugin::class, + StartPlugin::class, + PayPlugin::class, + AddPayloadBodyPlugin::class, + AddPayloadSignaturePlugin::class, + AddRadarPlugin::class, + ResponsePlugin::class, + VerifySignaturePlugin::class, ParserPlugin::class, ]; } diff --git a/src/Shortcut/Wechat/PapayShortcut.php b/src/Shortcut/Wechat/PapayShortcut.php deleted file mode 100644 index 132ab68..0000000 --- a/src/Shortcut/Wechat/PapayShortcut.php +++ /dev/null @@ -1,87 +0,0 @@ -{$typeMethod}($params); - } - - throw new InvalidParamsException(Exception::PARAMS_SHORTCUT_ACTION_INVALID, "Papay action [{$typeMethod}] not supported"); - } - - /** - * 返回只签约(委托代扣)参数. - * - * @see https://pay.weixin.qq.com/wiki/doc/api/wxpay_v2/papay/chapter3_3.shtml - */ - public function ContractPlugins(): array - { - return [ - PreparePlugin::class, - OnlyContractPlugin::class, - ]; - } - - /** - * 申请代扣. - * - * @see https://pay.weixin.qq.com/wiki/doc/api/wxpay_v2/papay/chapter3_8.shtml - */ - public function applyPlugins(): array - { - return [ - PreparePlugin::class, - ApplyPlugin::class, - RadarSignPlugin::class, - ParserPlugin::class, - ]; - } - - /** - * 支付中签约. - * - * @see https://pay.weixin.qq.com/wiki/doc/api/wxpay_v2/papay/chapter3_5.shtml - */ - protected function defaultPlugins(array $params): array - { - return [ - PreparePlugin::class, - ContractOrderPlugin::class, - RadarSignPlugin::class, - $this->getInvoke($params), - ParserPlugin::class, - ]; - } - - protected function getInvoke(array $params): string - { - return match ($params['_type'] ?? 'default') { - 'app' => \Yansongda\Pay\Plugin\Wechat\Pay\App\InvokePrepayV2Plugin::class, - 'mini' => \Yansongda\Pay\Plugin\Wechat\Pay\Mini\InvokePrepayV2Plugin::class, - default => InvokePrepayV2Plugin::class, - }; - } -} diff --git a/src/Shortcut/Wechat/PosShortcut.php b/src/Shortcut/Wechat/PosShortcut.php deleted file mode 100644 index 64746fe..0000000 --- a/src/Shortcut/Wechat/PosShortcut.php +++ /dev/null @@ -1,18 +0,0 @@ -combinePlugins(); } - $typeMethod = Str::camel($params['_action'] ?? 'default').'Plugins'; + $action = Str::camel($params['_action'] ?? 'default').'Plugins'; - if (method_exists($this, $typeMethod)) { - return $this->{$typeMethod}(); + if (method_exists($this, $action)) { + return $this->{$action}(); } - throw new InvalidParamsException(Exception::PARAMS_SHORTCUT_ACTION_INVALID, "Query action [{$typeMethod}] not supported"); + throw new InvalidParamsException(Exception::PARAMS_SHORTCUT_ACTION_INVALID, "Query action [{$action}] not supported"); } protected function defaultPlugins(): array { - return [ - PreparePlugin::class, - QueryPlugin::class, - RadarSignPlugin::class, - LaunchPlugin::class, - ParserPlugin::class, - ]; + return $this->jsapiPlugins(); } - protected function refundPlugins(): array + protected function appPlugins(): array { return [ - PreparePlugin::class, - QueryRefundPlugin::class, - RadarSignPlugin::class, - LaunchPlugin::class, + StartPlugin::class, + AppQueryPlugin::class, + AddPayloadBodyPlugin::class, + AddPayloadSignaturePlugin::class, + AddRadarPlugin::class, + ResponsePlugin::class, + VerifySignaturePlugin::class, ParserPlugin::class, ]; } @@ -60,10 +71,172 @@ class QueryShortcut implements ShortcutInterface protected function combinePlugins(): array { return [ - PreparePlugin::class, - \Yansongda\Pay\Plugin\Wechat\Pay\Combine\QueryPlugin::class, - RadarSignPlugin::class, - LaunchPlugin::class, + StartPlugin::class, + CombineQueryPlugin::class, + AddPayloadBodyPlugin::class, + AddPayloadSignaturePlugin::class, + AddRadarPlugin::class, + ResponsePlugin::class, + VerifySignaturePlugin::class, + ParserPlugin::class, + ]; + } + + protected function h5Plugins(): array + { + return [ + StartPlugin::class, + H5QueryPlugin::class, + AddPayloadBodyPlugin::class, + AddPayloadSignaturePlugin::class, + AddRadarPlugin::class, + ResponsePlugin::class, + VerifySignaturePlugin::class, + ParserPlugin::class, + ]; + } + + protected function jsapiPlugins(): array + { + return [ + StartPlugin::class, + JsapiQueryPlugin::class, + AddPayloadBodyPlugin::class, + AddPayloadSignaturePlugin::class, + AddRadarPlugin::class, + ResponsePlugin::class, + VerifySignaturePlugin::class, + ParserPlugin::class, + ]; + } + + protected function miniPlugins(): array + { + return [ + StartPlugin::class, + MiniQueryPlugin::class, + AddPayloadBodyPlugin::class, + AddPayloadSignaturePlugin::class, + AddRadarPlugin::class, + ResponsePlugin::class, + VerifySignaturePlugin::class, + ParserPlugin::class, + ]; + } + + protected function nativePlugins(): array + { + return [ + StartPlugin::class, + NativeQueryPlugin::class, + AddPayloadBodyPlugin::class, + AddPayloadSignaturePlugin::class, + AddRadarPlugin::class, + ResponsePlugin::class, + VerifySignaturePlugin::class, + ParserPlugin::class, + ]; + } + + protected function refundPlugins(): array + { + return $this->refundJsapiPlugins(); + } + + protected function refundAppPlugins(): array + { + return [ + StartPlugin::class, + AppRefundPlugin::class, + AddPayloadBodyPlugin::class, + AddPayloadSignaturePlugin::class, + AddRadarPlugin::class, + ResponsePlugin::class, + VerifySignaturePlugin::class, + ParserPlugin::class, + ]; + } + + protected function refundCombinePlugins(): array + { + return [ + StartPlugin::class, + CombineRefundPlugin::class, + AddPayloadBodyPlugin::class, + AddPayloadSignaturePlugin::class, + AddRadarPlugin::class, + ResponsePlugin::class, + VerifySignaturePlugin::class, + ParserPlugin::class, + ]; + } + + protected function refundH5Plugins(): array + { + return [ + StartPlugin::class, + H5RefundPlugin::class, + AddPayloadBodyPlugin::class, + AddPayloadSignaturePlugin::class, + AddRadarPlugin::class, + ResponsePlugin::class, + VerifySignaturePlugin::class, + ParserPlugin::class, + ]; + } + + protected function refundJsapiPlugins(): array + { + return [ + StartPlugin::class, + JsapiRefundPlugin::class, + AddPayloadBodyPlugin::class, + AddPayloadSignaturePlugin::class, + AddRadarPlugin::class, + ResponsePlugin::class, + VerifySignaturePlugin::class, + ParserPlugin::class, + ]; + } + + protected function refundMiniPlugins(): array + { + return [ + StartPlugin::class, + MiniRefundPlugin::class, + AddPayloadBodyPlugin::class, + AddPayloadSignaturePlugin::class, + AddRadarPlugin::class, + ResponsePlugin::class, + VerifySignaturePlugin::class, + ParserPlugin::class, + ]; + } + + protected function refundNativePlugins(): array + { + return [ + StartPlugin::class, + NativeRefundPlugin::class, + AddPayloadBodyPlugin::class, + AddPayloadSignaturePlugin::class, + AddRadarPlugin::class, + ResponsePlugin::class, + VerifySignaturePlugin::class, + ParserPlugin::class, + ]; + } + + protected function transferPlugins(): array + { + return [ + StartPlugin::class, + TransferQueryPlugin::class, + AddPayloadBodyPlugin::class, + AddPayloadSignaturePlugin::class, + AddRadarPlugin::class, + ResponsePlugin::class, + VerifySignaturePlugin::class, ParserPlugin::class, ]; } diff --git a/src/Shortcut/Wechat/RefundShortcut.php b/src/Shortcut/Wechat/RefundShortcut.php index eb9e3d8..c35974d 100644 --- a/src/Shortcut/Wechat/RefundShortcut.php +++ b/src/Shortcut/Wechat/RefundShortcut.php @@ -5,21 +5,124 @@ declare(strict_types=1); namespace Yansongda\Pay\Shortcut\Wechat; use Yansongda\Pay\Contract\ShortcutInterface; +use Yansongda\Pay\Exception\Exception; +use Yansongda\Pay\Exception\InvalidParamsException; use Yansongda\Pay\Plugin\ParserPlugin; -use Yansongda\Pay\Plugin\Wechat\LaunchPlugin; -use Yansongda\Pay\Plugin\Wechat\Pay\Common\RefundPlugin; -use Yansongda\Pay\Plugin\Wechat\PreparePlugin; -use Yansongda\Pay\Plugin\Wechat\RadarSignPlugin; +use Yansongda\Pay\Plugin\Wechat\AddPayloadBodyPlugin; +use Yansongda\Pay\Plugin\Wechat\AddPayloadSignaturePlugin; +use Yansongda\Pay\Plugin\Wechat\AddRadarPlugin; +use Yansongda\Pay\Plugin\Wechat\Pay\App\RefundPlugin as AppRefundPlugin; +use Yansongda\Pay\Plugin\Wechat\Pay\Combine\RefundPlugin as CombineRefundPlugin; +use Yansongda\Pay\Plugin\Wechat\Pay\H5\RefundPlugin as H5RefundPlugin; +use Yansongda\Pay\Plugin\Wechat\Pay\Jsapi\RefundPlugin as JsapiRefundPlugin; +use Yansongda\Pay\Plugin\Wechat\Pay\Mini\RefundPlugin as MiniRefundPlugin; +use Yansongda\Pay\Plugin\Wechat\Pay\Native\RefundPlugin as NativeRefundPlugin; +use Yansongda\Pay\Plugin\Wechat\ResponsePlugin; +use Yansongda\Pay\Plugin\Wechat\StartPlugin; +use Yansongda\Pay\Plugin\Wechat\VerifySignaturePlugin; +use Yansongda\Supports\Str; class RefundShortcut implements ShortcutInterface { + /** + * @throws InvalidParamsException + */ public function getPlugins(array $params): array + { + $action = Str::camel($params['_action'] ?? 'default').'Plugins'; + + if (method_exists($this, $action)) { + return $this->{$action}(); + } + + throw new InvalidParamsException(Exception::PARAMS_SHORTCUT_ACTION_INVALID, "Refund action [{$action}] not supported"); + } + + protected function defaultPlugins(): array + { + return $this->jsapiPlugins(); + } + + protected function appPlugins(): array { return [ - PreparePlugin::class, - RefundPlugin::class, - RadarSignPlugin::class, - LaunchPlugin::class, + StartPlugin::class, + AppRefundPlugin::class, + AddPayloadBodyPlugin::class, + AddPayloadSignaturePlugin::class, + AddRadarPlugin::class, + ResponsePlugin::class, + VerifySignaturePlugin::class, + ParserPlugin::class, + ]; + } + + protected function combinePlugins(): array + { + return [ + StartPlugin::class, + CombineRefundPlugin::class, + AddPayloadBodyPlugin::class, + AddPayloadSignaturePlugin::class, + AddRadarPlugin::class, + ResponsePlugin::class, + VerifySignaturePlugin::class, + ParserPlugin::class, + ]; + } + + protected function h5Plugins(): array + { + return [ + StartPlugin::class, + H5RefundPlugin::class, + AddPayloadBodyPlugin::class, + AddPayloadSignaturePlugin::class, + AddRadarPlugin::class, + ResponsePlugin::class, + VerifySignaturePlugin::class, + ParserPlugin::class, + ]; + } + + protected function jsapiPlugins(): array + { + return [ + StartPlugin::class, + JsapiRefundPlugin::class, + AddPayloadBodyPlugin::class, + AddPayloadSignaturePlugin::class, + AddRadarPlugin::class, + ResponsePlugin::class, + VerifySignaturePlugin::class, + ParserPlugin::class, + ]; + } + + protected function miniPlugins(): array + { + return [ + StartPlugin::class, + MiniRefundPlugin::class, + AddPayloadBodyPlugin::class, + AddPayloadSignaturePlugin::class, + AddRadarPlugin::class, + ResponsePlugin::class, + VerifySignaturePlugin::class, + ParserPlugin::class, + ]; + } + + protected function nativePlugins(): array + { + return [ + StartPlugin::class, + NativeRefundPlugin::class, + AddPayloadBodyPlugin::class, + AddPayloadSignaturePlugin::class, + AddRadarPlugin::class, + ResponsePlugin::class, + VerifySignaturePlugin::class, ParserPlugin::class, ]; } diff --git a/src/Shortcut/Wechat/ScanShortcut.php b/src/Shortcut/Wechat/ScanShortcut.php index 09baea7..446034f 100644 --- a/src/Shortcut/Wechat/ScanShortcut.php +++ b/src/Shortcut/Wechat/ScanShortcut.php @@ -6,20 +6,26 @@ namespace Yansongda\Pay\Shortcut\Wechat; use Yansongda\Pay\Contract\ShortcutInterface; use Yansongda\Pay\Plugin\ParserPlugin; -use Yansongda\Pay\Plugin\Wechat\LaunchPlugin; -use Yansongda\Pay\Plugin\Wechat\Pay\Native\PrepayPlugin; -use Yansongda\Pay\Plugin\Wechat\PreparePlugin; -use Yansongda\Pay\Plugin\Wechat\RadarSignPlugin; +use Yansongda\Pay\Plugin\Wechat\AddPayloadBodyPlugin; +use Yansongda\Pay\Plugin\Wechat\AddPayloadSignaturePlugin; +use Yansongda\Pay\Plugin\Wechat\AddRadarPlugin; +use Yansongda\Pay\Plugin\Wechat\Pay\Native\PayPlugin; +use Yansongda\Pay\Plugin\Wechat\ResponsePlugin; +use Yansongda\Pay\Plugin\Wechat\StartPlugin; +use Yansongda\Pay\Plugin\Wechat\VerifySignaturePlugin; class ScanShortcut implements ShortcutInterface { public function getPlugins(array $params): array { return [ - PreparePlugin::class, - PrepayPlugin::class, - RadarSignPlugin::class, - LaunchPlugin::class, + StartPlugin::class, + PayPlugin::class, + AddPayloadBodyPlugin::class, + AddPayloadSignaturePlugin::class, + AddRadarPlugin::class, + ResponsePlugin::class, + VerifySignaturePlugin::class, ParserPlugin::class, ]; } diff --git a/src/Shortcut/Wechat/TransferShortcut.php b/src/Shortcut/Wechat/TransferShortcut.php index 11403a8..aa72a6e 100644 --- a/src/Shortcut/Wechat/TransferShortcut.php +++ b/src/Shortcut/Wechat/TransferShortcut.php @@ -6,20 +6,26 @@ namespace Yansongda\Pay\Shortcut\Wechat; use Yansongda\Pay\Contract\ShortcutInterface; use Yansongda\Pay\Plugin\ParserPlugin; -use Yansongda\Pay\Plugin\Wechat\Fund\Transfer\CreatePlugin; -use Yansongda\Pay\Plugin\Wechat\LaunchPlugin; -use Yansongda\Pay\Plugin\Wechat\PreparePlugin; -use Yansongda\Pay\Plugin\Wechat\RadarSignPlugin; +use Yansongda\Pay\Plugin\Wechat\AddPayloadBodyPlugin; +use Yansongda\Pay\Plugin\Wechat\AddPayloadSignaturePlugin; +use Yansongda\Pay\Plugin\Wechat\AddRadarPlugin; +use Yansongda\Pay\Plugin\Wechat\Marketing\Transfer\CreatePlugin; +use Yansongda\Pay\Plugin\Wechat\ResponsePlugin; +use Yansongda\Pay\Plugin\Wechat\StartPlugin; +use Yansongda\Pay\Plugin\Wechat\VerifySignaturePlugin; class TransferShortcut implements ShortcutInterface { public function getPlugins(array $params): array { return [ - PreparePlugin::class, + StartPlugin::class, CreatePlugin::class, - RadarSignPlugin::class, - LaunchPlugin::class, + AddPayloadBodyPlugin::class, + AddPayloadSignaturePlugin::class, + AddRadarPlugin::class, + ResponsePlugin::class, + VerifySignaturePlugin::class, ParserPlugin::class, ]; } diff --git a/src/Shortcut/Wechat/WapShortcut.php b/src/Shortcut/Wechat/WapShortcut.php index 32aa39a..25ad773 100644 --- a/src/Shortcut/Wechat/WapShortcut.php +++ b/src/Shortcut/Wechat/WapShortcut.php @@ -6,20 +6,26 @@ namespace Yansongda\Pay\Shortcut\Wechat; use Yansongda\Pay\Contract\ShortcutInterface; use Yansongda\Pay\Plugin\ParserPlugin; -use Yansongda\Pay\Plugin\Wechat\LaunchPlugin; -use Yansongda\Pay\Plugin\Wechat\Pay\H5\PrepayPlugin; -use Yansongda\Pay\Plugin\Wechat\PreparePlugin; -use Yansongda\Pay\Plugin\Wechat\RadarSignPlugin; +use Yansongda\Pay\Plugin\Wechat\AddPayloadBodyPlugin; +use Yansongda\Pay\Plugin\Wechat\AddPayloadSignaturePlugin; +use Yansongda\Pay\Plugin\Wechat\AddRadarPlugin; +use Yansongda\Pay\Plugin\Wechat\Pay\H5\PayPlugin; +use Yansongda\Pay\Plugin\Wechat\ResponsePlugin; +use Yansongda\Pay\Plugin\Wechat\StartPlugin; +use Yansongda\Pay\Plugin\Wechat\VerifySignaturePlugin; class WapShortcut implements ShortcutInterface { public function getPlugins(array $params): array { return [ - PreparePlugin::class, - PrepayPlugin::class, - RadarSignPlugin::class, - LaunchPlugin::class, + StartPlugin::class, + PayPlugin::class, + AddPayloadBodyPlugin::class, + AddPayloadSignaturePlugin::class, + AddRadarPlugin::class, + ResponsePlugin::class, + VerifySignaturePlugin::class, ParserPlugin::class, ]; } diff --git a/src/Traits/GetUnipayCerts.php b/src/Traits/GetUnipayCerts.php index 47eb576..db855a3 100644 --- a/src/Traits/GetUnipayCerts.php +++ b/src/Traits/GetUnipayCerts.php @@ -28,7 +28,7 @@ trait GetUnipayCerts $ssl = openssl_x509_parse($certs['cert'] ?? ''); if (false === $ssl) { - throw new InvalidConfigException(Exception::CONFIG_UNIPAY_INVALID, 'Parse `mch_cert_path` Error'); + throw new InvalidConfigException(Exception::CONFIG_UNIPAY_INVALID, '配置异常: 解析银联 `mch_cert_path` 失败,请检查参数是否正确'); } $certs['cert_id'] = $ssl['serialNumber'] ?? ''; @@ -49,11 +49,11 @@ trait GetUnipayCerts $password = $config['mch_cert_password'] ?? null; if (is_null($path) || is_null($password)) { - throw new InvalidConfigException(Exception::CONFIG_UNIPAY_INVALID, 'Missing Unipay Config -- [mch_cert_path] or [mch_cert_password]'); + throw new InvalidConfigException(Exception::CONFIG_UNIPAY_INVALID, '配置异常: 缺少银联配置 -- [mch_cert_path] or [mch_cert_password]'); } if (false === openssl_pkcs12_read(file_get_contents($path), $certs, $password)) { - throw new InvalidConfigException(Exception::CONFIG_UNIPAY_INVALID, 'Read `mch_cert_path` Error'); + throw new InvalidConfigException(Exception::CONFIG_UNIPAY_INVALID, '配置异常: 读取银联 `mch_cert_path` 失败,请确认参数是否正确'); } return $certs; diff --git a/src/Traits/HasWechatEncryption.php b/src/Traits/HasWechatEncryption.php deleted file mode 100644 index 1bced56..0000000 --- a/src/Traits/HasWechatEncryption.php +++ /dev/null @@ -1,61 +0,0 @@ -parser->guide(new JsonPacker(), null); } diff --git a/tests/FunctionTest.php b/tests/FunctionTest.php index 075f8a4..d3483e0 100644 --- a/tests/FunctionTest.php +++ b/tests/FunctionTest.php @@ -13,17 +13,20 @@ use Yansongda\Pay\Contract\PackerInterface; use Yansongda\Pay\Direction\CollectionDirection; use Yansongda\Pay\Direction\NoHttpRequestDirection; use Yansongda\Pay\Direction\ResponseDirection; +use Yansongda\Pay\Exception\DecryptException; use Yansongda\Pay\Exception\Exception; use Yansongda\Pay\Exception\InvalidConfigException; -use Yansongda\Pay\Exception\InvalidResponseException; +use Yansongda\Pay\Exception\InvalidParamsException; use Yansongda\Pay\Packer\JsonPacker; use Yansongda\Pay\Pay; use Yansongda\Pay\Provider\Wechat; use Yansongda\Pay\Rocket; +use Yansongda\Supports\Collection; use Yansongda\Supports\Str; use function Yansongda\Pay\decrypt_wechat_resource; use function Yansongda\Pay\decrypt_wechat_resource_aes_256_gcm; use function Yansongda\Pay\encrypt_wechat_contents; +use function Yansongda\Pay\filter_params; use function Yansongda\Pay\get_alipay_config; use function Yansongda\Pay\get_direction; use function Yansongda\Pay\get_private_cert; @@ -31,10 +34,16 @@ use function Yansongda\Pay\get_public_cert; use function Yansongda\Pay\get_tenant; use function Yansongda\Pay\get_unipay_config; use function Yansongda\Pay\get_wechat_base_uri; +use function Yansongda\Pay\get_wechat_body; use function Yansongda\Pay\get_wechat_config; +use function Yansongda\Pay\get_wechat_type_key; +use function Yansongda\Pay\get_wechat_method; use function Yansongda\Pay\get_wechat_public_certs; +use function Yansongda\Pay\get_wechat_public_key; +use function Yansongda\Pay\get_wechat_serial_no; use function Yansongda\Pay\get_wechat_sign; use function Yansongda\Pay\get_wechat_sign_v2; +use function Yansongda\Pay\get_wechat_url; use function Yansongda\Pay\reload_wechat_public_certs; use function Yansongda\Pay\should_do_http_request; use function Yansongda\Pay\verify_alipay_sign; @@ -82,6 +91,44 @@ class FunctionTest extends TestCase get_direction('invalid'); } + public function testGetPublicCert() + { + $alipayPublicCertPath = __DIR__ . '/Cert/alipayPublicCert.crt'; + $alipayPublicCertCerPath = __DIR__ . '/Cert/alipayPublicCert.cer'; + + self::assertEquals(file_get_contents($alipayPublicCertCerPath), get_public_cert($alipayPublicCertCerPath)); + self::assertEquals(file_get_contents($alipayPublicCertPath), get_public_cert($alipayPublicCertPath)); + } + + public function testGetPrivateCert() + { + $appSecretCert = file_get_contents(__DIR__ . '/Cert/alipayAppSecret.txt'); + + self::assertTrue(Str::contains(get_private_cert($appSecretCert), 'PRIVATE KEY')); + } + + public function testFilterParams() + { + // none closure + $params = [ + 'name' => 'yansongda', + '_method' => 'foo', + 'a' => null, + ]; + self::assertEqualsCanonicalizing(['name' => 'yansongda'], filter_params($params)); + + // closure + $params = [ + 'name' => 'yansongda', + '_method' => 'foo', + 'sign' => 'aaa', + 'sign_type' => 'bbb', + 's' => '', + 'a' => null, + ]; + self::assertEqualsCanonicalizing(['name' => 'yansongda'], filter_params($params, fn ($k, $v) => '' !== $v && !is_null($v) && 'sign' != $k && 'sign_type' != $k)); + } + public function testGetAlipayConfig() { self::assertArrayHasKey('app_id', get_alipay_config([])); @@ -100,25 +147,9 @@ class FunctionTest extends TestCase self::assertEquals(['age' => 28], get_alipay_config(['_config' => 'c1'])); } - public function testGetPublicCert() - { - $alipayPublicCertPath = __DIR__ . '/Cert/alipayPublicCert.crt'; - $alipayPublicCertCerPath = __DIR__ . '/Cert/alipayPublicCert.cer'; - - self::assertEquals(file_get_contents($alipayPublicCertCerPath), get_public_cert($alipayPublicCertCerPath)); - self::assertEquals(file_get_contents($alipayPublicCertPath), get_public_cert($alipayPublicCertPath)); - } - - public function testGetPrivateCert() - { - $appSecretCert = file_get_contents(__DIR__ . '/Cert/alipayAppSecret.txt'); - - self::assertTrue(Str::contains(get_private_cert($appSecretCert), 'PRIVATE KEY')); - } - public function testVerifyAlipaySign() { - verify_alipay_sign([], json_encode([ + verify_alipay_sign(get_alipay_config(), json_encode([ "code" => "10000", "msg" => "Success", "order_id" => "20231220110070000002150000657610", @@ -142,7 +173,7 @@ class FunctionTest extends TestCase self::expectException(InvalidConfigException::class); self::expectExceptionCode(Exception::CONFIG_ALIPAY_INVALID); - verify_alipay_sign([], '', ''); + verify_alipay_sign(get_alipay_config(), '', ''); } public function testGetWechatConfig() @@ -161,37 +192,51 @@ class FunctionTest extends TestCase self::assertEquals(['age' => 28], get_wechat_config(['_config' => 'c1'])); } - public function testGetWechatBaseUri() + public function testGetWechatMethod() { - self::assertEquals(Wechat::URL[Pay::MODE_NORMAL], get_wechat_base_uri([])); + self::assertEquals('POST', get_wechat_method(null)); + self::assertEquals('GET', get_wechat_method(new Collection(['_method' => 'get']))); + self::assertEquals('POST', get_wechat_method(new Collection(['_method' => 'post']))); + } - $config2 = ['_force' => true, 'wechat' => [ - 'yansongda' => ['mode' => Pay::MODE_SANDBOX] - ]]; - Pay::config($config2); + public function testGetWechatUrl() + { + self::assertEquals('https://yansongda.cn', get_wechat_url([], new Collection(['_url' => 'https://yansongda.cn']))); + self::assertEquals('https://api.mch.weixin.qq.com/api/v1/yansongda', get_wechat_url([], new Collection(['_url' => 'api/v1/yansongda']))); + self::assertEquals('https://api.mch.weixin.qq.com/api/v1/service/yansongda', get_wechat_url(['mode' => Pay::MODE_SERVICE], new Collection(['_url' => 'api/v1/service/yansongda']))); + self::assertEquals('https://api.mch.weixin.qq.com/api/v1/service/yansongda', get_wechat_url(['mode' => Pay::MODE_SERVICE], new Collection(['_url' => 'foo', '_service_url' => 'api/v1/service/yansongda']))); - self::assertEquals(Wechat::URL[Pay::MODE_SANDBOX], get_wechat_base_uri(['_config' => 'yansongda'])); + self::expectException(InvalidParamsException::class); + self::expectExceptionCode(Exception::PARAMS_WECHAT_URL_MISSING); + get_wechat_url([], new Collection([])); + } + + public function testGetWechatBody() + { + self::assertEquals('https://yansongda.cn', get_wechat_body(new Collection(['_body' => 'https://yansongda.cn']))); + + self::expectException(InvalidParamsException::class); + self::expectExceptionCode(Exception::PARAMS_WECHAT_BODY_MISSING); + get_wechat_body(new Collection([])); + } + + public function testGetWechatConfigKey() + { + // default + self::assertEquals('mp_app_id', get_wechat_type_key([])); + // app + self::assertEquals('app_id', get_wechat_type_key(['_type' => 'app'])); + // mini + self::assertEquals('mini_app_id', get_wechat_type_key(['_type' => 'mini'])); } public function testGetWechatSign() { - $params = [ - 'out_trade_no' => 1626493236, - 'description' => 'yansongda 测试 - 1626493236', - 'amount' => [ - 'total' => 1, - ], - 'scene_info' => [ - 'payer_client_ip' => '127.0.0.1', - 'h5_info' => [ - 'type' => 'Wap', - ] - ]]; $contents = "POST\n/v3/pay/transactions/h5\n1626493236\nQqtzdVzxavZeXag9G5mtfzbfzFMf89p6\n{\"out_trade_no\":1626493236,\"description\":\"yansongda 测试 - 1626493236\",\"amount\":{\"total\":1},\"scene_info\":{\"payer_client_ip\":\"127.0.0.1\",\"h5_info\":{\"type\":\"Wap\"}},\"appid\":\"wx55955316af4ef13\",\"mchid\":\"1600314069\",\"notify_url\":\"http:\/\/127.0.0.1:8000\/wechat\/notify\"}\n"; self::assertEquals( 'KzIgMgiop3nQJNdBVR2Xah/JUwVBLDFFajyXPiSN8b8YAYEA4FuWfaCgFJ52+WFed+PhOYWx/ZPih4RaEuuSdYB8eZwYUx7RZGMQZk0bKCctAjjPuf4pJN+f/WsXKjPIy3diqF5x7gyxwSCaKWP4/KjsHNqgQpiC8q1uC5xmElzuhzSwj88LIoLtkAuSmtUVvdAt0Nz41ECHZgHWSGR32TfBo902r8afdaVKkFde8IoqcEJJcp6sMxdDO5l9R5KEWxrJ1SjsXVrb0IPH8Nj7e6hfhq7pucxojPpzsC+ZWAYvufZkAQx3kTiFmY87T+QhkP9FesOfWvkIRL4E6MP6ug==', - get_wechat_sign($params, $contents) + get_wechat_sign(get_wechat_config([]), $contents) ); // test config error @@ -354,7 +399,7 @@ class FunctionTest extends TestCase 'nonce' => '4196a5b75276', ]; - $result = decrypt_wechat_resource($resource, []); + $result = decrypt_wechat_resource($resource, get_wechat_config()); self::assertTrue(false !== strpos($result['ciphertext'], '-----BEGIN CERTIFICATE-----')); } @@ -376,11 +421,68 @@ class FunctionTest extends TestCase 'ciphertext' => 'kbbHAUhBwdjYZkHPW149MW/8WNpxQo1Gyp4kVNVjd+zrXnyOFhgZic2U2+tobFAgfdr93zr0JZF3FdbxgkaOAV2NAeCfU8jsUYXSfn7fM8487jXMVXKKEneGiiv1/bDLkz7KFsTfu2y5Rv+igWQ+bvCUQAwoNzjupTXnnDR5hBiofZcFLHL45govyYE2o0qD5SLiJHcFS4pg/IOx8SIqUFNepr3piKXUxKowU8/kNxXyRzL8yp7XnhrzAzclupvjveNwZyiw3TqlLZdR5TbEFLCogWaRHZRqz3vKEfgRaUYUtXCtQVrm+adbSDBFIq34v+XfeIHMz9pKhH/m80N5Hx69hPzbvIdBhzwaEDyN3h8gaeYKFyW9xIAs5jCrzzUEkKyMzOKzx7XA+1HRakSyvs6RlkRTa/ztBy6aZL0nxK6XMZ9tA7zdf2VnBX/7WPQYRzoky0cVyH1KRZxI7In2hfvpjSvl6P7Adzp+EZXYM/dINTrrg+RQRe60tPy7vgE8PZZf+SAWzSZPWIm7Lx6GksJX0vnT4gOeTAPw6EeFsYU/ZD7fYslJOEbA14yHBrJFkwDpSI8aSHp2nZYbruM0y8IKr0p3vjN80Ko3jiRPxj4uNdJliR9WDCV22b9JeadAaJhO9+oSNbbtFnFTCZjXbf8rMz5KCGVrGRvUyB70zhRxYIOdTYKAEkmbU7jcMLd0aufuQqIw0WviQHB+ztrkjBCFwPu5/hlRVj9opNFnzYNltfVGrA1XW3NQ4FaMNah95ahomAG/+S7zJqq4Gvk1O/PgQ9kMP0adY3GlrHUNqr2zC709IervMQ1pEdcuNEln3V5TSDiE0x7BjoMoN2m+MKAIhw59VxzHGNmJELbkKsZUhKKXFFyEXFsw143/9IYOyanmHQxujdIBKI0rxYkVz9QgaajisCzdnRf0ymnkceGGnYsP7VTYBnuCncjgHxbEn3emlTRygEjgj/epupsQL2tfW+snxnafEM+Pc079pUYmKeCUEUoX/FUmdFIf8hlSHBTjEVMGsNUI/u2W781RBDfk2X/2QQQm3NOjgZ3le6hxEQqc12yANTvdq7cFVllWqMHBsXPCjpHWIHcS5BMkImoD7s6WItq60yJA8ioGJf3Rba+Yb/YeBBNxjDnXtAmX/2hJIsxEFLTYGUvdmFC5jeb5ifrOuxnLciKM8y4nLZ28dDsvVsaBBAMAFYfWb5NymKUDhhngR5bDuW4sKccZ6DmYQeStHT1fn2yoSneGA70HctQSWZ2roTdNihPTCs7rYD0dFeQ+SfLOJzMN4c5GbJ6n5tdCjERcLGIaXEKacfySo7e4VZtHeHowvlvBclS9pooZqzHd+EFlJEYywEs9jURgsJY2yHJt2zTZeIdsvM8KK5v0NkH8FiPbWqFG8LaRmUrqhJGLuLLRTcJnt6YVYESxUVTb3pmriUbXfg/ThHF/y0THyrM6bVDNOwNWZOpMYPPNaVmOTX39JdYayWl2HX0n8AsIRmevXzD4N9iDh2HGwie4gh92Qdcogwua++uhkhSsLFuWBpJiaPdxVtzz3E3jHfy+yryfh6msaXc/jmhwqBm/ii3j76lDP5YaRv4+JWZmom72+pmZuKD8qPKrPRxI2/aGiKEqgs25knpLLnbAhWAEYeIzVK1sQkjc5JFss1Std8FdDrHeM6agAB+MWncK1LloXZmiwz/6WmlwSDepnGHqLEciXThAZq6FwunJZTcHY9LamJgIY81c9t/KHlSFqlc/9mW4OZHM4BOZQ5sTj5PWE+OP2Aq9CKdJqoK3OmphBg2ewjrZt5/tSn9jpk6NlVrHD7MsJcKi5a0he4qvNPh1cHqUqWcF4rBFmfPptdHIBV77LXnizJZMUAwf16KsmJpwJg==', 'nonce' => '4196a5b75276', ]; - self::expectException(InvalidResponseException::class); - self::expectExceptionCode(Exception::RESPONSE_ENCRYPTED_DATA_INVALID); + self::expectException(DecryptException::class); + self::expectExceptionCode(Exception::DECRYPT_WECHAT_ENCRYPTED_DATA_INVALID); decrypt_wechat_resource_aes_256_gcm(base64_decode($resource['ciphertext']), 'foo', $resource['nonce'], $resource['associated_data']); } + public function testGetWechatSerialNo() + { + // 不传证书 + $params = []; + $result = get_wechat_serial_no($params); + self::assertTrue(in_array($result, ['45F59D4DABF31918AFCEC556D5D2C6E376675D57', 'yansongda'])); + + // 传证书 + $params = ['_serial_no' => 'yansongda',]; + $result = get_wechat_serial_no($params); + self::assertEquals('yansongda', $result); + } + + public function testGetWechatSerialNoWithRequestWechat() + { + $response = new Response( + 200, + [], + json_encode([ + 'data' => [ + [ + 'effective_time' => '2021-07-16T17:51:10+08:00', + 'encrypt_certificate' => [ + 'algorithm' => 'AEAD_AES_256_GCM', + 'associated_data' => 'certificate', + 'ciphertext' => 'kbbHAUhBwdjYZkHPW149MW/8WNpxQo1Gyp4kVNVjd+zrXnyOFhgZic2U2+tobFAgfdr93zr0JZF3FdbxgkaOAV2NAeCfU8jsUYXSfn7fM8487jXMVXKKEneGiiv1/bDLkz7KFsTfu2y5Rv+igWQ+bvCUQAwoNzjupTXnnDR5hBiofZcFLHL45govyYE2o0qD5SLiJHcFS4pg/IOx8SIqUFNepr3piKXUxKowU8/kNxXyRzL8yp7XnhrzAzclupvjveNwZyiw3TqlLZdR5TbEFLCogWaRHZRqz3vKEfgRaUYUtXCtQVrm+adbSDBFIq34v+XfeIHMz9pKhH/m80N5Hx69hPzbvIdBhzwaEDyN3h8gaeYKFyW9xIAs5jCrzzUEkKyMzOKzx7XA+1HRakSyvs6RlkRTa/ztBy6aZL0nxK6XMZ9tA7zdf2VnBX/7WPQYRzoky0cVyH1KRZxI7In2hfvpjSvl6P7Adzp+EZXYM/dINTrrg+RQRe60tPy7vgE8PZZf+SAWzSZPWIm7Lx6GksJX0vnT4gOeTAPw6EeFsYU/ZD7fYslJOEbA14yHBrJFkwDpSI8aSHp2nZYbruM0y8IKr0p3vjN80Ko3jiRPxj4uNdJliR9WDCV22b9JeadAaJhO9+oSNbbtFnFTCZjXbf8rMz5KCGVrGRvUyB70zhRxYIOdTYKAEkmbU7jcMLd0aufuQqIw0WviQHB+ztrkjBCFwPu5/hlRVj9opNFnzYNltfVGrA1XW3NQ4FaMNah95ahomAG/+S7zJqq4Gvk1O/PgQ9kMP0adY3GlrHUNqr2zC709IervMQ1pEdcuNEln3V5TSDiE0x7BjoMoN2m+MKAIhw59VxzHGNmJELbkKsZUhKKXFFyEXFsw143/9IYOyanmHQxujdIBKI0rxYkVz9QgaajisCzdnRf0ymnkceGGnYsP7VTYBnuCncjgHxbEn3emlTRygEjgj/epupsQL2tfW+snxnafEM+Pc079pUYmKeCUEUoX/FUmdFIf8hlSHBTjEVMGsNUI/u2W781RBDfk2X/2QQQm3NOjgZ3le6hxEQqc12yANTvdq7cFVllWqMHBsXPCjpHWIHcS5BMkImoD7s6WItq60yJA8ioGJf3Rba+Yb/YeBBNxjDnXtAmX/2hJIsxEFLTYGUvdmFC5jeb5ifrOuxnLciKM8y4nLZ28dDsvVsaBBAMAFYfWb5NymKUDhhngR5bDuW4sKccZ6DmYQeStHT1fn2yoSneGA70HctQSWZ2roTdNihPTCs7rYD0dFeQ+SfLOJzMN4c5GbJ6n5tdCjERcLGIaXEKacfySo7e4VZtHeHowvlvBclS9pooZqzHd+EFlJEYywEs9jURgsJY2yHJt2zTZeIdsvM8KK5v0NkH8FiPbWqFG8LaRmUrqhJGLuLLRTcJnt6YVYESxUVTb3pmriUbXfg/ThHF/y0THyrM6bVDNOwNWZOpMYPPNaVmOTX39JdYayWl2HX0n8AsIRmevXzD4N9iDh2HGwie4gh92Qdcogwua++uhkhSsLFuWBpJiaPdxVtzz3E3jHfy+yryfh6msaXc/jmhwqBm/ii3j76lDP5YaRv4+JWZmom72+pmZuKD8qPKrPRxI2/aGiKEqgs25knpLLnbAhWAEYeIzVK1sQkjc5JFss1Std8FdDrHeM6agAB+MWncK1LloXZmiwz/6WmlwSDepnGHqLEciXThAZq6FwunJZTcHY9LamJgIY81c9t/KHlSFqlc/9mW4OZHM4BOZQ5sTj5PWE+OP2Aq9CKdJqoK3OmphBg2ewjrZt5/tSn9jpk6NlVrHD7MsJcKi5a0he4qvNPh1cHqUqWcF4rBFmfPptdHIBV77LXnizJZMUAwf16KsmJpwJg==', + 'nonce' => '4196a5b75276', + ], + 'expire_time' => '2026-07-15T17:51:10+08:00', + 'serial_no' => 'test-45F59D4DABF31918AFCEC556D5D2C6E376675D57', + ] + ] + ]) + ); + + $http = Mockery::mock(Client::class); + $http->shouldReceive('sendRequest')->andReturn($response); + + Pay::set(HttpClientInterface::class, $http); + + $params = ['_config' => 'empty_wechat_public_cert']; + $result = get_wechat_serial_no($params); + self::assertEquals('test-45F59D4DABF31918AFCEC556D5D2C6E376675D57', $result); + } + + public function testGetWechatPublicKey() + { + $serialNo = '45F59D4DABF31918AFCEC556D5D2C6E376675D57'; + $result = get_wechat_public_key(get_wechat_config(), $serialNo); + self::assertIsString($result); + + $serialNo = 'non-exist'; + self::expectException(InvalidParamsException::class); + self::expectExceptionCode(Exception::PARAMS_WECHAT_SERIAL_NOT_FOUND); + get_wechat_public_key(get_wechat_config(), $serialNo); + } + public function testGetUnipayConfig() { self::assertArrayHasKey('mch_id', get_unipay_config([])); @@ -435,7 +537,7 @@ Q0C300Eo+XOoO4M1WvsRBAF13g9RPSw=\r self::expectException(InvalidConfigException::class); self::expectExceptionCode(Exception::CONFIG_UNIPAY_INVALID); - self::expectExceptionMessage('Missing Unipay Config -- [unipay_public_cert_path]'); + self::expectExceptionMessage('配置异常: 缺少银联配置 -- [unipay_public_cert_path]'); Pay::get(ConfigInterface::class)->set('unipay.default.unipay_public_cert_path', null); verify_unipay_sign([], $contents, $sign); } diff --git a/tests/Plugin/Alipay/AddSignaturePluginTest.php b/tests/Plugin/Alipay/AddPayloadSignaturePluginTest.php similarity index 87% rename from tests/Plugin/Alipay/AddSignaturePluginTest.php rename to tests/Plugin/Alipay/AddPayloadSignaturePluginTest.php index dc8e807..dc47dde 100644 --- a/tests/Plugin/Alipay/AddSignaturePluginTest.php +++ b/tests/Plugin/Alipay/AddPayloadSignaturePluginTest.php @@ -2,20 +2,20 @@ namespace Yansongda\Pay\Tests\Plugin\Alipay; -use Yansongda\Pay\Plugin\Alipay\AddSignaturePlugin; +use Yansongda\Pay\Plugin\Alipay\AddPayloadSignaturePlugin; use Yansongda\Pay\Rocket; use Yansongda\Pay\Tests\TestCase; use Yansongda\Supports\Collection; -class AddSignaturePluginTest extends TestCase +class AddPayloadSignaturePluginTest extends TestCase { - protected AddSignaturePlugin $plugin; + protected AddPayloadSignaturePlugin $plugin; protected function setUp(): void { parent::setUp(); - $this->plugin = new AddSignaturePlugin(); + $this->plugin = new AddPayloadSignaturePlugin(); } public function testSignNormal() diff --git a/tests/Plugin/Alipay/FormatBizContentPluginTest.php b/tests/Plugin/Alipay/FormatPayloadBizContentPluginTest.php similarity index 83% rename from tests/Plugin/Alipay/FormatBizContentPluginTest.php rename to tests/Plugin/Alipay/FormatPayloadBizContentPluginTest.php index 58b1395..db417e6 100644 --- a/tests/Plugin/Alipay/FormatBizContentPluginTest.php +++ b/tests/Plugin/Alipay/FormatPayloadBizContentPluginTest.php @@ -2,20 +2,20 @@ namespace Yansongda\Pay\Tests\Plugin\Alipay; -use Yansongda\Pay\Plugin\Alipay\FormatBizContentPlugin; +use Yansongda\Pay\Plugin\Alipay\FormatPayloadBizContentPlugin; use Yansongda\Pay\Rocket; use Yansongda\Pay\Tests\TestCase; use Yansongda\Supports\Collection; -class FormatBizContentPluginTest extends TestCase +class FormatPayloadBizContentPluginTest extends TestCase { - protected FormatBizContentPlugin $plugin; + protected FormatPayloadBizContentPlugin $plugin; protected function setUp(): void { parent::setUp(); - $this->plugin = new FormatBizContentPlugin(); + $this->plugin = new FormatPayloadBizContentPlugin(); } public function testSignNormal() diff --git a/tests/Plugin/Alipay/Pay/Wap/ClosePluginTest.php b/tests/Plugin/Alipay/Pay/Wap/ClosePluginTest.php index 18a72b9..766967b 100644 --- a/tests/Plugin/Alipay/Pay/Wap/ClosePluginTest.php +++ b/tests/Plugin/Alipay/Pay/Wap/ClosePluginTest.php @@ -3,7 +3,7 @@ namespace Yansongda\Pay\Tests\Plugin\Alipay\Pay\Wap; use Yansongda\Pay\Direction\ResponseDirection; -use Yansongda\Pay\Plugin\Alipay\Pay\Wap\ClosePlugin; +use Yansongda\Pay\Plugin\Alipay\Pay\H5\ClosePlugin; use Yansongda\Pay\Rocket; use Yansongda\Pay\Tests\TestCase; diff --git a/tests/Plugin/Alipay/Pay/Wap/PayPluginTest.php b/tests/Plugin/Alipay/Pay/Wap/PayPluginTest.php index bb599f8..ff5c9cf 100644 --- a/tests/Plugin/Alipay/Pay/Wap/PayPluginTest.php +++ b/tests/Plugin/Alipay/Pay/Wap/PayPluginTest.php @@ -3,7 +3,7 @@ namespace Yansongda\Pay\Tests\Plugin\Alipay\Pay\Wap; use Yansongda\Pay\Direction\ResponseDirection; -use Yansongda\Pay\Plugin\Alipay\Pay\Wap\PayPlugin; +use Yansongda\Pay\Plugin\Alipay\Pay\H5\PayPlugin; use Yansongda\Pay\Rocket; use Yansongda\Pay\Tests\TestCase; diff --git a/tests/Plugin/Alipay/Pay/Wap/QueryBillUrlPluginTest.php b/tests/Plugin/Alipay/Pay/Wap/QueryBillUrlPluginTest.php index 6145df6..ee9bf40 100644 --- a/tests/Plugin/Alipay/Pay/Wap/QueryBillUrlPluginTest.php +++ b/tests/Plugin/Alipay/Pay/Wap/QueryBillUrlPluginTest.php @@ -3,7 +3,7 @@ namespace Yansongda\Pay\Tests\Plugin\Alipay\Pay\Wap; use Yansongda\Pay\Direction\ResponseDirection; -use Yansongda\Pay\Plugin\Alipay\Pay\Wap\QueryBillUrlPlugin; +use Yansongda\Pay\Plugin\Alipay\Pay\H5\QueryBillUrlPlugin; use Yansongda\Pay\Rocket; use Yansongda\Pay\Tests\TestCase; diff --git a/tests/Plugin/Alipay/Pay/Wap/QueryPluginTest.php b/tests/Plugin/Alipay/Pay/Wap/QueryPluginTest.php index 4676d08..5414935 100644 --- a/tests/Plugin/Alipay/Pay/Wap/QueryPluginTest.php +++ b/tests/Plugin/Alipay/Pay/Wap/QueryPluginTest.php @@ -3,7 +3,7 @@ namespace Yansongda\Pay\Tests\Plugin\Alipay\Pay\Wap; use Yansongda\Pay\Direction\ResponseDirection; -use Yansongda\Pay\Plugin\Alipay\Pay\Wap\QueryPlugin; +use Yansongda\Pay\Plugin\Alipay\Pay\H5\QueryPlugin; use Yansongda\Pay\Rocket; use Yansongda\Pay\Tests\TestCase; diff --git a/tests/Plugin/Alipay/Pay/Wap/QueryRefundPluginTest.php b/tests/Plugin/Alipay/Pay/Wap/QueryRefundPluginTest.php index 71b3d93..85ae3f4 100644 --- a/tests/Plugin/Alipay/Pay/Wap/QueryRefundPluginTest.php +++ b/tests/Plugin/Alipay/Pay/Wap/QueryRefundPluginTest.php @@ -3,7 +3,7 @@ namespace Yansongda\Pay\Tests\Plugin\Alipay\Pay\Wap; use Yansongda\Pay\Direction\ResponseDirection; -use Yansongda\Pay\Plugin\Alipay\Pay\Wap\QueryRefundPlugin; +use Yansongda\Pay\Plugin\Alipay\Pay\H5\QueryRefundPlugin; use Yansongda\Pay\Rocket; use Yansongda\Pay\Tests\TestCase; diff --git a/tests/Plugin/Alipay/Pay/Wap/RefundPluginTest.php b/tests/Plugin/Alipay/Pay/Wap/RefundPluginTest.php index ca307c5..44d20d4 100644 --- a/tests/Plugin/Alipay/Pay/Wap/RefundPluginTest.php +++ b/tests/Plugin/Alipay/Pay/Wap/RefundPluginTest.php @@ -3,7 +3,7 @@ namespace Yansongda\Pay\Tests\Plugin\Alipay\Pay\Wap; use Yansongda\Pay\Direction\ResponseDirection; -use Yansongda\Pay\Plugin\Alipay\Pay\Wap\RefundPlugin; +use Yansongda\Pay\Plugin\Alipay\Pay\H5\RefundPlugin; use Yansongda\Pay\Rocket; use Yansongda\Pay\Tests\TestCase; diff --git a/tests/Plugin/Alipay/StartPluginTest.php b/tests/Plugin/Alipay/StartPluginTest.php index 6827dfe..32319d4 100644 --- a/tests/Plugin/Alipay/StartPluginTest.php +++ b/tests/Plugin/Alipay/StartPluginTest.php @@ -32,7 +32,6 @@ class StartPluginTest extends TestCase self::assertEquals('e90dd23a37c5c7b616e003970817ff82', $payload->get('app_cert_sn')); self::assertEquals('687b59193f3f462dd5336e5abf83c5d8_02941eef3187dddf3d3b83462e1dfcf6', $payload->get('alipay_root_cert_sn')); - self::assertEquals('yansongda_token', $payload->get('app_auth_token')); } public function testGlobalBcscale() @@ -51,26 +50,24 @@ class StartPluginTest extends TestCase { $rocket = new Rocket(); $rocket->setParams([ - '_return_url' => 'https://yansongda.cn', + '_return_url' => 'https://yansongda.cna', ]); $result = $this->plugin->assembly($rocket, function ($rocket) { return $rocket; }); - self::assertEquals('', $result->getPayload()->get('notify_url')); - self::assertEquals('https://yansongda.cn', $result->getPayload()->get('return_url')); + self::assertEquals('https://yansongda.cna', $result->getPayload()->get('return_url')); } public function testCustomizedNotifyUrl() { $rocket = new Rocket(); $rocket->setParams([ - '_notify_url' => 'https://yansongda.cn', + '_notify_url' => 'https://yansongda.cna', ]); $result = $this->plugin->assembly($rocket, function ($rocket) { return $rocket; }); - self::assertEquals('', $result->getPayload()->get('return_url')); - self::assertEquals('https://yansongda.cn', $result->getPayload()->get('notify_url')); + self::assertEquals('https://yansongda.cna', $result->getPayload()->get('notify_url')); } public function testCustomizedReturnNotifyUrl() @@ -107,7 +104,7 @@ class StartPluginTest extends TestCase self::expectException(InvalidConfigException::class); self::expectExceptionCode(Exception::CONFIG_ALIPAY_INVALID); - self::expectExceptionMessage('Missing Alipay Config -- [app_public_cert_path]'); + self::expectExceptionMessage('配置异常: 缺少支付宝配置 -- [app_public_cert_path]'); $this->plugin->assembly($rocket, function ($rocket) { return $rocket; }); } diff --git a/tests/Plugin/Unipay/PreparePluginTest.php b/tests/Plugin/Unipay/PreparePluginTest.php index 4fb5753..e9dc009 100644 --- a/tests/Plugin/Unipay/PreparePluginTest.php +++ b/tests/Plugin/Unipay/PreparePluginTest.php @@ -33,12 +33,12 @@ class PreparePluginTest extends TestCase $payload = array_merge($params, [ 'version' => '5.1.0', 'encoding' => 'utf-8', - 'backUrl' => 'https://yansongda.cn/unipay/notify', + 'backUrl' => 'https://pay.yansongda.cn', 'accessType' => '0', 'signature' => '', 'signMethod' => '01', 'merId' => '777290058167151', - 'frontUrl' => 'https://yansongda.cn/unipay/return', + 'frontUrl' => 'https://pay.yansongda.cn', 'certId' => '69903319369', 'currencyCode' => '156', ]); diff --git a/tests/Plugin/Wechat/AddPayloadBodyPluginTest.php b/tests/Plugin/Wechat/AddPayloadBodyPluginTest.php new file mode 100644 index 0000000..07bcf45 --- /dev/null +++ b/tests/Plugin/Wechat/AddPayloadBodyPluginTest.php @@ -0,0 +1,68 @@ +plugin = new AddPayloadBodyPlugin(); + } + + public function testNormal() + { + $payload = [ + "name" => "yansongda", + 'age' => 30, + ]; + + $rocket = new Rocket(); + $rocket->setPayload(new Collection($payload)); + + $result = $this->plugin->assembly($rocket, function ($rocket) { return $rocket; }); + + self::assertSame((new JsonPacker())->pack($payload), $result->getPayload()->get('_body')); + } + + public function testUnderline() + { + $payload = [ + "name" => "yansongda", + '_age' => 30, + 'aaa' => null, + ]; + + $rocket = new Rocket(); + $rocket->setPayload(new Collection($payload)); + + $result = $this->plugin->assembly($rocket, function ($rocket) { return $rocket; }); + + unset($payload['_age'], $payload['aaa']); + + self::assertSame((new JsonPacker())->pack($payload), $result->getPayload()->get('_body')); + } + + public function testEmpty() + { + $payload = [ + '_age' => '30', + ]; + + $rocket = new Rocket(); + $rocket->setPayload(new Collection($payload)); + + $result = $this->plugin->assembly($rocket, function ($rocket) { return $rocket; }); + + self::assertSame('', $result->getPayload()->get('_body')); + } +} diff --git a/tests/Plugin/Wechat/RadarSignPluginTest.php b/tests/Plugin/Wechat/AddPayloadSignaturePluginTest.php similarity index 51% rename from tests/Plugin/Wechat/RadarSignPluginTest.php rename to tests/Plugin/Wechat/AddPayloadSignaturePluginTest.php index 4a1ec63..3e92291 100644 --- a/tests/Plugin/Wechat/RadarSignPluginTest.php +++ b/tests/Plugin/Wechat/AddPayloadSignaturePluginTest.php @@ -2,88 +2,64 @@ namespace Yansongda\Pay\Tests\Plugin\Wechat; -use GuzzleHttp\Psr7\Request; use ReflectionClass; use Yansongda\Pay\Contract\ConfigInterface; use Yansongda\Pay\Exception\Exception; use Yansongda\Pay\Exception\InvalidConfigException; use Yansongda\Pay\Packer\JsonPacker; -use Yansongda\Pay\Packer\XmlPacker; use Yansongda\Pay\Pay; -use Yansongda\Pay\Plugin\Wechat\RadarSignPlugin; -use Yansongda\Pay\Rocket; +use Yansongda\Pay\Plugin\Wechat\AddPayloadSignaturePlugin; use Yansongda\Pay\Tests\TestCase; use Yansongda\Supports\Collection; -use Yansongda\Supports\Str; +use function Yansongda\Pay\get_wechat_config; -class RadarSignPluginTest extends TestCase +class AddPayloadSignaturePluginTest extends TestCase { - protected RadarSignPlugin $plugin; + protected AddPayloadSignaturePlugin $plugin; protected function setUp(): void { parent::setUp(); - $this->plugin = new RadarSignPlugin(); + $this->plugin = new AddPayloadSignaturePlugin(); } - public function testNormal() + public function testGetSignatureContent() { + $timestamp = 1626493236; + $random = 'QqtzdVzxavZeXag9G5mtfzbfzFMf89p6'; $params = [ - 'name' => 'yansongda', - 'age' => 28, + 'out_trade_no' => 1626493236, + 'description' => 'yansongda 测试 - 1626493236', + 'amount' => [ + 'total' => 1, + ], + 'scene_info' => [ + 'payer_client_ip' => '127.0.0.1', + 'h5_info' => [ + 'type' => 'Wap', + ] + ], + 'appid' => "wx55955316af4ef13", + 'mchid' => "1600314069", + "notify_url" => "http://127.0.0.1:8000/wechat/notify", ]; - $rocket = (new Rocket())->setParams($params) - ->setPayload(new Collection($params)) - ->setRadar(new Request('GET', '127.0.0.1')); + $payload = new Collection([ + '_method' => 'POST', + '_url' => 'https://api.mch.weixin.qq.com/v3/pay/transactions/h5', + '_body' => (new JsonPacker())->pack($params), + ]); + $contents = "POST\n/v3/pay/transactions/h5\n1626493236\nQqtzdVzxavZeXag9G5mtfzbfzFMf89p6\n{\"out_trade_no\":1626493236,\"description\":\"yansongda 测试 - 1626493236\",\"amount\":{\"total\":1},\"scene_info\":{\"payer_client_ip\":\"127.0.0.1\",\"h5_info\":{\"type\":\"Wap\"}},\"appid\":\"wx55955316af4ef13\",\"mchid\":\"1600314069\",\"notify_url\":\"http:\/\/127.0.0.1:8000\/wechat\/notify\"}\n"; - $result = $this->plugin->assembly($rocket, function ($rocket) { return $rocket; }); - $radar = $result->getRadar(); + $class = new ReflectionClass($this->plugin); + $method = $class->getMethod('getSignatureContent'); - self::assertTrue($radar->hasHeader('Authorization')); - self::assertFalse($radar->hasHeader('Wechatpay-Serial')); - self::assertEquals(json_encode($params), (string) $radar->getBody()); + $result = $method->invokeArgs($this->plugin, [get_wechat_config($params), $payload, $timestamp, $random]); + + self::assertEquals($contents, $result); } - public function testNormalConstruct() - { - $this->plugin = new RadarSignPlugin(new JsonPacker(), new XmlPacker()); - - $params = [ - 'name' => 'yansongda', - 'age' => 28, - ]; - $rocket = (new Rocket())->setParams($params) - ->setPayload(new Collection($params)) - ->setRadar(new Request('GET', '127.0.0.1')); - - $result = $this->plugin->assembly($rocket, function ($rocket) { return $rocket; }); - $radar = $result->getRadar(); - - self::assertTrue($radar->hasHeader('Authorization')); - self::assertFalse($radar->hasHeader('Wechatpay-Serial')); - self::assertEquals(json_encode($params), (string) $radar->getBody()); - } - - public function testNormalWithWechatSerial() - { - $params = [ - '_serial_no' => 'yansongda', - 'name' => 'yansongda', - 'age' => 28, - ]; - $rocket = (new Rocket())->setParams($params) - ->setPayload(new Collection($params)) - ->setRadar(new Request('GET', '127.0.0.1')); - - $result = $this->plugin->assembly($rocket, function ($rocket) { return $rocket; }); - $radar = $result->getRadar(); - - self::assertTrue($radar->hasHeader('Authorization')); - self::assertTrue($radar->hasHeader('Wechatpay-Serial')); - } - - public function testGetWechatAuthorization() + public function testGetSignatureNormal() { $params = [ 'out_trade_no' => 1626493236, @@ -96,16 +72,16 @@ class RadarSignPluginTest extends TestCase 'h5_info' => [ 'type' => 'Wap', ] - ]]; + ] + ]; $timestamp = 1626493236; $random = 'QqtzdVzxavZeXag9G5mtfzbfzFMf89p6'; $contents = "POST\n/v3/pay/transactions/h5\n1626493236\nQqtzdVzxavZeXag9G5mtfzbfzFMf89p6\n{\"out_trade_no\":1626493236,\"description\":\"yansongda 测试 - 1626493236\",\"amount\":{\"total\":1},\"scene_info\":{\"payer_client_ip\":\"127.0.0.1\",\"h5_info\":{\"type\":\"Wap\"}},\"appid\":\"wx55955316af4ef13\",\"mchid\":\"1600314069\",\"notify_url\":\"http:\/\/127.0.0.1:8000\/wechat\/notify\"}\n"; $class = new ReflectionClass($this->plugin); - $method = $class->getMethod('v3GetWechatAuthorization'); - $method->setAccessible(true); + $method = $class->getMethod('getSignature'); - $result = $method->invokeArgs($this->plugin, [$params, $timestamp, $random, $contents]); + $result = $method->invokeArgs($this->plugin, [get_wechat_config($params), $timestamp, $random, $contents]); self::assertEquals( 'WECHATPAY2-SHA256-RSA2048 mchid="1600314069",nonce_str="QqtzdVzxavZeXag9G5mtfzbfzFMf89p6",timestamp="1626493236",serial_no="25F8AA5452D55497C24BA57DC81B1E5915DC2E77",signature="KzIgMgiop3nQJNdBVR2Xah/JUwVBLDFFajyXPiSN8b8YAYEA4FuWfaCgFJ52+WFed+PhOYWx/ZPih4RaEuuSdYB8eZwYUx7RZGMQZk0bKCctAjjPuf4pJN+f/WsXKjPIy3diqF5x7gyxwSCaKWP4/KjsHNqgQpiC8q1uC5xmElzuhzSwj88LIoLtkAuSmtUVvdAt0Nz41ECHZgHWSGR32TfBo902r8afdaVKkFde8IoqcEJJcp6sMxdDO5l9R5KEWxrJ1SjsXVrb0IPH8Nj7e6hfhq7pucxojPpzsC+ZWAYvufZkAQx3kTiFmY87T+QhkP9FesOfWvkIRL4E6MP6ug=="', @@ -113,7 +89,7 @@ class RadarSignPluginTest extends TestCase ); } - public function testGetWechatAuthorizationMissingMchPublicCert() + public function testGetSignatureMissingMchPublicCert() { $params = [ 'out_trade_no' => 1626493236, @@ -136,15 +112,14 @@ class RadarSignPluginTest extends TestCase self::expectException(InvalidConfigException::class); self::expectExceptionCode(Exception::CONFIG_WECHAT_INVALID); - self::expectExceptionMessage('Missing Wechat Config -- [mch_public_cert_path]'); + self::expectExceptionMessage('配置异常: 缺少微信配置 -- [mch_public_cert_path]'); $class = new ReflectionClass($this->plugin); - $method = $class->getMethod('v3GetWechatAuthorization'); - $method->setAccessible(true); - $method->invokeArgs($this->plugin, [$params, $timestamp, $random, $contents]); + $method = $class->getMethod('getSignature'); + $method->invokeArgs($this->plugin, [get_wechat_config($params), $timestamp, $random, $contents]); } - public function testGetWechatAuthorizationWrongMchPublicCert() + public function testGetSignatureWrongMchPublicCert() { $params = [ 'out_trade_no' => 1626493236, @@ -167,33 +142,10 @@ class RadarSignPluginTest extends TestCase self::expectException(InvalidConfigException::class); self::expectExceptionCode(Exception::CONFIG_WECHAT_INVALID); - self::expectExceptionMessage('Parse [mch_public_cert_path] Serial Number Error'); + self::expectExceptionMessage('配置异常: 解析微信配置 [mch_public_cert_path] 出错'); $class = new ReflectionClass($this->plugin); - $method = $class->getMethod('v3GetWechatAuthorization'); - $method->setAccessible(true); - $method->invokeArgs($this->plugin, [$params, $timestamp, $random, $contents]); - } - - public function testV2Normal() - { - $params = [ - 'name' => 'yansongda', - 'age' => 28, - ]; - $rocket = (new Rocket())->setParams(array_merge($params, ['_version' => 'v2'])) - ->setPayload(new Collection($params)) - ->setRadar(new Request('POST', '127.0.0.1')); - - $result = $this->plugin->assembly($rocket, function ($rocket) { return $rocket; }); - - $radar = $result->getRadar(); - $payload = $result->getPayload(); - - self::assertTrue($payload->has('sign')); - self::assertTrue($payload->has('nonce_str')); - self::assertTrue(Str::contains((string) $radar->getBody(), '')); - self::assertTrue(Str::contains((string) $radar->getBody(), '')); - self::assertTrue(Str::contains((string) $radar->getBody(), '')); + $method = $class->getMethod('getSignature'); + $method->invokeArgs($this->plugin, [get_wechat_config($params), $timestamp, $random, $contents]); } } diff --git a/tests/Plugin/Wechat/AddRadarPluginTest.php b/tests/Plugin/Wechat/AddRadarPluginTest.php new file mode 100644 index 0000000..a5905c0 --- /dev/null +++ b/tests/Plugin/Wechat/AddRadarPluginTest.php @@ -0,0 +1,60 @@ +plugin = new AddRadarPlugin(); + } + + public function testNormal() + { + $params = []; + $payload = new Collection([ + '_method' => 'POST', + '_url' => 'https://api.mch.weixin.qq.com/v3/pay/transactions/jsapi', + '_body' => '123', + '_authorization' => '456', + ]); + + $rocket = (new Rocket())->setParams($params)->setPayload($payload); + + $result = $this->plugin->assembly($rocket, function ($rocket) { return $rocket; }); + $radar = $result->getRadar(); + + self::assertTrue($radar->hasHeader('Authorization')); + self::assertFalse($radar->hasHeader('Wechatpay-Serial')); + self::assertEquals('123', (string) $radar->getBody()); + self::assertEquals('POST', $radar->getMethod()); + self::assertEquals('https://api.mch.weixin.qq.com/v3/pay/transactions/jsapi', (string) $radar->getUri()); + } + + public function testNormalWithWechatSerial() + { + $payload = new Collection([ + '_method' => 'POST', + '_url' => 'https://api.mch.weixin.qq.com/v3/pay/transactions/jsapi', + '_body' => '123', + '_authorization' => '456', + '_serial_no' => 'yansongda', + ]); + + $rocket = (new Rocket())->setParams([])->setPayload($payload); + + $result = $this->plugin->assembly($rocket, function ($rocket) { return $rocket; }); + $radar = $result->getRadar(); + + self::assertTrue($radar->hasHeader('Wechatpay-Serial')); + } +} diff --git a/tests/Plugin/Wechat/CallbackPluginTest.php b/tests/Plugin/Wechat/CallbackPluginTest.php index d372d18..246e1d3 100644 --- a/tests/Plugin/Wechat/CallbackPluginTest.php +++ b/tests/Plugin/Wechat/CallbackPluginTest.php @@ -10,10 +10,7 @@ use Yansongda\Supports\Collection; class CallbackPluginTest extends TestCase { - /** - * @var \Yansongda\Pay\Plugin\Wechat\CallbackPlugin - */ - protected $plugin; + protected CallbackPlugin $plugin; protected function setUp(): void { @@ -44,7 +41,7 @@ class CallbackPluginTest extends TestCase ); $rocket = (new Rocket()) - ->setParams(['request' => $request]); + ->setParams(['_request' => $request]); $result = $this->plugin->assembly($rocket, function ($rocket) { return $rocket; }); diff --git a/tests/Plugin/Wechat/Ecommerce/Refund/ApplyPluginTest.php b/tests/Plugin/Wechat/Ecommerce/Refund/ApplyPluginTest.php deleted file mode 100644 index 569c941..0000000 --- a/tests/Plugin/Wechat/Ecommerce/Refund/ApplyPluginTest.php +++ /dev/null @@ -1,112 +0,0 @@ -plugin = new ApplyPlugin(); - } - - public function testNotInServiceMode() - { - $rocket = new Rocket(); - $rocket->setParams([])->setPayload(new Collection()); - - $this->expectException(InvalidParamsException::class); - $this->expectExceptionCode(Exception::PARAMS_PLUGIN_ONLY_SUPPORT_SERVICE_MODE); - - $this->plugin->assembly($rocket, function ($rocket) {return $rocket; }); - } - - public function testNormal() - { - $rocket = new Rocket(); - $rocket->setParams(['_config' => 'service_provider'])->setPayload(new Collection([ - 'transaction_id' => '123', - 'out_refund_no' => '456', - 'amount' => [ - 'refund' => 1, - 'total' => 1, - 'currency' => 'CNY', - ], - ])); - - $result = $this->plugin->assembly($rocket, function ($rocket) {return $rocket; }); - - $payload = $result->getPayload(); - $radar = $result->getRadar(); - - self::assertEquals('POST', $radar->getMethod()); - self::assertEquals(new Uri(Wechat::URL[Pay::MODE_NORMAL].'v3/ecommerce/refunds/apply'), $radar->getUri()); - self::assertEquals('wx55955316af4ef13', $payload->get('sp_appid')); - self::assertEquals('1600314070', $payload->get('sub_mchid')); - self::assertEquals('123', $payload->get('transaction_id')); - self::assertEquals('456', $payload->get('out_refund_no')); - self::assertEquals([ - 'refund' => 1, - 'total' => 1, - 'currency' => 'CNY', - ], $payload->get('amount')); - } - - public function testPartnerDirectPayload() - { - $rocket = new Rocket(); - $rocket->setParams(['_config' => 'service_provider'])->setPayload(new Collection([ - 'test' => 'yansongda', - 'sub_mchid' => '123', - 'sp_appid' => '456', - ])); - - $result = $this->plugin->assembly($rocket, function ($rocket) {return $rocket; }); - - $payload = $result->getPayload(); - $radar = $result->getRadar(); - - self::assertEquals('POST', $radar->getMethod()); - self::assertEquals(new Uri(Wechat::URL[Pay::MODE_NORMAL].'v3/ecommerce/refunds/apply'), $radar->getUri()); - self::assertEquals('456', $payload->get('sp_appid')); - self::assertEquals('123', $payload->get('sub_mchid')); - self::assertEquals('yansongda', $payload->get('test')); - self::assertCount(4, $payload->all()); - } - - public function testPartnerType() - { - $rocket = new Rocket(); - $rocket->setParams(['_config' => 'service_provider', '_type' => 'mini'])->setPayload(new Collection([ - 'test' => 'yansongda', - ])); - - $result = $this->plugin->assembly($rocket, function ($rocket) {return $rocket; }); - - $payload = $result->getPayload(); - $radar = $result->getRadar(); - - self::assertEquals('POST', $radar->getMethod()); - self::assertEquals(new Uri(Wechat::URL[Pay::MODE_NORMAL].'v3/ecommerce/refunds/apply'), $radar->getUri()); - self::assertEquals('wx55955316af4ef14', $payload->get('sp_appid')); - self::assertEquals('1600314070', $payload->get('sub_mchid')); - self::assertEquals('yansongda', $payload->get('test')); - self::assertCount(4, $payload->all()); - } -} diff --git a/tests/Plugin/Wechat/Ecommerce/Refund/QueryPluginTest.php b/tests/Plugin/Wechat/Ecommerce/Refund/QueryPluginTest.php deleted file mode 100644 index 4c91a1b..0000000 --- a/tests/Plugin/Wechat/Ecommerce/Refund/QueryPluginTest.php +++ /dev/null @@ -1,76 +0,0 @@ -plugin = new QueryPlugin(); - } - - public function testNotInServiceMode() - { - $rocket = new Rocket(); - $rocket->setParams([])->setPayload(new Collection()); - - $this->expectException(InvalidParamsException::class); - $this->expectExceptionCode(Exception::PARAMS_PLUGIN_ONLY_SUPPORT_SERVICE_MODE); - - $this->plugin->assembly($rocket, function ($rocket) {return $rocket; }); - } - - public function testMissingParams() - { - $rocket = new Rocket(); - $rocket->setParams(['_config' => 'service_provider'])->setPayload(new Collection()); - - $this->expectException(InvalidParamsException::class); - $this->expectExceptionCode(Exception::PARAMS_NECESSARY_PARAMS_MISSING); - - $this->plugin->assembly($rocket, function ($rocket) {return $rocket; }); - } - - public function testPartnerRefundId() - { - $rocket = new Rocket(); - $rocket->setParams(['_config' => 'service_provider'])->setPayload(new Collection(['refund_id' => '123'])); - - $result = $this->plugin->assembly($rocket, function ($rocket) {return $rocket; }); - - $radar = $result->getRadar(); - - self::assertEquals(new Uri(Wechat::URL[Pay::MODE_SERVICE].'v3/ecommerce/refunds/id/123?sub_mchid=1600314070'), $radar->getUri()); - self::assertEquals('GET', $radar->getMethod()); - } - - public function testPartnerOutRefundNo() - { - $rocket = new Rocket(); - $rocket->setParams(['_config' => 'service_provider'])->setPayload(new Collection(['out_refund_no' => '123'])); - - $result = $this->plugin->assembly($rocket, function ($rocket) {return $rocket; }); - - $radar = $result->getRadar(); - - self::assertEquals(new Uri(Wechat::URL[Pay::MODE_SERVICE].'v3/ecommerce/refunds/out-refund-no/123?sub_mchid=1600314070'), $radar->getUri()); - self::assertEquals('GET', $radar->getMethod()); - } -} diff --git a/tests/Plugin/Wechat/Ecommerce/Refund/QueryReturnAdvancePluginTest.php b/tests/Plugin/Wechat/Ecommerce/Refund/QueryReturnAdvancePluginTest.php deleted file mode 100644 index 31a9071..0000000 --- a/tests/Plugin/Wechat/Ecommerce/Refund/QueryReturnAdvancePluginTest.php +++ /dev/null @@ -1,63 +0,0 @@ -plugin = new QueryReturnAdvancePlugin(); - } - - public function testNotInServiceMode() - { - $rocket = new Rocket(); - $rocket->setParams([])->setPayload(new Collection()); - - $this->expectException(InvalidParamsException::class); - $this->expectExceptionCode(Exception::PARAMS_PLUGIN_ONLY_SUPPORT_SERVICE_MODE); - - $this->plugin->assembly($rocket, function ($rocket) {return $rocket; }); - } - - public function testMissingRefundId() - { - $rocket = new Rocket(); - $rocket->setParams(['_config' => 'service_provider'])->setPayload(new Collection()); - - $this->expectException(InvalidParamsException::class); - $this->expectExceptionCode(Exception::PARAMS_NECESSARY_PARAMS_MISSING); - - $this->plugin->assembly($rocket, function ($rocket) {return $rocket; }); - } - - public function testNormal() - { - $rocket = new Rocket(); - $rocket->setParams(['_config' => 'service_provider'])->setPayload(new Collection(['refund_id' => '123'])); - - $result = $this->plugin->assembly($rocket, function ($rocket) { return $rocket; }); - - $radar = $result->getRadar(); - - self::assertEquals(new Uri(Wechat::URL[Pay::MODE_SERVICE].'v3/ecommerce/refunds/123/return-advance?sub_mchid=1600314070'), $radar->getUri()); - self::assertEquals('GET', $radar->getMethod()); - } -} diff --git a/tests/Plugin/Wechat/Ecommerce/Refund/ReturnAdvancePluginTest.php b/tests/Plugin/Wechat/Ecommerce/Refund/ReturnAdvancePluginTest.php deleted file mode 100644 index fdb03ab..0000000 --- a/tests/Plugin/Wechat/Ecommerce/Refund/ReturnAdvancePluginTest.php +++ /dev/null @@ -1,65 +0,0 @@ -plugin = new ReturnAdvancePlugin(); - } - - public function testNotInServiceMode() - { - $rocket = new Rocket(); - $rocket->setParams([])->setPayload(new Collection()); - - $this->expectException(InvalidParamsException::class); - $this->expectExceptionCode(Exception::PARAMS_PLUGIN_ONLY_SUPPORT_SERVICE_MODE); - - $this->plugin->assembly($rocket, function ($rocket) {return $rocket; }); - } - - public function testMissingParams() - { - $rocket = new Rocket(); - $rocket->setParams(['_config' => 'service_provider'])->setPayload(new Collection()); - - $this->expectException(InvalidParamsException::class); - $this->expectExceptionCode(Exception::PARAMS_NECESSARY_PARAMS_MISSING); - - $this->plugin->assembly($rocket, function ($rocket) {return $rocket; }); - } - - public function testNormal() - { - $rocket = new Rocket(); - $rocket->setParams(['_config' => 'service_provider'])->setPayload(new Collection(['refund_id' => '123'])); - - $result = $this->plugin->assembly($rocket, function ($rocket) {return $rocket; }); - - $radar = $result->getRadar(); - $payload = $result->getPayload(); - - self::assertEquals(new Uri(Wechat::URL[Pay::MODE_SERVICE].'v3/ecommerce/refunds/123/return-advance'), $radar->getUri()); - self::assertEquals('1600314070', $payload->get('sub_mchid')); - self::assertArrayNotHasKey('refund_id', $payload->all()); - } -} diff --git a/tests/Plugin/Wechat/Extend/Complaints/CompletePluginTest.php b/tests/Plugin/Wechat/Extend/Complaints/CompletePluginTest.php new file mode 100644 index 0000000..1577fe3 --- /dev/null +++ b/tests/Plugin/Wechat/Extend/Complaints/CompletePluginTest.php @@ -0,0 +1,72 @@ +plugin = new CompletePlugin(); + } + + public function testEmptyComplaintId() + { + $rocket = new Rocket(); + + self::expectException(InvalidParamsException::class); + self::expectExceptionCode(Exception::PARAMS_NECESSARY_PARAMS_MISSING); + self::expectExceptionMessage('参数异常: 反馈处理完成,参数缺少 `complaint_id`'); + + $this->plugin->assembly($rocket, function ($rocket) { return $rocket; }); + } + + public function testPayloadMchIdEmpty() + { + $payload = [ + "complaint_id" => "yansongda", + ]; + + $rocket = new Rocket(); + $rocket->setPayload(new Collection($payload)); + + $result = $this->plugin->assembly($rocket, function ($rocket) { return $rocket; }); + + self::assertEquals([ + '_method' => 'POST', + '_url' => 'v3/merchant-service/complaints-v2/yansongda/complete', + '_service_url' => 'v3/merchant-service/complaints-v2/yansongda/complete', + 'complainted_mchid' => '1600314069', + ], $result->getPayload()->all()); + } + + public function testPayloadMchIdNotEmpty() + { + $payload = [ + "complaint_id" => "yansongda", + 'complainted_mchid' => '123', + ]; + + $rocket = new Rocket(); + $rocket->setPayload(new Collection($payload)); + + $result = $this->plugin->assembly($rocket, function ($rocket) { return $rocket; }); + + self::assertEquals([ + '_method' => 'POST', + '_url' => 'v3/merchant-service/complaints-v2/yansongda/complete', + '_service_url' => 'v3/merchant-service/complaints-v2/yansongda/complete', + 'complainted_mchid' => '123', + ], $result->getPayload()->all()); + } +} diff --git a/tests/Plugin/Wechat/Extend/Complaints/DeleteCallbackPluginTest.php b/tests/Plugin/Wechat/Extend/Complaints/DeleteCallbackPluginTest.php new file mode 100644 index 0000000..ce50caa --- /dev/null +++ b/tests/Plugin/Wechat/Extend/Complaints/DeleteCallbackPluginTest.php @@ -0,0 +1,32 @@ +plugin = new DeleteCallbackPlugin(); + } + + public function testNormal() + { + $rocket = new Rocket(); + + $result = $this->plugin->assembly($rocket, function ($rocket) { return $rocket; }); + + self::assertEquals([ + '_method' => 'DELETE', + '_url' => 'v3/merchant-service/complaint-notifications', + '_service_url' => 'v3/merchant-service/complaint-notifications', + ], $result->getPayload()->all()); + } +} diff --git a/tests/Plugin/Wechat/Extend/Complaints/QueryCallbackPluginTest.php b/tests/Plugin/Wechat/Extend/Complaints/QueryCallbackPluginTest.php new file mode 100644 index 0000000..94e8f36 --- /dev/null +++ b/tests/Plugin/Wechat/Extend/Complaints/QueryCallbackPluginTest.php @@ -0,0 +1,32 @@ +plugin = new QueryCallbackPlugin(); + } + + public function testNormal() + { + $rocket = new Rocket(); + + $result = $this->plugin->assembly($rocket, function ($rocket) { return $rocket; }); + + self::assertEquals([ + '_method' => 'GET', + '_url' => 'v3/merchant-service/complaint-notifications', + '_service_url' => 'v3/merchant-service/complaint-notifications', + ], $result->getPayload()->all()); + } +} diff --git a/tests/Plugin/Wechat/Extend/Complaints/QueryDetailPluginTest.php b/tests/Plugin/Wechat/Extend/Complaints/QueryDetailPluginTest.php new file mode 100644 index 0000000..792abf9 --- /dev/null +++ b/tests/Plugin/Wechat/Extend/Complaints/QueryDetailPluginTest.php @@ -0,0 +1,51 @@ +plugin = new QueryDetailPlugin(); + } + + public function testEmptyComplaintId() + { + $rocket = new Rocket(); + + self::expectException(InvalidParamsException::class); + self::expectExceptionCode(Exception::PARAMS_NECESSARY_PARAMS_MISSING); + self::expectExceptionMessage('参数异常: 查询投诉单详情,参数缺少 `complaint_id`'); + + $this->plugin->assembly($rocket, function ($rocket) { return $rocket; }); + } + + public function testNormal() + { + $payload = [ + "complaint_id" => "yansongda", + ]; + + $rocket = new Rocket(); + $rocket->setPayload(new Collection($payload)); + + $result = $this->plugin->assembly($rocket, function ($rocket) { return $rocket; }); + + self::assertEquals([ + '_method' => 'GET', + '_url' => 'v3/merchant-service/complaints-v2/yansongda', + '_service_url' => 'v3/merchant-service/complaints-v2/yansongda', + ], $result->getPayload()->all()); + } +} diff --git a/tests/Plugin/Wechat/Extend/Complaints/QueryImagePluginTest.php b/tests/Plugin/Wechat/Extend/Complaints/QueryImagePluginTest.php new file mode 100644 index 0000000..9828d00 --- /dev/null +++ b/tests/Plugin/Wechat/Extend/Complaints/QueryImagePluginTest.php @@ -0,0 +1,51 @@ +plugin = new QueryImagePlugin(); + } + + public function testEmptyMediaId() + { + $rocket = new Rocket(); + + self::expectException(InvalidParamsException::class); + self::expectExceptionCode(Exception::PARAMS_NECESSARY_PARAMS_MISSING); + self::expectExceptionMessage('参数异常: 图片请求接口,参数缺少 `media_id`'); + + $this->plugin->assembly($rocket, function ($rocket) { return $rocket; }); + } + + public function testNormal() + { + $payload = [ + "media_id" => "yansongda", + ]; + + $rocket = new Rocket(); + $rocket->setPayload(new Collection($payload)); + + $result = $this->plugin->assembly($rocket, function ($rocket) { return $rocket; }); + + self::assertEquals([ + '_method' => 'GET', + '_url' => 'v3/merchant-service/images/yansongda', + '_service_url' => 'v3/merchant-service/images/yansongda', + ], $result->getPayload()->all()); + } +} diff --git a/tests/Plugin/Wechat/Extend/Complaints/QueryNegotiationPluginTest.php b/tests/Plugin/Wechat/Extend/Complaints/QueryNegotiationPluginTest.php new file mode 100644 index 0000000..ab1ff92 --- /dev/null +++ b/tests/Plugin/Wechat/Extend/Complaints/QueryNegotiationPluginTest.php @@ -0,0 +1,71 @@ +plugin = new QueryNegotiationPlugin(); + } + + public function testEmptyComplaintId() + { + $rocket = new Rocket(); + + self::expectException(InvalidParamsException::class); + self::expectExceptionCode(Exception::PARAMS_NECESSARY_PARAMS_MISSING); + self::expectExceptionMessage('参数异常: 查询投诉单协商历史,参数缺少 `complaint_id`'); + + $this->plugin->assembly($rocket, function ($rocket) { return $rocket; }); + } + + public function testQueryEmpty() + { + $payload = [ + "complaint_id" => "yansongda", + ]; + + $rocket = new Rocket(); + $rocket->setPayload(new Collection($payload)); + + $result = $this->plugin->assembly($rocket, function ($rocket) { return $rocket; }); + + self::assertEquals([ + '_method' => 'GET', + '_url' => 'v3/merchant-service/complaints-v2/yansongda/negotiation-historys', + '_service_url' => 'v3/merchant-service/complaints-v2/yansongda/negotiation-historys', + ], $result->getPayload()->all()); + } + + public function testQueryNotEmpty() + { + $payload = [ + "complaint_id" => "yansongda", + 'limit' => 2, + 'offset' => 3, + ]; + + $rocket = new Rocket(); + $rocket->setPayload(new Collection($payload)); + + $result = $this->plugin->assembly($rocket, function ($rocket) { return $rocket; }); + + self::assertEquals([ + '_method' => 'GET', + '_url' => 'v3/merchant-service/complaints-v2/yansongda/negotiation-historys?limit=2&offset=3', + '_service_url' => 'v3/merchant-service/complaints-v2/yansongda/negotiation-historys?limit=2&offset=3', + ], $result->getPayload()->all()); + } +} diff --git a/tests/Plugin/Wechat/Extend/Complaints/QueryPluginTest.php b/tests/Plugin/Wechat/Extend/Complaints/QueryPluginTest.php new file mode 100644 index 0000000..d6fd550 --- /dev/null +++ b/tests/Plugin/Wechat/Extend/Complaints/QueryPluginTest.php @@ -0,0 +1,54 @@ +plugin = new QueryPlugin(); + } + + public function testEmptyComplaintId() + { + $rocket = new Rocket(); + + self::expectException(InvalidParamsException::class); + self::expectExceptionCode(Exception::PARAMS_NECESSARY_PARAMS_MISSING); + self::expectExceptionMessage('参数异常: 查询投诉单列表,缺少必要参数'); + + $this->plugin->assembly($rocket, function ($rocket) { return $rocket; }); + } + + public function testNormal() + { + $payload = [ + 'limit' => 2, + 'offset' => 3, + 'begin_date' => '2021-06-06', + 'end_date' => '2021-06-07', + ]; + + $rocket = new Rocket(); + $rocket->setPayload(new Collection($payload)); + + $result = $this->plugin->assembly($rocket, function ($rocket) { return $rocket; }); + + self::assertEquals([ + '_method' => 'GET', + '_url' => 'v3/merchant-service/complaints-v2?limit=2&offset=3&begin_date=2021-06-06&end_date=2021-06-07', + '_service_url' => 'v3/merchant-service/complaints-v2?limit=2&offset=3&begin_date=2021-06-06&end_date=2021-06-07', + ], $result->getPayload()->all()); + } +} diff --git a/tests/Plugin/Wechat/Extend/Complaints/ResponsePluginTest.php b/tests/Plugin/Wechat/Extend/Complaints/ResponsePluginTest.php new file mode 100644 index 0000000..ac3fedb --- /dev/null +++ b/tests/Plugin/Wechat/Extend/Complaints/ResponsePluginTest.php @@ -0,0 +1,96 @@ +plugin = new ResponsePlugin(); + } + + public function testEmptyComplaintId() + { + $rocket = new Rocket(); + + self::expectException(InvalidParamsException::class); + self::expectExceptionCode(Exception::PARAMS_NECESSARY_PARAMS_MISSING); + self::expectExceptionMessage('参数异常: 回复用户,参数缺少 `complaint_id`'); + + $this->plugin->assembly($rocket, function ($rocket) { return $rocket; }); + } + + public function testPayloadMchIdEmpty() + { + $payload = [ + "complaint_id" => "yansongda", + ]; + + $rocket = new Rocket(); + $rocket->setPayload(new Collection($payload)); + + $result = $this->plugin->assembly($rocket, function ($rocket) { return $rocket; }); + + self::assertEquals([ + '_method' => 'POST', + '_url' => 'v3/merchant-service/complaints-v2/yansongda/response', + '_service_url' => 'v3/merchant-service/complaints-v2/yansongda/response', + 'complainted_mchid' => '1600314069', + ], $result->getPayload()->all()); + } + + public function testPayloadMchIdNotEmpty() + { + $payload = [ + "complaint_id" => "yansongda", + 'complainted_mchid' => '123', + ]; + + $rocket = new Rocket(); + $rocket->setPayload(new Collection($payload)); + + $result = $this->plugin->assembly($rocket, function ($rocket) { return $rocket; }); + + self::assertEquals([ + '_method' => 'POST', + '_url' => 'v3/merchant-service/complaints-v2/yansongda/response', + '_service_url' => 'v3/merchant-service/complaints-v2/yansongda/response', + 'complainted_mchid' => '123', + ], $result->getPayload()->all()); + } + + public function testPayloadOthers() + { + $payload = [ + "complaint_id" => "yansongda", + 'complainted_mchid' => '123', + 'name' => 'yansongda', + 'test' => 'abc', + ]; + + $rocket = new Rocket(); + $rocket->setPayload(new Collection($payload)); + + $result = $this->plugin->assembly($rocket, function ($rocket) { return $rocket; }); + + self::assertEquals([ + '_method' => 'POST', + '_url' => 'v3/merchant-service/complaints-v2/yansongda/response', + '_service_url' => 'v3/merchant-service/complaints-v2/yansongda/response', + 'complainted_mchid' => '123', + 'name' => 'yansongda', + 'test' => 'abc', + ], $result->getPayload()->all()); + } +} diff --git a/tests/Plugin/Wechat/Extend/Complaints/SetCallbackPluginTest.php b/tests/Plugin/Wechat/Extend/Complaints/SetCallbackPluginTest.php new file mode 100644 index 0000000..418ba6a --- /dev/null +++ b/tests/Plugin/Wechat/Extend/Complaints/SetCallbackPluginTest.php @@ -0,0 +1,39 @@ +plugin = new SetCallbackPlugin(); + } + + public function testNormal() + { + $payload = [ + "url" => "yansongda", + ]; + + $rocket = new Rocket(); + $rocket->setPayload(new Collection($payload)); + + $result = $this->plugin->assembly($rocket, function ($rocket) { return $rocket; }); + + self::assertEquals([ + '_method' => 'POST', + '_url' => 'v3/merchant-service/complaint-notifications', + '_service_url' => 'v3/merchant-service/complaint-notifications', + 'url' => 'yansongda', + ], $result->getPayload()->all()); + } +} diff --git a/tests/Plugin/Wechat/Extend/Complaints/UpdateCallbackPluginTest.php b/tests/Plugin/Wechat/Extend/Complaints/UpdateCallbackPluginTest.php new file mode 100644 index 0000000..d223035 --- /dev/null +++ b/tests/Plugin/Wechat/Extend/Complaints/UpdateCallbackPluginTest.php @@ -0,0 +1,39 @@ +plugin = new UpdateCallbackPlugin(); + } + + public function testNormal() + { + $payload = [ + "url" => "yansongda", + ]; + + $rocket = new Rocket(); + $rocket->setPayload(new Collection($payload)); + + $result = $this->plugin->assembly($rocket, function ($rocket) { return $rocket; }); + + self::assertEquals([ + '_method' => 'PUT', + '_url' => 'v3/merchant-service/complaint-notifications', + '_service_url' => 'v3/merchant-service/complaint-notifications', + 'url' => 'yansongda', + ], $result->getPayload()->all()); + } +} diff --git a/tests/Plugin/Wechat/Extend/Complaints/UpdateRefundPluginTest.php b/tests/Plugin/Wechat/Extend/Complaints/UpdateRefundPluginTest.php new file mode 100644 index 0000000..8545dc6 --- /dev/null +++ b/tests/Plugin/Wechat/Extend/Complaints/UpdateRefundPluginTest.php @@ -0,0 +1,57 @@ +plugin = new UpdateRefundPlugin(); + } + + public function testEmptyComplaintId() + { + $rocket = new Rocket(); + + self::expectException(InvalidParamsException::class); + self::expectExceptionCode(Exception::PARAMS_NECESSARY_PARAMS_MISSING); + self::expectExceptionMessage('参数异常: 更新退款审批结果,参数缺少 `complaint_id`'); + + $this->plugin->assembly($rocket, function ($rocket) { return $rocket; }); + } + + public function testPayload() + { + $payload = [ + "complaint_id" => "yansongda", + 'action' => 'APPROVE', + 'name' => 'yansongda', + ]; + + $rocket = new Rocket(); + $rocket->setPayload(new Collection($payload)); + + $result = $this->plugin->assembly($rocket, function ($rocket) { return $rocket; }); + + self::assertEquals([ + '_method' => 'POST', + '_url' => 'v3/merchant-service/complaints-v2/yansongda/update-refund-progress', + '_service_url' => 'v3/merchant-service/complaints-v2/yansongda/update-refund-progress', + 'action' => 'APPROVE', + 'name' => 'yansongda', + ], $result->getPayload()->all()); + } + +} diff --git a/tests/Plugin/Wechat/Extend/ProfitSharing/AddReceiverPluginTest.php b/tests/Plugin/Wechat/Extend/ProfitSharing/AddReceiverPluginTest.php new file mode 100644 index 0000000..bc8162e --- /dev/null +++ b/tests/Plugin/Wechat/Extend/ProfitSharing/AddReceiverPluginTest.php @@ -0,0 +1,154 @@ +plugin = new AddReceiverPlugin(); + } + + public function testEmptyPayload() + { + $rocket = new Rocket(); + + self::expectException(InvalidParamsException::class); + self::expectExceptionCode(Exception::PARAMS_NECESSARY_PARAMS_MISSING); + self::expectExceptionMessage('参数异常: 缺少分账参数'); + + $this->plugin->assembly($rocket, function ($rocket) { return $rocket; }); + } + + public function testNormalWithoutName() + { + $rocket = new Rocket(); + $rocket->setPayload(new Collection( [ + "test" => "yansongda", + ])); + + $result = $this->plugin->assembly($rocket, function ($rocket) { return $rocket; }); + + self::assertEquals([ + '_method' => 'POST', + '_url' => 'v3/profitsharing/receivers/add', + '_service_url' => 'v3/profitsharing/receivers/add', + 'test' => 'yansongda', + 'appid' => 'wx55955316af4ef13', + ], $result->getPayload()->all()); + } + + public function testNormalWithName() + { + $rocket = new Rocket(); + $rocket->setPayload(new Collection([ + "name" => "yansongda", + ])); + + $result = $this->plugin->assembly($rocket, function ($rocket) { + return $rocket; + }); + + $payload = $result->getPayload()->all(); + self::assertEquals('POST', $payload['_method']); + self::assertEquals('v3/profitsharing/receivers/add', $payload['_url']); + self::assertEquals('v3/profitsharing/receivers/add', $payload['_service_url']); + self::assertEquals('wx55955316af4ef13', $payload['appid']); + self::assertArrayHasKey('_serial_no', $payload); + self::assertArrayHasKey('name', $payload); + self::assertNotEquals('yansongda', $payload['name']); + } + + public function testServiceParams() + { + $rocket = new Rocket(); + $rocket->setParams(['_config' => 'service_provider'])->setPayload(new Collection([ + "test" => "yansongda", + 'sub_mchid' => '2222', + ])); + + $result = $this->plugin->assembly($rocket, function ($rocket) { return $rocket; }); + + self::assertEquals([ + '_method' => 'POST', + '_url' => 'v3/profitsharing/receivers/add', + '_service_url' => 'v3/profitsharing/receivers/add', + 'test' => 'yansongda', + 'appid' => 'wx55955316af4ef13', + 'sub_mchid' => '2222', + ], $result->getPayload()->all()); + } + + public function testServiceWithoutName() + { + $rocket = new Rocket(); + $rocket->setParams(['_config' => 'service_provider'])->setPayload(new Collection( [ + "test" => "yansongda", + ])); + + $result = $this->plugin->assembly($rocket, function ($rocket) { return $rocket; }); + + self::assertEquals([ + '_method' => 'POST', + '_url' => 'v3/profitsharing/receivers/add', + '_service_url' => 'v3/profitsharing/receivers/add', + 'test' => 'yansongda', + 'appid' => 'wx55955316af4ef13', + 'sub_mchid' => '1600314070', + ], $result->getPayload()->all()); + } + + public function testServiceWithName() + { + $rocket = new Rocket(); + $rocket->setParams(['_config' => 'service_provider'])->setPayload(new Collection([ + "name" => "yansongda", + ])); + + $result = $this->plugin->assembly($rocket, function ($rocket) { + return $rocket; + }); + + $payload = $result->getPayload()->all(); + self::assertEquals('POST', $payload['_method']); + self::assertEquals('v3/profitsharing/receivers/add', $payload['_url']); + self::assertEquals('v3/profitsharing/receivers/add', $payload['_service_url']); + self::assertEquals('wx55955316af4ef13', $payload['appid']); + self::assertArrayHasKey('_serial_no', $payload); + self::assertArrayHasKey('name', $payload); + self::assertNotEquals('yansongda', $payload['name']); + } + + public function testWithSubAppId() + { + $rocket = new Rocket(); + $rocket->setParams(['_config' => 'service_provider'])->setPayload(new Collection( [ + "test" => "yansongda", + 'type' => 'PERSONAL_SUB_OPENID', + ])); + + $result = $this->plugin->assembly($rocket, function ($rocket) { return $rocket; }); + + self::assertEquals([ + '_method' => 'POST', + '_url' => 'v3/profitsharing/receivers/add', + '_service_url' => 'v3/profitsharing/receivers/add', + 'test' => 'yansongda', + 'appid' => 'wx55955316af4ef13', + 'sub_mchid' => '1600314070', + 'sub_appid' => 'wx55955316af4ef15', + 'type' => 'PERSONAL_SUB_OPENID', + ], $result->getPayload()->all()); + } +} diff --git a/tests/Plugin/Wechat/Extend/ProfitSharing/CreatePluginTest.php b/tests/Plugin/Wechat/Extend/ProfitSharing/CreatePluginTest.php new file mode 100644 index 0000000..462a337 --- /dev/null +++ b/tests/Plugin/Wechat/Extend/ProfitSharing/CreatePluginTest.php @@ -0,0 +1,170 @@ +plugin = new CreatePlugin(); + } + + public function testEmptyPayload() + { + $rocket = new Rocket(); + + self::expectException(InvalidParamsException::class); + self::expectExceptionCode(Exception::PARAMS_NECESSARY_PARAMS_MISSING); + self::expectExceptionMessage('参数异常: 缺少分账参数'); + + $this->plugin->assembly($rocket, function ($rocket) { return $rocket; }); + } + + public function testNormalWithoutName() + { + $rocket = new Rocket(); + $rocket->setPayload(new Collection( [ + "test" => "yansongda", + ])); + + $result = $this->plugin->assembly($rocket, function ($rocket) { return $rocket; }); + + self::assertEquals([ + '_method' => 'POST', + '_url' => 'v3/profitsharing/orders', + '_service_url' => 'v3/profitsharing/orders', + 'test' => 'yansongda', + 'appid' => 'wx55955316af4ef13', + ], $result->getPayload()->all()); + } + + public function testNormalWithName() + { + $rocket = new Rocket(); + $rocket->setPayload(new Collection([ + 'receivers' => [ + [ + 'name' => 'yansongda', + ], + ], + ])); + + $result = $this->plugin->assembly($rocket, function ($rocket) { + return $rocket; + }); + + $payload = $result->getPayload()->all(); + self::assertEquals('POST', $payload['_method']); + self::assertEquals('v3/profitsharing/orders', $payload['_url']); + self::assertEquals('v3/profitsharing/orders', $payload['_service_url']); + self::assertEquals('wx55955316af4ef13', $payload['appid']); + self::assertArrayHasKey('_serial_no', $payload); + self::assertArrayHasKey('name', $payload['receivers'][0]); + self::assertNotEquals('yansongda', $payload['receivers'][0]['name']); + } + + public function testServiceParams() + { + $rocket = new Rocket(); + $rocket->setParams(['_config' => 'service_provider'])->setPayload(new Collection( [ + "test" => "yansongda", + 'sub_mchid' => '2222', + ])); + + $result = $this->plugin->assembly($rocket, function ($rocket) { return $rocket; }); + + self::assertEquals([ + '_method' => 'POST', + '_url' => 'v3/profitsharing/orders', + '_service_url' => 'v3/profitsharing/orders', + 'test' => 'yansongda', + 'appid' => 'wx55955316af4ef13', + 'sub_mchid' => '2222', + ], $result->getPayload()->all()); + } + + public function testServiceWithoutName() + { + $rocket = new Rocket(); + $rocket->setParams(['_config' => 'service_provider'])->setPayload(new Collection( [ + "test" => "yansongda", + ])); + + $result = $this->plugin->assembly($rocket, function ($rocket) { return $rocket; }); + + self::assertEquals([ + '_method' => 'POST', + '_url' => 'v3/profitsharing/orders', + '_service_url' => 'v3/profitsharing/orders', + 'test' => 'yansongda', + 'appid' => 'wx55955316af4ef13', + 'sub_mchid' => '1600314070', + ], $result->getPayload()->all()); + } + + public function testServiceWithName() + { + $rocket = new Rocket(); + $rocket->setParams(['_config' => 'service_provider'])->setPayload(new Collection([ + 'receivers' => [ + [ + 'name' => 'yansongda', + ], + ], + ])); + + $result = $this->plugin->assembly($rocket, function ($rocket) { + return $rocket; + }); + + $payload = $result->getPayload()->all(); + self::assertEquals('POST', $payload['_method']); + self::assertEquals('v3/profitsharing/orders', $payload['_url']); + self::assertEquals('v3/profitsharing/orders', $payload['_service_url']); + self::assertEquals('wx55955316af4ef13', $payload['appid']); + self::assertArrayHasKey('_serial_no', $payload); + self::assertArrayHasKey('name', $payload['receivers'][0]); + self::assertNotEquals('yansongda', $payload['receivers'][0]['name']); + } + + public function testWithSubAppId() + { + $rocket = new Rocket(); + $rocket->setParams(['_config' => 'service_provider'])->setPayload(new Collection( [ + "test" => "yansongda", + 'receivers' => [ + [ + 'type' => 'PERSONAL_SUB_OPENID', + ], + ], + ])); + + $result = $this->plugin->assembly($rocket, function ($rocket) { return $rocket; }); + + self::assertEquals([ + '_method' => 'POST', + '_url' => 'v3/profitsharing/orders', + '_service_url' => 'v3/profitsharing/orders', + 'test' => 'yansongda', + 'appid' => 'wx55955316af4ef13', + 'sub_mchid' => '1600314070', + 'sub_appid' => 'wx55955316af4ef15', + 'receivers' => [ + [ + 'type' => 'PERSONAL_SUB_OPENID', + ], + ], + ], $result->getPayload()->all()); + } +} diff --git a/tests/Plugin/Wechat/Extend/ProfitSharing/DeleteReceiverPluginTest.php b/tests/Plugin/Wechat/Extend/ProfitSharing/DeleteReceiverPluginTest.php new file mode 100644 index 0000000..60e02a1 --- /dev/null +++ b/tests/Plugin/Wechat/Extend/ProfitSharing/DeleteReceiverPluginTest.php @@ -0,0 +1,90 @@ +plugin = new DeleteReceiverPlugin(); + } + + public function testEmptyPayload() + { + $rocket = new Rocket(); + + self::expectException(InvalidParamsException::class); + self::expectExceptionCode(Exception::PARAMS_NECESSARY_PARAMS_MISSING); + self::expectExceptionMessage('参数异常: 缺少分账参数'); + + $this->plugin->assembly($rocket, function ($rocket) { return $rocket; }); + } + + public function testNormal() + { + $rocket = new Rocket(); + $rocket->setPayload(new Collection( [ + "test" => "yansongda", + ])); + + $result = $this->plugin->assembly($rocket, function ($rocket) { return $rocket; }); + + self::assertEquals([ + '_method' => 'POST', + '_url' => 'v3/profitsharing/receivers/delete', + '_service_url' => 'v3/profitsharing/receivers/delete', + 'test' => 'yansongda', + 'appid' => 'wx55955316af4ef13', + ], $result->getPayload()->all()); + } + + public function testServiceParams() + { + $rocket = new Rocket(); + $rocket->setParams(['_config' => 'service_provider'])->setPayload(new Collection( [ + "test" => "yansongda", + 'sub_mchid' => '2222', + ])); + + $result = $this->plugin->assembly($rocket, function ($rocket) { return $rocket; }); + + self::assertEquals([ + '_method' => 'POST', + '_url' => 'v3/profitsharing/receivers/delete', + '_service_url' => 'v3/profitsharing/receivers/delete', + 'test' => 'yansongda', + 'appid' => 'wx55955316af4ef13', + 'sub_mchid' => '2222', + ], $result->getPayload()->all()); + } + + public function testService() + { + $rocket = new Rocket(); + $rocket->setParams(['_config' => 'service_provider'])->setPayload(new Collection( [ + "test" => "yansongda", + ])); + + $result = $this->plugin->assembly($rocket, function ($rocket) { return $rocket; }); + + self::assertEquals([ + '_method' => 'POST', + '_url' => 'v3/profitsharing/receivers/delete', + '_service_url' => 'v3/profitsharing/receivers/delete', + 'test' => 'yansongda', + 'appid' => 'wx55955316af4ef13', + 'sub_mchid' => '1600314070', + ], $result->getPayload()->all()); + } +} diff --git a/tests/Plugin/Wechat/Pay/Common/DownloadBillPluginTest.php b/tests/Plugin/Wechat/Extend/ProfitSharing/DownloadBillPluginTest.php similarity index 51% rename from tests/Plugin/Wechat/Pay/Common/DownloadBillPluginTest.php rename to tests/Plugin/Wechat/Extend/ProfitSharing/DownloadBillPluginTest.php index 051926c..a08c633 100644 --- a/tests/Plugin/Wechat/Pay/Common/DownloadBillPluginTest.php +++ b/tests/Plugin/Wechat/Extend/ProfitSharing/DownloadBillPluginTest.php @@ -1,22 +1,17 @@ plugin = new DownloadBillPlugin(); } - public function testNormal() + public function testEmptyPayload() { $rocket = new Rocket(); - $rocket->setParams([])->setPayload(new Collection(['download_url' => 'https://yansongda.cn'])); - - $result = $this->plugin->assembly($rocket, function ($rocket) { return $rocket; }); - - $radar = $result->getRadar(); - - self::assertEquals(OriginResponseDirection::class, $result->getDirection()); - self::assertEquals('GET', $radar->getMethod()); - self::assertEquals(new Uri('https://yansongda.cn'), $radar->getUri()); - } - - public function testNormalNoDownloadUrl() - { - $rocket = new Rocket(); - $rocket->setParams([])->setPayload(new Collection()); self::expectException(InvalidParamsException::class); self::expectExceptionCode(Exception::PARAMS_NECESSARY_PARAMS_MISSING); + self::expectExceptionMessage('参数异常: 下载电子回单,参数缺少 `download_url`'); $this->plugin->assembly($rocket, function ($rocket) { return $rocket; }); } + + public function testNormal() + { + $rocket = new Rocket(); + $rocket->setPayload(new Collection( [ + "download_url" => "yansongda", + ])); + + $result = $this->plugin->assembly($rocket, function ($rocket) { return $rocket; }); + + self::assertEquals([ + '_method' => 'GET', + '_url' => 'yansongda', + '_service_url' => 'yansongda', + ], $result->getPayload()->all()); + } } diff --git a/tests/Plugin/Wechat/Extend/ProfitSharing/QueryAmountsPluginTest.php b/tests/Plugin/Wechat/Extend/ProfitSharing/QueryAmountsPluginTest.php new file mode 100644 index 0000000..ea560bf --- /dev/null +++ b/tests/Plugin/Wechat/Extend/ProfitSharing/QueryAmountsPluginTest.php @@ -0,0 +1,49 @@ +plugin = new QueryAmountsPlugin(); + } + + public function testEmptyPayload() + { + $rocket = new Rocket(); + + self::expectException(InvalidParamsException::class); + self::expectExceptionCode(Exception::PARAMS_NECESSARY_PARAMS_MISSING); + self::expectExceptionMessage('参数异常: 查询剩余待分金额,参数缺少 `transaction_id`'); + + $this->plugin->assembly($rocket, function ($rocket) { return $rocket; }); + } + + public function testNormal() + { + $rocket = new Rocket(); + $rocket->setPayload(new Collection( [ + "transaction_id" => "yansongda", + ])); + + $result = $this->plugin->assembly($rocket, function ($rocket) { return $rocket; }); + + self::assertEquals([ + '_method' => 'GET', + '_url' => 'v3/profitsharing/transactions/yansongda/amounts', + '_service_url' => 'v3/profitsharing/transactions/yansongda/amounts', + ], $result->getPayload()->all()); + } +} diff --git a/tests/Plugin/Wechat/Extend/ProfitSharing/QueryMerchantConfigsPluginTest.php b/tests/Plugin/Wechat/Extend/ProfitSharing/QueryMerchantConfigsPluginTest.php new file mode 100644 index 0000000..6ae1d45 --- /dev/null +++ b/tests/Plugin/Wechat/Extend/ProfitSharing/QueryMerchantConfigsPluginTest.php @@ -0,0 +1,62 @@ +plugin = new QueryMerchantConfigsPlugin(); + } + + public function testModeWrong() + { + $rocket = new Rocket(); + + self::expectException(InvalidParamsException::class); + self::expectExceptionCode(Exception::PARAMS_PLUGIN_ONLY_SUPPORT_SERVICE_MODE); + self::expectExceptionMessage('参数异常: 查询最大分账比例,只支持服务商模式,当前配置为普通商户模式'); + + $this->plugin->assembly($rocket, function ($rocket) { return $rocket; }); + } + + public function testNormal() + { + $rocket = new Rocket(); + $rocket->setParams(['_config' => 'service_provider']); + + $result = $this->plugin->assembly($rocket, function ($rocket) { return $rocket; }); + + self::assertEquals([ + '_method' => 'GET', + '_service_url' => 'v3/profitsharing/merchant-configs/1600314070', + ], $result->getPayload()->all()); + } + + public function testNormalParams() + { + $rocket = new Rocket(); + $rocket->setParams(['_config' => 'service_provider']) + ->setPayload(new Collection( [ + "sub_mch_id" => "yansongda", + ])); + + $result = $this->plugin->assembly($rocket, function ($rocket) { return $rocket; }); + + self::assertEquals([ + '_method' => 'GET', + '_service_url' => 'v3/profitsharing/merchant-configs/yansongda', + ], $result->getPayload()->all()); + } +} diff --git a/tests/Plugin/Wechat/Extend/ProfitSharing/QueryPluginTest.php b/tests/Plugin/Wechat/Extend/ProfitSharing/QueryPluginTest.php new file mode 100644 index 0000000..2f3e8d9 --- /dev/null +++ b/tests/Plugin/Wechat/Extend/ProfitSharing/QueryPluginTest.php @@ -0,0 +1,85 @@ +plugin = new QueryPlugin(); + } + + public function testEmptyPayload() + { + $rocket = new Rocket(); + + self::expectException(InvalidParamsException::class); + self::expectExceptionCode(Exception::PARAMS_NECESSARY_PARAMS_MISSING); + self::expectExceptionMessage('参数异常: 查询分账结果, 缺少必要参数 `out_order_no`, `transaction_id`'); + + $this->plugin->assembly($rocket, function ($rocket) { return $rocket; }); + } + + public function testNormal() + { + $rocket = new Rocket(); + $rocket->setPayload(new Collection( [ + "transaction_id" => "yansongda", + 'out_order_no' => '111', + ])); + + $result = $this->plugin->assembly($rocket, function ($rocket) { return $rocket; }); + + self::assertEquals([ + '_method' => 'GET', + '_url' => 'v3/profitsharing/orders/111?transaction_id=yansongda', + '_service_url' => 'v3/profitsharing/orders/111?sub_mchid=null&transaction_id=yansongda', + ], $result->getPayload()->all()); + } + + public function testService() + { + $rocket = new Rocket(); + $rocket->setParams(['_config' => 'service_provider'])->setPayload(new Collection( [ + "transaction_id" => "yansongda", + 'out_order_no' => '111', + ])); + + $result = $this->plugin->assembly($rocket, function ($rocket) { return $rocket; }); + + self::assertEquals([ + '_method' => 'GET', + '_url' => 'v3/profitsharing/orders/111?transaction_id=yansongda', + '_service_url' => 'v3/profitsharing/orders/111?sub_mchid=1600314070&transaction_id=yansongda', + ], $result->getPayload()->all()); + } + + public function testServiceParams() + { + $rocket = new Rocket(); + $rocket->setParams(['_config' => 'service_provider'])->setPayload(new Collection( [ + "transaction_id" => "yansongda", + 'out_order_no' => '111', + 'sub_mchid' => '222', + ])); + + $result = $this->plugin->assembly($rocket, function ($rocket) { return $rocket; }); + + self::assertEquals([ + '_method' => 'GET', + '_url' => 'v3/profitsharing/orders/111?transaction_id=yansongda', + '_service_url' => 'v3/profitsharing/orders/111?sub_mchid=222&transaction_id=yansongda', + ], $result->getPayload()->all()); + } +} diff --git a/tests/Plugin/Wechat/Extend/ProfitSharing/QueryReturnPluginTest.php b/tests/Plugin/Wechat/Extend/ProfitSharing/QueryReturnPluginTest.php new file mode 100644 index 0000000..3d6398d --- /dev/null +++ b/tests/Plugin/Wechat/Extend/ProfitSharing/QueryReturnPluginTest.php @@ -0,0 +1,85 @@ +plugin = new QueryReturnPlugin(); + } + + public function testEmptyPayload() + { + $rocket = new Rocket(); + + self::expectException(InvalidParamsException::class); + self::expectExceptionCode(Exception::PARAMS_NECESSARY_PARAMS_MISSING); + self::expectExceptionMessage('参数异常: 查询分账结果, 缺少必要参数 `out_order_no`, `out_return_no`'); + + $this->plugin->assembly($rocket, function ($rocket) { return $rocket; }); + } + + public function testNormal() + { + $rocket = new Rocket(); + $rocket->setPayload(new Collection( [ + "out_return_no" => "yansongda", + 'out_order_no' => '111', + ])); + + $result = $this->plugin->assembly($rocket, function ($rocket) { return $rocket; }); + + self::assertEquals([ + '_method' => 'GET', + '_url' => 'v3/profitsharing/return-orders/yansongda?out_order_no=111', + '_service_url' => 'v3/profitsharing/return-orders/yansongda?sub_mchid=null&out_order_no=111', + ], $result->getPayload()->all()); + } + + public function testService() + { + $rocket = new Rocket(); + $rocket->setParams(['_config' => 'service_provider'])->setPayload(new Collection( [ + "out_return_no" => "yansongda", + 'out_order_no' => '111', + ])); + + $result = $this->plugin->assembly($rocket, function ($rocket) { return $rocket; }); + + self::assertEquals([ + '_method' => 'GET', + '_url' => 'v3/profitsharing/return-orders/yansongda?out_order_no=111', + '_service_url' => 'v3/profitsharing/return-orders/yansongda?sub_mchid=1600314070&out_order_no=111', + ], $result->getPayload()->all()); + } + + public function testServiceParams() + { + $rocket = new Rocket(); + $rocket->setParams(['_config' => 'service_provider'])->setPayload(new Collection( [ + "out_return_no" => "yansongda", + 'out_order_no' => '111', + 'sub_mchid' => '222', + ])); + + $result = $this->plugin->assembly($rocket, function ($rocket) { return $rocket; }); + + self::assertEquals([ + '_method' => 'GET', + '_url' => 'v3/profitsharing/return-orders/yansongda?out_order_no=111', + '_service_url' => 'v3/profitsharing/return-orders/yansongda?sub_mchid=222&out_order_no=111', + ], $result->getPayload()->all()); + } +} diff --git a/tests/Plugin/Wechat/Extend/ProfitSharing/ReturnPluginTest.php b/tests/Plugin/Wechat/Extend/ProfitSharing/ReturnPluginTest.php new file mode 100644 index 0000000..62a3dd8 --- /dev/null +++ b/tests/Plugin/Wechat/Extend/ProfitSharing/ReturnPluginTest.php @@ -0,0 +1,110 @@ +plugin = new ReturnPlugin(); + } + + public function testEmptyPayload() + { + $rocket = new Rocket(); + + self::expectException(InvalidParamsException::class); + self::expectExceptionCode(Exception::PARAMS_NECESSARY_PARAMS_MISSING); + self::expectExceptionMessage('参数异常: 缺少分账参数'); + + $this->plugin->assembly($rocket, function ($rocket) { return $rocket; }); + } + + public function testNormalParams() + { + $rocket = new Rocket(); + $rocket->setPayload(new Collection( [ + "test" => "yansongda", + 'return_mchid' => '1111', + ])); + + $result = $this->plugin->assembly($rocket, function ($rocket) { return $rocket; }); + + self::assertEquals([ + '_method' => 'POST', + '_url' => 'v3/profitsharing/return-orders', + '_service_url' => 'v3/profitsharing/return-orders', + 'test' => 'yansongda', + 'return_mchid' => '1111', + ], $result->getPayload()->all()); + } + + public function testNormal() + { + $rocket = new Rocket(); + $rocket->setPayload(new Collection( [ + "test" => "yansongda", + ])); + + $result = $this->plugin->assembly($rocket, function ($rocket) { return $rocket; }); + + self::assertEquals([ + '_method' => 'POST', + '_url' => 'v3/profitsharing/return-orders', + '_service_url' => 'v3/profitsharing/return-orders', + 'test' => 'yansongda', + 'return_mchid' => '1600314069', + ], $result->getPayload()->all()); + } + + public function testServiceParams() + { + $rocket = new Rocket(); + $rocket->setParams(['_config' => 'service_provider'])->setPayload(new Collection( [ + "test" => "yansongda", + 'return_mchid' => '1111', + 'sub_mchid' => '2222', + ])); + + $result = $this->plugin->assembly($rocket, function ($rocket) { return $rocket; }); + + self::assertEquals([ + '_method' => 'POST', + '_url' => 'v3/profitsharing/return-orders', + '_service_url' => 'v3/profitsharing/return-orders', + 'test' => 'yansongda', + 'return_mchid' => '1111', + 'sub_mchid' => '2222', + ], $result->getPayload()->all()); + } + + public function testService() + { + $rocket = new Rocket(); + $rocket->setParams(['_config' => 'service_provider'])->setPayload(new Collection( [ + "test" => "yansongda", + ])); + + $result = $this->plugin->assembly($rocket, function ($rocket) { return $rocket; }); + + self::assertEquals([ + '_method' => 'POST', + '_url' => 'v3/profitsharing/return-orders', + '_service_url' => 'v3/profitsharing/return-orders', + 'test' => 'yansongda', + 'return_mchid' => '1600314069', + 'sub_mchid' => '1600314070', + ], $result->getPayload()->all()); + } +} diff --git a/tests/Plugin/Wechat/Extend/ProfitSharing/UnfreezePluginTest.php b/tests/Plugin/Wechat/Extend/ProfitSharing/UnfreezePluginTest.php new file mode 100644 index 0000000..9b61fa2 --- /dev/null +++ b/tests/Plugin/Wechat/Extend/ProfitSharing/UnfreezePluginTest.php @@ -0,0 +1,90 @@ +plugin = new UnfreezePlugin(); + } + + public function testEmptyPayload() + { + $rocket = new Rocket(); + + self::expectException(InvalidParamsException::class); + self::expectExceptionCode(Exception::PARAMS_NECESSARY_PARAMS_MISSING); + self::expectExceptionMessage('参数异常: 缺少分账参数'); + + $this->plugin->assembly($rocket, function ($rocket) { return $rocket; }); + } + + public function testNormal() + { + $rocket = new Rocket(); + $rocket->setPayload(new Collection( [ + "test" => "yansongda", + ])); + + $result = $this->plugin->assembly($rocket, function ($rocket) { return $rocket; }); + + self::assertEquals([ + '_method' => 'POST', + '_url' => 'v3/profitsharing/orders/unfreeze', + '_service_url' => 'v3/profitsharing/orders/unfreeze', + 'test' => 'yansongda', + ], $result->getPayload()->all()); + } + + public function testServiceParams() + { + $rocket = new Rocket(); + $rocket->setParams(['_config' => 'service_provider'])->setPayload(new Collection( [ + "test" => "yansongda", + 'notify_url' => '1111', + 'sub_mchid' => '2222', + ])); + + $result = $this->plugin->assembly($rocket, function ($rocket) { return $rocket; }); + + self::assertEquals([ + '_method' => 'POST', + '_url' => 'v3/profitsharing/orders/unfreeze', + '_service_url' => 'v3/profitsharing/orders/unfreeze', + 'test' => 'yansongda', + 'notify_url' => '1111', + 'sub_mchid' => '2222', + ], $result->getPayload()->all()); + } + + public function testService() + { + $rocket = new Rocket(); + $rocket->setParams(['_config' => 'service_provider'])->setPayload(new Collection( [ + "test" => "yansongda", + ])); + + $result = $this->plugin->assembly($rocket, function ($rocket) { return $rocket; }); + + self::assertEquals([ + '_method' => 'POST', + '_url' => 'v3/profitsharing/orders/unfreeze', + '_service_url' => 'v3/profitsharing/orders/unfreeze', + 'test' => 'yansongda', + 'notify_url' => null, + 'sub_mchid' => '1600314070', + ], $result->getPayload()->all()); + } +} diff --git a/tests/Plugin/Wechat/Fund/Balance/QueryDayEndPluginTest.php b/tests/Plugin/Wechat/Fund/Balance/QueryDayEndPluginTest.php deleted file mode 100644 index 041d0a6..0000000 --- a/tests/Plugin/Wechat/Fund/Balance/QueryDayEndPluginTest.php +++ /dev/null @@ -1,63 +0,0 @@ -plugin = new QueryDayEndPlugin(); - } - - public function testNormal() - { - $rocket = new Rocket(); - $rocket->setParams([])->setPayload(new Collection(['account_type' => '123', 'date' => '2021-10-23'])); - - $result = $this->plugin->assembly($rocket, function ($rocket) { return $rocket; }); - - $radar = $result->getRadar(); - - self::assertEquals(new Uri(Wechat::URL[Pay::MODE_NORMAL].'v3/merchant/fund/dayendbalance/123?date=2021-10-23'), $radar->getUri()); - self::assertEquals('GET', $radar->getMethod()); - } - - public function testNormalNoAccountType() - { - $rocket = new Rocket(); - $rocket->setParams([])->setPayload(new Collection(['date' => '2021-10-23'])); - - self::expectException(InvalidParamsException::class); - self::expectExceptionCode(Exception::PARAMS_NECESSARY_PARAMS_MISSING); - - $this->plugin->assembly($rocket, function ($rocket) { return $rocket; }); - } - - public function testNormalNoDate() - { - $rocket = new Rocket(); - $rocket->setParams([])->setPayload(new Collection(['account_type' => '123'])); - - self::expectException(InvalidParamsException::class); - self::expectExceptionCode(Exception::PARAMS_NECESSARY_PARAMS_MISSING); - - $this->plugin->assembly($rocket, function ($rocket) { return $rocket; }); - } -} diff --git a/tests/Plugin/Wechat/Fund/Profitsharing/AddReceiverPluginTest.php b/tests/Plugin/Wechat/Fund/Profitsharing/AddReceiverPluginTest.php deleted file mode 100644 index da8f480..0000000 --- a/tests/Plugin/Wechat/Fund/Profitsharing/AddReceiverPluginTest.php +++ /dev/null @@ -1,85 +0,0 @@ -plugin = new AddReceiverPlugin(); - } - - public function testNormal() - { - $rocket = new Rocket(); - $rocket->setParams([])->setPayload(new Collection()); - - $result = $this->plugin->assembly($rocket, function ($rocket) {return $rocket;}); - - $radar = $result->getRadar(); - $payload = $result->getPayload(); - - self::assertEquals(new Uri(Wechat::URL[Pay::MODE_NORMAL] . 'v3/profitsharing/receivers/add'), $radar->getUri()); - self::assertEquals('wx55955316af4ef13', $payload->get('appid')); - self::assertArrayNotHasKey('sub_mchid', $payload->all()); - } - - public function testPartner() - { - $rocket = new Rocket(); - $rocket->setParams(['_config' => 'service_provider'])->setPayload(new Collection()); - - $result = $this->plugin->assembly($rocket, function ($rocket) {return $rocket;}); - - $radar = $result->getRadar(); - $payload = $result->getPayload(); - - self::assertEquals(new Uri(Wechat::URL[Pay::MODE_SERVICE] . 'v3/profitsharing/receivers/add'), $radar->getUri()); - self::assertEquals('wx55955316af4ef13', $payload->get('appid')); - self::assertEquals('1600314070', $payload->get('sub_mchid')); - } - - public function testPartnerDirectPayload() - { - $rocket = new Rocket(); - $rocket->setParams(['_config' => 'service_provider'])->setPayload(new Collection(['sub_mchid' => '123'])); - - $result = $this->plugin->assembly($rocket, function ($rocket) {return $rocket;}); - - $payload = $result->getPayload(); - - self::assertEquals('wx55955316af4ef13', $payload->get('appid')); - self::assertEquals('123', $payload->get('sub_mchid')); - } - - public function testEncryptName() - { - $params = [ - 'name' => 'yansongda', - ]; - - $rocket = new Rocket(); - $rocket->setParams($params)->setPayload(new Collection()); - - $result = $this->plugin->assembly($rocket, function ($rocket) {return $rocket;}); - $payload = $result->getPayload(); - - self::assertNotEquals('yansongda', $payload->get('name')); - self::assertStringContainsString('==', $payload->get('name')); - } -} diff --git a/tests/Plugin/Wechat/Fund/Profitsharing/CreatePluginTest.php b/tests/Plugin/Wechat/Fund/Profitsharing/CreatePluginTest.php deleted file mode 100644 index efb37ea..0000000 --- a/tests/Plugin/Wechat/Fund/Profitsharing/CreatePluginTest.php +++ /dev/null @@ -1,89 +0,0 @@ -plugin = new CreatePlugin(); - } - - public function testNormal() - { - $rocket = new Rocket(); - $rocket->setParams([])->setPayload(new Collection()); - - $result = $this->plugin->assembly($rocket, function ($rocket) { return $rocket; }); - - $radar = $result->getRadar(); - $payload = $result->getPayload(); - - self::assertEquals(new Uri(Wechat::URL[Pay::MODE_NORMAL].'v3/profitsharing/orders'), $radar->getUri()); - self::assertEquals('wx55955316af4ef13', $payload->get('appid')); - self::assertArrayNotHasKey('sub_mchid', $payload->all()); - } - - public function testPartner() - { - $rocket = new Rocket(); - $rocket->setParams(['_config' => 'service_provider'])->setPayload(new Collection()); - - $result = $this->plugin->assembly($rocket, function ($rocket) { return $rocket; }); - - $radar = $result->getRadar(); - $payload = $result->getPayload(); - - self::assertEquals(new Uri(Wechat::URL[Pay::MODE_SERVICE].'v3/profitsharing/orders'), $radar->getUri()); - self::assertEquals('wx55955316af4ef13', $payload->get('appid')); - self::assertEquals('1600314070', $payload->get('sub_mchid')); - } - - public function testPartnerDirectPayload() - { - $rocket = new Rocket(); - $rocket->setParams(['_config' => 'service_provider'])->setPayload(new Collection(['sub_mchid' => '123'])); - - $result = $this->plugin->assembly($rocket, function ($rocket) { return $rocket; }); - - $payload = $result->getPayload(); - - self::assertEquals('wx55955316af4ef13', $payload->get('appid')); - self::assertEquals('123', $payload->get('sub_mchid')); - } - - public function testEncryptName() - { - $params = [ - 'receivers' => [ - [ - 'name' => 'yansongda' - ] - ] - ]; - - $rocket = new Rocket(); - $rocket->setParams($params)->setPayload(new Collection()); - - $result = $this->plugin->assembly($rocket, function ($rocket) { return $rocket; }); - $payload = $result->getPayload(); - - self::assertNotEquals('yansongda', $payload->get('receivers.0.name')); - self::assertStringContainsString('==', $payload->get('receivers.0.name')); - } -} diff --git a/tests/Plugin/Wechat/Fund/Profitsharing/DeleteReceiverPluginTest.php b/tests/Plugin/Wechat/Fund/Profitsharing/DeleteReceiverPluginTest.php deleted file mode 100644 index 357ebaf..0000000 --- a/tests/Plugin/Wechat/Fund/Profitsharing/DeleteReceiverPluginTest.php +++ /dev/null @@ -1,69 +0,0 @@ -plugin = new DeleteReceiverPlugin(); - } - - public function testNormal() - { - $rocket = new Rocket(); - $rocket->setParams([])->setPayload(new Collection()); - - $result = $this->plugin->assembly($rocket, function ($rocket) { return $rocket; }); - - $radar = $result->getRadar(); - $payload = $result->getPayload(); - - self::assertEquals(new Uri(Wechat::URL[Pay::MODE_NORMAL].'v3/profitsharing/receivers/delete'), $radar->getUri()); - self::assertEquals('wx55955316af4ef13', $payload->get('appid')); - self::assertArrayNotHasKey('sub_mchid', $payload->all()); - } - - public function testPartner() - { - $rocket = new Rocket(); - $rocket->setParams(['_config' => 'service_provider'])->setPayload(new Collection()); - - $result = $this->plugin->assembly($rocket, function ($rocket) { return $rocket; }); - - $radar = $result->getRadar(); - $payload = $result->getPayload(); - - self::assertEquals(new Uri(Wechat::URL[Pay::MODE_SERVICE].'v3/profitsharing/receivers/delete'), $radar->getUri()); - self::assertEquals('wx55955316af4ef13', $payload->get('appid')); - self::assertEquals('1600314070', $payload->get('sub_mchid')); - } - - public function testPartnerDirectPayload() - { - $rocket = new Rocket(); - $rocket->setParams(['_config' => 'service_provider'])->setPayload(new Collection(['sub_mchid' => '123'])); - - $result = $this->plugin->assembly($rocket, function ($rocket) { return $rocket; }); - - $payload = $result->getPayload(); - - self::assertEquals('wx55955316af4ef13', $payload->get('appid')); - self::assertEquals('123', $payload->get('sub_mchid')); - } -} diff --git a/tests/Plugin/Wechat/Fund/Profitsharing/QueryMerchantConfigsPluginTest.php b/tests/Plugin/Wechat/Fund/Profitsharing/QueryMerchantConfigsPluginTest.php deleted file mode 100644 index 0658be2..0000000 --- a/tests/Plugin/Wechat/Fund/Profitsharing/QueryMerchantConfigsPluginTest.php +++ /dev/null @@ -1,51 +0,0 @@ -plugin = new QueryMerchantConfigsPlugin(); - } - - public function testPartner() - { - $rocket = new Rocket(); - $rocket->setParams(['_config' => 'service_provider'])->setPayload(new Collection()); - - $result = $this->plugin->assembly($rocket, function ($rocket) { return $rocket; }); - - $radar = $result->getRadar(); - - self::assertEquals(new Uri(Wechat::URL[Pay::MODE_SERVICE].'v3/profitsharing/merchant-configs/1600314070'), $radar->getUri()); - self::assertEquals('GET', $radar->getMethod()); - } - - public function testPartnerDirectPayload() - { - $rocket = new Rocket(); - $rocket->setParams(['_config' => 'service_provider'])->setPayload(new Collection(['sub_mchid' => '123'])); - - $result = $this->plugin->assembly($rocket, function ($rocket) { return $rocket; }); - - $radar = $result->getRadar(); - - self::assertEquals(new Uri(Wechat::URL[Pay::MODE_SERVICE].'v3/profitsharing/merchant-configs/123'), $radar->getUri()); - } -} diff --git a/tests/Plugin/Wechat/Fund/Profitsharing/QueryPluginTest.php b/tests/Plugin/Wechat/Fund/Profitsharing/QueryPluginTest.php deleted file mode 100644 index 9203aff..0000000 --- a/tests/Plugin/Wechat/Fund/Profitsharing/QueryPluginTest.php +++ /dev/null @@ -1,89 +0,0 @@ -plugin = new QueryPlugin(); - } - - public function testNormal() - { - $rocket = new Rocket(); - $rocket->setParams([])->setPayload(new Collection(['out_order_no' => '123','transaction_id' => '456'])); - - $result = $this->plugin->assembly($rocket, function ($rocket) { return $rocket; }); - - $radar = $result->getRadar(); - - self::assertEquals(new Uri(Wechat::URL[Pay::MODE_NORMAL].'v3/profitsharing/orders/123?transaction_id=456'), $radar->getUri()); - self::assertEquals('GET', $radar->getMethod()); - } - - public function testNormalNoOutTradeNo() - { - $rocket = new Rocket(); - $rocket->setParams([])->setPayload(new Collection(['transaction_id' => '456'])); - - self::expectException(InvalidParamsException::class); - self::expectExceptionCode(Exception::PARAMS_NECESSARY_PARAMS_MISSING); - - $this->plugin->assembly($rocket, function ($rocket) { return $rocket; }); - } - - public function testNormalNoTransactionId() - { - $rocket = new Rocket(); - $rocket->setParams([])->setPayload(new Collection(['out_order_no' => '123'])); - - self::expectException(InvalidParamsException::class); - self::expectExceptionCode(Exception::PARAMS_NECESSARY_PARAMS_MISSING); - - $this->plugin->assembly($rocket, function ($rocket) { return $rocket; }); - } - - public function testPartner() - { - $rocket = new Rocket(); - $rocket->setParams(['_config' => 'service_provider'])->setPayload(new Collection(['out_order_no' => '123','transaction_id' => '456'])); - - $result = $this->plugin->assembly($rocket, function ($rocket) { return $rocket; }); - - $radar = $result->getRadar(); - - self::assertEquals(new Uri(Wechat::URL[Pay::MODE_SERVICE].'v3/profitsharing/orders/123?transaction_id=456&sub_mchid=1600314070'), $radar->getUri()); - self::assertEquals('GET', $radar->getMethod()); - } - - public function testPartnerDirectPayload() - { - $rocket = new Rocket(); - $rocket->setParams(['_config' => 'service_provider'])->setPayload(new Collection(['out_order_no' => '123','transaction_id' => '456','sub_mchid' => '123'])); - - $result = $this->plugin->assembly($rocket, function ($rocket) { return $rocket; }); - - $radar = $result->getRadar(); - - self::assertEquals(new Uri(Wechat::URL[Pay::MODE_SERVICE].'v3/profitsharing/orders/123?transaction_id=456&sub_mchid=123'), $radar->getUri()); - self::assertEquals('GET', $radar->getMethod()); - } -} diff --git a/tests/Plugin/Wechat/Fund/Profitsharing/QueryReturnPluginTest.php b/tests/Plugin/Wechat/Fund/Profitsharing/QueryReturnPluginTest.php deleted file mode 100644 index 2121119..0000000 --- a/tests/Plugin/Wechat/Fund/Profitsharing/QueryReturnPluginTest.php +++ /dev/null @@ -1,89 +0,0 @@ -plugin = new QueryReturnPlugin(); - } - - public function testNormal() - { - $rocket = new Rocket(); - $rocket->setParams([])->setPayload(new Collection(['out_order_no' => '123','out_return_no' => '456'])); - - $result = $this->plugin->assembly($rocket, function ($rocket) { return $rocket; }); - - $radar = $result->getRadar(); - - self::assertEquals(new Uri(Wechat::URL[Pay::MODE_NORMAL].'v3/profitsharing/return-orders/456?out_order_no=123'), $radar->getUri()); - self::assertEquals('GET', $radar->getMethod()); - } - - public function testNormalNoOutTradeNo() - { - $rocket = new Rocket(); - $rocket->setParams([])->setPayload(new Collection(['out_return_no' => '456'])); - - self::expectException(InvalidParamsException::class); - self::expectExceptionCode(Exception::PARAMS_NECESSARY_PARAMS_MISSING); - - $this->plugin->assembly($rocket, function ($rocket) { return $rocket; }); - } - - public function testNormalNoTransactionId() - { - $rocket = new Rocket(); - $rocket->setParams([])->setPayload(new Collection(['out_order_no' => '123'])); - - self::expectException(InvalidParamsException::class); - self::expectExceptionCode(Exception::PARAMS_NECESSARY_PARAMS_MISSING); - - $this->plugin->assembly($rocket, function ($rocket) { return $rocket; }); - } - - public function testPartner() - { - $rocket = new Rocket(); - $rocket->setParams(['_config' => 'service_provider'])->setPayload(new Collection(['out_order_no' => '123','out_return_no' => '456'])); - - $result = $this->plugin->assembly($rocket, function ($rocket) { return $rocket; }); - - $radar = $result->getRadar(); - - self::assertEquals(new Uri(Wechat::URL[Pay::MODE_SERVICE].'v3/profitsharing/return-orders/456?out_order_no=123&sub_mchid=1600314070'), $radar->getUri()); - self::assertEquals('GET', $radar->getMethod()); - } - - public function testPartnerDirectPayload() - { - $rocket = new Rocket(); - $rocket->setParams(['_config' => 'service_provider'])->setPayload(new Collection(['out_order_no' => '123','out_return_no' => '456','sub_mchid' => '123'])); - - $result = $this->plugin->assembly($rocket, function ($rocket) { return $rocket; }); - - $radar = $result->getRadar(); - - self::assertEquals(new Uri(Wechat::URL[Pay::MODE_SERVICE].'v3/profitsharing/return-orders/456?out_order_no=123&sub_mchid=123'), $radar->getUri()); - self::assertEquals('GET', $radar->getMethod()); - } -} diff --git a/tests/Plugin/Wechat/Fund/Profitsharing/ReturnPluginTest.php b/tests/Plugin/Wechat/Fund/Profitsharing/ReturnPluginTest.php deleted file mode 100644 index 40cba85..0000000 --- a/tests/Plugin/Wechat/Fund/Profitsharing/ReturnPluginTest.php +++ /dev/null @@ -1,68 +0,0 @@ -plugin = new ReturnPlugin(); - } - - public function testNormal() - { - $rocket = new Rocket(); - $rocket->setParams([])->setPayload(new Collection()); - - $result = $this->plugin->assembly($rocket, function ($rocket) { return $rocket; }); - - $radar = $result->getRadar(); - $payload = $result->getPayload(); - - self::assertEquals(new Uri(Wechat::URL[Pay::MODE_NORMAL].'v3/profitsharing/return-orders'), $radar->getUri()); - self::assertEquals('POST', $radar->getMethod()); - self::assertArrayNotHasKey('sub_mchid', $payload->all()); - } - - public function testPartner() - { - $rocket = new Rocket(); - $rocket->setParams(['_config' => 'service_provider'])->setPayload(new Collection()); - - $result = $this->plugin->assembly($rocket, function ($rocket) { return $rocket; }); - - $radar = $result->getRadar(); - $payload = $result->getPayload(); - - self::assertEquals(new Uri(Wechat::URL[Pay::MODE_SERVICE].'v3/profitsharing/return-orders'), $radar->getUri()); - self::assertEquals('POST', $radar->getMethod()); - self::assertEquals('1600314070', $payload->get('sub_mchid')); - } - - public function testPartnerDirectPayload() - { - $rocket = new Rocket(); - $rocket->setParams(['_config' => 'service_provider'])->setPayload(new Collection(['sub_mchid' => '123'])); - - $result = $this->plugin->assembly($rocket, function ($rocket) { return $rocket; }); - - $payload = $result->getPayload(); - - self::assertEquals('123', $payload->get('sub_mchid')); - } -} diff --git a/tests/Plugin/Wechat/Fund/Profitsharing/UnfreezePluginTest.php b/tests/Plugin/Wechat/Fund/Profitsharing/UnfreezePluginTest.php deleted file mode 100644 index 268ec31..0000000 --- a/tests/Plugin/Wechat/Fund/Profitsharing/UnfreezePluginTest.php +++ /dev/null @@ -1,68 +0,0 @@ -plugin = new UnfreezePlugin(); - } - - public function testNormal() - { - $rocket = new Rocket(); - $rocket->setParams([])->setPayload(new Collection()); - - $result = $this->plugin->assembly($rocket, function ($rocket) { return $rocket; }); - - $radar = $result->getRadar(); - $payload = $result->getPayload(); - - self::assertEquals(new Uri(Wechat::URL[Pay::MODE_NORMAL].'v3/profitsharing/orders/unfreeze'), $radar->getUri()); - self::assertEquals('POST', $radar->getMethod()); - self::assertArrayNotHasKey('sub_mchid', $payload->all()); - } - - public function testPartner() - { - $rocket = new Rocket(); - $rocket->setParams(['_config' => 'service_provider'])->setPayload(new Collection()); - - $result = $this->plugin->assembly($rocket, function ($rocket) { return $rocket; }); - - $radar = $result->getRadar(); - $payload = $result->getPayload(); - - self::assertEquals(new Uri(Wechat::URL[Pay::MODE_SERVICE].'v3/profitsharing/orders/unfreeze'), $radar->getUri()); - self::assertEquals('POST', $radar->getMethod()); - self::assertEquals('1600314070', $payload->get('sub_mchid')); - } - - public function testPartnerDirectPayload() - { - $rocket = new Rocket(); - $rocket->setParams(['_config' => 'service_provider'])->setPayload(new Collection(['sub_mchid' => '123'])); - - $result = $this->plugin->assembly($rocket, function ($rocket) { return $rocket; }); - - $payload = $result->getPayload(); - - self::assertEquals('123', $payload->get('sub_mchid')); - } -} diff --git a/tests/Plugin/Wechat/Fund/Transfer/CreateBillReceiptPluginTest.php b/tests/Plugin/Wechat/Fund/Transfer/CreateBillReceiptPluginTest.php deleted file mode 100644 index c18a7c5..0000000 --- a/tests/Plugin/Wechat/Fund/Transfer/CreateBillReceiptPluginTest.php +++ /dev/null @@ -1,67 +0,0 @@ -plugin = new CreateBillReceiptPlugin(); - } - - public function testNormal() - { - $rocket = new Rocket(); - $rocket->setParams([])->setPayload(new Collection(['out_batch_no' => '123'])); - - $result = $this->plugin->assembly($rocket, function ($rocket) { return $rocket; }); - - $radar = $result->getRadar(); - $payload = $result->getPayload(); - - self::assertEquals(new Uri(Wechat::URL[Pay::MODE_NORMAL].'v3/transfer/bill-receipt'), $radar->getUri()); - self::assertEquals('123', $payload->get('out_batch_no')); - } - - public function testNormalNoOutBatchNo() - { - $rocket = new Rocket(); - $rocket->setParams([])->setPayload(new Collection()); - - self::expectException(InvalidParamsException::class); - self::expectExceptionCode(Exception::PARAMS_NECESSARY_PARAMS_MISSING); - - $this->plugin->assembly($rocket, function ($rocket) { return $rocket; }); - } - - public function testPartner() - { - $rocket = new Rocket(); - $rocket->setParams(['_config' => 'service_provider'])->setPayload(new Collection(['out_batch_no' => '123'])); - - $result = $this->plugin->assembly($rocket, function ($rocket) { return $rocket; }); - - $radar = $result->getRadar(); - $payload = $result->getPayload(); - - self::assertEquals(new Uri(Wechat::URL[Pay::MODE_NORMAL].'v3/transfer/bill-receipt'), $radar->getUri()); - self::assertEquals('123', $payload->get('out_batch_no')); - } -} diff --git a/tests/Plugin/Wechat/Fund/Transfer/CreateDetailReceiptPluginTest.php b/tests/Plugin/Wechat/Fund/Transfer/CreateDetailReceiptPluginTest.php deleted file mode 100644 index 70a995e..0000000 --- a/tests/Plugin/Wechat/Fund/Transfer/CreateDetailReceiptPluginTest.php +++ /dev/null @@ -1,80 +0,0 @@ -plugin = new CreateDetailReceiptPlugin(); - } - - public function testNormal() - { - $rocket = new Rocket(); - $rocket->setParams([])->setPayload(new Collection(['out_detail_no' => '123', 'accept_type' => '456'])); - - $result = $this->plugin->assembly($rocket, function ($rocket) { return $rocket; }); - - $radar = $result->getRadar(); - $payload = $result->getPayload(); - - self::assertEquals(new Uri(Wechat::URL[Pay::MODE_NORMAL].'v3/transfer-detail/electronic-receipts'), $radar->getUri()); - self::assertEquals('123', $payload->get('out_detail_no')); - self::assertEquals('456', $payload->get('accept_type')); - } - - public function testNormalNoOutBatchNo() - { - $rocket = new Rocket(); - $rocket->setParams([])->setPayload(new Collection(['accept_type' => '456'])); - - self::expectException(InvalidParamsException::class); - self::expectExceptionCode(Exception::PARAMS_NECESSARY_PARAMS_MISSING); - - $this->plugin->assembly($rocket, function ($rocket) { return $rocket; }); - } - - public function testNormalNoAcceptType() - { - $rocket = new Rocket(); - $rocket->setParams([])->setPayload(new Collection(['out_detail_no' => '123'])); - - self::expectException(InvalidParamsException::class); - self::expectExceptionCode(Exception::PARAMS_NECESSARY_PARAMS_MISSING); - - $this->plugin->assembly($rocket, function ($rocket) { return $rocket; }); - } - - public function testPartner() - { - $rocket = new Rocket(); - $rocket->setParams(['_config' => 'service_provider'])->setPayload(new Collection(['out_detail_no' => '123', 'accept_type' => '456'])); - - $result = $this->plugin->assembly($rocket, function ($rocket) { return $rocket; }); - - $radar = $result->getRadar(); - $payload = $result->getPayload(); - - self::assertEquals(new Uri(Wechat::URL[Pay::MODE_NORMAL].'v3/transfer-detail/electronic-receipts'), $radar->getUri()); - self::assertEquals('123', $payload->get('out_detail_no')); - self::assertEquals('456', $payload->get('accept_type')); - } -} diff --git a/tests/Plugin/Wechat/Fund/Transfer/CreatePluginTest.php b/tests/Plugin/Wechat/Fund/Transfer/CreatePluginTest.php deleted file mode 100644 index 07226d7..0000000 --- a/tests/Plugin/Wechat/Fund/Transfer/CreatePluginTest.php +++ /dev/null @@ -1,118 +0,0 @@ -plugin = new CreatePlugin(); - } - - public function testNormal() - { - $rocket = new Rocket(); - $rocket->setParams([])->setPayload(new Collection()); - - $result = $this->plugin->assembly($rocket, function ($rocket) { return $rocket; }); - - $radar = $result->getRadar(); - $payload = $result->getPayload(); - - self::assertEquals(new Uri(Wechat::URL[Pay::MODE_NORMAL].'v3/transfer/batches'), $radar->getUri()); - self::assertEquals('wx55955316af4ef13', $payload->get('appid')); - } - - public function testPartner() - { - $rocket = new Rocket(); - $rocket->setParams(['_config' => 'service_provider'])->setPayload(new Collection()); - - $result = $this->plugin->assembly($rocket, function ($rocket) { return $rocket; }); - - $radar = $result->getRadar(); - $payload = $result->getPayload(); - - self::assertEquals(new Uri(Wechat::URL[Pay::MODE_NORMAL].'v3/partner-transfer/batches'), $radar->getUri()); - self::assertEquals('1600314070', $payload->get('sub_mchid')); - self::assertNull($payload->get('appid')); - } - - public function testUsername() - { - // 不传证书 - $params = [ - 'transfer_detail_list' => [ - [ - 'out_detail_no' => time().'-1', - 'transfer_amount' => 1, - 'transfer_remark' => 'test', - 'openid' => 'MYE42l80oelYMDE34nYD456Xoy', - 'user_name' => 'yansongda' // 明文传参即可,sdk 会自动加密 - ] - ], - ]; - - $rocket = new Rocket(); - $rocket->setParams($params)->setPayload(new Collection()); - $result = $this->plugin->assembly($rocket, function ($rocket) { return $rocket; }); - - $userName = $result->getPayload()->get('transfer_detail_list')[0]['user_name']; - - self::assertTrue(in_array($result->getParams()['_serial_no'], ['45F59D4DABF31918AFCEC556D5D2C6E376675D57', 'yansongda'])); - self::assertNotEquals('yansongda', $userName); - self::assertStringContainsString('==', $userName); - - // 传证书 - $params = [ - '_serial_no' => 'yansongda', - 'transfer_detail_list' => [ - [ - 'out_detail_no' => time().'-1', - 'transfer_amount' => 1, - 'transfer_remark' => 'test', - 'openid' => 'MYE42l80oelYMDE34nYD456Xoy', - 'user_name' => 'yansongda' // 明文传参即可,sdk 会自动加密 - ] - ], - ]; - - $rocket = new Rocket(); - $rocket->setParams($params)->setPayload(new Collection()); - $result = $this->plugin->assembly($rocket, function ($rocket) { return $rocket; }); - - $userName = $result->getPayload()->get('transfer_detail_list')[0]['user_name']; - - self::assertEquals('yansongda', $result->getParams()['_serial_no']); - self::assertStringContainsString('==', $userName); - } - - public function testNormalOtherType() - { - $rocket = new Rocket(); - $rocket->setParams(['_type' => 'mini'])->setPayload(new Collection()); - - $result = $this->plugin->assembly($rocket, function ($rocket) { return $rocket; }); - - $radar = $result->getRadar(); - $payload = $result->getPayload(); - - self::assertEquals(new Uri(Wechat::URL[Pay::MODE_NORMAL].'v3/transfer/batches'), $radar->getUri()); - self::assertEquals('wx55955316af4ef14', $payload->get('appid')); - } -} diff --git a/tests/Plugin/Wechat/Fund/Transfer/DownloadReceiptPluginTest.php b/tests/Plugin/Wechat/Fund/Transfer/DownloadReceiptPluginTest.php deleted file mode 100644 index 3ec1db0..0000000 --- a/tests/Plugin/Wechat/Fund/Transfer/DownloadReceiptPluginTest.php +++ /dev/null @@ -1,52 +0,0 @@ -plugin = new DownloadReceiptPlugin(); - } - - public function testNormal() - { - $rocket = new Rocket(); - $rocket->setParams([])->setPayload(new Collection(['download_url' => 'https://yansongda.cn'])); - - $result = $this->plugin->assembly($rocket, function ($rocket) { return $rocket; }); - - $radar = $result->getRadar(); - - self::assertEquals(OriginResponseDirection::class, $result->getDirection()); - self::assertEquals('GET', $radar->getMethod()); - self::assertEquals(new Uri('https://yansongda.cn'), $radar->getUri()); - } - - public function testNormalNoDownloadUrl() - { - $rocket = new Rocket(); - $rocket->setParams([])->setPayload(new Collection()); - - self::expectException(InvalidParamsException::class); - self::expectExceptionCode(Exception::PARAMS_NECESSARY_PARAMS_MISSING); - - $this->plugin->assembly($rocket, function ($rocket) { return $rocket; }); - } -} diff --git a/tests/Plugin/Wechat/Fund/Transfer/QueryBatchDetailIdPluginTest.php b/tests/Plugin/Wechat/Fund/Transfer/QueryBatchDetailIdPluginTest.php deleted file mode 100644 index dd702f6..0000000 --- a/tests/Plugin/Wechat/Fund/Transfer/QueryBatchDetailIdPluginTest.php +++ /dev/null @@ -1,98 +0,0 @@ -plugin = new QueryBatchDetailIdPlugin(); - } - - public function testNormal() - { - $rocket = new Rocket(); - $rocket->setParams([])->setPayload(new Collection(['batch_id' => '123', 'detail_id' => '456'])); - - $result = $this->plugin->assembly($rocket, function ($rocket) { return $rocket; }); - - $radar = $result->getRadar(); - - self::assertEquals(new Uri(Wechat::URL[Pay::MODE_NORMAL].'v3/transfer/batches/batch-id/123/details/detail-id/456'), $radar->getUri()); - self::assertEquals('GET', $radar->getMethod()); - } - - public function testNormalNoBatchId() - { - $rocket = new Rocket(); - $rocket->setParams([])->setPayload(new Collection(['detail' => '456'])); - - self::expectException(InvalidParamsException::class); - self::expectExceptionCode(Exception::PARAMS_NECESSARY_PARAMS_MISSING); - - $this->plugin->assembly($rocket, function ($rocket) { return $rocket; }); - } - - public function testNormalNoDetailId() - { - $rocket = new Rocket(); - $rocket->setParams([])->setPayload(new Collection(['batch_id' => '123'])); - - self::expectException(InvalidParamsException::class); - self::expectExceptionCode(Exception::PARAMS_NECESSARY_PARAMS_MISSING); - - $this->plugin->assembly($rocket, function ($rocket) { return $rocket; }); - } - - public function testPartner() - { - $rocket = new Rocket(); - $rocket->setParams(['_config' => 'service_provider'])->setPayload(new Collection(['batch_id' => '123', 'detail_id' => '456'])); - - $result = $this->plugin->assembly($rocket, function ($rocket) { return $rocket; }); - - $radar = $result->getRadar(); - - self::assertEquals(new Uri(Wechat::URL[Pay::MODE_NORMAL].'v3/partner-transfer/batches/batch-id/123/details/detail-id/456'), $radar->getUri()); - self::assertEquals('GET', $radar->getMethod()); - } - - public function testPartnerNoBatchId() - { - $rocket = new Rocket(); - $rocket->setParams(['_config' => 'service_provider'])->setPayload(new Collection(['detail' => '456'])); - - self::expectException(InvalidParamsException::class); - self::expectExceptionCode(Exception::PARAMS_NECESSARY_PARAMS_MISSING); - - $this->plugin->assembly($rocket, function ($rocket) { return $rocket; }); - } - - public function testPartnerNoDetailId() - { - $rocket = new Rocket(); - $rocket->setParams(['_config' => 'service_provider'])->setPayload(new Collection(['batch_id' => '123'])); - - self::expectException(InvalidParamsException::class); - self::expectExceptionCode(Exception::PARAMS_NECESSARY_PARAMS_MISSING); - - $this->plugin->assembly($rocket, function ($rocket) { return $rocket; }); - } -} diff --git a/tests/Plugin/Wechat/Fund/Transfer/QueryBatchIdPluginTest.php b/tests/Plugin/Wechat/Fund/Transfer/QueryBatchIdPluginTest.php deleted file mode 100644 index 3c1f6c8..0000000 --- a/tests/Plugin/Wechat/Fund/Transfer/QueryBatchIdPluginTest.php +++ /dev/null @@ -1,99 +0,0 @@ -plugin = new QueryBatchIdPlugin(); - } - - public function testNormal() - { - $rocket = new Rocket(); - $rocket->setParams([])->setPayload(new Collection(['batch_id' => '123', 'need_query_detail' => false])); - - $result = $this->plugin->assembly($rocket, function ($rocket) { return $rocket; }); - - $radar = $result->getRadar(); - $url = $radar->getUri(); - - self::assertEquals('/v3/transfer/batches/batch-id/123', $url->getPath()); - self::assertEquals('need_query_detail=0', $url->getQuery()); - self::assertEquals('GET', $radar->getMethod()); - } - - public function testNormalNoBatchId() - { - $rocket = new Rocket(); - $rocket->setParams([])->setPayload(new Collection(['need_query_detail' => false])); - - self::expectException(InvalidParamsException::class); - self::expectExceptionCode(Exception::PARAMS_NECESSARY_PARAMS_MISSING); - - $this->plugin->assembly($rocket, function ($rocket) { return $rocket; }); - } - - public function testNormalNoNeedQueryDetail() - { - $rocket = new Rocket(); - $rocket->setParams([])->setPayload(new Collection(['batch_id' => '123'])); - - self::expectException(InvalidParamsException::class); - self::expectExceptionCode(Exception::PARAMS_NECESSARY_PARAMS_MISSING); - - $this->plugin->assembly($rocket, function ($rocket) { return $rocket; }); - } - - public function testPartner() - { - $rocket = new Rocket(); - $rocket->setParams(['_config' => 'service_provider'])->setPayload(new Collection(['batch_id' => '123', 'need_query_detail' => false])); - - $result = $this->plugin->assembly($rocket, function ($rocket) { return $rocket; }); - - $radar = $result->getRadar(); - $url = $radar->getUri(); - - self::assertEquals('/v3/partner-transfer/batches/batch-id/123', $url->getPath()); - self::assertEquals('need_query_detail=0', $url->getQuery()); - self::assertEquals('GET', $radar->getMethod()); - } - - public function testPartnerNoBatchId() - { - $rocket = new Rocket(); - $rocket->setParams(['_config' => 'service_provider'])->setPayload(new Collection(['need_query_detail' => false])); - - self::expectException(InvalidParamsException::class); - self::expectExceptionCode(Exception::PARAMS_NECESSARY_PARAMS_MISSING); - - $this->plugin->assembly($rocket, function ($rocket) { return $rocket; }); - } - - public function testPartnerNoNeedQueryDetail() - { - $rocket = new Rocket(); - $rocket->setParams(['_config' => 'service_provider'])->setPayload(new Collection(['batch_id' => '123'])); - - self::expectException(InvalidParamsException::class); - self::expectExceptionCode(Exception::PARAMS_NECESSARY_PARAMS_MISSING); - - $this->plugin->assembly($rocket, function ($rocket) { return $rocket; }); - } -} diff --git a/tests/Plugin/Wechat/Fund/Transfer/QueryBillReceiptPluginTest.php b/tests/Plugin/Wechat/Fund/Transfer/QueryBillReceiptPluginTest.php deleted file mode 100644 index 70d9aa5..0000000 --- a/tests/Plugin/Wechat/Fund/Transfer/QueryBillReceiptPluginTest.php +++ /dev/null @@ -1,76 +0,0 @@ -plugin = new QueryBillReceiptPlugin(); - } - - public function testNormal() - { - $rocket = new Rocket(); - $rocket->setParams([])->setPayload(new Collection(['out_batch_no' => '123'])); - - $result = $this->plugin->assembly($rocket, function ($rocket) { return $rocket; }); - - $radar = $result->getRadar(); - - self::assertEquals(new Uri(Wechat::URL[Pay::MODE_NORMAL].'v3/transfer/bill-receipt/123'), $radar->getUri()); - self::assertEquals('GET', $radar->getMethod()); - } - - public function testNormalNoOutBatchNo() - { - $rocket = new Rocket(); - $rocket->setParams([])->setPayload(new Collection()); - - self::expectException(InvalidParamsException::class); - self::expectExceptionCode(Exception::PARAMS_NECESSARY_PARAMS_MISSING); - - $this->plugin->assembly($rocket, function ($rocket) { return $rocket; }); - } - - public function testPartner() - { - $rocket = new Rocket(); - $rocket->setParams(['_config' => 'service_provider'])->setPayload(new Collection(['out_batch_no' => '123'])); - - $result = $this->plugin->assembly($rocket, function ($rocket) { return $rocket; }); - - $radar = $result->getRadar(); - - self::assertEquals(new Uri(Wechat::URL[Pay::MODE_NORMAL].'v3/transfer/bill-receipt/123'), $radar->getUri()); - self::assertEquals('GET', $radar->getMethod()); - } - - public function testPartnerNoOutBatchNo() - { - $rocket = new Rocket(); - $rocket->setParams(['_config' => 'service_provider'])->setPayload(new Collection()); - - self::expectException(InvalidParamsException::class); - self::expectExceptionCode(Exception::PARAMS_NECESSARY_PARAMS_MISSING); - - $this->plugin->assembly($rocket, function ($rocket) { return $rocket; }); - } -} diff --git a/tests/Plugin/Wechat/Fund/Transfer/QueryDetailReceiptPluginTest.php b/tests/Plugin/Wechat/Fund/Transfer/QueryDetailReceiptPluginTest.php deleted file mode 100644 index b3d7b00..0000000 --- a/tests/Plugin/Wechat/Fund/Transfer/QueryDetailReceiptPluginTest.php +++ /dev/null @@ -1,63 +0,0 @@ -plugin = new QueryDetailReceiptPlugin(); - } - - public function testNormal() - { - $rocket = new Rocket(); - $rocket->setParams([])->setPayload(new Collection(['out_detail_no' => '123', 'accept_type' => '456'])); - - $result = $this->plugin->assembly($rocket, function ($rocket) { return $rocket; }); - - $radar = $result->getRadar(); - $url = $radar->getUri(); - - self::assertEquals('/v3/transfer-detail/electronic-receipts', $url->getPath()); - self::assertStringContainsString('out_detail_no=123', $url->getQuery()); - self::assertStringContainsString('accept_type=456', $url->getQuery()); - self::assertEquals('GET', $radar->getMethod()); - } - - public function testNormalNoOutDetailNo() - { - $rocket = new Rocket(); - $rocket->setParams([])->setPayload(new Collection(['accept_type' => '456'])); - - self::expectException(InvalidParamsException::class); - self::expectExceptionCode(Exception::PARAMS_NECESSARY_PARAMS_MISSING); - - $this->plugin->assembly($rocket, function ($rocket) { return $rocket; }); - } - - public function testNormalNoAcceptType() - { - $rocket = new Rocket(); - $rocket->setParams([])->setPayload(new Collection(['out_detail_no' => '123'])); - - self::expectException(InvalidParamsException::class); - self::expectExceptionCode(Exception::PARAMS_NECESSARY_PARAMS_MISSING); - - $this->plugin->assembly($rocket, function ($rocket) { return $rocket; }); - } -} diff --git a/tests/Plugin/Wechat/Fund/Transfer/QueryOutBatchDetailNoPluginTest.php b/tests/Plugin/Wechat/Fund/Transfer/QueryOutBatchDetailNoPluginTest.php deleted file mode 100644 index a94605c..0000000 --- a/tests/Plugin/Wechat/Fund/Transfer/QueryOutBatchDetailNoPluginTest.php +++ /dev/null @@ -1,98 +0,0 @@ -plugin = new QueryOutBatchDetailNoPlugin(); - } - - public function testNormal() - { - $rocket = new Rocket(); - $rocket->setParams([])->setPayload(new Collection(['out_batch_no' => '123', 'out_detail_no' => '456'])); - - $result = $this->plugin->assembly($rocket, function ($rocket) { return $rocket; }); - - $radar = $result->getRadar(); - - self::assertEquals(new Uri(Wechat::URL[Pay::MODE_NORMAL].'v3/transfer/batches/out-batch-no/123/details/out-detail-no/456'), $radar->getUri()); - self::assertEquals('GET', $radar->getMethod()); - } - - public function testNormalNoBatchId() - { - $rocket = new Rocket(); - $rocket->setParams([])->setPayload(new Collection(['out_detail_no' => '456'])); - - self::expectException(InvalidParamsException::class); - self::expectExceptionCode(Exception::PARAMS_NECESSARY_PARAMS_MISSING); - - $this->plugin->assembly($rocket, function ($rocket) { return $rocket; }); - } - - public function testNormalNoDetailId() - { - $rocket = new Rocket(); - $rocket->setParams([])->setPayload(new Collection(['out_batch_no' => '123'])); - - self::expectException(InvalidParamsException::class); - self::expectExceptionCode(Exception::PARAMS_NECESSARY_PARAMS_MISSING); - - $this->plugin->assembly($rocket, function ($rocket) { return $rocket; }); - } - - public function testPartner() - { - $rocket = new Rocket(); - $rocket->setParams(['_config' => 'service_provider'])->setPayload(new Collection(['out_batch_no' => '123', 'out_detail_no' => '456'])); - - $result = $this->plugin->assembly($rocket, function ($rocket) { return $rocket; }); - - $radar = $result->getRadar(); - - self::assertEquals(new Uri(Wechat::URL[Pay::MODE_NORMAL].'v3/partner-transfer/batches/out-batch-no/123/details/out-detail-no/456'), $radar->getUri()); - self::assertEquals('GET', $radar->getMethod()); - } - - public function testPartnerNoBatchId() - { - $rocket = new Rocket(); - $rocket->setParams(['_config' => 'service_provider'])->setPayload(new Collection(['out_detail_no' => '456'])); - - self::expectException(InvalidParamsException::class); - self::expectExceptionCode(Exception::PARAMS_NECESSARY_PARAMS_MISSING); - - $this->plugin->assembly($rocket, function ($rocket) { return $rocket; }); - } - - public function testPartnerNoDetailId() - { - $rocket = new Rocket(); - $rocket->setParams(['_config' => 'service_provider'])->setPayload(new Collection(['out_batch_no' => '123'])); - - self::expectException(InvalidParamsException::class); - self::expectExceptionCode(Exception::PARAMS_NECESSARY_PARAMS_MISSING); - - $this->plugin->assembly($rocket, function ($rocket) { return $rocket; }); - } -} diff --git a/tests/Plugin/Wechat/Fund/Transfer/QueryOutBatchNoPluginTest.php b/tests/Plugin/Wechat/Fund/Transfer/QueryOutBatchNoPluginTest.php deleted file mode 100644 index 48ccf6d..0000000 --- a/tests/Plugin/Wechat/Fund/Transfer/QueryOutBatchNoPluginTest.php +++ /dev/null @@ -1,99 +0,0 @@ -plugin = new QueryOutBatchNoPlugin(); - } - - public function testNormal() - { - $rocket = new Rocket(); - $rocket->setParams([])->setPayload(new Collection(['out_batch_no' => '123', 'need_query_detail' => false])); - - $result = $this->plugin->assembly($rocket, function ($rocket) { return $rocket; }); - - $radar = $result->getRadar(); - $url = $radar->getUri(); - - self::assertEquals('/v3/transfer/batches/out-batch-no/123', $url->getPath()); - self::assertEquals('need_query_detail=0', $url->getQuery()); - self::assertEquals('GET', $radar->getMethod()); - } - - public function testNormalNoOutBatchNo() - { - $rocket = new Rocket(); - $rocket->setParams([])->setPayload(new Collection(['need_query_detail' => false])); - - self::expectException(InvalidParamsException::class); - self::expectExceptionCode(Exception::PARAMS_NECESSARY_PARAMS_MISSING); - - $this->plugin->assembly($rocket, function ($rocket) { return $rocket; }); - } - - public function testNormalNoNeedQueryDetail() - { - $rocket = new Rocket(); - $rocket->setParams([])->setPayload(new Collection(['out_batch_no' => '123'])); - - self::expectException(InvalidParamsException::class); - self::expectExceptionCode(Exception::PARAMS_NECESSARY_PARAMS_MISSING); - - $this->plugin->assembly($rocket, function ($rocket) { return $rocket; }); - } - - public function testPartner() - { - $rocket = new Rocket(); - $rocket->setParams(['_config' => 'service_provider'])->setPayload(new Collection(['out_batch_no' => '123', 'need_query_detail' => false])); - - $result = $this->plugin->assembly($rocket, function ($rocket) { return $rocket; }); - - $radar = $result->getRadar(); - $url = $radar->getUri(); - - self::assertEquals('/v3/partner-transfer/batches/out-batch-no/123', $url->getPath()); - self::assertEquals('need_query_detail=0', $url->getQuery()); - self::assertEquals('GET', $radar->getMethod()); - } - - public function testPartnerNoOutBatchNo() - { - $rocket = new Rocket(); - $rocket->setParams(['_config' => 'service_provider'])->setPayload(new Collection(['need_query_detail' => false])); - - self::expectException(InvalidParamsException::class); - self::expectExceptionCode(Exception::PARAMS_NECESSARY_PARAMS_MISSING); - - $this->plugin->assembly($rocket, function ($rocket) { return $rocket; }); - } - - public function testPartnerNoNeedQueryDetail() - { - $rocket = new Rocket(); - $rocket->setParams(['_config' => 'service_provider'])->setPayload(new Collection(['out_batch_no' => '123'])); - - self::expectException(InvalidParamsException::class); - self::expectExceptionCode(Exception::PARAMS_NECESSARY_PARAMS_MISSING); - - $this->plugin->assembly($rocket, function ($rocket) { return $rocket; }); - } -} diff --git a/tests/Plugin/Wechat/GeneralPluginTest.php b/tests/Plugin/Wechat/GeneralPluginTest.php deleted file mode 100644 index 6595fef..0000000 --- a/tests/Plugin/Wechat/GeneralPluginTest.php +++ /dev/null @@ -1,67 +0,0 @@ -plugin = new WechatGeneralPluginStub(); - } - - public function testNormal() - { - $rocket = new Rocket(); - $rocket->setParams([]); - - $result = $this->plugin->assembly($rocket, function ($rocket) { return $rocket; }); - - $radar = $result->getRadar(); - - self::assertInstanceOf(RequestInterface::class, $radar); - self::assertEquals('POST', $radar->getMethod()); - self::assertEquals(new Uri(Wechat::URL[Pay::MODE_NORMAL].'yansongda/pay'), $radar->getUri()); - self::assertEquals('mp_app_id', $result->getPayload()['config_key']); - } - - public function testPartner() - { - $rocket = new Rocket(); - $rocket->setParams(['_config' => 'service_provider']); - - $result = $this->plugin->assembly($rocket, function ($rocket) { return $rocket; }); - - $radar = $result->getRadar(); - - self::assertInstanceOf(RequestInterface::class, $radar); - self::assertEquals('POST', $radar->getMethod()); - self::assertEquals(new Uri(Wechat::URL[Pay::MODE_SERVICE].'yansongda/pay/partner'), $radar->getUri()); - } - - public function testGetConfigKey() - { - $rocket = new Rocket(); - $rocket->setParams(['_type' => 'mini']); - - $result = $this->plugin->assembly($rocket, function ($rocket) { return $rocket; }); - - $radar = $result->getRadar(); - - self::assertInstanceOf(RequestInterface::class, $radar); - self::assertEquals('POST', $radar->getMethod()); - self::assertEquals(new Uri(Wechat::URL[Pay::MODE_NORMAL].'yansongda/pay'), $radar->getUri()); - self::assertEquals('mini_app_id', $result->getPayload()['config_key']); - } -} diff --git a/tests/Plugin/Wechat/GeneralV2PluginTest.php b/tests/Plugin/Wechat/GeneralV2PluginTest.php deleted file mode 100644 index 14bac89..0000000 --- a/tests/Plugin/Wechat/GeneralV2PluginTest.php +++ /dev/null @@ -1,46 +0,0 @@ -plugin = new WechatGeneralV2PluginStub(); - } - - public function testNormal() - { - $rocket = new Rocket(); - $rocket->setParams([]); - - $result = $this->plugin->assembly($rocket, function ($rocket) { return $rocket; }); - - $radar = $result->getRadar(); - $params = $result->getParams(); - $payload = $result->getPayload(); - - self::assertEquals(XmlPacker::class, $result->getPacker()); - self::assertInstanceOf(RequestInterface::class, $radar); - self::assertEquals('POST', $radar->getMethod()); - self::assertEquals(new Uri(Wechat::URL[Pay::MODE_NORMAL].'yansongda/pay'), $radar->getUri()); - self::assertEquals('1600314069', $payload->get('mch_id')); - self::assertEquals('wx55955316af4ef13', $payload->get('appid')); - self::assertEquals('v2', $params['_version']); - self::assertEquals('application/xml', $radar->getHeaderLine('Content-Type')); - self::assertEquals('yansongda/pay-v3', $radar->getHeaderLine('User-Agent')); - } -} diff --git a/tests/Plugin/Wechat/Marketing/Coupon/CreatePluginTest.php b/tests/Plugin/Wechat/Marketing/Coupon/CreatePluginTest.php index 7dea32f..904d48e 100644 --- a/tests/Plugin/Wechat/Marketing/Coupon/CreatePluginTest.php +++ b/tests/Plugin/Wechat/Marketing/Coupon/CreatePluginTest.php @@ -2,10 +2,7 @@ namespace Yansongda\Pay\Tests\Plugin\Wechat\Marketing\Coupon; -use GuzzleHttp\Psr7\Uri; -use Yansongda\Pay\Pay; use Yansongda\Pay\Plugin\Wechat\Marketing\Coupon\CreatePlugin; -use Yansongda\Pay\Provider\Wechat; use Yansongda\Pay\Rocket; use Yansongda\Pay\Tests\TestCase; use Yansongda\Supports\Collection; @@ -21,22 +18,39 @@ class CreatePluginTest extends TestCase $this->plugin = new CreatePlugin(); } - public function testNormal() + public function testNormalParams() { - $rocket = (new Rocket())->setParams([])->setPayload(new Collection([ - 'stock_name' => '7890', - 'available_begin_time' => '2020-01-01T00:00:00+08:00', + $rocket = new Rocket(); + $rocket->setPayload(new Collection( [ + "test" => "yansongda", + 'belong_merchant' => '1111', ])); - $result = $this->plugin->assembly($rocket, function ($rocket) {return $rocket; }); + $result = $this->plugin->assembly($rocket, function ($rocket) { return $rocket; }); - $radar = $result->getRadar(); - - self::assertEquals('POST', $radar->getMethod()); - self::assertEquals(new Uri(Wechat::URL[Pay::MODE_NORMAL].'v3/marketing/favor/coupon-stocks'), $radar->getUri()); self::assertEquals([ - 'stock_name' => '7890', - 'available_begin_time' => '2020-01-01T00:00:00+08:00', + '_method' => 'POST', + '_url' => 'v3/marketing/favor/coupon-stocks', + '_service_url' => 'v3/marketing/favor/coupon-stocks', + 'test' => 'yansongda', + 'belong_merchant' => '1111', + ], $result->getPayload()->all()); + } + + public function testNormal() + { + $rocket = new Rocket(); + $rocket->setPayload(new Collection( [ + "test" => "yansongda", + ])); + + $result = $this->plugin->assembly($rocket, function ($rocket) { return $rocket; }); + + self::assertEquals([ + '_method' => 'POST', + '_url' => 'v3/marketing/favor/coupon-stocks', + '_service_url' => 'v3/marketing/favor/coupon-stocks', + 'test' => 'yansongda', 'belong_merchant' => '1600314069', ], $result->getPayload()->all()); } diff --git a/tests/Plugin/Wechat/Marketing/Coupon/PausePluginTest.php b/tests/Plugin/Wechat/Marketing/Coupon/PausePluginTest.php index b7b6f1a..45f5765 100644 --- a/tests/Plugin/Wechat/Marketing/Coupon/PausePluginTest.php +++ b/tests/Plugin/Wechat/Marketing/Coupon/PausePluginTest.php @@ -2,10 +2,9 @@ namespace Yansongda\Pay\Tests\Plugin\Wechat\Marketing\Coupon; -use GuzzleHttp\Psr7\Uri; -use Yansongda\Pay\Pay; +use Yansongda\Pay\Exception\Exception; +use Yansongda\Pay\Exception\InvalidParamsException; use Yansongda\Pay\Plugin\Wechat\Marketing\Coupon\PausePlugin; -use Yansongda\Pay\Provider\Wechat; use Yansongda\Pay\Rocket; use Yansongda\Pay\Tests\TestCase; use Yansongda\Supports\Collection; @@ -21,19 +20,48 @@ class PausePluginTest extends TestCase $this->plugin = new PausePlugin(); } - public function testNormal() + public function testEmptyPayload() { - $rocket = (new Rocket())->setParams([])->setPayload(new Collection([ - 'stock_id' => '7890', + $rocket = new Rocket(); + + self::expectException(InvalidParamsException::class); + self::expectExceptionCode(Exception::PARAMS_NECESSARY_PARAMS_MISSING); + self::expectExceptionMessage('参数异常: 暂停代金券批次,参数缺少 `stock_id`'); + + $this->plugin->assembly($rocket, function ($rocket) { return $rocket; }); + } + + public function testNormalParams() + { + $rocket = new Rocket(); + $rocket->setPayload(new Collection( [ + "stock_id" => "yansongda", + 'stock_creator_mchid' => '1111', ])); - $result = $this->plugin->assembly($rocket, function ($rocket) {return $rocket; }); + $result = $this->plugin->assembly($rocket, function ($rocket) { return $rocket; }); - $radar = $result->getRadar(); - - self::assertEquals('POST', $radar->getMethod()); - self::assertEquals(new Uri(Wechat::URL[Pay::MODE_NORMAL].'v3/marketing/favor/stocks/7890/pause'), $radar->getUri()); self::assertEquals([ + '_method' => 'POST', + '_url' => 'v3/marketing/favor/stocks/yansongda/pause', + '_service_url' => 'v3/marketing/favor/stocks/yansongda/pause', + 'stock_creator_mchid' => '1111', + ], $result->getPayload()->all()); + } + + public function testNormal() + { + $rocket = new Rocket(); + $rocket->setPayload(new Collection( [ + "stock_id" => "yansongda", + ])); + + $result = $this->plugin->assembly($rocket, function ($rocket) { return $rocket; }); + + self::assertEquals([ + '_method' => 'POST', + '_url' => 'v3/marketing/favor/stocks/yansongda/pause', + '_service_url' => 'v3/marketing/favor/stocks/yansongda/pause', 'stock_creator_mchid' => '1600314069', ], $result->getPayload()->all()); } diff --git a/tests/Plugin/Wechat/Marketing/Coupon/QueryCallbackPluginTest.php b/tests/Plugin/Wechat/Marketing/Coupon/QueryCallbackPluginTest.php new file mode 100644 index 0000000..fc4c9bf --- /dev/null +++ b/tests/Plugin/Wechat/Marketing/Coupon/QueryCallbackPluginTest.php @@ -0,0 +1,51 @@ +plugin = new QueryCallbackPlugin(); + } + + public function testNormalParams() + { + $rocket = new Rocket(); + $rocket->setPayload(new Collection( [ + "mchid" => "yansongda", + ])); + + $result = $this->plugin->assembly($rocket, function ($rocket) { return $rocket; }); + + self::assertEquals([ + '_method' => 'GET', + '_url' => 'v3/marketing/favor/callbacks?mchid=yansongda', + '_service_url' => 'v3/marketing/favor/callbacks?mchid=yansongda', + ], $result->getPayload()->all()); + } + + public function testNormal() + { + $rocket = new Rocket(); + $rocket->setPayload(new Collection( [ + ])); + + $result = $this->plugin->assembly($rocket, function ($rocket) { return $rocket; }); + + self::assertEquals([ + '_method' => 'GET', + '_url' => 'v3/marketing/favor/callbacks?mchid=1600314069', + '_service_url' => 'v3/marketing/favor/callbacks?mchid=1600314069', + ], $result->getPayload()->all()); + } +} diff --git a/tests/Plugin/Wechat/Marketing/Coupon/QueryCouponDetailPluginTest.php b/tests/Plugin/Wechat/Marketing/Coupon/QueryCouponDetailPluginTest.php index 4edb16a..5a067f9 100644 --- a/tests/Plugin/Wechat/Marketing/Coupon/QueryCouponDetailPluginTest.php +++ b/tests/Plugin/Wechat/Marketing/Coupon/QueryCouponDetailPluginTest.php @@ -2,12 +2,9 @@ namespace Yansongda\Pay\Tests\Plugin\Wechat\Marketing\Coupon; -use GuzzleHttp\Psr7\Uri; use Yansongda\Pay\Exception\Exception; use Yansongda\Pay\Exception\InvalidParamsException; -use Yansongda\Pay\Pay; use Yansongda\Pay\Plugin\Wechat\Marketing\Coupon\QueryCouponDetailPlugin; -use Yansongda\Pay\Provider\Wechat; use Yansongda\Pay\Rocket; use Yansongda\Pay\Tests\TestCase; use Yansongda\Supports\Collection; @@ -23,48 +20,49 @@ class QueryCouponDetailPluginTest extends TestCase $this->plugin = new QueryCouponDetailPlugin(); } - public function testNormal() + public function testEmptyPayload() { - $rocket = (new Rocket())->setParams([])->setPayload(new Collection([ - 'coupon_id' => '123456', - 'openid' => '7890', - ])); + $rocket = new Rocket(); - $result = $this->plugin->assembly($rocket, function ($rocket) {return $rocket; }); - - $radar = $result->getRadar(); - - self::assertEquals('GET', $radar->getMethod()); - self::assertNull($result->getPayload()); - self::assertEquals(new Uri(Wechat::URL[Pay::MODE_NORMAL].'v3/marketing/favor/users/7890/coupons/123456?appid=wx55955316af4ef13'), $radar->getUri()); - } - - public function testException() - { self::expectException(InvalidParamsException::class); self::expectExceptionCode(Exception::PARAMS_NECESSARY_PARAMS_MISSING); + self::expectExceptionMessage('参数异常: 查询代金券详情,参数缺少 `openid` 或 `coupon_id`'); - $rocket = (new Rocket())->setParams([])->setPayload(new Collection([ - 'coupon_id' => '123456', - // 'openid' => '7890', - ])); - - $this->plugin->assembly($rocket, function ($rocket) {return $rocket; }); + $this->plugin->assembly($rocket, function ($rocket) { return $rocket; }); } - public function testOtherAppId() + public function testNormalParams() { - $rocket = (new Rocket())->setParams(['_type' => 'mini'])->setPayload(new Collection([ - 'coupon_id' => '123456', - 'openid' => '7890', + $rocket = new Rocket(); + $rocket->setPayload(new Collection( [ + "openid" => "111", + 'coupon_id' => '222', + 'appid' => '333', ])); - $result = $this->plugin->assembly($rocket, function ($rocket) {return $rocket; }); + $result = $this->plugin->assembly($rocket, function ($rocket) { return $rocket; }); - $radar = $result->getRadar(); + self::assertEquals([ + '_method' => 'GET', + '_url' => 'v3/marketing/favor/users/111/coupons/222?appid=333', + '_service_url' => 'v3/marketing/favor/users/111/coupons/222?appid=333', + ], $result->getPayload()->all()); + } - self::assertEquals('GET', $radar->getMethod()); - self::assertNull($result->getPayload()); - self::assertEquals(new Uri(Wechat::URL[Pay::MODE_NORMAL].'v3/marketing/favor/users/7890/coupons/123456?appid=wx55955316af4ef14'), $radar->getUri()); + public function testNormal() + { + $rocket = new Rocket(); + $rocket->setPayload(new Collection( [ + "openid" => "111", + 'coupon_id' => '222', + ])); + + $result = $this->plugin->assembly($rocket, function ($rocket) { return $rocket; }); + + self::assertEquals([ + '_method' => 'GET', + '_url' => 'v3/marketing/favor/users/111/coupons/222?appid=wx55955316af4ef13', + '_service_url' => 'v3/marketing/favor/users/111/coupons/222?appid=wx55955316af4ef13', + ], $result->getPayload()->all()); } } diff --git a/tests/Plugin/Wechat/Marketing/Coupon/QueryStockDetailPluginTest.php b/tests/Plugin/Wechat/Marketing/Coupon/QueryStockDetailPluginTest.php index 2c1af50..997c664 100644 --- a/tests/Plugin/Wechat/Marketing/Coupon/QueryStockDetailPluginTest.php +++ b/tests/Plugin/Wechat/Marketing/Coupon/QueryStockDetailPluginTest.php @@ -2,12 +2,9 @@ namespace Yansongda\Pay\Tests\Plugin\Wechat\Marketing\Coupon; -use GuzzleHttp\Psr7\Uri; use Yansongda\Pay\Exception\Exception; use Yansongda\Pay\Exception\InvalidParamsException; -use Yansongda\Pay\Pay; use Yansongda\Pay\Plugin\Wechat\Marketing\Coupon\QueryStockDetailPlugin; -use Yansongda\Pay\Provider\Wechat; use Yansongda\Pay\Rocket; use Yansongda\Pay\Tests\TestCase; use Yansongda\Supports\Collection; @@ -23,28 +20,47 @@ class QueryStockDetailPluginTest extends TestCase $this->plugin = new QueryStockDetailPlugin(); } - public function testNormal() + public function testEmptyPayload() { - $rocket = (new Rocket())->setParams([])->setPayload(new Collection([ - 'stock_id' => '123456', - ])); + $rocket = new Rocket(); - $result = $this->plugin->assembly($rocket, function ($rocket) {return $rocket; }); - - $radar = $result->getRadar(); - - self::assertEquals('GET', $radar->getMethod()); - self::assertNull($result->getPayload()); - self::assertEquals(new Uri(Wechat::URL[Pay::MODE_NORMAL].'v3/marketing/favor/stocks/123456?stock_creator_mchid=1600314069'), $radar->getUri()); - } - - public function testException() - { self::expectException(InvalidParamsException::class); self::expectExceptionCode(Exception::PARAMS_NECESSARY_PARAMS_MISSING); + self::expectExceptionMessage('参数异常: 查询代金券批次详情,参数缺少 `stock_id`'); - $rocket = (new Rocket())->setParams([])->setPayload(new Collection()); + $this->plugin->assembly($rocket, function ($rocket) { return $rocket; }); + } - $this->plugin->assembly($rocket, function ($rocket) {return $rocket; }); + public function testNormalParams() + { + $rocket = new Rocket(); + $rocket->setPayload(new Collection( [ + "stock_id" => "111", + 'stock_creator_mchid' => '222', + ])); + + $result = $this->plugin->assembly($rocket, function ($rocket) { return $rocket; }); + + self::assertEquals([ + '_method' => 'GET', + '_url' => 'v3/marketing/favor/stocks/111?stock_creator_mchid=222', + '_service_url' => 'v3/marketing/favor/stocks/111?stock_creator_mchid=222', + ], $result->getPayload()->all()); + } + + public function testNormal() + { + $rocket = new Rocket(); + $rocket->setPayload(new Collection( [ + "stock_id" => "111", + ])); + + $result = $this->plugin->assembly($rocket, function ($rocket) { return $rocket; }); + + self::assertEquals([ + '_method' => 'GET', + '_url' => 'v3/marketing/favor/stocks/111?stock_creator_mchid=1600314069', + '_service_url' => 'v3/marketing/favor/stocks/111?stock_creator_mchid=1600314069', + ], $result->getPayload()->all()); } } diff --git a/tests/Plugin/Wechat/Marketing/Coupon/QueryStockItemsPluginTest.php b/tests/Plugin/Wechat/Marketing/Coupon/QueryStockItemsPluginTest.php index 6a26ec7..1ea9bb1 100644 --- a/tests/Plugin/Wechat/Marketing/Coupon/QueryStockItemsPluginTest.php +++ b/tests/Plugin/Wechat/Marketing/Coupon/QueryStockItemsPluginTest.php @@ -2,12 +2,9 @@ namespace Yansongda\Pay\Tests\Plugin\Wechat\Marketing\Coupon; -use GuzzleHttp\Psr7\Uri; use Yansongda\Pay\Exception\Exception; use Yansongda\Pay\Exception\InvalidParamsException; -use Yansongda\Pay\Pay; use Yansongda\Pay\Plugin\Wechat\Marketing\Coupon\QueryStockItemsPlugin; -use Yansongda\Pay\Provider\Wechat; use Yansongda\Pay\Rocket; use Yansongda\Pay\Tests\TestCase; use Yansongda\Supports\Collection; @@ -23,29 +20,47 @@ class QueryStockItemsPluginTest extends TestCase $this->plugin = new QueryStockItemsPlugin(); } - public function testNormal() + public function testEmptyPayload() { - $rocket = (new Rocket())->setParams([])->setPayload(new Collection([ - 'stock_id' => '123456', - 'limit' => 1, - ])); + $rocket = new Rocket(); - $result = $this->plugin->assembly($rocket, function ($rocket) {return $rocket; }); - - $radar = $result->getRadar(); - - self::assertEquals('GET', $radar->getMethod()); - self::assertNull($result->getPayload()); - self::assertEquals(new Uri(Wechat::URL[Pay::MODE_NORMAL].'v3/marketing/favor/stocks/123456/items?limit=1&stock_creator_mchid=1600314069'), $radar->getUri()); - } - - public function testException() - { self::expectException(InvalidParamsException::class); self::expectExceptionCode(Exception::PARAMS_NECESSARY_PARAMS_MISSING); + self::expectExceptionMessage('参数异常: 查询代金券可用单品,参数缺少 `stock_id`'); - $rocket = (new Rocket())->setParams([])->setPayload(new Collection()); + $this->plugin->assembly($rocket, function ($rocket) { return $rocket; }); + } - $this->plugin->assembly($rocket, function ($rocket) {return $rocket; }); + public function testNormalParams() + { + $rocket = new Rocket(); + $rocket->setPayload(new Collection( [ + "stock_id" => "111", + 'stock_creator_mchid' => '222', + ])); + + $result = $this->plugin->assembly($rocket, function ($rocket) { return $rocket; }); + + self::assertEquals([ + '_method' => 'GET', + '_url' => 'v3/marketing/favor/stocks/111/items?stock_creator_mchid=222', + '_service_url' => 'v3/marketing/favor/stocks/111/items?stock_creator_mchid=222', + ], $result->getPayload()->all()); + } + + public function testNormal() + { + $rocket = new Rocket(); + $rocket->setPayload(new Collection( [ + "stock_id" => "111", + ])); + + $result = $this->plugin->assembly($rocket, function ($rocket) { return $rocket; }); + + self::assertEquals([ + '_method' => 'GET', + '_url' => 'v3/marketing/favor/stocks/111/items?stock_creator_mchid=1600314069', + '_service_url' => 'v3/marketing/favor/stocks/111/items?stock_creator_mchid=1600314069', + ], $result->getPayload()->all()); } } diff --git a/tests/Plugin/Wechat/Marketing/Coupon/QueryStockMerchantsPluginTest.php b/tests/Plugin/Wechat/Marketing/Coupon/QueryStockMerchantsPluginTest.php index 622790d..7bf1b5e 100644 --- a/tests/Plugin/Wechat/Marketing/Coupon/QueryStockMerchantsPluginTest.php +++ b/tests/Plugin/Wechat/Marketing/Coupon/QueryStockMerchantsPluginTest.php @@ -2,12 +2,9 @@ namespace Yansongda\Pay\Tests\Plugin\Wechat\Marketing\Coupon; -use GuzzleHttp\Psr7\Uri; use Yansongda\Pay\Exception\Exception; use Yansongda\Pay\Exception\InvalidParamsException; -use Yansongda\Pay\Pay; use Yansongda\Pay\Plugin\Wechat\Marketing\Coupon\QueryStockMerchantsPlugin; -use Yansongda\Pay\Provider\Wechat; use Yansongda\Pay\Rocket; use Yansongda\Pay\Tests\TestCase; use Yansongda\Supports\Collection; @@ -23,29 +20,47 @@ class QueryStockMerchantsPluginTest extends TestCase $this->plugin = new QueryStockMerchantsPlugin(); } - public function testNormal() + public function testEmptyPayload() { - $rocket = (new Rocket())->setParams([])->setPayload(new Collection([ - 'stock_id' => '123456', - 'limit' => 1, - ])); + $rocket = new Rocket(); - $result = $this->plugin->assembly($rocket, function ($rocket) {return $rocket; }); - - $radar = $result->getRadar(); - - self::assertEquals('GET', $radar->getMethod()); - self::assertNull($result->getPayload()); - self::assertEquals(new Uri(Wechat::URL[Pay::MODE_NORMAL].'v3/marketing/favor/stocks/123456/merchants?limit=1&stock_creator_mchid=1600314069'), $radar->getUri()); - } - - public function testException() - { self::expectException(InvalidParamsException::class); self::expectExceptionCode(Exception::PARAMS_NECESSARY_PARAMS_MISSING); + self::expectExceptionMessage('参数异常: 查询代金券可用商户,参数缺少 `stock_id`'); - $rocket = (new Rocket())->setParams([])->setPayload(new Collection()); + $this->plugin->assembly($rocket, function ($rocket) { return $rocket; }); + } - $this->plugin->assembly($rocket, function ($rocket) {return $rocket; }); + public function testNormalParams() + { + $rocket = new Rocket(); + $rocket->setPayload(new Collection( [ + "stock_id" => "111", + 'stock_creator_mchid' => '222', + ])); + + $result = $this->plugin->assembly($rocket, function ($rocket) { return $rocket; }); + + self::assertEquals([ + '_method' => 'GET', + '_url' => 'v3/marketing/favor/stocks/111/merchants?stock_creator_mchid=222', + '_service_url' => 'v3/marketing/favor/stocks/111/merchants?stock_creator_mchid=222', + ], $result->getPayload()->all()); + } + + public function testNormal() + { + $rocket = new Rocket(); + $rocket->setPayload(new Collection( [ + "stock_id" => "111", + ])); + + $result = $this->plugin->assembly($rocket, function ($rocket) { return $rocket; }); + + self::assertEquals([ + '_method' => 'GET', + '_url' => 'v3/marketing/favor/stocks/111/merchants?stock_creator_mchid=1600314069', + '_service_url' => 'v3/marketing/favor/stocks/111/merchants?stock_creator_mchid=1600314069', + ], $result->getPayload()->all()); } } diff --git a/tests/Plugin/Wechat/Marketing/Coupon/QueryStockRefundFlowPluginTest.php b/tests/Plugin/Wechat/Marketing/Coupon/QueryStockRefundFlowPluginTest.php index 8895ccc..7fe2e32 100644 --- a/tests/Plugin/Wechat/Marketing/Coupon/QueryStockRefundFlowPluginTest.php +++ b/tests/Plugin/Wechat/Marketing/Coupon/QueryStockRefundFlowPluginTest.php @@ -2,12 +2,9 @@ namespace Yansongda\Pay\Tests\Plugin\Wechat\Marketing\Coupon; -use GuzzleHttp\Psr7\Uri; use Yansongda\Pay\Exception\Exception; use Yansongda\Pay\Exception\InvalidParamsException; -use Yansongda\Pay\Pay; use Yansongda\Pay\Plugin\Wechat\Marketing\Coupon\QueryStockRefundFlowPlugin; -use Yansongda\Pay\Provider\Wechat; use Yansongda\Pay\Rocket; use Yansongda\Pay\Tests\TestCase; use Yansongda\Supports\Collection; @@ -23,28 +20,30 @@ class QueryStockRefundFlowPluginTest extends TestCase $this->plugin = new QueryStockRefundFlowPlugin(); } - public function testNormal() + public function testEmptyPayload() { - $rocket = (new Rocket())->setParams([])->setPayload(new Collection([ - 'stock_id' => '123456', - ])); + $rocket = new Rocket(); - $result = $this->plugin->assembly($rocket, function ($rocket) {return $rocket; }); - - $radar = $result->getRadar(); - - self::assertEquals('GET', $radar->getMethod()); - self::assertNull($result->getPayload()); - self::assertEquals(new Uri(Wechat::URL[Pay::MODE_NORMAL].'v3/marketing/favor/stocks/123456/refund-flow'), $radar->getUri()); - } - - public function testException() - { self::expectException(InvalidParamsException::class); self::expectExceptionCode(Exception::PARAMS_NECESSARY_PARAMS_MISSING); + self::expectExceptionMessage('参数异常: 下载批次退款明细,参数缺少 `stock_id`'); - $rocket = (new Rocket())->setParams([])->setPayload(new Collection()); + $this->plugin->assembly($rocket, function ($rocket) { return $rocket; }); + } - $this->plugin->assembly($rocket, function ($rocket) {return $rocket; }); + public function testNormal() + { + $rocket = new Rocket(); + $rocket->setPayload(new Collection( [ + "stock_id" => "yansongda", + ])); + + $result = $this->plugin->assembly($rocket, function ($rocket) { return $rocket; }); + + self::assertEquals([ + '_method' => 'GET', + '_url' => 'v3/marketing/favor/stocks/yansongda/refund-flow', + '_service_url' => 'v3/marketing/favor/stocks/yansongda/refund-flow', + ], $result->getPayload()->all()); } } diff --git a/tests/Plugin/Wechat/Marketing/Coupon/QueryStockUseFlowPluginTest.php b/tests/Plugin/Wechat/Marketing/Coupon/QueryStockUseFlowPluginTest.php index e3e91b3..eb073d8 100644 --- a/tests/Plugin/Wechat/Marketing/Coupon/QueryStockUseFlowPluginTest.php +++ b/tests/Plugin/Wechat/Marketing/Coupon/QueryStockUseFlowPluginTest.php @@ -2,12 +2,9 @@ namespace Yansongda\Pay\Tests\Plugin\Wechat\Marketing\Coupon; -use GuzzleHttp\Psr7\Uri; use Yansongda\Pay\Exception\Exception; use Yansongda\Pay\Exception\InvalidParamsException; -use Yansongda\Pay\Pay; use Yansongda\Pay\Plugin\Wechat\Marketing\Coupon\QueryStockUseFlowPlugin; -use Yansongda\Pay\Provider\Wechat; use Yansongda\Pay\Rocket; use Yansongda\Pay\Tests\TestCase; use Yansongda\Supports\Collection; @@ -23,28 +20,30 @@ class QueryStockUseFlowPluginTest extends TestCase $this->plugin = new QueryStockUseFlowPlugin(); } - public function testNormal() + public function testEmptyPayload() { - $rocket = (new Rocket())->setParams([])->setPayload(new Collection([ - 'stock_id' => '123456', - ])); + $rocket = new Rocket(); - $result = $this->plugin->assembly($rocket, function ($rocket) {return $rocket; }); - - $radar = $result->getRadar(); - - self::assertEquals('GET', $radar->getMethod()); - self::assertNull($result->getPayload()); - self::assertEquals(new Uri(Wechat::URL[Pay::MODE_NORMAL].'v3/marketing/favor/stocks/123456/use-flow'), $radar->getUri()); - } - - public function testException() - { self::expectException(InvalidParamsException::class); self::expectExceptionCode(Exception::PARAMS_NECESSARY_PARAMS_MISSING); + self::expectExceptionMessage('参数异常: 下载批次核销明细,参数缺少 `stock_id`'); - $rocket = (new Rocket())->setParams([])->setPayload(new Collection()); + $this->plugin->assembly($rocket, function ($rocket) { return $rocket; }); + } - $this->plugin->assembly($rocket, function ($rocket) {return $rocket; }); + public function testNormal() + { + $rocket = new Rocket(); + $rocket->setPayload(new Collection( [ + "stock_id" => "111", + ])); + + $result = $this->plugin->assembly($rocket, function ($rocket) { return $rocket; }); + + self::assertEquals([ + '_method' => 'GET', + '_url' => 'v3/marketing/favor/stocks/111/use-flow', + '_service_url' => 'v3/marketing/favor/stocks/111/use-flow', + ], $result->getPayload()->all()); } } diff --git a/tests/Plugin/Wechat/Marketing/Coupon/QueryStocksPluginTest.php b/tests/Plugin/Wechat/Marketing/Coupon/QueryStocksPluginTest.php index 8a1a4c0..a6b9a36 100644 --- a/tests/Plugin/Wechat/Marketing/Coupon/QueryStocksPluginTest.php +++ b/tests/Plugin/Wechat/Marketing/Coupon/QueryStocksPluginTest.php @@ -2,10 +2,9 @@ namespace Yansongda\Pay\Tests\Plugin\Wechat\Marketing\Coupon; -use GuzzleHttp\Psr7\Uri; -use Yansongda\Pay\Pay; +use Yansongda\Pay\Exception\Exception; +use Yansongda\Pay\Exception\InvalidParamsException; use Yansongda\Pay\Plugin\Wechat\Marketing\Coupon\QueryStocksPlugin; -use Yansongda\Pay\Provider\Wechat; use Yansongda\Pay\Rocket; use Yansongda\Pay\Tests\TestCase; use Yansongda\Supports\Collection; @@ -21,32 +20,47 @@ class QueryStocksPluginTest extends TestCase $this->plugin = new QueryStocksPlugin(); } + public function testEmptyPayload() + { + $rocket = new Rocket(); + + self::expectException(InvalidParamsException::class); + self::expectExceptionCode(Exception::PARAMS_NECESSARY_PARAMS_MISSING); + self::expectExceptionMessage('参数异常: 缺少代金券相关参数'); + + $this->plugin->assembly($rocket, function ($rocket) { return $rocket; }); + } + + public function testNormalParams() + { + $rocket = new Rocket(); + $rocket->setPayload(new Collection( [ + "stock_id" => "111", + 'stock_creator_mchid' => '222', + ])); + + $result = $this->plugin->assembly($rocket, function ($rocket) { return $rocket; }); + + self::assertEquals([ + '_method' => 'GET', + '_url' => 'v3/marketing/favor/stocks?stock_id=111&stock_creator_mchid=222', + '_service_url' => 'v3/marketing/favor/stocks?stock_id=111&stock_creator_mchid=222', + ], $result->getPayload()->all()); + } + public function testNormal() { - $rocket = (new Rocket())->setParams([])->setPayload(new Collection([ - 'limit' => 1, + $rocket = new Rocket(); + $rocket->setPayload(new Collection( [ + "stock_id" => "111", ])); - $result = $this->plugin->assembly($rocket, function ($rocket) {return $rocket; }); + $result = $this->plugin->assembly($rocket, function ($rocket) { return $rocket; }); - $radar = $result->getRadar(); - - self::assertEquals('GET', $radar->getMethod()); - self::assertNull($result->getPayload()); - self::assertEquals(new Uri(Wechat::URL[Pay::MODE_NORMAL].'v3/marketing/favor/stocks?limit=1&stock_creator_mchid=1600314069'), $radar->getUri()); - } - - public function testExistMchId() - { - $rocket = (new Rocket())->setParams([])->setPayload(new Collection([ - 'limit' => 1, - 'stock_creator_mchid' => '123', - ])); - - $result = $this->plugin->assembly($rocket, function ($rocket) {return $rocket; }); - - $radar = $result->getRadar(); - - self::assertEquals(new Uri(Wechat::URL[Pay::MODE_NORMAL].'v3/marketing/favor/stocks?limit=1&stock_creator_mchid=123'), $radar->getUri()); + self::assertEquals([ + '_method' => 'GET', + '_url' => 'v3/marketing/favor/stocks?stock_id=111&stock_creator_mchid=1600314069', + '_service_url' => 'v3/marketing/favor/stocks?stock_id=111&stock_creator_mchid=1600314069', + ], $result->getPayload()->all()); } } diff --git a/tests/Plugin/Wechat/Marketing/Coupon/QueryUserCouponsPluginTest.php b/tests/Plugin/Wechat/Marketing/Coupon/QueryUserCouponsPluginTest.php index ba8f5f7..95d6e39 100644 --- a/tests/Plugin/Wechat/Marketing/Coupon/QueryUserCouponsPluginTest.php +++ b/tests/Plugin/Wechat/Marketing/Coupon/QueryUserCouponsPluginTest.php @@ -2,12 +2,9 @@ namespace Yansongda\Pay\Tests\Plugin\Wechat\Marketing\Coupon; -use GuzzleHttp\Psr7\Uri; use Yansongda\Pay\Exception\Exception; use Yansongda\Pay\Exception\InvalidParamsException; -use Yansongda\Pay\Pay; use Yansongda\Pay\Plugin\Wechat\Marketing\Coupon\QueryUserCouponsPlugin; -use Yansongda\Pay\Provider\Wechat; use Yansongda\Pay\Rocket; use Yansongda\Pay\Tests\TestCase; use Yansongda\Supports\Collection; @@ -23,43 +20,47 @@ class QueryUserCouponsPluginTest extends TestCase $this->plugin = new QueryUserCouponsPlugin(); } - public function testNormal() + public function testEmptyPayload() { - $rocket = (new Rocket())->setParams([])->setPayload(new Collection([ - 'openid' => '123', - 'limit' => 1, - ])); + $rocket = new Rocket(); - $result = $this->plugin->assembly($rocket, function ($rocket) {return $rocket; }); - - $radar = $result->getRadar(); - - self::assertEquals('GET', $radar->getMethod()); - self::assertNull($result->getPayload()); - self::assertEquals(new Uri(Wechat::URL[Pay::MODE_NORMAL].'v3/marketing/favor/users/123/coupons?limit=1&appid=wx55955316af4ef13&creator_mchid=1600314069'), $radar->getUri()); - } - - public function testException() - { self::expectException(InvalidParamsException::class); self::expectExceptionCode(Exception::PARAMS_NECESSARY_PARAMS_MISSING); + self::expectExceptionMessage('参数异常: 根据商户号查用户的券,参数缺少 `openid`'); - $rocket = (new Rocket())->setParams([])->setPayload(new Collection()); - - $this->plugin->assembly($rocket, function ($rocket) {return $rocket; }); + $this->plugin->assembly($rocket, function ($rocket) { return $rocket; }); } - public function testOtherAppId() + public function testNormalParams() { - $rocket = (new Rocket())->setParams(['_type' => 'mini'])->setPayload(new Collection([ - 'openid' => '123', - 'limit' => 1, + $rocket = new Rocket(); + $rocket->setPayload(new Collection( [ + "openid" => "111", + 'appid' => '222', ])); - $result = $this->plugin->assembly($rocket, function ($rocket) {return $rocket; }); + $result = $this->plugin->assembly($rocket, function ($rocket) { return $rocket; }); - $radar = $result->getRadar(); + self::assertEquals([ + '_method' => 'GET', + '_url' => 'v3/marketing/favor/users/111/coupons?appid=222', + '_service_url' => 'v3/marketing/favor/users/111/coupons?appid=222', + ], $result->getPayload()->all()); + } - self::assertEquals(new Uri(Wechat::URL[Pay::MODE_NORMAL].'v3/marketing/favor/users/123/coupons?limit=1&appid=wx55955316af4ef14&creator_mchid=1600314069'), $radar->getUri()); + public function testNormal() + { + $rocket = new Rocket(); + $rocket->setPayload(new Collection( [ + "openid" => "111", + ])); + + $result = $this->plugin->assembly($rocket, function ($rocket) { return $rocket; }); + + self::assertEquals([ + '_method' => 'GET', + '_url' => 'v3/marketing/favor/users/111/coupons?appid=wx55955316af4ef13', + '_service_url' => 'v3/marketing/favor/users/111/coupons?appid=wx55955316af4ef13', + ], $result->getPayload()->all()); } } diff --git a/tests/Plugin/Wechat/Marketing/Coupon/RestartPluginTest.php b/tests/Plugin/Wechat/Marketing/Coupon/RestartPluginTest.php index fbe453a..35a0cd6 100644 --- a/tests/Plugin/Wechat/Marketing/Coupon/RestartPluginTest.php +++ b/tests/Plugin/Wechat/Marketing/Coupon/RestartPluginTest.php @@ -2,12 +2,9 @@ namespace Yansongda\Pay\Tests\Plugin\Wechat\Marketing\Coupon; -use GuzzleHttp\Psr7\Uri; use Yansongda\Pay\Exception\Exception; use Yansongda\Pay\Exception\InvalidParamsException; -use Yansongda\Pay\Pay; use Yansongda\Pay\Plugin\Wechat\Marketing\Coupon\RestartPlugin; -use Yansongda\Pay\Provider\Wechat; use Yansongda\Pay\Rocket; use Yansongda\Pay\Tests\TestCase; use Yansongda\Supports\Collection; @@ -23,47 +20,49 @@ class RestartPluginTest extends TestCase $this->plugin = new RestartPlugin(); } - public function testNormal() + public function testEmptyPayload() { - $rocket = (new Rocket())->setParams([])->setPayload(new Collection([ - 'stock_id' => '7890', + $rocket = new Rocket(); + + self::expectException(InvalidParamsException::class); + self::expectExceptionCode(Exception::PARAMS_NECESSARY_PARAMS_MISSING); + self::expectExceptionMessage('参数异常: 激活代金券,参数缺少 `stock_id`'); + + $this->plugin->assembly($rocket, function ($rocket) { return $rocket; }); + } + + public function testNormalParams() + { + $rocket = new Rocket(); + $rocket->setPayload(new Collection( [ + "stock_id" => "111", + 'stock_creator_mchid' => '222', ])); - $result = $this->plugin->assembly($rocket, function ($rocket) {return $rocket; }); + $result = $this->plugin->assembly($rocket, function ($rocket) { return $rocket; }); - $radar = $result->getRadar(); - - self::assertEquals('POST', $radar->getMethod()); - self::assertEquals(new Uri(Wechat::URL[Pay::MODE_NORMAL].'v3/marketing/favor/stocks/7890/restart'), $radar->getUri()); self::assertEquals([ + '_method' => 'POST', + '_url' => 'v3/marketing/favor/stocks/111/restart', + '_service_url' => 'v3/marketing/favor/stocks/111/restart', + 'stock_creator_mchid' => '222', + ], $result->getPayload()->all()); + } + + public function testNormal() + { + $rocket = new Rocket(); + $rocket->setPayload(new Collection( [ + "stock_id" => "111", + ])); + + $result = $this->plugin->assembly($rocket, function ($rocket) { return $rocket; }); + + self::assertEquals([ + '_method' => 'POST', + '_url' => 'v3/marketing/favor/stocks/111/restart', + '_service_url' => 'v3/marketing/favor/stocks/111/restart', 'stock_creator_mchid' => '1600314069', ], $result->getPayload()->all()); } - - public function testException() - { - self::expectException(InvalidParamsException::class); - self::expectExceptionCode(Exception::PARAMS_NECESSARY_PARAMS_MISSING); - - $rocket = (new Rocket())->setParams([])->setPayload(new Collection()); - - $this->plugin->assembly($rocket, function ($rocket) {return $rocket; }); - } - - public function testExistMchId() - { - $rocket = (new Rocket())->setParams([])->setPayload(new Collection([ - 'stock_id' => '7890', - 'stock_creator_mchid' => '123', - ])); - - $result = $this->plugin->assembly($rocket, function ($rocket) {return $rocket; }); - - $radar = $result->getRadar(); - - self::assertEquals(new Uri(Wechat::URL[Pay::MODE_NORMAL].'v3/marketing/favor/stocks/7890/restart'), $radar->getUri()); - self::assertEquals([ - 'stock_creator_mchid' => '123', - ], $result->getPayload()->all()); - } } diff --git a/tests/Plugin/Wechat/Marketing/Coupon/SendPluginTest.php b/tests/Plugin/Wechat/Marketing/Coupon/SendPluginTest.php index 1f243d2..6916bde 100644 --- a/tests/Plugin/Wechat/Marketing/Coupon/SendPluginTest.php +++ b/tests/Plugin/Wechat/Marketing/Coupon/SendPluginTest.php @@ -2,12 +2,9 @@ namespace Yansongda\Pay\Tests\Plugin\Wechat\Marketing\Coupon; -use GuzzleHttp\Psr7\Uri; use Yansongda\Pay\Exception\Exception; use Yansongda\Pay\Exception\InvalidParamsException; -use Yansongda\Pay\Pay; use Yansongda\Pay\Plugin\Wechat\Marketing\Coupon\SendPlugin; -use Yansongda\Pay\Provider\Wechat; use Yansongda\Pay\Rocket; use Yansongda\Pay\Tests\TestCase; use Yansongda\Supports\Collection; @@ -23,73 +20,56 @@ class SendPluginTest extends TestCase $this->plugin = new SendPlugin(); } - public function testNormal() + public function testEmptyPayload() { - $rocket = (new Rocket())->setParams([])->setPayload(new Collection([ - 'openid' => '7890', - 'stock_id' => '123', - ])); + $rocket = new Rocket(); - $result = $this->plugin->assembly($rocket, function ($rocket) {return $rocket; }); - - $radar = $result->getRadar(); - - self::assertEquals('POST', $radar->getMethod()); - self::assertEquals(new Uri(Wechat::URL[Pay::MODE_NORMAL].'v3/marketing/favor/users/7890/coupons'), $radar->getUri()); - self::assertEquals([ - 'stock_id' => '123', - 'appid' => 'wx55955316af4ef13', - 'stock_creator_mchid' => '1600314069', - ], $result->getPayload()->all()); - } - - public function testException() - { self::expectException(InvalidParamsException::class); self::expectExceptionCode(Exception::PARAMS_NECESSARY_PARAMS_MISSING); + self::expectExceptionMessage('参数异常: 发放指定批次的代金券,参数缺少 `openid`'); - $rocket = (new Rocket())->setParams([])->setPayload(new Collection()); - - $this->plugin->assembly($rocket, function ($rocket) {return $rocket; }); + $this->plugin->assembly($rocket, function ($rocket) { return $rocket; }); } - public function testExistMchId() + public function testNormalParams() { - $rocket = (new Rocket())->setParams([])->setPayload(new Collection([ - 'openid' => '7890', - 'stock_id' => '123', - 'stock_creator_mchid' => '123', + $rocket = new Rocket(); + $rocket->setPayload(new Collection([ + 'openid' => '111', + "appid" => "222", + 'stock_creator_mchid' => '333', + 'test' => 'yansongda' ])); - $result = $this->plugin->assembly($rocket, function ($rocket) {return $rocket; }); + $result = $this->plugin->assembly($rocket, function ($rocket) { return $rocket; }); - $radar = $result->getRadar(); - - self::assertEquals(new Uri(Wechat::URL[Pay::MODE_NORMAL].'v3/marketing/favor/users/7890/coupons'), $radar->getUri()); self::assertEquals([ - 'stock_id' => '123', - 'appid' => 'wx55955316af4ef13', - 'stock_creator_mchid' => '123', + '_method' => 'POST', + '_url' => 'v3/marketing/favor/users/111/coupons', + '_service_url' => 'v3/marketing/favor/users/111/coupons', + 'appid' => '222', + 'stock_creator_mchid' => '333', + 'test' => 'yansongda', ], $result->getPayload()->all()); } - - public function testOtherAppId() + + public function testNormal() { - $rocket = (new Rocket())->setParams(['_type' => 'mini'])->setPayload(new Collection([ - 'openid' => '7890', - 'stock_id' => '123', + $rocket = new Rocket(); + $rocket->setPayload(new Collection([ + 'openid' => '111', + "test" => "yansongda", ])); - $result = $this->plugin->assembly($rocket, function ($rocket) {return $rocket; }); + $result = $this->plugin->assembly($rocket, function ($rocket) { return $rocket; }); - $radar = $result->getRadar(); - - self::assertEquals('POST', $radar->getMethod()); - self::assertEquals(new Uri(Wechat::URL[Pay::MODE_NORMAL].'v3/marketing/favor/users/7890/coupons'), $radar->getUri()); self::assertEquals([ - 'stock_id' => '123', - 'appid' => 'wx55955316af4ef14', + '_method' => 'POST', + '_url' => 'v3/marketing/favor/users/111/coupons', + '_service_url' => 'v3/marketing/favor/users/111/coupons', + 'appid' => 'wx55955316af4ef13', 'stock_creator_mchid' => '1600314069', + 'test' => 'yansongda', ], $result->getPayload()->all()); } } diff --git a/tests/Plugin/Wechat/Marketing/Coupon/SetCallbackPluginTest.php b/tests/Plugin/Wechat/Marketing/Coupon/SetCallbackPluginTest.php index a501811..6bdff43 100644 --- a/tests/Plugin/Wechat/Marketing/Coupon/SetCallbackPluginTest.php +++ b/tests/Plugin/Wechat/Marketing/Coupon/SetCallbackPluginTest.php @@ -2,10 +2,7 @@ namespace Yansongda\Pay\Tests\Plugin\Wechat\Marketing\Coupon; -use GuzzleHttp\Psr7\Uri; -use Yansongda\Pay\Pay; use Yansongda\Pay\Plugin\Wechat\Marketing\Coupon\SetCallbackPlugin; -use Yansongda\Pay\Provider\Wechat; use Yansongda\Pay\Rocket; use Yansongda\Pay\Tests\TestCase; use Yansongda\Supports\Collection; @@ -21,21 +18,47 @@ class SetCallbackPluginTest extends TestCase $this->plugin = new SetCallbackPlugin(); } + public function testNormalParams() + { + $payload = [ + "mchid" => "yansongda", + "notify_url" => "https://www.yansongda.cn", + 'test' => 'aaa', + ]; + + $rocket = new Rocket(); + $rocket->setPayload(new Collection($payload)); + + $result = $this->plugin->assembly($rocket, function ($rocket) { return $rocket; }); + + self::assertEquals([ + '_method' => 'POST', + '_url' => 'v3/marketing/favor/callbacks', + '_service_url' => 'v3/marketing/favor/callbacks', + 'mchid' => 'yansongda', + 'notify_url' => 'https://www.yansongda.cn', + 'test' => 'aaa', + ], $result->getPayload()->all()); + } + public function testNormal() { - $rocket = (new Rocket())->setParams([])->setPayload(new Collection([ - 'enable' => true, - ])); + $payload = [ + 'test' => 'aaa', + ]; - $result = $this->plugin->assembly($rocket, function ($rocket) {return $rocket; }); + $rocket = new Rocket(); + $rocket->setPayload(new Collection($payload)); - $radar = $result->getRadar(); + $result = $this->plugin->assembly($rocket, function ($rocket) { return $rocket; }); - self::assertEquals('POST', $radar->getMethod()); - self::assertEquals(new Uri(Wechat::URL[Pay::MODE_NORMAL].'v3/marketing/favor/callbacks'), $radar->getUri()); self::assertEquals([ - 'enable' => true, + '_method' => 'POST', + '_url' => 'v3/marketing/favor/callbacks', + '_service_url' => 'v3/marketing/favor/callbacks', 'mchid' => '1600314069', + 'notify_url' => 'https://pay.yansongda.cn', + 'test' => 'aaa', ], $result->getPayload()->all()); } } diff --git a/tests/Plugin/Wechat/Marketing/Coupon/StartPluginTest.php b/tests/Plugin/Wechat/Marketing/Coupon/StartPluginTest.php index a7c1c93..2e80e42 100644 --- a/tests/Plugin/Wechat/Marketing/Coupon/StartPluginTest.php +++ b/tests/Plugin/Wechat/Marketing/Coupon/StartPluginTest.php @@ -2,12 +2,9 @@ namespace Yansongda\Pay\Tests\Plugin\Wechat\Marketing\Coupon; -use GuzzleHttp\Psr7\Uri; use Yansongda\Pay\Exception\Exception; use Yansongda\Pay\Exception\InvalidParamsException; -use Yansongda\Pay\Pay; use Yansongda\Pay\Plugin\Wechat\Marketing\Coupon\StartPlugin; -use Yansongda\Pay\Provider\Wechat; use Yansongda\Pay\Rocket; use Yansongda\Pay\Tests\TestCase; use Yansongda\Supports\Collection; @@ -23,47 +20,49 @@ class StartPluginTest extends TestCase $this->plugin = new StartPlugin(); } - public function testNormal() + public function testEmptyPayload() { - $rocket = (new Rocket())->setParams([])->setPayload(new Collection([ - 'stock_id' => '123', + $rocket = new Rocket(); + + self::expectException(InvalidParamsException::class); + self::expectExceptionCode(Exception::PARAMS_NECESSARY_PARAMS_MISSING); + self::expectExceptionMessage('参数异常: 激活代金券,参数缺少 `stock_id`'); + + $this->plugin->assembly($rocket, function ($rocket) { return $rocket; }); + } + + public function testNormalParams() + { + $rocket = new Rocket(); + $rocket->setPayload(new Collection( [ + "stock_id" => "111", + 'stock_creator_mchid' => '222', ])); - $result = $this->plugin->assembly($rocket, function ($rocket) {return $rocket; }); + $result = $this->plugin->assembly($rocket, function ($rocket) { return $rocket; }); - $radar = $result->getRadar(); - - self::assertEquals('POST', $radar->getMethod()); - self::assertEquals(new Uri(Wechat::URL[Pay::MODE_NORMAL].'v3/marketing/favor/stocks/123/start'), $radar->getUri()); self::assertEquals([ + '_method' => 'POST', + '_url' => 'v3/marketing/favor/stocks/111/start', + '_service_url' => 'v3/marketing/favor/stocks/111/start', + 'stock_creator_mchid' => '222', + ], $result->getPayload()->all()); + } + + public function testNormal() + { + $rocket = new Rocket(); + $rocket->setPayload(new Collection( [ + "stock_id" => "111", + ])); + + $result = $this->plugin->assembly($rocket, function ($rocket) { return $rocket; }); + + self::assertEquals([ + '_method' => 'POST', + '_url' => 'v3/marketing/favor/stocks/111/start', + '_service_url' => 'v3/marketing/favor/stocks/111/start', 'stock_creator_mchid' => '1600314069', ], $result->getPayload()->all()); } - - public function testException() - { - self::expectException(InvalidParamsException::class); - self::expectExceptionCode(Exception::PARAMS_NECESSARY_PARAMS_MISSING); - - $rocket = (new Rocket())->setParams([])->setPayload(new Collection()); - - $this->plugin->assembly($rocket, function ($rocket) {return $rocket; }); - } - - public function testExistMchId() - { - $rocket = (new Rocket())->setParams([])->setPayload(new Collection([ - 'stock_id' => '123', - 'stock_creator_mchid' => '123', - ])); - - $result = $this->plugin->assembly($rocket, function ($rocket) {return $rocket; }); - - $radar = $result->getRadar(); - - self::assertEquals(new Uri(Wechat::URL[Pay::MODE_NORMAL].'v3/marketing/favor/stocks/123/start'), $radar->getUri()); - self::assertEquals([ - 'stock_creator_mchid' => '123', - ], $result->getPayload()->all()); - } } diff --git a/tests/Plugin/Wechat/Marketing/ECommerceBalance/QueryDayEndPluginTest.php b/tests/Plugin/Wechat/Marketing/ECommerceBalance/QueryDayEndPluginTest.php new file mode 100644 index 0000000..8ad8dc8 --- /dev/null +++ b/tests/Plugin/Wechat/Marketing/ECommerceBalance/QueryDayEndPluginTest.php @@ -0,0 +1,78 @@ +plugin = new QueryDayEndPlugin(); + } + + public function testModeWrong() + { + $rocket = new Rocket(); + + self::expectException(InvalidParamsException::class); + self::expectExceptionCode(Exception::PARAMS_PLUGIN_ONLY_SUPPORT_SERVICE_MODE); + self::expectExceptionMessage('参数异常: 查询电商平台账户日终余额,只支持服务商模式,当前配置为普通商户模式'); + + $this->plugin->assembly($rocket, function ($rocket) { return $rocket; }); + } + + public function testEmptyPayload() + { + $rocket = new Rocket(); + $rocket->setParams(['_config' => 'service_provider']); + + self::expectException(InvalidParamsException::class); + self::expectExceptionCode(Exception::PARAMS_NECESSARY_PARAMS_MISSING); + self::expectExceptionMessage('参数异常: 查询电商平台账户日终余额,参数缺少 `account_type`'); + + $this->plugin->assembly($rocket, function ($rocket) { return $rocket; }); + } + + public function testNormalParams() + { + $rocket = new Rocket(); + $rocket->setParams(['_config' => 'service_provider']) + ->setPayload(new Collection( [ + "account_type" => "111", + 'aaa' => '222', + ])); + + $result = $this->plugin->assembly($rocket, function ($rocket) { return $rocket; }); + + self::assertEquals([ + '_method' => 'GET', + '_service_url' => 'v3/merchant/fund/dayendbalance/111?aaa=222', + ], $result->getPayload()->all()); + } + + public function testNormal() + { + $rocket = new Rocket(); + $rocket->setParams(['_config' => 'service_provider']) + ->setPayload(new Collection( [ + "account_type" => "111", + ])); + + $result = $this->plugin->assembly($rocket, function ($rocket) { return $rocket; }); + + self::assertEquals([ + '_method' => 'GET', + '_service_url' => 'v3/merchant/fund/dayendbalance/111', + ], $result->getPayload()->all()); + } +} diff --git a/tests/Plugin/Wechat/Marketing/ECommerceBalance/QueryPluginTest.php b/tests/Plugin/Wechat/Marketing/ECommerceBalance/QueryPluginTest.php new file mode 100644 index 0000000..ced90d5 --- /dev/null +++ b/tests/Plugin/Wechat/Marketing/ECommerceBalance/QueryPluginTest.php @@ -0,0 +1,78 @@ +plugin = new QueryPlugin(); + } + + public function testModeWrong() + { + $rocket = new Rocket(); + + self::expectException(InvalidParamsException::class); + self::expectExceptionCode(Exception::PARAMS_PLUGIN_ONLY_SUPPORT_SERVICE_MODE); + self::expectExceptionMessage('参数异常: 查询电商平台账户实时余额,只支持服务商模式,当前配置为普通商户模式'); + + $this->plugin->assembly($rocket, function ($rocket) { return $rocket; }); + } + + public function testEmptyPayload() + { + $rocket = new Rocket(); + $rocket->setParams(['_config' => 'service_provider']); + + self::expectException(InvalidParamsException::class); + self::expectExceptionCode(Exception::PARAMS_NECESSARY_PARAMS_MISSING); + self::expectExceptionMessage('参数异常: 查询电商平台账户实时余额,参数缺少 `account_type`'); + + $this->plugin->assembly($rocket, function ($rocket) { return $rocket; }); + } + + public function testNormalParams() + { + $rocket = new Rocket(); + $rocket->setParams(['_config' => 'service_provider']) + ->setPayload(new Collection( [ + "account_type" => "111", + 'aaa' => '222', + ])); + + $result = $this->plugin->assembly($rocket, function ($rocket) { return $rocket; }); + + self::assertEquals([ + '_method' => 'GET', + '_service_url' => 'v3/merchant/fund/balance/111', + ], $result->getPayload()->all()); + } + + public function testNormal() + { + $rocket = new Rocket(); + $rocket->setParams(['_config' => 'service_provider']) + ->setPayload(new Collection( [ + "account_type" => "111", + ])); + + $result = $this->plugin->assembly($rocket, function ($rocket) { return $rocket; }); + + self::assertEquals([ + '_method' => 'GET', + '_service_url' => 'v3/merchant/fund/balance/111', + ], $result->getPayload()->all()); + } +} diff --git a/tests/Plugin/Wechat/Marketing/ECommerceRefund/ApplyPluginTest.php b/tests/Plugin/Wechat/Marketing/ECommerceRefund/ApplyPluginTest.php new file mode 100644 index 0000000..1bb8945 --- /dev/null +++ b/tests/Plugin/Wechat/Marketing/ECommerceRefund/ApplyPluginTest.php @@ -0,0 +1,86 @@ +plugin = new ApplyPlugin(); + } + + public function testModeWrong() + { + $rocket = new Rocket(); + + self::expectException(InvalidParamsException::class); + self::expectExceptionCode(Exception::PARAMS_PLUGIN_ONLY_SUPPORT_SERVICE_MODE); + self::expectExceptionMessage('参数异常: 平台收付通(退款)-申请退款,只支持服务商模式,当前配置为普通商户模式'); + + $this->plugin->assembly($rocket, function ($rocket) { return $rocket; }); + } + + public function testEmptyPayload() + { + $rocket = new Rocket(); + $rocket->setParams(['_config' => 'service_provider']); + + self::expectException(InvalidParamsException::class); + self::expectExceptionCode(Exception::PARAMS_NECESSARY_PARAMS_MISSING); + self::expectExceptionMessage('参数异常: 平台收付通(退款)-申请退款,缺少必要参数'); + + $this->plugin->assembly($rocket, function ($rocket) { return $rocket; }); + } + + public function testNormalParams() + { + $rocket = new Rocket(); + $rocket->setParams(['_config' => 'service_provider'])->setPayload(new Collection( [ + "test" => "yansongda", + 'sub_mchid' => '1111', + 'sp_appid' => '2222', + 'notify_url' => '3333', + ])); + + $result = $this->plugin->assembly($rocket, function ($rocket) { return $rocket; }); + + self::assertEquals([ + '_method' => 'POST', + '_service_url' => 'v3/ecommerce/refunds/apply', + 'sub_mchid' => '1111', + 'sp_appid' => '2222', + 'notify_url' => '3333', + 'test' => 'yansongda', + ], $result->getPayload()->all()); + } + + public function testNormal() + { + $rocket = new Rocket(); + $rocket->setParams(['_config' => 'service_provider'])->setPayload(new Collection( [ + "test" => "yansongda", + ])); + + $result = $this->plugin->assembly($rocket, function ($rocket) { return $rocket; }); + + self::assertEquals([ + '_method' => 'POST', + '_service_url' => 'v3/ecommerce/refunds/apply', + 'sub_mchid' => '1600314070', + 'sp_appid' => 'wx55955316af4ef13', + 'notify_url' => null, + 'test' => 'yansongda', + ], $result->getPayload()->all()); + } +} diff --git a/tests/Plugin/Wechat/Marketing/ECommerceRefund/QueryByWxPluginTest.php b/tests/Plugin/Wechat/Marketing/ECommerceRefund/QueryByWxPluginTest.php new file mode 100644 index 0000000..d7785c1 --- /dev/null +++ b/tests/Plugin/Wechat/Marketing/ECommerceRefund/QueryByWxPluginTest.php @@ -0,0 +1,78 @@ +plugin = new QueryByWxPlugin(); + } + + public function testModeWrong() + { + $rocket = new Rocket(); + + self::expectException(InvalidParamsException::class); + self::expectExceptionCode(Exception::PARAMS_PLUGIN_ONLY_SUPPORT_SERVICE_MODE); + self::expectExceptionMessage('参数异常: 平台收付通(退款)-查询单笔退款(按微信支付退款单号),只支持服务商模式,当前配置为普通商户模式'); + + $this->plugin->assembly($rocket, function ($rocket) { return $rocket; }); + } + + public function testEmptyPayload() + { + $rocket = new Rocket(); + $rocket->setParams(['_config' => 'service_provider']); + + self::expectException(InvalidParamsException::class); + self::expectExceptionCode(Exception::PARAMS_NECESSARY_PARAMS_MISSING); + self::expectExceptionMessage('参数异常: 平台收付通(退款)-查询单笔退款(按微信支付退款单号),缺少必要参数 `refund_id`'); + + $this->plugin->assembly($rocket, function ($rocket) { return $rocket; }); + } + + public function testNormalParams() + { + $rocket = new Rocket(); + $rocket->setParams(['_config' => 'service_provider']) + ->setPayload(new Collection( [ + "refund_id" => "111", + 'sub_mchid' => '222', + ])); + + $result = $this->plugin->assembly($rocket, function ($rocket) { return $rocket; }); + + self::assertEquals([ + '_method' => 'GET', + '_service_url' => 'v3/ecommerce/refunds/id/111?sub_mchid=222', + ], $result->getPayload()->all()); + } + + public function testNormal() + { + $rocket = new Rocket(); + $rocket->setParams(['_config' => 'service_provider']) + ->setPayload(new Collection( [ + "refund_id" => "111", + ])); + + $result = $this->plugin->assembly($rocket, function ($rocket) { return $rocket; }); + + self::assertEquals([ + '_method' => 'GET', + '_service_url' => 'v3/ecommerce/refunds/id/111?sub_mchid=1600314070', + ], $result->getPayload()->all()); + } +} diff --git a/tests/Plugin/Wechat/Marketing/ECommerceRefund/QueryPluginTest.php b/tests/Plugin/Wechat/Marketing/ECommerceRefund/QueryPluginTest.php new file mode 100644 index 0000000..6117926 --- /dev/null +++ b/tests/Plugin/Wechat/Marketing/ECommerceRefund/QueryPluginTest.php @@ -0,0 +1,79 @@ +plugin = new QueryPlugin(); + } + + public function testModeWrong() + { + $rocket = new Rocket(); + + self::expectException(InvalidParamsException::class); + self::expectExceptionCode(Exception::PARAMS_PLUGIN_ONLY_SUPPORT_SERVICE_MODE); + self::expectExceptionMessage('参数异常: 平台收付通(退款)-查询单笔退款(按商户退款单号),只支持服务商模式,当前配置为普通商户模式'); + + $this->plugin->assembly($rocket, function ($rocket) { return $rocket; }); + } + + public function testEmptyPayload() + { + $rocket = new Rocket(); + $rocket->setParams(['_config' => 'service_provider']); + + self::expectException(InvalidParamsException::class); + self::expectExceptionCode(Exception::PARAMS_NECESSARY_PARAMS_MISSING); + self::expectExceptionMessage('参数异常: 平台收付通(退款)-查询单笔退款(按商户退款单号),缺少必要参数 `out_refund_no`'); + + $this->plugin->assembly($rocket, function ($rocket) { return $rocket; }); + } + + public function testNormalParams() + { + $rocket = new Rocket(); + $rocket->setParams(['_config' => 'service_provider']) + ->setPayload(new Collection( [ + "out_refund_no" => "111", + 'sub_mchid' => '222', + ])); + + $result = $this->plugin->assembly($rocket, function ($rocket) { return $rocket; }); + + self::assertEquals([ + '_method' => 'GET', + '_service_url' => 'v3/ecommerce/refunds/out-refund-no/111?sub_mchid=222', + ], $result->getPayload()->all()); + } + + public function testNormal() + { + $rocket = new Rocket(); + $rocket->setParams(['_config' => 'service_provider']) + ->setPayload(new Collection( [ + "out_refund_no" => "111", + ])); + + $result = $this->plugin->assembly($rocket, function ($rocket) { return $rocket; }); + + self::assertEquals([ + '_method' => 'GET', + '_service_url' => 'v3/ecommerce/refunds/out-refund-no/111?sub_mchid=1600314070', + ], $result->getPayload()->all()); + } +} diff --git a/tests/Plugin/Wechat/Marketing/ECommerceRefund/QueryReturnAdvancePluginTest.php b/tests/Plugin/Wechat/Marketing/ECommerceRefund/QueryReturnAdvancePluginTest.php new file mode 100644 index 0000000..f1e575d --- /dev/null +++ b/tests/Plugin/Wechat/Marketing/ECommerceRefund/QueryReturnAdvancePluginTest.php @@ -0,0 +1,80 @@ +plugin = new QueryReturnAdvancePlugin(); + } + + public function testModeWrong() + { + $rocket = new Rocket(); + + self::expectException(InvalidParamsException::class); + self::expectExceptionCode(Exception::PARAMS_PLUGIN_ONLY_SUPPORT_SERVICE_MODE); + self::expectExceptionMessage('参数异常: 平台收付通(退款)-查询垫付回补结果,只支持服务商模式,当前配置为普通商户模式'); + + $this->plugin->assembly($rocket, function ($rocket) { return $rocket; }); + } + + public function testEmptyPayload() + { + $rocket = new Rocket(); + $rocket->setParams(['_config' => 'service_provider']); + + self::expectException(InvalidParamsException::class); + self::expectExceptionCode(Exception::PARAMS_NECESSARY_PARAMS_MISSING); + self::expectExceptionMessage('参数异常: 平台收付通(退款)-查询垫付回补结果,缺少必要参数 `refund_id`'); + + $this->plugin->assembly($rocket, function ($rocket) { return $rocket; }); + } + + public function testNormalParams() + { + $rocket = new Rocket(); + $rocket->setParams(['_config' => 'service_provider']) + ->setPayload(new Collection( [ + "refund_id" => "111", + 'sub_mchid' => '222', + ])); + + $result = $this->plugin->assembly($rocket, function ($rocket) { return $rocket; }); + + self::assertEquals([ + '_method' => 'GET', + '_service_url' => 'v3/ecommerce/refunds/111/return-advance?sub_mchid=222', + ], $result->getPayload()->all()); + } + + public function testNormal() + { + $rocket = new Rocket(); + $rocket->setParams(['_config' => 'service_provider']) + ->setPayload(new Collection( [ + "refund_id" => "111", + ])); + + $result = $this->plugin->assembly($rocket, function ($rocket) { return $rocket; }); + + self::assertEquals([ + '_method' => 'GET', + '_service_url' => 'v3/ecommerce/refunds/111/return-advance?sub_mchid=1600314070', + ], $result->getPayload()->all()); + } +} diff --git a/tests/Plugin/Wechat/Marketing/ECommerceRefund/ReturnAdvancePluginTest.php b/tests/Plugin/Wechat/Marketing/ECommerceRefund/ReturnAdvancePluginTest.php new file mode 100644 index 0000000..76921a3 --- /dev/null +++ b/tests/Plugin/Wechat/Marketing/ECommerceRefund/ReturnAdvancePluginTest.php @@ -0,0 +1,80 @@ +plugin = new ReturnAdvancePlugin(); + } + + public function testModeWrong() + { + $rocket = new Rocket(); + + self::expectException(InvalidParamsException::class); + self::expectExceptionCode(Exception::PARAMS_PLUGIN_ONLY_SUPPORT_SERVICE_MODE); + self::expectExceptionMessage('参数异常: 平台收付通(退款)-垫付退款回补,只支持服务商模式,当前配置为普通商户模式'); + + $this->plugin->assembly($rocket, function ($rocket) { return $rocket; }); + } + + public function testEmptyPayload() + { + $rocket = new Rocket(); + $rocket->setParams(['_config' => 'service_provider']); + + self::expectException(InvalidParamsException::class); + self::expectExceptionCode(Exception::PARAMS_NECESSARY_PARAMS_MISSING); + self::expectExceptionMessage('参数异常: 平台收付通(退款)-垫付退款回补,缺少必要参数 `refund_id`'); + + $this->plugin->assembly($rocket, function ($rocket) { return $rocket; }); + } + + public function testNormalParams() + { + $rocket = new Rocket(); + $rocket->setParams(['_config' => 'service_provider']) + ->setPayload(new Collection( [ + "refund_id" => "111", + 'sub_mchid' => '222', + ])); + + $result = $this->plugin->assembly($rocket, function ($rocket) { return $rocket; }); + + self::assertEquals([ + '_method' => 'POST', + '_service_url' => 'v3/ecommerce/refunds/111/return-advance', + 'sub_mchid' => '222', + ], $result->getPayload()->all()); + } + + public function testNormal() + { + $rocket = new Rocket(); + $rocket->setParams(['_config' => 'service_provider']) + ->setPayload(new Collection( [ + "refund_id" => "111", + ])); + + $result = $this->plugin->assembly($rocket, function ($rocket) { return $rocket; }); + + self::assertEquals([ + '_method' => 'POST', + '_service_url' => 'v3/ecommerce/refunds/111/return-advance', + 'sub_mchid' => '1600314070', + ], $result->getPayload()->all()); + } +} diff --git a/tests/Plugin/Wechat/Marketing/Transfer/CreatePluginTest.php b/tests/Plugin/Wechat/Marketing/Transfer/CreatePluginTest.php new file mode 100644 index 0000000..c79bea4 --- /dev/null +++ b/tests/Plugin/Wechat/Marketing/Transfer/CreatePluginTest.php @@ -0,0 +1,106 @@ +plugin = new CreatePlugin(); + } + + public function testModeWrong() + { + $rocket = new Rocket(); + $rocket->setParams(['_config' => 'service_provider']); + + self::expectException(InvalidParamsException::class); + self::expectExceptionCode(Exception::PARAMS_PLUGIN_ONLY_SUPPORT_NORMAL_MODE); + self::expectExceptionMessage('参数异常: 发起商家转账,只支持普通商户模式,当前配置为服务商模式'); + + $this->plugin->assembly($rocket, function ($rocket) { return $rocket; }); + } + + public function testEmptyPayload() + { + $rocket = new Rocket(); + + self::expectException(InvalidParamsException::class); + self::expectExceptionCode(Exception::PARAMS_NECESSARY_PARAMS_MISSING); + self::expectExceptionMessage('发起商家转账参数,参数缺失'); + + $this->plugin->assembly($rocket, function ($rocket) { return $rocket; }); + } + + public function testNormalParams() + { + $rocket = new Rocket(); + $rocket->setPayload(new Collection( [ + "test" => "yansongda", + 'appid' => '1111', + ])); + + $result = $this->plugin->assembly($rocket, function ($rocket) { return $rocket; }); + + self::assertEquals([ + '_method' => 'POST', + '_url' => 'v3/transfer/batches', + 'test' => 'yansongda', + 'appid' => '1111', + ], $result->getPayload()->all()); + } + + public function testNormalWithoutName() + { + $rocket = new Rocket(); + $rocket->setPayload(new Collection( [ + "test" => "yansongda", + ])); + + $result = $this->plugin->assembly($rocket, function ($rocket) { return $rocket; }); + + self::assertEquals([ + '_method' => 'POST', + '_url' => 'v3/transfer/batches', + 'test' => 'yansongda', + 'appid' => 'wx55955316af4ef13', + ], $result->getPayload()->all()); + } + + public function testNormalWithName() + { + $rocket = new Rocket(); + $rocket->setPayload(new Collection([ + "test" => "111", + 'transfer_detail_list' => [ + [ + 'user_name' => 'yansongda' + ] + ] + ])); + + $result = $this->plugin->assembly($rocket, function ($rocket) { + return $rocket; + }); + + $payload = $result->getPayload()->all(); + self::assertEquals('POST', $payload['_method']); + self::assertEquals('v3/transfer/batches', $payload['_url']); + self::assertEquals('wx55955316af4ef13', $payload['appid']); + self::assertEquals('111', $payload['test']); + self::assertArrayHasKey('_serial_no', $payload); + self::assertArrayHasKey('user_name', $payload['transfer_detail_list'][0]); + self::assertNotEquals('yansongda', $payload['transfer_detail_list'][0]['user_name']); + } +} diff --git a/tests/Plugin/Wechat/Marketing/Transfer/CreateReceiptDetailPluginTest.php b/tests/Plugin/Wechat/Marketing/Transfer/CreateReceiptDetailPluginTest.php new file mode 100644 index 0000000..0fa6d6b --- /dev/null +++ b/tests/Plugin/Wechat/Marketing/Transfer/CreateReceiptDetailPluginTest.php @@ -0,0 +1,50 @@ +plugin = new CreateReceiptDetailPlugin(); + } + + public function testModeWrong() + { + $rocket = new Rocket(); + $rocket->setParams(['_config' => 'service_provider']); + + self::expectException(InvalidParamsException::class); + self::expectExceptionCode(Exception::PARAMS_PLUGIN_ONLY_SUPPORT_NORMAL_MODE); + self::expectExceptionMessage('参数异常: 受理转账明细电子回单,只支持普通商户模式,当前配置为服务商模式'); + + $this->plugin->assembly($rocket, function ($rocket) { return $rocket; }); + } + + public function testNormal() + { + $rocket = new Rocket(); + $rocket->setPayload(new Collection( [ + "test" => "yansongda", + ])); + + $result = $this->plugin->assembly($rocket, function ($rocket) { return $rocket; }); + + self::assertEquals([ + '_method' => 'POST', + '_url' => 'v3/transfer-detail/electronic-receipts', + 'test' => 'yansongda', + ], $result->getPayload()->all()); + } +} diff --git a/tests/Plugin/Wechat/Marketing/Transfer/CreateReceiptPluginTest.php b/tests/Plugin/Wechat/Marketing/Transfer/CreateReceiptPluginTest.php new file mode 100644 index 0000000..e0d8518 --- /dev/null +++ b/tests/Plugin/Wechat/Marketing/Transfer/CreateReceiptPluginTest.php @@ -0,0 +1,50 @@ +plugin = new CreateReceiptPlugin(); + } + + public function testModeWrong() + { + $rocket = new Rocket(); + $rocket->setParams(['_config' => 'service_provider']); + + self::expectException(InvalidParamsException::class); + self::expectExceptionCode(Exception::PARAMS_PLUGIN_ONLY_SUPPORT_NORMAL_MODE); + self::expectExceptionMessage('参数异常: 转账账单电子回单申请受理接口,只支持普通商户模式,当前配置为服务商模式'); + + $this->plugin->assembly($rocket, function ($rocket) { return $rocket; }); + } + + public function testNormal() + { + $rocket = new Rocket(); + $rocket->setPayload(new Collection( [ + "test" => "yansongda", + ])); + + $result = $this->plugin->assembly($rocket, function ($rocket) { return $rocket; }); + + self::assertEquals([ + '_method' => 'POST', + '_url' => 'v3/transfer/bill-receipt', + 'test' => 'yansongda', + ], $result->getPayload()->all()); + } +} diff --git a/tests/Plugin/Wechat/Marketing/Transfer/DownloadReceiptPluginTest.php b/tests/Plugin/Wechat/Marketing/Transfer/DownloadReceiptPluginTest.php new file mode 100644 index 0000000..9727f7a --- /dev/null +++ b/tests/Plugin/Wechat/Marketing/Transfer/DownloadReceiptPluginTest.php @@ -0,0 +1,60 @@ +plugin = new DownloadReceiptPlugin(); + } + + public function testModeWrong() + { + $rocket = new Rocket(); + $rocket->setParams(['_config' => 'service_provider']); + + self::expectException(InvalidParamsException::class); + self::expectExceptionCode(Exception::PARAMS_PLUGIN_ONLY_SUPPORT_NORMAL_MODE); + self::expectExceptionMessage('参数异常: 下载电子回单,只支持普通商户模式,当前配置为服务商模式'); + + $this->plugin->assembly($rocket, function ($rocket) { return $rocket; }); + } + + public function testEmptyPayload() + { + $rocket = new Rocket(); + + self::expectException(InvalidParamsException::class); + self::expectExceptionCode(Exception::PARAMS_NECESSARY_PARAMS_MISSING); + self::expectExceptionMessage('参数异常: 下载电子回单,参数缺少 `download_url`'); + + $this->plugin->assembly($rocket, function ($rocket) { return $rocket; }); + } + + public function testNormal() + { + $rocket = new Rocket(); + $rocket->setPayload(new Collection( [ + "download_url" => "yansongda", + ])); + + $result = $this->plugin->assembly($rocket, function ($rocket) { return $rocket; }); + + self::assertEquals([ + '_method' => 'GET', + '_url' => 'yansongda', + ], $result->getPayload()->all()); + } +} diff --git a/tests/Plugin/Wechat/Marketing/Transfer/QueryBatchByWxPluginTest.php b/tests/Plugin/Wechat/Marketing/Transfer/QueryBatchByWxPluginTest.php new file mode 100644 index 0000000..137877f --- /dev/null +++ b/tests/Plugin/Wechat/Marketing/Transfer/QueryBatchByWxPluginTest.php @@ -0,0 +1,61 @@ +plugin = new QueryBatchByWxPlugin(); + } + + public function testModeWrong() + { + $rocket = new Rocket(); + $rocket->setParams(['_config' => 'service_provider']); + + self::expectException(InvalidParamsException::class); + self::expectExceptionCode(Exception::PARAMS_PLUGIN_ONLY_SUPPORT_NORMAL_MODE); + self::expectExceptionMessage('参数异常: 通过微信批次单号查询批次单,只支持普通商户模式,当前配置为服务商模式'); + + $this->plugin->assembly($rocket, function ($rocket) { return $rocket; }); + } + + public function testEmptyPayload() + { + $rocket = new Rocket(); + + self::expectException(InvalidParamsException::class); + self::expectExceptionCode(Exception::PARAMS_NECESSARY_PARAMS_MISSING); + self::expectExceptionMessage('参数异常: 通过微信批次单号查询批次单,参数缺少 `batch_id`'); + + $this->plugin->assembly($rocket, function ($rocket) { return $rocket; }); + } + + public function testNormalParams() + { + $rocket = new Rocket(); + $rocket->setPayload(new Collection( [ + "batch_id" => "111", + 'detail_id' => '222', + ])); + + $result = $this->plugin->assembly($rocket, function ($rocket) { return $rocket; }); + + self::assertEquals([ + '_method' => 'GET', + '_url' => 'v3/transfer/batches/batch-id/111?detail_id=222', + ], $result->getPayload()->all()); + } +} diff --git a/tests/Plugin/Wechat/Marketing/Transfer/QueryBatchPluginTest.php b/tests/Plugin/Wechat/Marketing/Transfer/QueryBatchPluginTest.php new file mode 100644 index 0000000..c3f9fd9 --- /dev/null +++ b/tests/Plugin/Wechat/Marketing/Transfer/QueryBatchPluginTest.php @@ -0,0 +1,61 @@ +plugin = new QueryBatchPlugin(); + } + + public function testModeWrong() + { + $rocket = new Rocket(); + $rocket->setParams(['_config' => 'service_provider']); + + self::expectException(InvalidParamsException::class); + self::expectExceptionCode(Exception::PARAMS_PLUGIN_ONLY_SUPPORT_NORMAL_MODE); + self::expectExceptionMessage('参数异常: 通过商家批次单号查询批次单,只支持普通商户模式,当前配置为服务商模式'); + + $this->plugin->assembly($rocket, function ($rocket) { return $rocket; }); + } + + public function testEmptyPayload() + { + $rocket = new Rocket(); + + self::expectException(InvalidParamsException::class); + self::expectExceptionCode(Exception::PARAMS_NECESSARY_PARAMS_MISSING); + self::expectExceptionMessage('参数异常: 通过商家批次单号查询批次单,参数缺少 `out_batch_no`'); + + $this->plugin->assembly($rocket, function ($rocket) { return $rocket; }); + } + + public function testNormalParams() + { + $rocket = new Rocket(); + $rocket->setPayload(new Collection( [ + "out_batch_no" => "111", + 'detail_id' => '222', + ])); + + $result = $this->plugin->assembly($rocket, function ($rocket) { return $rocket; }); + + self::assertEquals([ + '_method' => 'GET', + '_url' => 'v3/transfer/batches/out-batch-no/111?detail_id=222', + ], $result->getPayload()->all()); + } +} diff --git a/tests/Plugin/Wechat/Marketing/Transfer/QueryDetailByWxPluginTest.php b/tests/Plugin/Wechat/Marketing/Transfer/QueryDetailByWxPluginTest.php new file mode 100644 index 0000000..f4e08c2 --- /dev/null +++ b/tests/Plugin/Wechat/Marketing/Transfer/QueryDetailByWxPluginTest.php @@ -0,0 +1,61 @@ +plugin = new QueryDetailByWxPlugin(); + } + + public function testModeWrong() + { + $rocket = new Rocket(); + $rocket->setParams(['_config' => 'service_provider']); + + self::expectException(InvalidParamsException::class); + self::expectExceptionCode(Exception::PARAMS_PLUGIN_ONLY_SUPPORT_NORMAL_MODE); + self::expectExceptionMessage('参数异常: 通过微信明细单号查询明细单,只支持普通商户模式,当前配置为服务商模式'); + + $this->plugin->assembly($rocket, function ($rocket) { return $rocket; }); + } + + public function testEmptyPayload() + { + $rocket = new Rocket(); + + self::expectException(InvalidParamsException::class); + self::expectExceptionCode(Exception::PARAMS_NECESSARY_PARAMS_MISSING); + self::expectExceptionMessage('参数异常: 通过微信明细单号查询明细单,参数缺少 `batch_id` 或 `detail_id`'); + + $this->plugin->assembly($rocket, function ($rocket) { return $rocket; }); + } + + public function testNormalParams() + { + $rocket = new Rocket(); + $rocket->setPayload(new Collection( [ + "batch_id" => "111", + 'detail_id' => '222', + ])); + + $result = $this->plugin->assembly($rocket, function ($rocket) { return $rocket; }); + + self::assertEquals([ + '_method' => 'GET', + '_url' => 'v3/transfer/batches/batch-id/111/details/detail-id/222', + ], $result->getPayload()->all()); + } +} diff --git a/tests/Plugin/Wechat/Marketing/Transfer/QueryDetailPluginTest.php b/tests/Plugin/Wechat/Marketing/Transfer/QueryDetailPluginTest.php new file mode 100644 index 0000000..825046a --- /dev/null +++ b/tests/Plugin/Wechat/Marketing/Transfer/QueryDetailPluginTest.php @@ -0,0 +1,61 @@ +plugin = new QueryDetailPlugin(); + } + + public function testModeWrong() + { + $rocket = new Rocket(); + $rocket->setParams(['_config' => 'service_provider']); + + self::expectException(InvalidParamsException::class); + self::expectExceptionCode(Exception::PARAMS_PLUGIN_ONLY_SUPPORT_NORMAL_MODE); + self::expectExceptionMessage('参数异常: 通过商家明细单号查询明细单,只支持普通商户模式,当前配置为服务商模式'); + + $this->plugin->assembly($rocket, function ($rocket) { return $rocket; }); + } + + public function testEmptyPayload() + { + $rocket = new Rocket(); + + self::expectException(InvalidParamsException::class); + self::expectExceptionCode(Exception::PARAMS_NECESSARY_PARAMS_MISSING); + self::expectExceptionMessage('参数异常: 通过商家明细单号查询明细单,参数缺少 `out_batch_no` 或 `out_detail_no`'); + + $this->plugin->assembly($rocket, function ($rocket) { return $rocket; }); + } + + public function testNormalParams() + { + $rocket = new Rocket(); + $rocket->setPayload(new Collection( [ + "out_batch_no" => "111", + 'out_detail_no' => '222', + ])); + + $result = $this->plugin->assembly($rocket, function ($rocket) { return $rocket; }); + + self::assertEquals([ + '_method' => 'GET', + '_url' => 'v3/transfer/batches/out-batch-no/111/details/out-detail-no/222', + ], $result->getPayload()->all()); + } +} diff --git a/tests/Plugin/Wechat/Marketing/Transfer/QueryReceiptDetailPluginTest.php b/tests/Plugin/Wechat/Marketing/Transfer/QueryReceiptDetailPluginTest.php new file mode 100644 index 0000000..cba5688 --- /dev/null +++ b/tests/Plugin/Wechat/Marketing/Transfer/QueryReceiptDetailPluginTest.php @@ -0,0 +1,61 @@ +plugin = new QueryReceiptDetailPlugin(); + } + + public function testModeWrong() + { + $rocket = new Rocket(); + $rocket->setParams(['_config' => 'service_provider']); + + self::expectException(InvalidParamsException::class); + self::expectExceptionCode(Exception::PARAMS_PLUGIN_ONLY_SUPPORT_NORMAL_MODE); + self::expectExceptionMessage('参数异常: 查询转账明细电子回单受理结果API,只支持普通商户模式,当前配置为服务商模式'); + + $this->plugin->assembly($rocket, function ($rocket) { return $rocket; }); + } + + public function testEmptyPayload() + { + $rocket = new Rocket(); + + self::expectException(InvalidParamsException::class); + self::expectExceptionCode(Exception::PARAMS_NECESSARY_PARAMS_MISSING); + self::expectExceptionMessage('参数异常: 查询转账明细电子回单受理结果API,参数为空'); + + $this->plugin->assembly($rocket, function ($rocket) { return $rocket; }); + } + + public function testNormalParams() + { + $rocket = new Rocket(); + $rocket->setPayload(new Collection( [ + "out_batch_no" => "111", + 'out_detail_no' => '222', + ])); + + $result = $this->plugin->assembly($rocket, function ($rocket) { return $rocket; }); + + self::assertEquals([ + '_method' => 'GET', + '_url' => 'v3/transfer-detail/electronic-receipts?out_batch_no=111&out_detail_no=222', + ], $result->getPayload()->all()); + } +} diff --git a/tests/Plugin/Wechat/Marketing/Transfer/QueryReceiptPluginTest.php b/tests/Plugin/Wechat/Marketing/Transfer/QueryReceiptPluginTest.php new file mode 100644 index 0000000..23e01f8 --- /dev/null +++ b/tests/Plugin/Wechat/Marketing/Transfer/QueryReceiptPluginTest.php @@ -0,0 +1,61 @@ +plugin = new QueryReceiptPlugin(); + } + + public function testModeWrong() + { + $rocket = new Rocket(); + $rocket->setParams(['_config' => 'service_provider']); + + self::expectException(InvalidParamsException::class); + self::expectExceptionCode(Exception::PARAMS_PLUGIN_ONLY_SUPPORT_NORMAL_MODE); + self::expectExceptionMessage('参数异常: 查询转账账单电子回单接口,只支持普通商户模式,当前配置为服务商模式'); + + $this->plugin->assembly($rocket, function ($rocket) { return $rocket; }); + } + + public function testEmptyPayload() + { + $rocket = new Rocket(); + + self::expectException(InvalidParamsException::class); + self::expectExceptionCode(Exception::PARAMS_NECESSARY_PARAMS_MISSING); + self::expectExceptionMessage('参数异常: 查询转账账单电子回单接口,参数缺少 `out_batch_no`'); + + $this->plugin->assembly($rocket, function ($rocket) { return $rocket; }); + } + + public function testNormalParams() + { + $rocket = new Rocket(); + $rocket->setPayload(new Collection( [ + "out_batch_no" => "111", + 'out_detail_no' => '222', + ])); + + $result = $this->plugin->assembly($rocket, function ($rocket) { return $rocket; }); + + self::assertEquals([ + '_method' => 'GET', + '_url' => 'v3/transfer/bill-receipt/111', + ], $result->getPayload()->all()); + } +} diff --git a/tests/Plugin/Wechat/Papay/ApplyPluginTest.php b/tests/Plugin/Wechat/Papay/ApplyPluginTest.php deleted file mode 100644 index c25dc25..0000000 --- a/tests/Plugin/Wechat/Papay/ApplyPluginTest.php +++ /dev/null @@ -1,46 +0,0 @@ -plugin = new ApplyPlugin(); - } - - public function testNormal() - { - $rocket = new Rocket(); - $rocket->setParams([]); - - $result = $this->plugin->assembly($rocket, function ($rocket) { return $rocket; }); - - $radar = $result->getRadar(); - $params = $result->getParams(); - $payload = $result->getPayload(); - - self::assertEquals(XmlPacker::class, $result->getPacker()); - self::assertInstanceOf(RequestInterface::class, $radar); - self::assertEquals('POST', $radar->getMethod()); - self::assertEquals(new Uri(Wechat::URL[Pay::MODE_NORMAL].'pay/pappayapply'), $radar->getUri()); - self::assertEquals('1600314069', $payload->get('mch_id')); - self::assertEquals('wx55955316af4ef13', $payload->get('appid')); - self::assertEquals('v2', $params['_version']); - self::assertEquals('application/xml', $radar->getHeaderLine('Content-Type')); - self::assertEquals('yansongda/pay-v3', $radar->getHeaderLine('User-Agent')); - } -} diff --git a/tests/Plugin/Wechat/Papay/ContractOrderPluginTest.php b/tests/Plugin/Wechat/Papay/ContractOrderPluginTest.php deleted file mode 100644 index 6eb6614..0000000 --- a/tests/Plugin/Wechat/Papay/ContractOrderPluginTest.php +++ /dev/null @@ -1,46 +0,0 @@ -plugin = new ContractOrderPlugin(); - } - - public function testNormal() - { - $rocket = new Rocket(); - $rocket->setParams([]); - - $result = $this->plugin->assembly($rocket, function ($rocket) { return $rocket; }); - - $radar = $result->getRadar(); - $params = $result->getParams(); - $payload = $result->getPayload(); - - self::assertEquals(XmlPacker::class, $result->getPacker()); - self::assertInstanceOf(RequestInterface::class, $radar); - self::assertEquals('POST', $radar->getMethod()); - self::assertEquals(new Uri(Wechat::URL[Pay::MODE_NORMAL].'pay/contractorder'), $radar->getUri()); - self::assertEquals('1600314069', $payload->get('mch_id')); - self::assertEquals('wx55955316af4ef13', $payload->get('appid')); - self::assertEquals('v2', $params['_version']); - self::assertEquals('application/xml', $radar->getHeaderLine('Content-Type')); - self::assertEquals('yansongda/pay-v3', $radar->getHeaderLine('User-Agent')); - } -} diff --git a/tests/Plugin/Wechat/Papay/OnlyContractPluginTest.php b/tests/Plugin/Wechat/Papay/OnlyContractPluginTest.php deleted file mode 100644 index f90436b..0000000 --- a/tests/Plugin/Wechat/Papay/OnlyContractPluginTest.php +++ /dev/null @@ -1,61 +0,0 @@ -plugin = new OnlyContractPlugin(); - } - - public function testNormal() - { - $rocket = (new Rocket())->setParams([])->setPayload(new Collection()); - - $result = $this->plugin->assembly($rocket, function ($rocket) { return $rocket; }); - - $payload = $result->getPayload(); - - self::assertEquals('1600314069', $payload->get('mch_id')); - self::assertEquals('wx55955316af4ef13', $payload->get('appid')); - self::assertArrayHasKey('notify_url', $payload->all()); - self::assertArrayHasKey('sign', $payload->all()); - } - - public function testGetConfigKey() - { - // mini - $rocket = (new Rocket())->setParams(['_type' => 'mini'])->setPayload(new Collection()); - - $result = $this->plugin->assembly($rocket, function ($rocket) { return $rocket; }); - - $payload = $result->getPayload(); - - self::assertEquals('1600314069', $payload->get('mch_id')); - self::assertEquals('wx55955316af4ef14', $payload->get('appid')); - self::assertArrayHasKey('notify_url', $payload->all()); - self::assertArrayHasKey('sign', $payload->all()); - - // app - $rocket = (new Rocket())->setParams(['_type' => 'app'])->setPayload(new Collection()); - - $result = $this->plugin->assembly($rocket, function ($rocket) { return $rocket; }); - - $payload = $result->getPayload(); - - self::assertEquals('1600314069', $payload->get('mch_id')); - self::assertEquals('yansongda', $payload->get('appid')); - self::assertArrayHasKey('notify_url', $payload->all()); - self::assertArrayHasKey('sign', $payload->all()); - } -} diff --git a/tests/Plugin/Wechat/Pay/App/ClosePluginTest.php b/tests/Plugin/Wechat/Pay/App/ClosePluginTest.php new file mode 100644 index 0000000..1909442 --- /dev/null +++ b/tests/Plugin/Wechat/Pay/App/ClosePluginTest.php @@ -0,0 +1,87 @@ +plugin = new ClosePlugin(); + } + + public function testEmptyPayload() + { + $rocket = new Rocket(); + + self::expectException(InvalidParamsException::class); + self::expectExceptionCode(Exception::PARAMS_NECESSARY_PARAMS_MISSING); + self::expectExceptionMessage('参数异常: App 关闭订单,参数缺少 `out_trade_no`'); + + $this->plugin->assembly($rocket, function ($rocket) { return $rocket; }); + } + + public function testNormal() + { + $rocket = new Rocket(); + $rocket->setPayload(new Collection( [ + "out_trade_no" => "111", + ])); + + $result = $this->plugin->assembly($rocket, function ($rocket) { return $rocket; }); + + self::assertEquals([ + '_method' => 'POST', + '_url' => 'v3/pay/transactions/out-trade-no/111/close', + '_service_url' => 'v3/pay/partner/transactions/out-trade-no/111/close', + 'mchid' => '1600314069', + ], $result->getPayload()->all()); + } + + public function testServiceParams() + { + $rocket = new Rocket(); + $rocket->setParams(['_config' => 'service_provider'])->setPayload(new Collection( [ + "out_trade_no" => "111", + 'sub_mchid' => '333', + ])); + + $result = $this->plugin->assembly($rocket, function ($rocket) { return $rocket; }); + + self::assertEquals([ + '_method' => 'POST', + '_url' => 'v3/pay/transactions/out-trade-no/111/close', + '_service_url' => 'v3/pay/partner/transactions/out-trade-no/111/close', + 'sp_mchid' => '1600314069', + 'sub_mchid' => '333', + ], $result->getPayload()->all()); + } + + public function testService() + { + $rocket = new Rocket(); + $rocket->setParams(['_config' => 'service_provider'])->setPayload(new Collection( [ + "out_trade_no" => "111", + ])); + + $result = $this->plugin->assembly($rocket, function ($rocket) { return $rocket; }); + + self::assertEquals([ + '_method' => 'POST', + '_url' => 'v3/pay/transactions/out-trade-no/111/close', + '_service_url' => 'v3/pay/partner/transactions/out-trade-no/111/close', + 'sp_mchid' => '1600314069', + 'sub_mchid' => '1600314070', + ], $result->getPayload()->all()); + } +} diff --git a/tests/Plugin/Wechat/Fund/Profitsharing/DownloadBillPluginTest.php b/tests/Plugin/Wechat/Pay/App/DownloadBillPluginTest.php similarity index 50% rename from tests/Plugin/Wechat/Fund/Profitsharing/DownloadBillPluginTest.php rename to tests/Plugin/Wechat/Pay/App/DownloadBillPluginTest.php index ca415d7..14c81f2 100644 --- a/tests/Plugin/Wechat/Fund/Profitsharing/DownloadBillPluginTest.php +++ b/tests/Plugin/Wechat/Pay/App/DownloadBillPluginTest.php @@ -1,22 +1,17 @@ plugin = new DownloadBillPlugin(); } - public function testNormal() + public function testEmptyPayload() { $rocket = new Rocket(); - $rocket->setParams([])->setPayload(new Collection(['download_url' => 'https://yansongda.cn'])); - - $result = $this->plugin->assembly($rocket, function ($rocket) { return $rocket; }); - - $radar = $result->getRadar(); - - self::assertEquals(OriginResponseDirection::class, $result->getDirection()); - self::assertEquals('GET', $radar->getMethod()); - self::assertEquals(new Uri('https://yansongda.cn'), $radar->getUri()); - } - - public function testNormalNoDownloadUrl() - { - $rocket = new Rocket(); - $rocket->setParams([])->setPayload(new Collection()); self::expectException(InvalidParamsException::class); self::expectExceptionCode(Exception::PARAMS_NECESSARY_PARAMS_MISSING); + self::expectExceptionMessage('参数异常: App 下载交易对账单,参数缺少 `download_url`'); $this->plugin->assembly($rocket, function ($rocket) { return $rocket; }); } + + public function testNormal() + { + $rocket = new Rocket(); + $rocket->setPayload(new Collection( [ + "download_url" => "111", + ])); + + $result = $this->plugin->assembly($rocket, function ($rocket) { return $rocket; }); + + self::assertEquals([ + '_method' => 'GET', + '_url' => '111', + '_service_url' => '111', + ], $result->getPayload()->all()); + } } diff --git a/tests/Plugin/Wechat/Pay/App/GetFundBillPluginTest.php b/tests/Plugin/Wechat/Pay/App/GetFundBillPluginTest.php new file mode 100644 index 0000000..39324ca --- /dev/null +++ b/tests/Plugin/Wechat/Pay/App/GetFundBillPluginTest.php @@ -0,0 +1,49 @@ +plugin = new GetFundBillPlugin(); + } + + public function testEmptyPayload() + { + $rocket = new Rocket(); + + self::expectException(InvalidParamsException::class); + self::expectExceptionCode(Exception::PARAMS_NECESSARY_PARAMS_MISSING); + self::expectExceptionMessage('参数异常: App 申请资金账单,参数为空'); + + $this->plugin->assembly($rocket, function ($rocket) { return $rocket; }); + } + + public function testNormal() + { + $rocket = new Rocket(); + $rocket->setPayload(new Collection( [ + "download_url" => "111", + ])); + + $result = $this->plugin->assembly($rocket, function ($rocket) { return $rocket; }); + + self::assertEquals([ + '_method' => 'GET', + '_url' => 'v3/bill/fundflowbill?download_url=111', + '_service_url' => 'v3/bill/fundflowbill?download_url=111', + ], $result->getPayload()->all()); + } +} diff --git a/tests/Plugin/Wechat/Pay/App/GetTradeBillPluginTest.php b/tests/Plugin/Wechat/Pay/App/GetTradeBillPluginTest.php new file mode 100644 index 0000000..b7f7b59 --- /dev/null +++ b/tests/Plugin/Wechat/Pay/App/GetTradeBillPluginTest.php @@ -0,0 +1,49 @@ +plugin = new GetTradeBillPlugin(); + } + + public function testEmptyPayload() + { + $rocket = new Rocket(); + + self::expectException(InvalidParamsException::class); + self::expectExceptionCode(Exception::PARAMS_NECESSARY_PARAMS_MISSING); + self::expectExceptionMessage('参数异常: App 申请交易账单,参数为空'); + + $this->plugin->assembly($rocket, function ($rocket) { return $rocket; }); + } + + public function testNormal() + { + $rocket = new Rocket(); + $rocket->setPayload(new Collection( [ + "download_url" => "111", + ])); + + $result = $this->plugin->assembly($rocket, function ($rocket) { return $rocket; }); + + self::assertEquals([ + '_method' => 'GET', + '_url' => 'v3/bill/tradebill?download_url=111', + '_service_url' => 'v3/bill/tradebill?download_url=111', + ], $result->getPayload()->all()); + } +} diff --git a/tests/Plugin/Wechat/Pay/App/InvokePluginTest.php b/tests/Plugin/Wechat/Pay/App/InvokePluginTest.php new file mode 100644 index 0000000..306a19c --- /dev/null +++ b/tests/Plugin/Wechat/Pay/App/InvokePluginTest.php @@ -0,0 +1,108 @@ +plugin = new InvokePlugin(); + } + + public function testMissingPrepayId() + { + $rocket = new Rocket(); + + self::expectException(InvalidResponseException::class); + self::expectExceptionCode(Exception::RESPONSE_MISSING_NECESSARY_PARAMS); + self::expectExceptionMessage('预下单失败:响应缺少 `prepay_id` 参数,请自行检查参数是否符合微信要求'); + + $this->plugin->assembly($rocket, function ($rocket) { return $rocket; }); + } + + public function testNormalParams() + { + $rocket = (new Rocket()) + ->setDestination(new Collection(['prepay_id' => 'yansongda'])) + ->setPayload(['_invoke_appid' => '111', '_invoke_partnerid' => '222']); + + $result = $this->plugin->assembly($rocket, function ($rocket) { return $rocket; }); + + $contents = $result->getDestination(); + + self::assertArrayHasKey('sign', $contents->all()); + self::assertArrayHasKey('timestamp', $contents->all()); + self::assertArrayHasKey('noncestr', $contents->all()); + self::assertEquals('111', $contents->get('appid')); + self::assertEquals('Sign=WXPay', $contents->get('package')); + self::assertEquals('222', $contents->get('partnerid')); + self::assertEquals('yansongda', $contents->get('prepayid')); + } + + public function testNormal() + { + $rocket = (new Rocket())->setDestination(new Collection(['prepay_id' => 'yansongda'])); + + $result = $this->plugin->assembly($rocket, function ($rocket) { return $rocket; }); + + $contents = $result->getDestination(); + + self::assertArrayHasKey('sign', $contents->all()); + self::assertArrayHasKey('timestamp', $contents->all()); + self::assertArrayHasKey('noncestr', $contents->all()); + self::assertEquals('yansongda', $contents->get('appid')); + self::assertEquals('Sign=WXPay', $contents->get('package')); + self::assertEquals('1600314069', $contents->get('partnerid')); + self::assertEquals('yansongda', $contents->get('prepayid')); + } + + public function testServiceParams() + { + $rocket = (new Rocket()) + ->setParams(['_config' => 'service_provider4']) + ->setDestination(new Collection(['prepay_id' => 'yansongda'])) + ->setPayload(['_invoke_appid' => '111', '_invoke_partnerid' => '222']); + + $result = $this->plugin->assembly($rocket, function ($rocket) { return $rocket; }); + + $contents = $result->getDestination(); + + self::assertArrayHasKey('sign', $contents->all()); + self::assertArrayHasKey('timestamp', $contents->all()); + self::assertArrayHasKey('noncestr', $contents->all()); + self::assertEquals('111', $contents->get('appid')); + self::assertEquals('Sign=WXPay', $contents->get('package')); + self::assertEquals('222', $contents->get('partnerid')); + self::assertEquals('yansongda', $contents->get('prepayid')); + } + + public function testService() + { + $rocket = (new Rocket()) + ->setParams(['_config' => 'service_provider4']) + ->setDestination(new Collection(['prepay_id' => 'yansongda'])); + + $result = $this->plugin->assembly($rocket, function ($rocket) { return $rocket; }); + + $contents = $result->getDestination(); + + self::assertArrayHasKey('sign', $contents->all()); + self::assertArrayHasKey('timestamp', $contents->all()); + self::assertArrayHasKey('noncestr', $contents->all()); + self::assertEquals('wx55955316af4ef16', $contents->get('appid')); + self::assertEquals('Sign=WXPay', $contents->get('package')); + self::assertEquals('1600314069', $contents->get('partnerid')); + self::assertEquals('yansongda', $contents->get('prepayid')); + } +} \ No newline at end of file diff --git a/tests/Plugin/Wechat/Pay/App/InvokePrepayPluginTest.php b/tests/Plugin/Wechat/Pay/App/InvokePrepayPluginTest.php deleted file mode 100644 index 25c0993..0000000 --- a/tests/Plugin/Wechat/Pay/App/InvokePrepayPluginTest.php +++ /dev/null @@ -1,53 +0,0 @@ -plugin = new InvokePrepayPlugin(); - } - - public function testNormal() - { - $rocket = (new Rocket())->setDestination(new Collection(['prepay_id' => 'yansongda'])); - - $result = $this->plugin->assembly($rocket, function ($rocket) { return $rocket; }); - - $contents = $result->getDestination(); - - self::assertArrayHasKey('appid', $contents->all()); - self::assertArrayHasKey('partnerid', $contents->all()); - self::assertArrayHasKey('package', $contents->all()); - self::assertEquals('Sign=WXPay', $contents->get('package')); - self::assertArrayHasKey('sign', $contents->all()); - self::assertArrayHasKey('timestamp', $contents->all()); - self::assertArrayHasKey('noncestr', $contents->all()); - self::assertEquals('yansongda', $contents->get('appid')); - } - - public function testPartner() - { - $rocket = (new Rocket()) - ->setParams(['_config' => 'service_provider4']) - ->setPayload(new Collection(['sub_appid' => '123'])) - ->setDestination(new Collection(['prepay_id' => 'yansongda'])); - - $result = $this->plugin->assembly($rocket, function ($rocket) { return $rocket; }); - - $contents = $result->getDestination(); - - self::assertArrayHasKey('appid', $contents->all()); - self::assertEquals('123', $contents->get('appid')); - } -} diff --git a/tests/Plugin/Wechat/Pay/App/InvokePrepayV2PluginTest.php b/tests/Plugin/Wechat/Pay/App/InvokePrepayV2PluginTest.php deleted file mode 100644 index f8fd0d2..0000000 --- a/tests/Plugin/Wechat/Pay/App/InvokePrepayV2PluginTest.php +++ /dev/null @@ -1,39 +0,0 @@ -plugin = new InvokePrepayV2Plugin(); - } - - public function testNormal() - { - $rocket = (new Rocket())->setDestination(new Collection(['prepay_id' => 'yansongda'])); - $config = get_wechat_config($rocket->getParams()); - - $result = $this->plugin->assembly($rocket, function ($rocket) { return $rocket; }); - - $contents = $result->getDestination(); - - self::assertArrayHasKey('partnerId', $contents->all()); - self::assertEquals('yansongda', $contents->get('prepayId')); - self::assertEquals('Sign=WXPay', $contents->get('package')); - self::assertArrayHasKey('sign', $contents->all()); - self::assertArrayHasKey('timeStamp', $contents->all()); - self::assertArrayHasKey('nonceStr', $contents->all()); - self::assertEquals($config['app_id'], $contents->get('appId')); - } -} diff --git a/tests/Plugin/Wechat/Pay/App/PayPluginTest.php b/tests/Plugin/Wechat/Pay/App/PayPluginTest.php new file mode 100644 index 0000000..21497c7 --- /dev/null +++ b/tests/Plugin/Wechat/Pay/App/PayPluginTest.php @@ -0,0 +1,97 @@ +plugin = new PayPlugin(); + } + + public function testEmptyPayload() + { + $rocket = new Rocket(); + + self::expectException(InvalidParamsException::class); + self::expectExceptionCode(Exception::PARAMS_NECESSARY_PARAMS_MISSING); + self::expectExceptionMessage('参数异常: APP下单,参数为空'); + + $this->plugin->assembly($rocket, function ($rocket) { return $rocket; }); + } + + public function testNormal() + { + $rocket = new Rocket(); + $rocket->setPayload(new Collection( [ + "name" => "yansongda", + ])); + + $result = $this->plugin->assembly($rocket, function ($rocket) { return $rocket; }); + + self::assertEquals([ + '_method' => 'POST', + '_url' => 'v3/pay/transactions/app', + '_service_url' => 'v3/pay/partner/transactions/app', + "appid" => "yansongda", + 'mchid' => '1600314069', + 'notify_url' => 'https://pay.yansongda.cn', + 'name' => 'yansongda', + ], $result->getPayload()->all()); + } + + public function testServiceParams() + { + $rocket = new Rocket(); + $rocket->setParams(['_config' => 'service_provider'])->setPayload(new Collection( [ + 'sub_mchid' => '333', + 'notify_url' => '444', + 'name' => 'yansongda', + ])); + + $result = $this->plugin->assembly($rocket, function ($rocket) { return $rocket; }); + + self::assertEquals([ + '_method' => 'POST', + '_url' => 'v3/pay/transactions/app', + '_service_url' => 'v3/pay/partner/transactions/app', + "sp_appid" => "yansongdaa", + 'sp_mchid' => '1600314069', + 'sub_mchid' => '333', + 'notify_url' => '444', + 'name' => 'yansongda', + ], $result->getPayload()->all()); + } + + public function testService() + { + $rocket = new Rocket(); + $rocket->setParams(['_config' => 'service_provider'])->setPayload(new Collection( [ + 'name' => 'yansongda', + ])); + + $result = $this->plugin->assembly($rocket, function ($rocket) { return $rocket; }); + + self::assertEquals([ + '_method' => 'POST', + '_url' => 'v3/pay/transactions/app', + '_service_url' => 'v3/pay/partner/transactions/app', + "sp_appid" => "yansongdaa", + 'sp_mchid' => '1600314069', + 'sub_mchid' => '1600314070', + 'notify_url' => '', + 'name' => 'yansongda', + ], $result->getPayload()->all()); + } +} diff --git a/tests/Plugin/Wechat/Pay/App/PrepayPluginTest.php b/tests/Plugin/Wechat/Pay/App/PrepayPluginTest.php deleted file mode 100644 index 796f415..0000000 --- a/tests/Plugin/Wechat/Pay/App/PrepayPluginTest.php +++ /dev/null @@ -1,75 +0,0 @@ -plugin = new PrepayPlugin(); - } - - public function testWechatIdNormal() - { - $rocket = new Rocket(); - $rocket->setParams([])->setPayload(new Collection()); - - $result = $this->plugin->assembly($rocket, function ($rocket) { return $rocket; }); - - $payload = $result->getPayload(); - - self::assertEquals('yansongda', $payload->get('appid')); - self::assertEquals('1600314069', $payload->get('mchid')); - } - - public function testWechatIdNormalWithType() - { - $rocket = new Rocket(); - $rocket->setParams(['_type' => 'mini'])->setPayload(new Collection()); - - $result = $this->plugin->assembly($rocket, function ($rocket) { return $rocket; }); - - $payload = $result->getPayload(); - - self::assertEquals('yansongda', $payload->get('appid')); - self::assertEquals('1600314069', $payload->get('mchid')); - } - - public function testWechatIdPartner() - { - $rocket = new Rocket(); - $rocket->setParams(['_config' => 'service_provider'])->setPayload(new Collection()); - - $result = $this->plugin->assembly($rocket, function ($rocket) { return $rocket; }); - - $payload = $result->getPayload(); - - self::assertEquals('wx55955316af4ef16', $payload->get('sub_appid')); - self::assertEquals('1600314070', $payload->get('sub_mchid')); - } - - public function testWechatIdPartnerDirect() - { - $rocket = new Rocket(); - $rocket->setParams(['_config' => 'service_provider'])->setPayload(new Collection(['sub_appid' => '123'])); - - $result = $this->plugin->assembly($rocket, function ($rocket) { return $rocket; }); - - $payload = $result->getPayload(); - - self::assertEquals('123', $payload->get('sub_appid')); - self::assertEquals('1600314070', $payload->get('sub_mchid')); - } -} diff --git a/tests/Plugin/Wechat/Pay/App/QueryByWxPluginTest.php b/tests/Plugin/Wechat/Pay/App/QueryByWxPluginTest.php new file mode 100644 index 0000000..ce0a4d0 --- /dev/null +++ b/tests/Plugin/Wechat/Pay/App/QueryByWxPluginTest.php @@ -0,0 +1,73 @@ +plugin = new QueryByWxPlugin(); + } + + public function testEmptyPayload() + { + $rocket = new Rocket(); + + self::expectException(InvalidParamsException::class); + self::expectExceptionCode(Exception::PARAMS_NECESSARY_PARAMS_MISSING); + self::expectExceptionMessage('参数异常: App 通过微信订单号查询订单,参数缺少 `transaction_id`'); + + $this->plugin->assembly($rocket, function ($rocket) { return $rocket; }); + } + + public function testNormal() + { + $rocket = new Rocket(); + $rocket->setPayload(new Collection( [ + "transaction_id" => "111", + ])); + + $result = $this->plugin->assembly($rocket, function ($rocket) { return $rocket; }); + + self::assertEquals('GET', $result->getPayload()->get('_method')); + self::assertEquals('v3/pay/transactions/id/111?mchid=1600314069', $result->getPayload()->get('_url')); + } + + public function testServiceParams() + { + $rocket = new Rocket(); + $rocket->setPayload(new Collection( [ + "transaction_id" => "111", + 'sub_mchid' => '333', + ])); + + $result = $this->plugin->assembly($rocket, function ($rocket) { return $rocket; }); + + self::assertEquals('GET', $result->getPayload()->get('_method')); + self::assertEquals('v3/pay/partner/transactions/id/111?sp_mchid=1600314069&sub_mchid=333', $result->getPayload()->get('_service_url')); + } + + public function testService() + { + $rocket = new Rocket(); + $rocket->setParams(['_config' => 'service_provider'])->setPayload(new Collection( [ + "transaction_id" => "111", + ])); + + $result = $this->plugin->assembly($rocket, function ($rocket) { return $rocket; }); + + self::assertEquals('GET', $result->getPayload()->get('_method')); + self::assertEquals('v3/pay/partner/transactions/id/111?sp_mchid=1600314069&sub_mchid=1600314070', $result->getPayload()->get('_service_url')); + } +} diff --git a/tests/Plugin/Wechat/Pay/App/QueryPluginTest.php b/tests/Plugin/Wechat/Pay/App/QueryPluginTest.php new file mode 100644 index 0000000..8f63fcf --- /dev/null +++ b/tests/Plugin/Wechat/Pay/App/QueryPluginTest.php @@ -0,0 +1,73 @@ +plugin = new QueryPlugin(); + } + + public function testEmptyPayload() + { + $rocket = new Rocket(); + + self::expectException(InvalidParamsException::class); + self::expectExceptionCode(Exception::PARAMS_NECESSARY_PARAMS_MISSING); + self::expectExceptionMessage('参数异常: App 通过商户订单号查询订单,参数缺少 `out_trade_no`'); + + $this->plugin->assembly($rocket, function ($rocket) { return $rocket; }); + } + + public function testNormal() + { + $rocket = new Rocket(); + $rocket->setPayload(new Collection( [ + "out_trade_no" => "111", + ])); + + $result = $this->plugin->assembly($rocket, function ($rocket) { return $rocket; }); + + self::assertEquals('GET', $result->getPayload()->get('_method')); + self::assertEquals('v3/pay/transactions/out-trade-no/111?mchid=1600314069', $result->getPayload()->get('_url')); + } + + public function testServiceParams() + { + $rocket = new Rocket(); + $rocket->setPayload(new Collection( [ + "out_trade_no" => "111", + 'sub_mchid' => '333', + ])); + + $result = $this->plugin->assembly($rocket, function ($rocket) { return $rocket; }); + + self::assertEquals('GET', $result->getPayload()->get('_method')); + self::assertEquals('v3/pay/partner/transactions/out-trade-no/111?sp_mchid=1600314069&sub_mchid=333', $result->getPayload()->get('_service_url')); + } + + public function testService() + { + $rocket = new Rocket(); + $rocket->setParams(['_config' => 'service_provider'])->setPayload(new Collection( [ + "out_trade_no" => "111", + ])); + + $result = $this->plugin->assembly($rocket, function ($rocket) { return $rocket; }); + + self::assertEquals('GET', $result->getPayload()->get('_method')); + self::assertEquals('v3/pay/partner/transactions/out-trade-no/111?sp_mchid=1600314069&sub_mchid=1600314070', $result->getPayload()->get('_service_url')); + } +} diff --git a/tests/Plugin/Wechat/Pay/App/QueryRefundPluginTest.php b/tests/Plugin/Wechat/Pay/App/QueryRefundPluginTest.php new file mode 100644 index 0000000..3272655 --- /dev/null +++ b/tests/Plugin/Wechat/Pay/App/QueryRefundPluginTest.php @@ -0,0 +1,73 @@ +plugin = new QueryRefundPlugin(); + } + + public function testEmptyPayload() + { + $rocket = new Rocket(); + + self::expectException(InvalidParamsException::class); + self::expectExceptionCode(Exception::PARAMS_NECESSARY_PARAMS_MISSING); + self::expectExceptionMessage('参数异常: App 查询退款订单,参数缺少 `out_refund_no`'); + + $this->plugin->assembly($rocket, function ($rocket) { return $rocket; }); + } + + public function testNormal() + { + $rocket = new Rocket(); + $rocket->setPayload(new Collection( [ + "out_refund_no" => "111", + ])); + + $result = $this->plugin->assembly($rocket, function ($rocket) { return $rocket; }); + + self::assertEquals('GET', $result->getPayload()->get('_method')); + self::assertEquals('v3/refund/domestic/refunds/111', $result->getPayload()->get('_url')); + } + + public function testServiceParams() + { + $rocket = new Rocket(); + $rocket->setPayload(new Collection( [ + "out_refund_no" => "111", + 'sub_mchid' => '333', + ])); + + $result = $this->plugin->assembly($rocket, function ($rocket) { return $rocket; }); + + self::assertEquals('GET', $result->getPayload()->get('_method')); + self::assertEquals('v3/refund/domestic/refunds/111?sub_mchid=333', $result->getPayload()->get('_service_url')); + } + + public function testService() + { + $rocket = new Rocket(); + $rocket->setParams(['_config' => 'service_provider'])->setPayload(new Collection( [ + "out_refund_no" => "111", + ])); + + $result = $this->plugin->assembly($rocket, function ($rocket) { return $rocket; }); + + self::assertEquals('GET', $result->getPayload()->get('_method')); + self::assertEquals('v3/refund/domestic/refunds/111?sub_mchid=1600314070', $result->getPayload()->get('_service_url')); + } +} diff --git a/tests/Plugin/Wechat/Pay/App/RefundPluginTest.php b/tests/Plugin/Wechat/Pay/App/RefundPluginTest.php new file mode 100644 index 0000000..83fb5b0 --- /dev/null +++ b/tests/Plugin/Wechat/Pay/App/RefundPluginTest.php @@ -0,0 +1,110 @@ +plugin = new RefundPlugin(); + } + + public function testEmptyPayload() + { + $rocket = new Rocket(); + + self::expectException(InvalidParamsException::class); + self::expectExceptionCode(Exception::PARAMS_NECESSARY_PARAMS_MISSING); + self::expectExceptionMessage('参数异常: App 退款申请,参数为空'); + + $this->plugin->assembly($rocket, function ($rocket) { return $rocket; }); + } + + public function testNormalParams() + { + $rocket = new Rocket(); + $rocket->setPayload(new Collection( [ + "notify_url" => "111", + 'name' => '222', + ])); + + $result = $this->plugin->assembly($rocket, function ($rocket) { return $rocket; }); + + self::assertEquals([ + '_method' => 'POST', + '_url' => 'v3/refund/domestic/refunds', + '_service_url' => 'v3/refund/domestic/refunds', + 'notify_url' => '111', + 'name' => '222', + ], $result->getPayload()->all()); + } + + public function testNormal() + { + $rocket = new Rocket(); + $rocket->setPayload(new Collection( [ + "out_trade_no" => "111", + ])); + + $result = $this->plugin->assembly($rocket, function ($rocket) { return $rocket; }); + + self::assertEquals([ + '_method' => 'POST', + '_url' => 'v3/refund/domestic/refunds', + '_service_url' => 'v3/refund/domestic/refunds', + 'notify_url' => 'https://pay.yansongda.cn', + 'out_trade_no' => '111', + ], $result->getPayload()->all()); + } + + public function testServiceParams() + { + $rocket = new Rocket(); + $rocket->setParams(['_config' => 'service_provider'])->setPayload(new Collection( [ + "notify_url" => "111", + 'sub_mchid' => '222', + 'name' => 'yansongda', + ])); + + $result = $this->plugin->assembly($rocket, function ($rocket) { return $rocket; }); + + self::assertEquals([ + '_method' => 'POST', + '_url' => 'v3/refund/domestic/refunds', + '_service_url' => 'v3/refund/domestic/refunds', + 'notify_url' => '111', + 'sub_mchid' => '222', + 'name' => 'yansongda', + ], $result->getPayload()->all()); + } + + public function testService() + { + $rocket = new Rocket(); + $rocket->setParams(['_config' => 'service_provider'])->setPayload(new Collection([ + 'name' => 'yansongda', + ])); + + $result = $this->plugin->assembly($rocket, function ($rocket) { return $rocket; }); + + self::assertEquals([ + '_method' => 'POST', + '_url' => 'v3/refund/domestic/refunds', + '_service_url' => 'v3/refund/domestic/refunds', + 'name' => 'yansongda', + 'notify_url' => null, + 'sub_mchid' => '1600314070', + ], $result->getPayload()->all()); + } +} diff --git a/tests/Plugin/Wechat/Pay/Combine/AppInvokePluginTest.php b/tests/Plugin/Wechat/Pay/Combine/AppInvokePluginTest.php new file mode 100644 index 0000000..0e531a8 --- /dev/null +++ b/tests/Plugin/Wechat/Pay/Combine/AppInvokePluginTest.php @@ -0,0 +1,108 @@ +plugin = new AppInvokePlugin(); + } + + public function testMissingPrepayId() + { + $rocket = new Rocket(); + + self::expectException(InvalidResponseException::class); + self::expectExceptionCode(Exception::RESPONSE_MISSING_NECESSARY_PARAMS); + self::expectExceptionMessage('预下单失败:响应缺少 `prepay_id` 参数,请自行检查参数是否符合微信要求'); + + $this->plugin->assembly($rocket, function ($rocket) { return $rocket; }); + } + + public function testNormalParams() + { + $rocket = (new Rocket()) + ->setDestination(new Collection(['prepay_id' => 'yansongda'])) + ->setPayload(['_invoke_appid' => '111', '_invoke_partnerid' => '222']); + + $result = $this->plugin->assembly($rocket, function ($rocket) { return $rocket; }); + + $contents = $result->getDestination(); + + self::assertArrayHasKey('sign', $contents->all()); + self::assertArrayHasKey('timestamp', $contents->all()); + self::assertArrayHasKey('noncestr', $contents->all()); + self::assertEquals('111', $contents->get('appid')); + self::assertEquals('Sign=WXPay', $contents->get('package')); + self::assertEquals('222', $contents->get('partnerid')); + self::assertEquals('yansongda', $contents->get('prepayid')); + } + + public function testNormal() + { + $rocket = (new Rocket())->setDestination(new Collection(['prepay_id' => 'yansongda'])); + + $result = $this->plugin->assembly($rocket, function ($rocket) { return $rocket; }); + + $contents = $result->getDestination(); + + self::assertArrayHasKey('sign', $contents->all()); + self::assertArrayHasKey('timestamp', $contents->all()); + self::assertArrayHasKey('noncestr', $contents->all()); + self::assertEquals('yansongda', $contents->get('appid')); + self::assertEquals('Sign=WXPay', $contents->get('package')); + self::assertEquals('1600314069', $contents->get('partnerid')); + self::assertEquals('yansongda', $contents->get('prepayid')); + } + + public function testServiceParams() + { + $rocket = (new Rocket()) + ->setParams(['_config' => 'service_provider4']) + ->setDestination(new Collection(['prepay_id' => 'yansongda'])) + ->setPayload(['_invoke_appid' => '111', '_invoke_partnerid' => '222']); + + $result = $this->plugin->assembly($rocket, function ($rocket) { return $rocket; }); + + $contents = $result->getDestination(); + + self::assertArrayHasKey('sign', $contents->all()); + self::assertArrayHasKey('timestamp', $contents->all()); + self::assertArrayHasKey('noncestr', $contents->all()); + self::assertEquals('111', $contents->get('appid')); + self::assertEquals('Sign=WXPay', $contents->get('package')); + self::assertEquals('222', $contents->get('partnerid')); + self::assertEquals('yansongda', $contents->get('prepayid')); + } + + public function testService() + { + $rocket = (new Rocket()) + ->setParams(['_config' => 'service_provider4']) + ->setDestination(new Collection(['prepay_id' => 'yansongda'])); + + $result = $this->plugin->assembly($rocket, function ($rocket) { return $rocket; }); + + $contents = $result->getDestination(); + + self::assertArrayHasKey('sign', $contents->all()); + self::assertArrayHasKey('timestamp', $contents->all()); + self::assertArrayHasKey('noncestr', $contents->all()); + self::assertEquals('wx55955316af4ef16', $contents->get('appid')); + self::assertEquals('Sign=WXPay', $contents->get('package')); + self::assertEquals('1600314069', $contents->get('partnerid')); + self::assertEquals('yansongda', $contents->get('prepayid')); + } +} \ No newline at end of file diff --git a/tests/Plugin/Wechat/Pay/Combine/AppPayPluginTest.php b/tests/Plugin/Wechat/Pay/Combine/AppPayPluginTest.php new file mode 100644 index 0000000..910ad7c --- /dev/null +++ b/tests/Plugin/Wechat/Pay/Combine/AppPayPluginTest.php @@ -0,0 +1,76 @@ +plugin = new AppPayPlugin(); + } + + public function testEmptyPayload() + { + $rocket = new Rocket(); + + self::expectException(InvalidParamsException::class); + self::expectExceptionCode(Exception::PARAMS_NECESSARY_PARAMS_MISSING); + self::expectExceptionMessage('参数异常: APP合单 下单,参数为空'); + + $this->plugin->assembly($rocket, function ($rocket) { return $rocket; }); + } + + public function testNormalParams() + { + $rocket = new Rocket(); + $rocket->setPayload(new Collection( [ + 'combine_mchid' => '333', + 'combine_appid' => 'yansongdaaa', + 'notify_url' => '444', + 'name' => 'yansongda', + ])); + + $result = $this->plugin->assembly($rocket, function ($rocket) { return $rocket; }); + + self::assertEquals([ + '_method' => 'POST', + '_url' => 'v3/combine-transactions/app', + '_service_url' => 'v3/combine-transactions/app', + "combine_appid" => "yansongdaaa", + 'combine_mchid' => '333', + 'notify_url' => '444', + 'name' => 'yansongda', + ], $result->getPayload()->all()); + } + + public function testNormal() + { + $rocket = new Rocket(); + $rocket->setPayload(new Collection( [ + 'name' => 'yansongda', + ])); + + $result = $this->plugin->assembly($rocket, function ($rocket) { return $rocket; }); + + self::assertEquals([ + '_method' => 'POST', + '_url' => 'v3/combine-transactions/app', + '_service_url' => 'v3/combine-transactions/app', + "combine_appid" => "yansongda", + 'combine_mchid' => '1600314069', + 'notify_url' => 'https://pay.yansongda.cn', + 'name' => 'yansongda', + ], $result->getPayload()->all()); + } +} diff --git a/tests/Plugin/Wechat/Pay/Combine/ClosePluginTest.php b/tests/Plugin/Wechat/Pay/Combine/ClosePluginTest.php new file mode 100644 index 0000000..6fb24ad --- /dev/null +++ b/tests/Plugin/Wechat/Pay/Combine/ClosePluginTest.php @@ -0,0 +1,70 @@ +plugin = new ClosePlugin(); + } + + public function testEmptyPayload() + { + $rocket = new Rocket(); + + self::expectException(InvalidParamsException::class); + self::expectExceptionCode(Exception::PARAMS_NECESSARY_PARAMS_MISSING); + self::expectExceptionMessage('参数异常: 合单关单,参数缺少 `combine_out_trade_no`'); + + $this->plugin->assembly($rocket, function ($rocket) { return $rocket; }); + } + + public function testNormalParams() + { + $rocket = new Rocket(); + $rocket->setPayload(new Collection( [ + "combine_out_trade_no" => "111", + 'combine_appid' => '333', + 'name' => 'yansongda', + ])); + + $result = $this->plugin->assembly($rocket, function ($rocket) { return $rocket; }); + + self::assertEquals([ + '_method' => 'POST', + '_url' => 'v3/combine-transactions/out-trade-no/111/close', + '_service_url' => 'v3/combine-transactions/out-trade-no/111/close', + 'combine_appid' => '333', + 'name' => 'yansongda', + ], $result->getPayload()->all()); + } + + public function testNormal() + { + $rocket = new Rocket(); + $rocket->setPayload(new Collection( [ + "combine_out_trade_no" => "111", + ])); + + $result = $this->plugin->assembly($rocket, function ($rocket) { return $rocket; }); + + self::assertEquals([ + '_method' => 'POST', + '_url' => 'v3/combine-transactions/out-trade-no/111/close', + '_service_url' => 'v3/combine-transactions/out-trade-no/111/close', + 'combine_appid' => 'wx55955316af4ef13', + ], $result->getPayload()->all()); + } +} diff --git a/tests/Plugin/Wechat/Pay/Combine/DownloadBillPluginTest.php b/tests/Plugin/Wechat/Pay/Combine/DownloadBillPluginTest.php new file mode 100644 index 0000000..ce938e0 --- /dev/null +++ b/tests/Plugin/Wechat/Pay/Combine/DownloadBillPluginTest.php @@ -0,0 +1,49 @@ +plugin = new DownloadBillPlugin(); + } + + public function testEmptyPayload() + { + $rocket = new Rocket(); + + self::expectException(InvalidParamsException::class); + self::expectExceptionCode(Exception::PARAMS_NECESSARY_PARAMS_MISSING); + self::expectExceptionMessage('参数异常: 合单 下载交易对账单,参数缺少 `download_url`'); + + $this->plugin->assembly($rocket, function ($rocket) { return $rocket; }); + } + + public function testNormal() + { + $rocket = new Rocket(); + $rocket->setPayload(new Collection( [ + "download_url" => "111", + ])); + + $result = $this->plugin->assembly($rocket, function ($rocket) { return $rocket; }); + + self::assertEquals([ + '_method' => 'GET', + '_url' => '111', + '_service_url' => '111', + ], $result->getPayload()->all()); + } +} diff --git a/tests/Plugin/Wechat/Pay/Combine/GetFundBillPluginTest.php b/tests/Plugin/Wechat/Pay/Combine/GetFundBillPluginTest.php new file mode 100644 index 0000000..0fa7956 --- /dev/null +++ b/tests/Plugin/Wechat/Pay/Combine/GetFundBillPluginTest.php @@ -0,0 +1,49 @@ +plugin = new GetFundBillPlugin(); + } + + public function testEmptyPayload() + { + $rocket = new Rocket(); + + self::expectException(InvalidParamsException::class); + self::expectExceptionCode(Exception::PARAMS_NECESSARY_PARAMS_MISSING); + self::expectExceptionMessage('参数异常: 合单 申请资金账单,参数为空'); + + $this->plugin->assembly($rocket, function ($rocket) { return $rocket; }); + } + + public function testNormal() + { + $rocket = new Rocket(); + $rocket->setPayload(new Collection( [ + "download_url" => "111", + ])); + + $result = $this->plugin->assembly($rocket, function ($rocket) { return $rocket; }); + + self::assertEquals([ + '_method' => 'GET', + '_url' => 'v3/bill/fundflowbill?download_url=111', + '_service_url' => 'v3/bill/fundflowbill?download_url=111', + ], $result->getPayload()->all()); + } +} diff --git a/tests/Plugin/Wechat/Pay/Combine/GetTradeBillPluginTest.php b/tests/Plugin/Wechat/Pay/Combine/GetTradeBillPluginTest.php new file mode 100644 index 0000000..8f917a1 --- /dev/null +++ b/tests/Plugin/Wechat/Pay/Combine/GetTradeBillPluginTest.php @@ -0,0 +1,49 @@ +plugin = new GetTradeBillPlugin(); + } + + public function testEmptyPayload() + { + $rocket = new Rocket(); + + self::expectException(InvalidParamsException::class); + self::expectExceptionCode(Exception::PARAMS_NECESSARY_PARAMS_MISSING); + self::expectExceptionMessage('参数异常: 合单 申请交易账单,参数为空'); + + $this->plugin->assembly($rocket, function ($rocket) { return $rocket; }); + } + + public function testNormal() + { + $rocket = new Rocket(); + $rocket->setPayload(new Collection( [ + "download_url" => "111", + ])); + + $result = $this->plugin->assembly($rocket, function ($rocket) { return $rocket; }); + + self::assertEquals([ + '_method' => 'GET', + '_url' => 'v3/bill/tradebill?download_url=111', + '_service_url' => 'v3/bill/tradebill?download_url=111', + ], $result->getPayload()->all()); + } +} diff --git a/tests/Plugin/Wechat/Pay/Combine/H5PayPluginTest.php b/tests/Plugin/Wechat/Pay/Combine/H5PayPluginTest.php new file mode 100644 index 0000000..00c172e --- /dev/null +++ b/tests/Plugin/Wechat/Pay/Combine/H5PayPluginTest.php @@ -0,0 +1,76 @@ +plugin = new H5PayPlugin(); + } + + public function testEmptyPayload() + { + $rocket = new Rocket(); + + self::expectException(InvalidParamsException::class); + self::expectExceptionCode(Exception::PARAMS_NECESSARY_PARAMS_MISSING); + self::expectExceptionMessage('参数异常: H5合单 下单,参数为空'); + + $this->plugin->assembly($rocket, function ($rocket) { return $rocket; }); + } + + public function testNormalParams() + { + $rocket = new Rocket(); + $rocket->setPayload(new Collection( [ + 'combine_mchid' => '333', + 'combine_appid' => 'yansongdaaa', + 'notify_url' => '444', + 'name' => 'yansongda', + ])); + + $result = $this->plugin->assembly($rocket, function ($rocket) { return $rocket; }); + + self::assertEquals([ + '_method' => 'POST', + '_url' => 'v3/combine-transactions/h5', + '_service_url' => 'v3/combine-transactions/h5', + "combine_appid" => "yansongdaaa", + 'combine_mchid' => '333', + 'notify_url' => '444', + 'name' => 'yansongda', + ], $result->getPayload()->all()); + } + + public function testNormal() + { + $rocket = new Rocket(); + $rocket->setPayload(new Collection( [ + 'name' => 'yansongda', + ])); + + $result = $this->plugin->assembly($rocket, function ($rocket) { return $rocket; }); + + self::assertEquals([ + '_method' => 'POST', + '_url' => 'v3/combine-transactions/h5', + '_service_url' => 'v3/combine-transactions/h5', + "combine_appid" => "wx55955316af4ef13", + 'combine_mchid' => '1600314069', + 'notify_url' => 'https://pay.yansongda.cn', + 'name' => 'yansongda', + ], $result->getPayload()->all()); + } +} diff --git a/tests/Plugin/Wechat/Pay/Combine/JsapiInvokePluginTest.php b/tests/Plugin/Wechat/Pay/Combine/JsapiInvokePluginTest.php new file mode 100644 index 0000000..b3099aa --- /dev/null +++ b/tests/Plugin/Wechat/Pay/Combine/JsapiInvokePluginTest.php @@ -0,0 +1,104 @@ +plugin = new JsapiInvokePlugin(); + } + + public function testMissingPrepayId() + { + $rocket = new Rocket(); + + self::expectException(InvalidResponseException::class); + self::expectExceptionCode(Exception::RESPONSE_MISSING_NECESSARY_PARAMS); + self::expectExceptionMessage('预下单失败:响应缺少 `prepay_id` 参数,请自行检查参数是否符合微信要求'); + + $this->plugin->assembly($rocket, function ($rocket) { return $rocket; }); + } + + public function testNormalParams() + { + $rocket = (new Rocket()) + ->setDestination(new Collection(['prepay_id' => 'yansongda'])) + ->setPayload(['_invoke_appid' => '111']); + + $result = $this->plugin->assembly($rocket, function ($rocket) { return $rocket; }); + + $contents = $result->getDestination(); + + self::assertArrayHasKey('paySign', $contents->all()); + self::assertArrayHasKey('timeStamp', $contents->all()); + self::assertArrayHasKey('nonceStr', $contents->all()); + self::assertEquals('111', $contents->get('appId')); + self::assertEquals('prepay_id=yansongda', $contents->get('package')); + self::assertEquals('RSA', $contents->get('signType')); + } + + public function testNormal() + { + $rocket = (new Rocket())->setDestination(new Collection(['prepay_id' => 'yansongda'])); + + $result = $this->plugin->assembly($rocket, function ($rocket) { return $rocket; }); + + $contents = $result->getDestination(); + + self::assertArrayHasKey('paySign', $contents->all()); + self::assertArrayHasKey('timeStamp', $contents->all()); + self::assertArrayHasKey('nonceStr', $contents->all()); + self::assertEquals('wx55955316af4ef13', $contents->get('appId')); + self::assertEquals('prepay_id=yansongda', $contents->get('package')); + self::assertEquals('RSA', $contents->get('signType')); + } + + public function testServiceParams() + { + $rocket = (new Rocket()) + ->setParams(['_config' => 'service_provider4']) + ->setDestination(new Collection(['prepay_id' => 'yansongda'])) + ->setPayload(['_invoke_appid' => '111']); + + $result = $this->plugin->assembly($rocket, function ($rocket) { return $rocket; }); + + $contents = $result->getDestination(); + + self::assertArrayHasKey('paySign', $contents->all()); + self::assertArrayHasKey('timeStamp', $contents->all()); + self::assertArrayHasKey('nonceStr', $contents->all()); + self::assertEquals('111', $contents->get('appId')); + self::assertEquals('prepay_id=yansongda', $contents->get('package')); + self::assertEquals('RSA', $contents->get('signType')); + } + + public function testService() + { + $rocket = (new Rocket()) + ->setParams(['_config' => 'service_provider']) + ->setDestination(new Collection(['prepay_id' => 'yansongda'])); + + $result = $this->plugin->assembly($rocket, function ($rocket) { return $rocket; }); + + $contents = $result->getDestination(); + + self::assertArrayHasKey('paySign', $contents->all()); + self::assertArrayHasKey('timeStamp', $contents->all()); + self::assertArrayHasKey('nonceStr', $contents->all()); + self::assertEquals('wx55955316af4ef15', $contents->get('appId')); + self::assertEquals('prepay_id=yansongda', $contents->get('package')); + self::assertEquals('RSA', $contents->get('signType')); + } +} \ No newline at end of file diff --git a/tests/Plugin/Wechat/Pay/Combine/JsapiPayPluginTest.php b/tests/Plugin/Wechat/Pay/Combine/JsapiPayPluginTest.php new file mode 100644 index 0000000..137abba --- /dev/null +++ b/tests/Plugin/Wechat/Pay/Combine/JsapiPayPluginTest.php @@ -0,0 +1,77 @@ +plugin = new JsapiPayPlugin(); + } + + public function testEmptyPayload() + { + $rocket = new Rocket(); + + self::expectException(InvalidParamsException::class); + self::expectExceptionCode(Exception::PARAMS_NECESSARY_PARAMS_MISSING); + self::expectExceptionMessage('参数异常: Jsapi合单 下单,参数为空'); + + $this->plugin->assembly($rocket, function ($rocket) { return $rocket; }); + } + + public function testNormalParams() + { + $rocket = new Rocket(); + $rocket->setPayload(new Collection( [ + 'combine_mchid' => '333', + 'combine_appid' => 'yansongdaaa', + 'notify_url' => '444', + 'name' => 'yansongda', + ])); + + $result = $this->plugin->assembly($rocket, function ($rocket) { return $rocket; }); + + self::assertEquals([ + '_method' => 'POST', + '_url' => 'v3/combine-transactions/jsapi', + '_service_url' => 'v3/combine-transactions/jsapi', + "combine_appid" => "yansongdaaa", + 'combine_mchid' => '333', + 'notify_url' => '444', + 'name' => 'yansongda', + ], $result->getPayload()->all()); + } + + public function testNormal() + { + $rocket = new Rocket(); + $rocket->setPayload(new Collection( [ + 'name' => 'yansongda', + ])); + + $result = $this->plugin->assembly($rocket, function ($rocket) { return $rocket; }); + + self::assertEquals([ + '_method' => 'POST', + '_url' => 'v3/combine-transactions/jsapi', + '_service_url' => 'v3/combine-transactions/jsapi', + "combine_appid" => "wx55955316af4ef13", + 'combine_mchid' => '1600314069', + 'notify_url' => 'https://pay.yansongda.cn', + 'name' => 'yansongda', + ], $result->getPayload()->all()); + } +} diff --git a/tests/Plugin/Wechat/Pay/Combine/MiniInvokePluginTest.php b/tests/Plugin/Wechat/Pay/Combine/MiniInvokePluginTest.php new file mode 100644 index 0000000..dd4386f --- /dev/null +++ b/tests/Plugin/Wechat/Pay/Combine/MiniInvokePluginTest.php @@ -0,0 +1,105 @@ +plugin = new MiniInvokePlugin(); + } + + public function testMissingPrepayId() + { + $rocket = new Rocket(); + + self::expectException(InvalidResponseException::class); + self::expectExceptionCode(Exception::RESPONSE_MISSING_NECESSARY_PARAMS); + self::expectExceptionMessage('预下单失败:响应缺少 `prepay_id` 参数,请自行检查参数是否符合微信要求'); + + $this->plugin->assembly($rocket, function ($rocket) { return $rocket; }); + } + + public function testNormalParams() + { + $rocket = (new Rocket()) + ->setDestination(new Collection(['prepay_id' => 'yansongda'])) + ->setPayload(['_invoke_appid' => '111']); + + $result = $this->plugin->assembly($rocket, function ($rocket) { return $rocket; }); + + $contents = $result->getDestination(); + + self::assertArrayHasKey('paySign', $contents->all()); + self::assertArrayHasKey('timeStamp', $contents->all()); + self::assertArrayHasKey('nonceStr', $contents->all()); + self::assertEquals('111', $contents->get('appId')); + self::assertEquals('prepay_id=yansongda', $contents->get('package')); + self::assertEquals('RSA', $contents->get('signType')); + } + + public function testNormal() + { + $rocket = (new Rocket())->setDestination(new Collection(['prepay_id' => 'yansongda'])); + + $result = $this->plugin->assembly($rocket, function ($rocket) { return $rocket; }); + + $contents = $result->getDestination(); + + self::assertArrayHasKey('paySign', $contents->all()); + self::assertArrayHasKey('timeStamp', $contents->all()); + self::assertArrayHasKey('nonceStr', $contents->all()); + self::assertEquals('wx55955316af4ef14', $contents->get('appId')); + self::assertEquals('prepay_id=yansongda', $contents->get('package')); + self::assertEquals('RSA', $contents->get('signType')); + } + + public function testServiceParams() + { + $rocket = (new Rocket()) + ->setParams(['_config' => 'service_provider4']) + ->setDestination(new Collection(['prepay_id' => 'yansongda'])) + ->setPayload(['_invoke_appid' => '111']); + + $result = $this->plugin->assembly($rocket, function ($rocket) { return $rocket; }); + + $contents = $result->getDestination(); + + self::assertArrayHasKey('paySign', $contents->all()); + self::assertArrayHasKey('timeStamp', $contents->all()); + self::assertArrayHasKey('nonceStr', $contents->all()); + self::assertEquals('111', $contents->get('appId')); + self::assertEquals('prepay_id=yansongda', $contents->get('package')); + self::assertEquals('RSA', $contents->get('signType')); + } + + public function testService() + { + $rocket = (new Rocket()) + ->setParams(['_config' => 'service_provider4']) + ->setDestination(new Collection(['prepay_id' => 'yansongda'])); + + $result = $this->plugin->assembly($rocket, function ($rocket) { return $rocket; }); + + $contents = $result->getDestination(); + + self::assertArrayHasKey('paySign', $contents->all()); + self::assertArrayHasKey('timeStamp', $contents->all()); + self::assertArrayHasKey('nonceStr', $contents->all()); + self::assertEquals('wx55955316af4ef17', $contents->get('appId')); + self::assertEquals('prepay_id=yansongda', $contents->get('package')); + self::assertEquals('RSA', $contents->get('signType')); + } +} \ No newline at end of file diff --git a/tests/Plugin/Wechat/Pay/Combine/MiniPayPluginTest.php b/tests/Plugin/Wechat/Pay/Combine/MiniPayPluginTest.php new file mode 100644 index 0000000..5e2ca75 --- /dev/null +++ b/tests/Plugin/Wechat/Pay/Combine/MiniPayPluginTest.php @@ -0,0 +1,78 @@ +plugin = new MiniPayPlugin(); + } + + public function testEmptyPayload() + { + $rocket = new Rocket(); + + self::expectException(InvalidParamsException::class); + self::expectExceptionCode(Exception::PARAMS_NECESSARY_PARAMS_MISSING); + self::expectExceptionMessage('参数异常: Mini合单 下单,参数为空'); + + $this->plugin->assembly($rocket, function ($rocket) { return $rocket; }); + } + + public function testNormalParams() + { + $rocket = new Rocket(); + $rocket->setPayload(new Collection( [ + 'combine_mchid' => '333', + 'combine_appid' => 'yansongdaaa', + 'notify_url' => '444', + 'name' => 'yansongda', + ])); + + $result = $this->plugin->assembly($rocket, function ($rocket) { return $rocket; }); + + self::assertEquals([ + '_method' => 'POST', + '_url' => 'v3/combine-transactions/jsapi', + '_service_url' => 'v3/combine-transactions/jsapi', + "combine_appid" => "yansongdaaa", + 'combine_mchid' => '333', + 'notify_url' => '444', + 'name' => 'yansongda', + ], $result->getPayload()->all()); + } + + public function testNormal() + { + $rocket = new Rocket(); + $rocket->setPayload(new Collection( [ + 'name' => 'yansongda', + ])); + + $result = $this->plugin->assembly($rocket, function ($rocket) { return $rocket; }); + + self::assertEquals([ + '_method' => 'POST', + '_url' => 'v3/combine-transactions/jsapi', + '_service_url' => 'v3/combine-transactions/jsapi', + "combine_appid" => "wx55955316af4ef14", + 'combine_mchid' => '1600314069', + 'notify_url' => 'https://pay.yansongda.cn', + 'name' => 'yansongda', + ], $result->getPayload()->all()); + } +} diff --git a/tests/Plugin/Wechat/Pay/Combine/NativePayPluginTest.php b/tests/Plugin/Wechat/Pay/Combine/NativePayPluginTest.php new file mode 100644 index 0000000..31ac2df --- /dev/null +++ b/tests/Plugin/Wechat/Pay/Combine/NativePayPluginTest.php @@ -0,0 +1,76 @@ +plugin = new NativePayPlugin(); + } + + public function testEmptyPayload() + { + $rocket = new Rocket(); + + self::expectException(InvalidParamsException::class); + self::expectExceptionCode(Exception::PARAMS_NECESSARY_PARAMS_MISSING); + self::expectExceptionMessage('参数异常: Native合单 下单,参数为空'); + + $this->plugin->assembly($rocket, function ($rocket) { return $rocket; }); + } + + public function testNormalParams() + { + $rocket = new Rocket(); + $rocket->setPayload(new Collection( [ + 'combine_mchid' => '333', + 'combine_appid' => 'yansongdaaa', + 'notify_url' => '444', + 'name' => 'yansongda', + ])); + + $result = $this->plugin->assembly($rocket, function ($rocket) { return $rocket; }); + + self::assertEquals([ + '_method' => 'POST', + '_url' => 'v3/combine-transactions/native', + '_service_url' => 'v3/combine-transactions/native', + "combine_appid" => "yansongdaaa", + 'combine_mchid' => '333', + 'notify_url' => '444', + 'name' => 'yansongda', + ], $result->getPayload()->all()); + } + + public function testNormal() + { + $rocket = new Rocket(); + $rocket->setPayload(new Collection( [ + 'name' => 'yansongda', + ])); + + $result = $this->plugin->assembly($rocket, function ($rocket) { return $rocket; }); + + self::assertEquals([ + '_method' => 'POST', + '_url' => 'v3/combine-transactions/native', + '_service_url' => 'v3/combine-transactions/native', + "combine_appid" => "wx55955316af4ef13", + 'combine_mchid' => '1600314069', + 'notify_url' => 'https://pay.yansongda.cn', + 'name' => 'yansongda', + ], $result->getPayload()->all()); + } +} diff --git a/tests/Plugin/Wechat/Fund/Balance/QueryPluginTest.php b/tests/Plugin/Wechat/Pay/Combine/QueryPluginTest.php similarity index 52% rename from tests/Plugin/Wechat/Fund/Balance/QueryPluginTest.php rename to tests/Plugin/Wechat/Pay/Combine/QueryPluginTest.php index 17e654a..511d4ed 100644 --- a/tests/Plugin/Wechat/Fund/Balance/QueryPluginTest.php +++ b/tests/Plugin/Wechat/Pay/Combine/QueryPluginTest.php @@ -1,23 +1,17 @@ plugin = new QueryPlugin(); } - public function testNormal() + public function testEmptyPayload() { $rocket = new Rocket(); - $rocket->setParams([])->setPayload(new Collection(['account_type' => '123'])); - - $result = $this->plugin->assembly($rocket, function ($rocket) { return $rocket; }); - - $radar = $result->getRadar(); - - self::assertEquals(new Uri(Wechat::URL[Pay::MODE_NORMAL].'v3/merchant/fund/balance/123'), $radar->getUri()); - self::assertEquals('GET', $radar->getMethod()); - } - - public function testNormalNoAccountType() - { - $rocket = new Rocket(); - $rocket->setParams([])->setPayload(new Collection()); self::expectException(InvalidParamsException::class); self::expectExceptionCode(Exception::PARAMS_NECESSARY_PARAMS_MISSING); + self::expectExceptionMessage('参数异常: 合单查询,参数缺少 `combine_out_trade_no`'); $this->plugin->assembly($rocket, function ($rocket) { return $rocket; }); } + + public function testNormal() + { + $rocket = new Rocket(); + $rocket->setPayload(new Collection( [ + "combine_out_trade_no" => "111", + ])); + + $result = $this->plugin->assembly($rocket, function ($rocket) { return $rocket; }); + + self::assertEquals('GET', $result->getPayload()->get('_method')); + self::assertEquals('v3/combine-transactions/out-trade-no/111', $result->getPayload()->get('_url')); + self::assertEquals('v3/combine-transactions/out-trade-no/111', $result->getPayload()->get('_service_url')); + } } diff --git a/tests/Plugin/Wechat/Pay/Combine/QueryRefundPluginTest.php b/tests/Plugin/Wechat/Pay/Combine/QueryRefundPluginTest.php new file mode 100644 index 0000000..58bd5e2 --- /dev/null +++ b/tests/Plugin/Wechat/Pay/Combine/QueryRefundPluginTest.php @@ -0,0 +1,73 @@ +plugin = new QueryRefundPlugin(); + } + + public function testEmptyPayload() + { + $rocket = new Rocket(); + + self::expectException(InvalidParamsException::class); + self::expectExceptionCode(Exception::PARAMS_NECESSARY_PARAMS_MISSING); + self::expectExceptionMessage('参数异常: 合单查询退款订单,参数缺少 `out_refund_no`'); + + $this->plugin->assembly($rocket, function ($rocket) { return $rocket; }); + } + + public function testNormal() + { + $rocket = new Rocket(); + $rocket->setPayload(new Collection( [ + "out_refund_no" => "111", + ])); + + $result = $this->plugin->assembly($rocket, function ($rocket) { return $rocket; }); + + self::assertEquals('GET', $result->getPayload()->get('_method')); + self::assertEquals('v3/refund/domestic/refunds/111', $result->getPayload()->get('_url')); + } + + public function testServiceParams() + { + $rocket = new Rocket(); + $rocket->setPayload(new Collection( [ + "out_refund_no" => "111", + 'sub_mchid' => '333', + ])); + + $result = $this->plugin->assembly($rocket, function ($rocket) { return $rocket; }); + + self::assertEquals('GET', $result->getPayload()->get('_method')); + self::assertEquals('v3/refund/domestic/refunds/111?sub_mchid=333', $result->getPayload()->get('_service_url')); + } + + public function testService() + { + $rocket = new Rocket(); + $rocket->setParams(['_config' => 'service_provider'])->setPayload(new Collection( [ + "out_refund_no" => "111", + ])); + + $result = $this->plugin->assembly($rocket, function ($rocket) { return $rocket; }); + + self::assertEquals('GET', $result->getPayload()->get('_method')); + self::assertEquals('v3/refund/domestic/refunds/111?sub_mchid=1600314070', $result->getPayload()->get('_service_url')); + } +} diff --git a/tests/Plugin/Wechat/Pay/Combine/RefundPluginTest.php b/tests/Plugin/Wechat/Pay/Combine/RefundPluginTest.php new file mode 100644 index 0000000..3c8ef4a --- /dev/null +++ b/tests/Plugin/Wechat/Pay/Combine/RefundPluginTest.php @@ -0,0 +1,110 @@ +plugin = new RefundPlugin(); + } + + public function testEmptyPayload() + { + $rocket = new Rocket(); + + self::expectException(InvalidParamsException::class); + self::expectExceptionCode(Exception::PARAMS_NECESSARY_PARAMS_MISSING); + self::expectExceptionMessage('参数异常: 合单 退款申请,参数为空'); + + $this->plugin->assembly($rocket, function ($rocket) { return $rocket; }); + } + + public function testNormalParams() + { + $rocket = new Rocket(); + $rocket->setPayload(new Collection( [ + "notify_url" => "111", + 'name' => '222', + ])); + + $result = $this->plugin->assembly($rocket, function ($rocket) { return $rocket; }); + + self::assertEquals([ + '_method' => 'POST', + '_url' => 'v3/refund/domestic/refunds', + '_service_url' => 'v3/refund/domestic/refunds', + 'notify_url' => '111', + 'name' => '222', + ], $result->getPayload()->all()); + } + + public function testNormal() + { + $rocket = new Rocket(); + $rocket->setPayload(new Collection( [ + "out_trade_no" => "111", + ])); + + $result = $this->plugin->assembly($rocket, function ($rocket) { return $rocket; }); + + self::assertEquals([ + '_method' => 'POST', + '_url' => 'v3/refund/domestic/refunds', + '_service_url' => 'v3/refund/domestic/refunds', + 'notify_url' => 'https://pay.yansongda.cn', + 'out_trade_no' => '111', + ], $result->getPayload()->all()); + } + + public function testServiceParams() + { + $rocket = new Rocket(); + $rocket->setParams(['_config' => 'service_provider'])->setPayload(new Collection( [ + "notify_url" => "111", + 'sub_mchid' => '222', + 'name' => 'yansongda', + ])); + + $result = $this->plugin->assembly($rocket, function ($rocket) { return $rocket; }); + + self::assertEquals([ + '_method' => 'POST', + '_url' => 'v3/refund/domestic/refunds', + '_service_url' => 'v3/refund/domestic/refunds', + 'notify_url' => '111', + 'sub_mchid' => '222', + 'name' => 'yansongda', + ], $result->getPayload()->all()); + } + + public function testService() + { + $rocket = new Rocket(); + $rocket->setParams(['_config' => 'service_provider'])->setPayload(new Collection([ + 'name' => 'yansongda', + ])); + + $result = $this->plugin->assembly($rocket, function ($rocket) { return $rocket; }); + + self::assertEquals([ + '_method' => 'POST', + '_url' => 'v3/refund/domestic/refunds', + '_service_url' => 'v3/refund/domestic/refunds', + 'name' => 'yansongda', + 'notify_url' => null, + 'sub_mchid' => '1600314070', + ], $result->getPayload()->all()); + } +} diff --git a/tests/Plugin/Wechat/Pay/Common/ClosePluginTest.php b/tests/Plugin/Wechat/Pay/Common/ClosePluginTest.php deleted file mode 100644 index 16cf343..0000000 --- a/tests/Plugin/Wechat/Pay/Common/ClosePluginTest.php +++ /dev/null @@ -1,81 +0,0 @@ -plugin = new ClosePlugin(); - } - - public function testNormal() - { - $rocket = new Rocket(); - $rocket->setParams([])->setPayload(new Collection(['out_trade_no' => '123'])); - - $result = $this->plugin->assembly($rocket, function ($rocket) { return $rocket; }); - - $radar = $result->getRadar(); - $payload = $result->getPayload(); - - self::assertEquals(new Uri(Wechat::URL[Pay::MODE_NORMAL].'v3/pay/transactions/out-trade-no/123/close'), $radar->getUri()); - self::assertEquals('POST', $radar->getMethod()); - self::assertEquals('1600314069', $payload->get('mchid')); - self::assertArrayNotHasKey('sp_mchid', $payload->all()); - self::assertArrayNotHasKey('sub_mchid', $payload->all()); - } - - public function testNormalNoOutTradeNo() - { - $rocket = new Rocket(); - $rocket->setParams([])->setPayload(new Collection()); - - self::expectException(InvalidParamsException::class); - self::expectExceptionCode(Exception::PARAMS_NECESSARY_PARAMS_MISSING); - - $this->plugin->assembly($rocket, function ($rocket) { return $rocket; }); - } - - public function testPartner() - { - $rocket = new Rocket(); - $rocket->setParams(['_config' => 'service_provider'])->setPayload(new Collection(['out_trade_no' => '123'])); - - $result = $this->plugin->assembly($rocket, function ($rocket) { return $rocket; }); - - $radar = $result->getRadar(); - $payload = $result->getPayload(); - - self::assertEquals(new Uri(Wechat::URL[Pay::MODE_NORMAL].'v3/pay/partner/transactions/out-trade-no/123/close'), $radar->getUri()); - self::assertEquals('1600314069', $payload->get('sp_mchid')); - self::assertEquals('1600314070', $payload->get('sub_mchid')); - self::assertArrayNotHasKey('mchid', $payload->all()); - } - - public function testPartnerDirectPayload() - { - $rocket = new Rocket(); - $rocket->setParams(['_config' => 'service_provider'])->setPayload(new Collection(['out_trade_no' => '123', 'sub_mchid' => '123'])); - - $result = $this->plugin->assembly($rocket, function ($rocket) { return $rocket; }); - - $payload = $result->getPayload(); - - self::assertEquals('123', $payload->get('sub_mchid')); - } -} diff --git a/tests/Plugin/Wechat/Pay/Common/InvokePrepayPluginTest.php b/tests/Plugin/Wechat/Pay/Common/InvokePrepayPluginTest.php deleted file mode 100644 index a1d98ed..0000000 --- a/tests/Plugin/Wechat/Pay/Common/InvokePrepayPluginTest.php +++ /dev/null @@ -1,67 +0,0 @@ -plugin = new InvokePrepayPlugin(); - } - - public function testNormal() - { - $rocket = (new Rocket())->setDestination(new Collection(['prepay_id' => 'yansongda'])); - - $result = $this->plugin->assembly($rocket, function ($rocket) { return $rocket; }); - - $contents = $result->getDestination(); - - self::assertArrayHasKey('appId', $contents->all()); - self::assertArrayHasKey('package', $contents->all()); - self::assertArrayHasKey('paySign', $contents->all()); - self::assertArrayHasKey('timeStamp', $contents->all()); - self::assertArrayHasKey('nonceStr', $contents->all()); - self::assertEquals('wx55955316af4ef13', $contents->get('appId')); - } - - public function testWrongPrepayId() - { - $rocket = (new Rocket())->setDestination(new Collection([])); - - self::expectException(InvalidResponseException::class); - self::expectExceptionCode(Exception::RESPONSE_MISSING_NECESSARY_PARAMS); - - $this->plugin->assembly($rocket, function ($rocket) { return $rocket; }); - } - - public function testPartner() - { - $rocket = (new Rocket()) - ->setParams(['_config' => 'service_provider4']) - ->setPayload(new Collection(['sub_appid' => '123'])) - ->setDestination(new Collection(['prepay_id' => 'yansongda'])); - - $result = $this->plugin->assembly($rocket, function ($rocket) { return $rocket; }); - - $contents = $result->getDestination(); - - self::assertArrayHasKey('appId', $contents->all()); - self::assertArrayHasKey('package', $contents->all()); - self::assertArrayHasKey('paySign', $contents->all()); - self::assertArrayHasKey('timeStamp', $contents->all()); - self::assertArrayHasKey('nonceStr', $contents->all()); - self::assertEquals('123', $contents->get('appId')); - } -} diff --git a/tests/Plugin/Wechat/Pay/Common/InvokePrepayV2PluginTest.php b/tests/Plugin/Wechat/Pay/Common/InvokePrepayV2PluginTest.php deleted file mode 100644 index f299b2f..0000000 --- a/tests/Plugin/Wechat/Pay/Common/InvokePrepayV2PluginTest.php +++ /dev/null @@ -1,50 +0,0 @@ -plugin = new InvokePrepayV2Plugin(); - } - - public function testNormal() - { - $rocket = (new Rocket())->setDestination(new Collection(['prepay_id' => 'yansongda'])); - $config = get_wechat_config($rocket->getParams()); - - $result = $this->plugin->assembly($rocket, function ($rocket) { return $rocket; }); - - $contents = $result->getDestination(); - - self::assertArrayHasKey('paySign', $contents->all()); - self::assertArrayHasKey('timeStamp', $contents->all()); - self::assertArrayHasKey('nonceStr', $contents->all()); - self::assertEquals('prepay_id=yansongda', $contents->get('package')); - self::assertEquals('MD5', $contents->get('signType')); - self::assertEquals($config['mp_app_id'], $contents->get('appId')); - } - - public function testWrongPrepayId() - { - $rocket = (new Rocket())->setDestination(new Collection([])); - - self::expectException(InvalidResponseException::class); - self::expectExceptionCode(Exception::RESPONSE_MISSING_NECESSARY_PARAMS); - - $this->plugin->assembly($rocket, function ($rocket) { return $rocket; }); - } -} diff --git a/tests/Plugin/Wechat/Pay/Common/PrepayPluginTest.php b/tests/Plugin/Wechat/Pay/Common/PrepayPluginTest.php deleted file mode 100644 index b2f5cc7..0000000 --- a/tests/Plugin/Wechat/Pay/Common/PrepayPluginTest.php +++ /dev/null @@ -1,118 +0,0 @@ -plugin = new PrepayPlugin(); - } - - public function testNormal() - { - $rocket = new Rocket(); - $rocket->setParams([])->setPayload(new Collection()); - - $result = $this->plugin->assembly($rocket, function ($rocket) { return $rocket; }); - - $radar = $result->getRadar(); - $payload = $result->getPayload(); - - self::assertInstanceOf(RequestInterface::class, $radar); - self::assertEquals('POST', $radar->getMethod()); - self::assertEquals(new Uri(Wechat::URL[Pay::MODE_NORMAL].'v3/pay/transactions/jsapi'), $radar->getUri()); - self::assertArrayNotHasKey('sp_appid', $payload->all()); - self::assertArrayNotHasKey('sp_mchid', $payload->all()); - self::assertArrayNotHasKey('sub_appid', $payload->all()); - self::assertArrayNotHasKey('sub_mchid', $payload->all()); - self::assertEquals('wx55955316af4ef13', $payload->get('appid')); - self::assertEquals('1600314069', $payload->get('mchid')); - } - - public function testNormalType() - { - $rocket = new Rocket(); - $rocket->setParams(['_type' => 'mini'])->setPayload(new Collection()); - - $result = $this->plugin->assembly($rocket, function ($rocket) { return $rocket; }); - - $radar = $result->getRadar(); - $payload = $result->getPayload(); - - self::assertInstanceOf(RequestInterface::class, $radar); - self::assertEquals('POST', $radar->getMethod()); - self::assertEquals(new Uri(Wechat::URL[Pay::MODE_NORMAL].'v3/pay/transactions/jsapi'), $radar->getUri()); - self::assertArrayNotHasKey('sp_appid', $payload->all()); - self::assertArrayNotHasKey('sp_mchid', $payload->all()); - self::assertArrayNotHasKey('sub_appid', $payload->all()); - self::assertArrayNotHasKey('sub_mchid', $payload->all()); - self::assertEquals('wx55955316af4ef14', $payload->get('appid')); - self::assertEquals('1600314069', $payload->get('mchid')); - } - - public function testPartner() - { - $rocket = new Rocket(); - $rocket->setParams(['_config' => 'service_provider'])->setPayload(new Collection()); - - $result = $this->plugin->assembly($rocket, function ($rocket) { return $rocket; }); - - $radar = $result->getRadar(); - $payload = $result->getPayload(); - - self::assertInstanceOf(RequestInterface::class, $radar); - self::assertEquals('POST', $radar->getMethod()); - self::assertEquals(new Uri(Wechat::URL[Pay::MODE_SERVICE].'v3/pay/partner/transactions/jsapi'), $radar->getUri()); - self::assertArrayNotHasKey('appid', $payload->all()); - self::assertArrayNotHasKey('mchid', $payload->all()); - self::assertArrayNotHasKey('appid', $payload->all()); - self::assertArrayNotHasKey('mchid', $payload->all()); - self::assertEquals('wx55955316af4ef13', $payload->get('sp_appid')); - self::assertEquals('1600314069', $payload->get('sp_mchid')); - self::assertEquals('wx55955316af4ef15', $payload->get('sub_appid')); - self::assertEquals('1600314070', $payload->get('sub_mchid')); - } - - public function testPartnerDirectPayload() - { - $rocket = new Rocket(); - $rocket->setParams(['_config' => 'service_provider'])->setPayload(new Collection(['sub_appid' => '123'])); - - $result = $this->plugin->assembly($rocket, function ($rocket) { return $rocket; }); - - $payload = $result->getPayload(); - - self::assertEquals('123', $payload->get('sub_appid')); - self::assertEquals('1600314070', $payload->get('sub_mchid')); - } - - public function testPartnerDirectPayloadWithoutSubAppId() - { - $rocket = new Rocket(); - $rocket->setParams(['_config' => 'service_provider4'])->setPayload(new Collection()); - - $result = $this->plugin->assembly($rocket, function ($rocket) { return $rocket; }); - - $payload = $result->getPayload(); - - self::assertArrayNotHasKey('sub_appid', $payload->all()); - self::assertEquals('1600314070', $payload->get('sub_mchid')); - } -} diff --git a/tests/Plugin/Wechat/Pay/Common/QueryPluginTest.php b/tests/Plugin/Wechat/Pay/Common/QueryPluginTest.php deleted file mode 100644 index a7b5a5b..0000000 --- a/tests/Plugin/Wechat/Pay/Common/QueryPluginTest.php +++ /dev/null @@ -1,86 +0,0 @@ -plugin = new QueryPlugin(); - } - - public function testNormalTransactionId() - { - $rocket = new Rocket(); - $config = get_wechat_config($rocket->getParams([])); - - $rocket->setPayload(new Collection(['transaction_id'=>'121212'])); - - $result = $this->plugin->assembly($rocket, function ($rocket) { return $rocket; }); - $radar = $result->getRadar(); - - self::assertEquals('1600314069', $config['mch_id']); - self::assertEquals('/v3/pay/transactions/id/121212', $radar->getUri()->getPath()); - self::assertEquals('mchid=1600314069', $radar->getUri()->getQuery()); - self::assertEquals('GET', $radar->getMethod()); - self::assertStringNotContainsString('sp_mchid', $radar->getUri()->getQuery()); - } - - public function testNormalOutTradeNo() - { - $rocket = new Rocket(); - - $rocket->setPayload(new Collection(['out_trade_no'=>'121212'])); - - $result = $this->plugin->assembly($rocket, function ($rocket) { return $rocket; }); - $radar = $result->getRadar(); - - self::assertEquals('/v3/pay/transactions/out-trade-no/121212', $radar->getUri()->getPath()); - self::assertEquals('mchid=1600314069', $radar->getUri()->getQuery()); - self::assertEquals('GET', $radar->getMethod()); - self::assertStringNotContainsString('sp_mchid', $radar->getUri()->getQuery()); - } - - public function testPartnerTransactionId() - { - $rocket = new Rocket(); - $rocket->setParams(['_config' => 'service_provider']); - $rocket->setPayload(new Collection(['transaction_id'=>'121212','sub_mchid' => '1600314077'])); - - $result = $this->plugin->assembly($rocket, function ($rocket) { return $rocket; }); - $radar = $result->getRadar(); - - self::assertEquals('/v3/pay/partner/transactions/id/121212', $radar->getUri()->getPath()); - self::assertEquals('GET', $radar->getMethod()); - self::assertStringContainsString('sub_mchid=1600314077', $radar->getUri()->getQuery()); - self::assertStringContainsString('sp_mchid=1600314069', $radar->getUri()->getQuery()); - } - - public function testPartnerOutTradeNo() - { - $rocket = new Rocket(); - $rocket->setParams(['_config' => 'service_provider']); - $rocket->setPayload(new Collection(['out_trade_no'=>'121218','sub_mchid' => '1600314099'])); - - $result = $this->plugin->assembly($rocket, function ($rocket) { return $rocket; }); - $radar = $result->getRadar(); - - self::assertEquals('/v3/pay/partner/transactions/out-trade-no/121218', $radar->getUri()->getPath()); - self::assertEquals('GET', $radar->getMethod()); - self::assertStringContainsString('sub_mchid=1600314099', $radar->getUri()->getQuery()); - self::assertStringContainsString('sp_mchid=1600314069', $radar->getUri()->getQuery()); - } -} diff --git a/tests/Plugin/Wechat/Pay/Common/QueryRefundPluginTest.php b/tests/Plugin/Wechat/Pay/Common/QueryRefundPluginTest.php deleted file mode 100644 index 2c8360f..0000000 --- a/tests/Plugin/Wechat/Pay/Common/QueryRefundPluginTest.php +++ /dev/null @@ -1,71 +0,0 @@ -plugin = new QueryRefundPlugin(); - } - - public function testNormal() - { - $rocket = new Rocket(); - $rocket->setParams([])->setPayload(new Collection(['out_refund_no' => '123'])); - - $result = $this->plugin->assembly($rocket, function ($rocket) { return $rocket; }); - - $radar = $result->getRadar(); - $payload = $result->getPayload(); - - self::assertInstanceOf(RequestInterface::class, $radar); - self::assertEquals('GET', $radar->getMethod()); - self::assertEquals(new Uri(Wechat::URL[Pay::MODE_NORMAL].'v3/refund/domestic/refunds/123'), $radar->getUri()); - self::assertNull($payload); - } - - public function testPartner() - { - $rocket = new Rocket(); - $rocket->setParams(['_config' => 'service_provider'])->setPayload(new Collection(['out_refund_no' => '123'])); - - $result = $this->plugin->assembly($rocket, function ($rocket) { return $rocket; }); - - $radar = $result->getRadar(); - $payload = $result->getPayload(); - - self::assertInstanceOf(RequestInterface::class, $radar); - self::assertEquals('GET', $radar->getMethod()); - self::assertEquals(new Uri(Wechat::URL[Pay::MODE_SERVICE].'v3/refund/domestic/refunds/123?sub_mchid=1600314070'), $radar->getUri()); - self::assertNull($payload); - } - - public function testPartnerDirectPayload() - { - $rocket = new Rocket(); - $rocket->setParams(['_config' => 'service_provider'])->setPayload(new Collection(['sub_mchid' => '123','out_refund_no' => '456'])); - - $result = $this->plugin->assembly($rocket, function ($rocket) { return $rocket; }); - - $radar = $result->getRadar(); - - self::assertEquals(new Uri(Wechat::URL[Pay::MODE_SERVICE].'v3/refund/domestic/refunds/456?sub_mchid=123'), $radar->getUri()); - } -} diff --git a/tests/Plugin/Wechat/Pay/Common/RefundPluginTest.php b/tests/Plugin/Wechat/Pay/Common/RefundPluginTest.php deleted file mode 100644 index 4c1928f..0000000 --- a/tests/Plugin/Wechat/Pay/Common/RefundPluginTest.php +++ /dev/null @@ -1,91 +0,0 @@ -plugin = new RefundPlugin(); - } - - public function testNormal() - { - $rocket = new Rocket(); - $rocket->setParams([])->setPayload(new Collection()); - - $result = $this->plugin->assembly($rocket, function ($rocket) { return $rocket; }); - - $radar = $result->getRadar(); - - self::assertInstanceOf(RequestInterface::class, $radar); - self::assertEquals('POST', $radar->getMethod()); - self::assertEquals(new Uri(Wechat::URL[Pay::MODE_NORMAL].'v3/refund/domestic/refunds'), $radar->getUri()); - } - - public function testPartner() - { - $rocket = new Rocket(); - $rocket->setParams(['_config' => 'service_provider'])->setPayload(new Collection()); - - $result = $this->plugin->assembly($rocket, function ($rocket) { return $rocket; }); - - $radar = $result->getRadar(); - $payload = $result->getPayload(); - - self::assertInstanceOf(RequestInterface::class, $radar); - self::assertEquals('POST', $radar->getMethod()); - self::assertEquals(new Uri(Wechat::URL[Pay::MODE_SERVICE].'v3/refund/domestic/refunds'), $radar->getUri()); - self::assertEquals('1600314070', $payload->get('sub_mchid')); - } - - public function testPartnerDirectPayload() - { - $rocket = new Rocket(); - $rocket->setParams(['_config' => 'service_provider'])->setPayload(new Collection(['sub_mchid' => '123'])); - - $result = $this->plugin->assembly($rocket, function ($rocket) { return $rocket; }); - - $payload = $result->getPayload(); - - self::assertEquals('123', $payload->get('sub_mchid')); - } - - public function testNormalNotifyUrl() - { - $rocket = (new Rocket()) - ->setParams([])->setPayload(new Collection()); - $result = $this->plugin->assembly($rocket, function ($rocket) { return $rocket; }); - self::assertEquals('pay.yansongda.cn', $result->getPayload()->get('notify_url')); - - $rocket = (new Rocket()) - ->setParams([])->setPayload(new Collection(['notify_url' => 'yansongda.cn'])); - $result = $this->plugin->assembly($rocket, function ($rocket) { return $rocket; }); - self::assertEquals('yansongda.cn', $result->getPayload()->get('notify_url')); - } - - public function testEmptyNotifyUrl() - { - $rocket = (new Rocket()) - ->setParams(['_config' => 'empty_wechat_public_cert'])->setPayload(new Collection()); - $result = $this->plugin->assembly($rocket, function ($rocket) { return $rocket; }); - - self::assertArrayNotHasKey('notify_url', $result->getPayload()->all()); - } -} diff --git a/tests/Plugin/Wechat/Pay/H5/ClosePluginTest.php b/tests/Plugin/Wechat/Pay/H5/ClosePluginTest.php new file mode 100644 index 0000000..643c888 --- /dev/null +++ b/tests/Plugin/Wechat/Pay/H5/ClosePluginTest.php @@ -0,0 +1,87 @@ +plugin = new ClosePlugin(); + } + + public function testEmptyPayload() + { + $rocket = new Rocket(); + + self::expectException(InvalidParamsException::class); + self::expectExceptionCode(Exception::PARAMS_NECESSARY_PARAMS_MISSING); + self::expectExceptionMessage('参数异常: H5 关闭订单,参数缺少 `out_trade_no`'); + + $this->plugin->assembly($rocket, function ($rocket) { return $rocket; }); + } + + public function testNormal() + { + $rocket = new Rocket(); + $rocket->setPayload(new Collection( [ + "out_trade_no" => "111", + ])); + + $result = $this->plugin->assembly($rocket, function ($rocket) { return $rocket; }); + + self::assertEquals([ + '_method' => 'POST', + '_url' => 'v3/pay/transactions/out-trade-no/111/close', + '_service_url' => 'v3/pay/partner/transactions/out-trade-no/111/close', + 'mchid' => '1600314069', + ], $result->getPayload()->all()); + } + + public function testServiceParams() + { + $rocket = new Rocket(); + $rocket->setParams(['_config' => 'service_provider'])->setPayload(new Collection( [ + "out_trade_no" => "111", + 'sub_mchid' => '333', + ])); + + $result = $this->plugin->assembly($rocket, function ($rocket) { return $rocket; }); + + self::assertEquals([ + '_method' => 'POST', + '_url' => 'v3/pay/transactions/out-trade-no/111/close', + '_service_url' => 'v3/pay/partner/transactions/out-trade-no/111/close', + 'sp_mchid' => '1600314069', + 'sub_mchid' => '333', + ], $result->getPayload()->all()); + } + + public function testService() + { + $rocket = new Rocket(); + $rocket->setParams(['_config' => 'service_provider'])->setPayload(new Collection( [ + "out_trade_no" => "111", + ])); + + $result = $this->plugin->assembly($rocket, function ($rocket) { return $rocket; }); + + self::assertEquals([ + '_method' => 'POST', + '_url' => 'v3/pay/transactions/out-trade-no/111/close', + '_service_url' => 'v3/pay/partner/transactions/out-trade-no/111/close', + 'sp_mchid' => '1600314069', + 'sub_mchid' => '1600314070', + ], $result->getPayload()->all()); + } +} diff --git a/tests/Plugin/Wechat/Pay/H5/DownloadBillPluginTest.php b/tests/Plugin/Wechat/Pay/H5/DownloadBillPluginTest.php new file mode 100644 index 0000000..b2564fb --- /dev/null +++ b/tests/Plugin/Wechat/Pay/H5/DownloadBillPluginTest.php @@ -0,0 +1,49 @@ +plugin = new DownloadBillPlugin(); + } + + public function testEmptyPayload() + { + $rocket = new Rocket(); + + self::expectException(InvalidParamsException::class); + self::expectExceptionCode(Exception::PARAMS_NECESSARY_PARAMS_MISSING); + self::expectExceptionMessage('参数异常: H5 下载交易对账单,参数缺少 `download_url`'); + + $this->plugin->assembly($rocket, function ($rocket) { return $rocket; }); + } + + public function testNormal() + { + $rocket = new Rocket(); + $rocket->setPayload(new Collection( [ + "download_url" => "111", + ])); + + $result = $this->plugin->assembly($rocket, function ($rocket) { return $rocket; }); + + self::assertEquals([ + '_method' => 'GET', + '_url' => '111', + '_service_url' => '111', + ], $result->getPayload()->all()); + } +} diff --git a/tests/Plugin/Wechat/Pay/H5/GetFundBillPluginTest.php b/tests/Plugin/Wechat/Pay/H5/GetFundBillPluginTest.php new file mode 100644 index 0000000..097349a --- /dev/null +++ b/tests/Plugin/Wechat/Pay/H5/GetFundBillPluginTest.php @@ -0,0 +1,49 @@ +plugin = new GetFundBillPlugin(); + } + + public function testEmptyPayload() + { + $rocket = new Rocket(); + + self::expectException(InvalidParamsException::class); + self::expectExceptionCode(Exception::PARAMS_NECESSARY_PARAMS_MISSING); + self::expectExceptionMessage('参数异常: H5 申请资金账单,参数为空'); + + $this->plugin->assembly($rocket, function ($rocket) { return $rocket; }); + } + + public function testNormal() + { + $rocket = new Rocket(); + $rocket->setPayload(new Collection( [ + "download_url" => "111", + ])); + + $result = $this->plugin->assembly($rocket, function ($rocket) { return $rocket; }); + + self::assertEquals([ + '_method' => 'GET', + '_url' => 'v3/bill/fundflowbill?download_url=111', + '_service_url' => 'v3/bill/fundflowbill?download_url=111', + ], $result->getPayload()->all()); + } +} diff --git a/tests/Plugin/Wechat/Pay/H5/GetTradeBillPluginTest.php b/tests/Plugin/Wechat/Pay/H5/GetTradeBillPluginTest.php new file mode 100644 index 0000000..cc2caf8 --- /dev/null +++ b/tests/Plugin/Wechat/Pay/H5/GetTradeBillPluginTest.php @@ -0,0 +1,49 @@ +plugin = new GetTradeBillPlugin(); + } + + public function testEmptyPayload() + { + $rocket = new Rocket(); + + self::expectException(InvalidParamsException::class); + self::expectExceptionCode(Exception::PARAMS_NECESSARY_PARAMS_MISSING); + self::expectExceptionMessage('参数异常: H5 申请交易账单,参数为空'); + + $this->plugin->assembly($rocket, function ($rocket) { return $rocket; }); + } + + public function testNormal() + { + $rocket = new Rocket(); + $rocket->setPayload(new Collection( [ + "download_url" => "111", + ])); + + $result = $this->plugin->assembly($rocket, function ($rocket) { return $rocket; }); + + self::assertEquals([ + '_method' => 'GET', + '_url' => 'v3/bill/tradebill?download_url=111', + '_service_url' => 'v3/bill/tradebill?download_url=111', + ], $result->getPayload()->all()); + } +} diff --git a/tests/Plugin/Wechat/Pay/H5/PayPluginTest.php b/tests/Plugin/Wechat/Pay/H5/PayPluginTest.php new file mode 100644 index 0000000..9d624be --- /dev/null +++ b/tests/Plugin/Wechat/Pay/H5/PayPluginTest.php @@ -0,0 +1,97 @@ +plugin = new PayPlugin(); + } + + public function testEmptyPayload() + { + $rocket = new Rocket(); + + self::expectException(InvalidParamsException::class); + self::expectExceptionCode(Exception::PARAMS_NECESSARY_PARAMS_MISSING); + self::expectExceptionMessage('参数异常: H5 下单,参数为空'); + + $this->plugin->assembly($rocket, function ($rocket) { return $rocket; }); + } + + public function testNormal() + { + $rocket = new Rocket(); + $rocket->setPayload(new Collection( [ + "name" => "yansongda", + ])); + + $result = $this->plugin->assembly($rocket, function ($rocket) { return $rocket; }); + + self::assertEquals([ + '_method' => 'POST', + '_url' => 'v3/pay/transactions/h5', + '_service_url' => 'v3/pay/partner/transactions/h5', + "appid" => "wx55955316af4ef13", + 'mchid' => '1600314069', + 'notify_url' => 'https://pay.yansongda.cn', + 'name' => 'yansongda', + ], $result->getPayload()->all()); + } + + public function testServiceParams() + { + $rocket = new Rocket(); + $rocket->setParams(['_config' => 'service_provider'])->setPayload(new Collection( [ + 'sub_mchid' => '333', + 'notify_url' => '444', + 'name' => 'yansongda', + ])); + + $result = $this->plugin->assembly($rocket, function ($rocket) { return $rocket; }); + + self::assertEquals([ + '_method' => 'POST', + '_url' => 'v3/pay/transactions/h5', + '_service_url' => 'v3/pay/partner/transactions/h5', + "sp_appid" => "wx55955316af4ef13", + 'sp_mchid' => '1600314069', + 'sub_mchid' => '333', + 'notify_url' => '444', + 'name' => 'yansongda', + ], $result->getPayload()->all()); + } + + public function testService() + { + $rocket = new Rocket(); + $rocket->setParams(['_config' => 'service_provider'])->setPayload(new Collection( [ + 'name' => 'yansongda', + ])); + + $result = $this->plugin->assembly($rocket, function ($rocket) { return $rocket; }); + + self::assertEquals([ + '_method' => 'POST', + '_url' => 'v3/pay/transactions/h5', + '_service_url' => 'v3/pay/partner/transactions/h5', + "sp_appid" => "wx55955316af4ef13", + 'sp_mchid' => '1600314069', + 'sub_mchid' => '1600314070', + 'notify_url' => '', + 'name' => 'yansongda', + ], $result->getPayload()->all()); + } +} diff --git a/tests/Plugin/Wechat/Pay/H5/PrepayPluginTest.php b/tests/Plugin/Wechat/Pay/H5/PrepayPluginTest.php deleted file mode 100644 index 621a7e9..0000000 --- a/tests/Plugin/Wechat/Pay/H5/PrepayPluginTest.php +++ /dev/null @@ -1,145 +0,0 @@ -plugin = new PrepayPlugin(); - } - - public function testNormal() - { - $rocket = new Rocket(); - $rocket->setParams([])->setPayload(new Collection()); - - $result = $this->plugin->assembly($rocket, function ($rocket) { return $rocket; }); - - $radar = $result->getRadar(); - $payload = $result->getPayload(); - - self::assertInstanceOf(RequestInterface::class, $radar); - self::assertEquals('POST', $radar->getMethod()); - self::assertEquals(new Uri(Wechat::URL[Pay::MODE_NORMAL].'v3/pay/transactions/h5'), $radar->getUri()); - self::assertArrayNotHasKey('sp_appid', $payload->all()); - self::assertArrayNotHasKey('sp_mchid', $payload->all()); - self::assertArrayNotHasKey('sub_appid', $payload->all()); - self::assertArrayNotHasKey('sub_mchid', $payload->all()); - self::assertEquals('wx55955316af4ef13', $payload->get('appid')); - self::assertEquals('1600314069', $payload->get('mchid')); - } - - public function testNormalType() - { - $rocket = new Rocket(); - $rocket->setParams(['_type' => 'mini'])->setPayload(new Collection()); - - $result = $this->plugin->assembly($rocket, function ($rocket) { return $rocket; }); - - $radar = $result->getRadar(); - $payload = $result->getPayload(); - - self::assertInstanceOf(RequestInterface::class, $radar); - self::assertEquals('POST', $radar->getMethod()); - self::assertEquals(new Uri(Wechat::URL[Pay::MODE_NORMAL].'v3/pay/transactions/h5'), $radar->getUri()); - self::assertArrayNotHasKey('sp_appid', $payload->all()); - self::assertArrayNotHasKey('sp_mchid', $payload->all()); - self::assertArrayNotHasKey('sub_appid', $payload->all()); - self::assertArrayNotHasKey('sub_mchid', $payload->all()); - self::assertEquals('wx55955316af4ef14', $payload->get('appid')); - self::assertEquals('1600314069', $payload->get('mchid')); - } - - public function testNormalTypeApp() - { - $rocket = new Rocket(); - $rocket->setParams(['_type' => 'app'])->setPayload(new Collection()); - - $result = $this->plugin->assembly($rocket, function ($rocket) { return $rocket; }); - - $radar = $result->getRadar(); - $payload = $result->getPayload(); - - self::assertInstanceOf(RequestInterface::class, $radar); - self::assertEquals('POST', $radar->getMethod()); - self::assertEquals(new Uri(Wechat::URL[Pay::MODE_NORMAL].'v3/pay/transactions/h5'), $radar->getUri()); - self::assertArrayNotHasKey('sp_appid', $payload->all()); - self::assertArrayNotHasKey('sp_mchid', $payload->all()); - self::assertArrayNotHasKey('sub_appid', $payload->all()); - self::assertArrayNotHasKey('sub_mchid', $payload->all()); - self::assertEquals('yansongda', $payload->get('appid')); - self::assertEquals('1600314069', $payload->get('mchid')); - } - - public function testPartner() - { - $rocket = new Rocket(); - $rocket->setParams(['_config' => 'service_provider'])->setPayload(new Collection()); - - $result = $this->plugin->assembly($rocket, function ($rocket) { return $rocket; }); - - $radar = $result->getRadar(); - $payload = $result->getPayload(); - - self::assertInstanceOf(RequestInterface::class, $radar); - self::assertEquals('POST', $radar->getMethod()); - self::assertEquals(new Uri(Wechat::URL[Pay::MODE_SERVICE].'v3/pay/partner/transactions/h5'), $radar->getUri()); - self::assertArrayNotHasKey('appid', $payload->all()); - self::assertArrayNotHasKey('mchid', $payload->all()); - self::assertEquals('wx55955316af4ef13', $payload->get('sp_appid')); - self::assertEquals('1600314069', $payload->get('sp_mchid')); - self::assertEquals('wx55955316af4ef15', $payload->get('sub_appid')); - self::assertEquals('1600314070', $payload->get('sub_mchid')); - } - - public function testPartnerType() - { - $rocket = new Rocket(); - $rocket->setParams(['_config' => 'service_provider', '_type' => 'mini'])->setPayload(new Collection()); - - $result = $this->plugin->assembly($rocket, function ($rocket) { return $rocket; }); - - $radar = $result->getRadar(); - $payload = $result->getPayload(); - - self::assertInstanceOf(RequestInterface::class, $radar); - self::assertEquals('POST', $radar->getMethod()); - self::assertEquals(new Uri(Wechat::URL[Pay::MODE_SERVICE].'v3/pay/partner/transactions/h5'), $radar->getUri()); - self::assertArrayNotHasKey('appid', $payload->all()); - self::assertArrayNotHasKey('mchid', $payload->all()); - self::assertEquals('wx55955316af4ef14', $payload->get('sp_appid')); - self::assertEquals('1600314069', $payload->get('sp_mchid')); - self::assertEquals('wx55955316af4ef17', $payload->get('sub_appid')); - self::assertEquals('1600314070', $payload->get('sub_mchid')); - } - - public function testPartnerDirectPayload() - { - $rocket = new Rocket(); - $rocket->setParams(['_config' => 'service_provider'])->setPayload(new Collection(['sub_appid' => '123'])); - - $result = $this->plugin->assembly($rocket, function ($rocket) { return $rocket; }); - - $payload = $result->getPayload(); - - self::assertEquals('123', $payload->get('sub_appid')); - self::assertEquals('1600314070', $payload->get('sub_mchid')); - } -} diff --git a/tests/Plugin/Wechat/Pay/H5/QueryByWxPluginTest.php b/tests/Plugin/Wechat/Pay/H5/QueryByWxPluginTest.php new file mode 100644 index 0000000..da859f3 --- /dev/null +++ b/tests/Plugin/Wechat/Pay/H5/QueryByWxPluginTest.php @@ -0,0 +1,73 @@ +plugin = new QueryByWxPlugin(); + } + + public function testEmptyPayload() + { + $rocket = new Rocket(); + + self::expectException(InvalidParamsException::class); + self::expectExceptionCode(Exception::PARAMS_NECESSARY_PARAMS_MISSING); + self::expectExceptionMessage('参数异常: H5 通过微信订单号查询订单,参数缺少 `transaction_id`'); + + $this->plugin->assembly($rocket, function ($rocket) { return $rocket; }); + } + + public function testNormal() + { + $rocket = new Rocket(); + $rocket->setPayload(new Collection( [ + "transaction_id" => "111", + ])); + + $result = $this->plugin->assembly($rocket, function ($rocket) { return $rocket; }); + + self::assertEquals('GET', $result->getPayload()->get('_method')); + self::assertEquals('v3/pay/transactions/id/111?mchid=1600314069', $result->getPayload()->get('_url')); + } + + public function testServiceParams() + { + $rocket = new Rocket(); + $rocket->setPayload(new Collection( [ + "transaction_id" => "111", + 'sub_mchid' => '333', + ])); + + $result = $this->plugin->assembly($rocket, function ($rocket) { return $rocket; }); + + self::assertEquals('GET', $result->getPayload()->get('_method')); + self::assertEquals('v3/pay/partner/transactions/id/111?sp_mchid=1600314069&sub_mchid=333', $result->getPayload()->get('_service_url')); + } + + public function testService() + { + $rocket = new Rocket(); + $rocket->setParams(['_config' => 'service_provider'])->setPayload(new Collection( [ + "transaction_id" => "111", + ])); + + $result = $this->plugin->assembly($rocket, function ($rocket) { return $rocket; }); + + self::assertEquals('GET', $result->getPayload()->get('_method')); + self::assertEquals('v3/pay/partner/transactions/id/111?sp_mchid=1600314069&sub_mchid=1600314070', $result->getPayload()->get('_service_url')); + } +} diff --git a/tests/Plugin/Wechat/Pay/H5/QueryPluginTest.php b/tests/Plugin/Wechat/Pay/H5/QueryPluginTest.php new file mode 100644 index 0000000..6d61a25 --- /dev/null +++ b/tests/Plugin/Wechat/Pay/H5/QueryPluginTest.php @@ -0,0 +1,73 @@ +plugin = new QueryPlugin(); + } + + public function testEmptyPayload() + { + $rocket = new Rocket(); + + self::expectException(InvalidParamsException::class); + self::expectExceptionCode(Exception::PARAMS_NECESSARY_PARAMS_MISSING); + self::expectExceptionMessage('参数异常: H5 通过商户订单号查询订单,参数缺少 `out_trade_no`'); + + $this->plugin->assembly($rocket, function ($rocket) { return $rocket; }); + } + + public function testNormal() + { + $rocket = new Rocket(); + $rocket->setPayload(new Collection( [ + "out_trade_no" => "111", + ])); + + $result = $this->plugin->assembly($rocket, function ($rocket) { return $rocket; }); + + self::assertEquals('GET', $result->getPayload()->get('_method')); + self::assertEquals('v3/pay/transactions/out-trade-no/111?mchid=1600314069', $result->getPayload()->get('_url')); + } + + public function testServiceParams() + { + $rocket = new Rocket(); + $rocket->setPayload(new Collection( [ + "out_trade_no" => "111", + 'sub_mchid' => '333', + ])); + + $result = $this->plugin->assembly($rocket, function ($rocket) { return $rocket; }); + + self::assertEquals('GET', $result->getPayload()->get('_method')); + self::assertEquals('v3/pay/partner/transactions/out-trade-no/111?sp_mchid=1600314069&sub_mchid=333', $result->getPayload()->get('_service_url')); + } + + public function testService() + { + $rocket = new Rocket(); + $rocket->setParams(['_config' => 'service_provider'])->setPayload(new Collection( [ + "out_trade_no" => "111", + ])); + + $result = $this->plugin->assembly($rocket, function ($rocket) { return $rocket; }); + + self::assertEquals('GET', $result->getPayload()->get('_method')); + self::assertEquals('v3/pay/partner/transactions/out-trade-no/111?sp_mchid=1600314069&sub_mchid=1600314070', $result->getPayload()->get('_service_url')); + } +} diff --git a/tests/Plugin/Wechat/Pay/H5/QueryRefundPluginTest.php b/tests/Plugin/Wechat/Pay/H5/QueryRefundPluginTest.php new file mode 100644 index 0000000..28e6b7b --- /dev/null +++ b/tests/Plugin/Wechat/Pay/H5/QueryRefundPluginTest.php @@ -0,0 +1,73 @@ +plugin = new QueryRefundPlugin(); + } + + public function testEmptyPayload() + { + $rocket = new Rocket(); + + self::expectException(InvalidParamsException::class); + self::expectExceptionCode(Exception::PARAMS_NECESSARY_PARAMS_MISSING); + self::expectExceptionMessage('参数异常: H5 查询退款订单,参数缺少 `out_refund_no`'); + + $this->plugin->assembly($rocket, function ($rocket) { return $rocket; }); + } + + public function testNormal() + { + $rocket = new Rocket(); + $rocket->setPayload(new Collection( [ + "out_refund_no" => "111", + ])); + + $result = $this->plugin->assembly($rocket, function ($rocket) { return $rocket; }); + + self::assertEquals('GET', $result->getPayload()->get('_method')); + self::assertEquals('v3/refund/domestic/refunds/111', $result->getPayload()->get('_url')); + } + + public function testServiceParams() + { + $rocket = new Rocket(); + $rocket->setPayload(new Collection( [ + "out_refund_no" => "111", + 'sub_mchid' => '333', + ])); + + $result = $this->plugin->assembly($rocket, function ($rocket) { return $rocket; }); + + self::assertEquals('GET', $result->getPayload()->get('_method')); + self::assertEquals('v3/refund/domestic/refunds/111?sub_mchid=333', $result->getPayload()->get('_service_url')); + } + + public function testService() + { + $rocket = new Rocket(); + $rocket->setParams(['_config' => 'service_provider'])->setPayload(new Collection( [ + "out_refund_no" => "111", + ])); + + $result = $this->plugin->assembly($rocket, function ($rocket) { return $rocket; }); + + self::assertEquals('GET', $result->getPayload()->get('_method')); + self::assertEquals('v3/refund/domestic/refunds/111?sub_mchid=1600314070', $result->getPayload()->get('_service_url')); + } +} diff --git a/tests/Plugin/Wechat/Pay/H5/RefundPluginTest.php b/tests/Plugin/Wechat/Pay/H5/RefundPluginTest.php new file mode 100644 index 0000000..0c61d1d --- /dev/null +++ b/tests/Plugin/Wechat/Pay/H5/RefundPluginTest.php @@ -0,0 +1,110 @@ +plugin = new RefundPlugin(); + } + + public function testEmptyPayload() + { + $rocket = new Rocket(); + + self::expectException(InvalidParamsException::class); + self::expectExceptionCode(Exception::PARAMS_NECESSARY_PARAMS_MISSING); + self::expectExceptionMessage('参数异常: H5 退款申请,参数为空'); + + $this->plugin->assembly($rocket, function ($rocket) { return $rocket; }); + } + + public function testNormalParams() + { + $rocket = new Rocket(); + $rocket->setPayload(new Collection( [ + "notify_url" => "111", + 'name' => '222', + ])); + + $result = $this->plugin->assembly($rocket, function ($rocket) { return $rocket; }); + + self::assertEquals([ + '_method' => 'POST', + '_url' => 'v3/refund/domestic/refunds', + '_service_url' => 'v3/refund/domestic/refunds', + 'notify_url' => '111', + 'name' => '222', + ], $result->getPayload()->all()); + } + + public function testNormal() + { + $rocket = new Rocket(); + $rocket->setPayload(new Collection( [ + "out_trade_no" => "111", + ])); + + $result = $this->plugin->assembly($rocket, function ($rocket) { return $rocket; }); + + self::assertEquals([ + '_method' => 'POST', + '_url' => 'v3/refund/domestic/refunds', + '_service_url' => 'v3/refund/domestic/refunds', + 'notify_url' => 'https://pay.yansongda.cn', + 'out_trade_no' => '111', + ], $result->getPayload()->all()); + } + + public function testServiceParams() + { + $rocket = new Rocket(); + $rocket->setParams(['_config' => 'service_provider'])->setPayload(new Collection( [ + "notify_url" => "111", + 'sub_mchid' => '222', + 'name' => 'yansongda', + ])); + + $result = $this->plugin->assembly($rocket, function ($rocket) { return $rocket; }); + + self::assertEquals([ + '_method' => 'POST', + '_url' => 'v3/refund/domestic/refunds', + '_service_url' => 'v3/refund/domestic/refunds', + 'notify_url' => '111', + 'sub_mchid' => '222', + 'name' => 'yansongda', + ], $result->getPayload()->all()); + } + + public function testService() + { + $rocket = new Rocket(); + $rocket->setParams(['_config' => 'service_provider'])->setPayload(new Collection([ + 'name' => 'yansongda', + ])); + + $result = $this->plugin->assembly($rocket, function ($rocket) { return $rocket; }); + + self::assertEquals([ + '_method' => 'POST', + '_url' => 'v3/refund/domestic/refunds', + '_service_url' => 'v3/refund/domestic/refunds', + 'name' => 'yansongda', + 'notify_url' => null, + 'sub_mchid' => '1600314070', + ], $result->getPayload()->all()); + } +} diff --git a/tests/Plugin/Wechat/Pay/Jsapi/ClosePluginTest.php b/tests/Plugin/Wechat/Pay/Jsapi/ClosePluginTest.php new file mode 100644 index 0000000..400de6b --- /dev/null +++ b/tests/Plugin/Wechat/Pay/Jsapi/ClosePluginTest.php @@ -0,0 +1,87 @@ +plugin = new ClosePlugin(); + } + + public function testEmptyPayload() + { + $rocket = new Rocket(); + + self::expectException(InvalidParamsException::class); + self::expectExceptionCode(Exception::PARAMS_NECESSARY_PARAMS_MISSING); + self::expectExceptionMessage('参数异常: Jsapi 关闭订单,参数缺少 `out_trade_no`'); + + $this->plugin->assembly($rocket, function ($rocket) { return $rocket; }); + } + + public function testNormal() + { + $rocket = new Rocket(); + $rocket->setPayload(new Collection( [ + "out_trade_no" => "111", + ])); + + $result = $this->plugin->assembly($rocket, function ($rocket) { return $rocket; }); + + self::assertEquals([ + '_method' => 'POST', + '_url' => 'v3/pay/transactions/out-trade-no/111/close', + '_service_url' => 'v3/pay/partner/transactions/out-trade-no/111/close', + 'mchid' => '1600314069', + ], $result->getPayload()->all()); + } + + public function testServiceParams() + { + $rocket = new Rocket(); + $rocket->setParams(['_config' => 'service_provider'])->setPayload(new Collection( [ + "out_trade_no" => "111", + 'sub_mchid' => '333', + ])); + + $result = $this->plugin->assembly($rocket, function ($rocket) { return $rocket; }); + + self::assertEquals([ + '_method' => 'POST', + '_url' => 'v3/pay/transactions/out-trade-no/111/close', + '_service_url' => 'v3/pay/partner/transactions/out-trade-no/111/close', + 'sp_mchid' => '1600314069', + 'sub_mchid' => '333', + ], $result->getPayload()->all()); + } + + public function testService() + { + $rocket = new Rocket(); + $rocket->setParams(['_config' => 'service_provider'])->setPayload(new Collection( [ + "out_trade_no" => "111", + ])); + + $result = $this->plugin->assembly($rocket, function ($rocket) { return $rocket; }); + + self::assertEquals([ + '_method' => 'POST', + '_url' => 'v3/pay/transactions/out-trade-no/111/close', + '_service_url' => 'v3/pay/partner/transactions/out-trade-no/111/close', + 'sp_mchid' => '1600314069', + 'sub_mchid' => '1600314070', + ], $result->getPayload()->all()); + } +} diff --git a/tests/Plugin/Wechat/Pay/Jsapi/DownloadBillPluginTest.php b/tests/Plugin/Wechat/Pay/Jsapi/DownloadBillPluginTest.php new file mode 100644 index 0000000..9e78879 --- /dev/null +++ b/tests/Plugin/Wechat/Pay/Jsapi/DownloadBillPluginTest.php @@ -0,0 +1,49 @@ +plugin = new DownloadBillPlugin(); + } + + public function testEmptyPayload() + { + $rocket = new Rocket(); + + self::expectException(InvalidParamsException::class); + self::expectExceptionCode(Exception::PARAMS_NECESSARY_PARAMS_MISSING); + self::expectExceptionMessage('参数异常: Jsapi 下载交易对账单,参数缺少 `download_url`'); + + $this->plugin->assembly($rocket, function ($rocket) { return $rocket; }); + } + + public function testNormal() + { + $rocket = new Rocket(); + $rocket->setPayload(new Collection( [ + "download_url" => "111", + ])); + + $result = $this->plugin->assembly($rocket, function ($rocket) { return $rocket; }); + + self::assertEquals([ + '_method' => 'GET', + '_url' => '111', + '_service_url' => '111', + ], $result->getPayload()->all()); + } +} diff --git a/tests/Plugin/Wechat/Pay/Jsapi/GetFundBillPluginTest.php b/tests/Plugin/Wechat/Pay/Jsapi/GetFundBillPluginTest.php new file mode 100644 index 0000000..4c189f4 --- /dev/null +++ b/tests/Plugin/Wechat/Pay/Jsapi/GetFundBillPluginTest.php @@ -0,0 +1,49 @@ +plugin = new GetFundBillPlugin(); + } + + public function testEmptyPayload() + { + $rocket = new Rocket(); + + self::expectException(InvalidParamsException::class); + self::expectExceptionCode(Exception::PARAMS_NECESSARY_PARAMS_MISSING); + self::expectExceptionMessage('参数异常: Jsapi 申请资金账单,参数为空'); + + $this->plugin->assembly($rocket, function ($rocket) { return $rocket; }); + } + + public function testNormal() + { + $rocket = new Rocket(); + $rocket->setPayload(new Collection( [ + "download_url" => "111", + ])); + + $result = $this->plugin->assembly($rocket, function ($rocket) { return $rocket; }); + + self::assertEquals([ + '_method' => 'GET', + '_url' => 'v3/bill/fundflowbill?download_url=111', + '_service_url' => 'v3/bill/fundflowbill?download_url=111', + ], $result->getPayload()->all()); + } +} diff --git a/tests/Plugin/Wechat/Pay/Jsapi/GetTradeBillPluginTest.php b/tests/Plugin/Wechat/Pay/Jsapi/GetTradeBillPluginTest.php new file mode 100644 index 0000000..5e1ddf9 --- /dev/null +++ b/tests/Plugin/Wechat/Pay/Jsapi/GetTradeBillPluginTest.php @@ -0,0 +1,49 @@ +plugin = new GetTradeBillPlugin(); + } + + public function testEmptyPayload() + { + $rocket = new Rocket(); + + self::expectException(InvalidParamsException::class); + self::expectExceptionCode(Exception::PARAMS_NECESSARY_PARAMS_MISSING); + self::expectExceptionMessage('参数异常: Jsapi 申请交易账单,参数为空'); + + $this->plugin->assembly($rocket, function ($rocket) { return $rocket; }); + } + + public function testNormal() + { + $rocket = new Rocket(); + $rocket->setPayload(new Collection( [ + "download_url" => "111", + ])); + + $result = $this->plugin->assembly($rocket, function ($rocket) { return $rocket; }); + + self::assertEquals([ + '_method' => 'GET', + '_url' => 'v3/bill/tradebill?download_url=111', + '_service_url' => 'v3/bill/tradebill?download_url=111', + ], $result->getPayload()->all()); + } +} diff --git a/tests/Plugin/Wechat/Pay/Jsapi/InvokePluginTest.php b/tests/Plugin/Wechat/Pay/Jsapi/InvokePluginTest.php new file mode 100644 index 0000000..5369f81 --- /dev/null +++ b/tests/Plugin/Wechat/Pay/Jsapi/InvokePluginTest.php @@ -0,0 +1,104 @@ +plugin = new InvokePlugin(); + } + + public function testMissingPrepayId() + { + $rocket = new Rocket(); + + self::expectException(InvalidResponseException::class); + self::expectExceptionCode(Exception::RESPONSE_MISSING_NECESSARY_PARAMS); + self::expectExceptionMessage('预下单失败:响应缺少 `prepay_id` 参数,请自行检查参数是否符合微信要求'); + + $this->plugin->assembly($rocket, function ($rocket) { return $rocket; }); + } + + public function testNormalParams() + { + $rocket = (new Rocket()) + ->setDestination(new Collection(['prepay_id' => 'yansongda'])) + ->setPayload(['_invoke_appid' => '111']); + + $result = $this->plugin->assembly($rocket, function ($rocket) { return $rocket; }); + + $contents = $result->getDestination(); + + self::assertArrayHasKey('paySign', $contents->all()); + self::assertArrayHasKey('timeStamp', $contents->all()); + self::assertArrayHasKey('nonceStr', $contents->all()); + self::assertEquals('111', $contents->get('appId')); + self::assertEquals('prepay_id=yansongda', $contents->get('package')); + self::assertEquals('RSA', $contents->get('signType')); + } + + public function testNormal() + { + $rocket = (new Rocket())->setDestination(new Collection(['prepay_id' => 'yansongda'])); + + $result = $this->plugin->assembly($rocket, function ($rocket) { return $rocket; }); + + $contents = $result->getDestination(); + + self::assertArrayHasKey('paySign', $contents->all()); + self::assertArrayHasKey('timeStamp', $contents->all()); + self::assertArrayHasKey('nonceStr', $contents->all()); + self::assertEquals('wx55955316af4ef13', $contents->get('appId')); + self::assertEquals('prepay_id=yansongda', $contents->get('package')); + self::assertEquals('RSA', $contents->get('signType')); + } + + public function testServiceParams() + { + $rocket = (new Rocket()) + ->setParams(['_config' => 'service_provider4']) + ->setDestination(new Collection(['prepay_id' => 'yansongda'])) + ->setPayload(['_invoke_appid' => '111']); + + $result = $this->plugin->assembly($rocket, function ($rocket) { return $rocket; }); + + $contents = $result->getDestination(); + + self::assertArrayHasKey('paySign', $contents->all()); + self::assertArrayHasKey('timeStamp', $contents->all()); + self::assertArrayHasKey('nonceStr', $contents->all()); + self::assertEquals('111', $contents->get('appId')); + self::assertEquals('prepay_id=yansongda', $contents->get('package')); + self::assertEquals('RSA', $contents->get('signType')); + } + + public function testService() + { + $rocket = (new Rocket()) + ->setParams(['_config' => 'service_provider']) + ->setDestination(new Collection(['prepay_id' => 'yansongda'])); + + $result = $this->plugin->assembly($rocket, function ($rocket) { return $rocket; }); + + $contents = $result->getDestination(); + + self::assertArrayHasKey('paySign', $contents->all()); + self::assertArrayHasKey('timeStamp', $contents->all()); + self::assertArrayHasKey('nonceStr', $contents->all()); + self::assertEquals('wx55955316af4ef15', $contents->get('appId')); + self::assertEquals('prepay_id=yansongda', $contents->get('package')); + self::assertEquals('RSA', $contents->get('signType')); + } +} \ No newline at end of file diff --git a/tests/Plugin/Wechat/Pay/Jsapi/PayPluginTest.php b/tests/Plugin/Wechat/Pay/Jsapi/PayPluginTest.php new file mode 100644 index 0000000..453e9b3 --- /dev/null +++ b/tests/Plugin/Wechat/Pay/Jsapi/PayPluginTest.php @@ -0,0 +1,97 @@ +plugin = new PayPlugin(); + } + + public function testEmptyPayload() + { + $rocket = new Rocket(); + + self::expectException(InvalidParamsException::class); + self::expectExceptionCode(Exception::PARAMS_NECESSARY_PARAMS_MISSING); + self::expectExceptionMessage('参数异常: Jsapi 下单,参数为空'); + + $this->plugin->assembly($rocket, function ($rocket) { return $rocket; }); + } + + public function testNormal() + { + $rocket = new Rocket(); + $rocket->setPayload(new Collection( [ + "name" => "yansongda", + ])); + + $result = $this->plugin->assembly($rocket, function ($rocket) { return $rocket; }); + + self::assertEquals([ + '_method' => 'POST', + '_url' => 'v3/pay/transactions/jsapi', + '_service_url' => 'v3/pay/partner/transactions/jsapi', + "appid" => "wx55955316af4ef13", + 'mchid' => '1600314069', + 'notify_url' => 'https://pay.yansongda.cn', + 'name' => 'yansongda', + ], $result->getPayload()->all()); + } + + public function testServiceParams() + { + $rocket = new Rocket(); + $rocket->setParams(['_config' => 'service_provider'])->setPayload(new Collection( [ + 'sub_mchid' => '333', + 'notify_url' => '444', + 'name' => 'yansongda', + ])); + + $result = $this->plugin->assembly($rocket, function ($rocket) { return $rocket; }); + + self::assertEquals([ + '_method' => 'POST', + '_url' => 'v3/pay/transactions/jsapi', + '_service_url' => 'v3/pay/partner/transactions/jsapi', + "sp_appid" => "wx55955316af4ef13", + 'sp_mchid' => '1600314069', + 'sub_mchid' => '333', + 'notify_url' => '444', + 'name' => 'yansongda', + ], $result->getPayload()->all()); + } + + public function testService() + { + $rocket = new Rocket(); + $rocket->setParams(['_config' => 'service_provider'])->setPayload(new Collection( [ + 'name' => 'yansongda', + ])); + + $result = $this->plugin->assembly($rocket, function ($rocket) { return $rocket; }); + + self::assertEquals([ + '_method' => 'POST', + '_url' => 'v3/pay/transactions/jsapi', + '_service_url' => 'v3/pay/partner/transactions/jsapi', + "sp_appid" => "wx55955316af4ef13", + 'sp_mchid' => '1600314069', + 'sub_mchid' => '1600314070', + 'notify_url' => '', + 'name' => 'yansongda', + ], $result->getPayload()->all()); + } +} diff --git a/tests/Plugin/Wechat/Pay/Jsapi/QueryByWxPluginTest.php b/tests/Plugin/Wechat/Pay/Jsapi/QueryByWxPluginTest.php new file mode 100644 index 0000000..fc9ee2e --- /dev/null +++ b/tests/Plugin/Wechat/Pay/Jsapi/QueryByWxPluginTest.php @@ -0,0 +1,73 @@ +plugin = new QueryByWxPlugin(); + } + + public function testEmptyPayload() + { + $rocket = new Rocket(); + + self::expectException(InvalidParamsException::class); + self::expectExceptionCode(Exception::PARAMS_NECESSARY_PARAMS_MISSING); + self::expectExceptionMessage('参数异常: Jsapi 通过微信订单号查询订单,参数缺少 `transaction_id`'); + + $this->plugin->assembly($rocket, function ($rocket) { return $rocket; }); + } + + public function testNormal() + { + $rocket = new Rocket(); + $rocket->setPayload(new Collection( [ + "transaction_id" => "111", + ])); + + $result = $this->plugin->assembly($rocket, function ($rocket) { return $rocket; }); + + self::assertEquals('GET', $result->getPayload()->get('_method')); + self::assertEquals('v3/pay/transactions/id/111?mchid=1600314069', $result->getPayload()->get('_url')); + } + + public function testServiceParams() + { + $rocket = new Rocket(); + $rocket->setPayload(new Collection( [ + "transaction_id" => "111", + 'sub_mchid' => '333', + ])); + + $result = $this->plugin->assembly($rocket, function ($rocket) { return $rocket; }); + + self::assertEquals('GET', $result->getPayload()->get('_method')); + self::assertEquals('v3/pay/partner/transactions/id/111?sp_mchid=1600314069&sub_mchid=333', $result->getPayload()->get('_service_url')); + } + + public function testService() + { + $rocket = new Rocket(); + $rocket->setParams(['_config' => 'service_provider'])->setPayload(new Collection( [ + "transaction_id" => "111", + ])); + + $result = $this->plugin->assembly($rocket, function ($rocket) { return $rocket; }); + + self::assertEquals('GET', $result->getPayload()->get('_method')); + self::assertEquals('v3/pay/partner/transactions/id/111?sp_mchid=1600314069&sub_mchid=1600314070', $result->getPayload()->get('_service_url')); + } +} diff --git a/tests/Plugin/Wechat/Pay/Jsapi/QueryPluginTest.php b/tests/Plugin/Wechat/Pay/Jsapi/QueryPluginTest.php new file mode 100644 index 0000000..e3886cd --- /dev/null +++ b/tests/Plugin/Wechat/Pay/Jsapi/QueryPluginTest.php @@ -0,0 +1,73 @@ +plugin = new QueryPlugin(); + } + + public function testEmptyPayload() + { + $rocket = new Rocket(); + + self::expectException(InvalidParamsException::class); + self::expectExceptionCode(Exception::PARAMS_NECESSARY_PARAMS_MISSING); + self::expectExceptionMessage('参数异常: Jsapi 通过商户订单号查询订单,参数缺少 `out_trade_no`'); + + $this->plugin->assembly($rocket, function ($rocket) { return $rocket; }); + } + + public function testNormal() + { + $rocket = new Rocket(); + $rocket->setPayload(new Collection( [ + "out_trade_no" => "111", + ])); + + $result = $this->plugin->assembly($rocket, function ($rocket) { return $rocket; }); + + self::assertEquals('GET', $result->getPayload()->get('_method')); + self::assertEquals('v3/pay/transactions/out-trade-no/111?mchid=1600314069', $result->getPayload()->get('_url')); + } + + public function testServiceParams() + { + $rocket = new Rocket(); + $rocket->setPayload(new Collection( [ + "out_trade_no" => "111", + 'sub_mchid' => '333', + ])); + + $result = $this->plugin->assembly($rocket, function ($rocket) { return $rocket; }); + + self::assertEquals('GET', $result->getPayload()->get('_method')); + self::assertEquals('v3/pay/partner/transactions/out-trade-no/111?sp_mchid=1600314069&sub_mchid=333', $result->getPayload()->get('_service_url')); + } + + public function testService() + { + $rocket = new Rocket(); + $rocket->setParams(['_config' => 'service_provider'])->setPayload(new Collection( [ + "out_trade_no" => "111", + ])); + + $result = $this->plugin->assembly($rocket, function ($rocket) { return $rocket; }); + + self::assertEquals('GET', $result->getPayload()->get('_method')); + self::assertEquals('v3/pay/partner/transactions/out-trade-no/111?sp_mchid=1600314069&sub_mchid=1600314070', $result->getPayload()->get('_service_url')); + } +} diff --git a/tests/Plugin/Wechat/Pay/Jsapi/QueryRefundPluginTest.php b/tests/Plugin/Wechat/Pay/Jsapi/QueryRefundPluginTest.php new file mode 100644 index 0000000..04da1bf --- /dev/null +++ b/tests/Plugin/Wechat/Pay/Jsapi/QueryRefundPluginTest.php @@ -0,0 +1,73 @@ +plugin = new QueryRefundPlugin(); + } + + public function testEmptyPayload() + { + $rocket = new Rocket(); + + self::expectException(InvalidParamsException::class); + self::expectExceptionCode(Exception::PARAMS_NECESSARY_PARAMS_MISSING); + self::expectExceptionMessage('参数异常: Jsapi 查询退款订单,参数缺少 `out_refund_no`'); + + $this->plugin->assembly($rocket, function ($rocket) { return $rocket; }); + } + + public function testNormal() + { + $rocket = new Rocket(); + $rocket->setPayload(new Collection( [ + "out_refund_no" => "111", + ])); + + $result = $this->plugin->assembly($rocket, function ($rocket) { return $rocket; }); + + self::assertEquals('GET', $result->getPayload()->get('_method')); + self::assertEquals('v3/refund/domestic/refunds/111', $result->getPayload()->get('_url')); + } + + public function testServiceParams() + { + $rocket = new Rocket(); + $rocket->setPayload(new Collection( [ + "out_refund_no" => "111", + 'sub_mchid' => '333', + ])); + + $result = $this->plugin->assembly($rocket, function ($rocket) { return $rocket; }); + + self::assertEquals('GET', $result->getPayload()->get('_method')); + self::assertEquals('v3/refund/domestic/refunds/111?sub_mchid=333', $result->getPayload()->get('_service_url')); + } + + public function testService() + { + $rocket = new Rocket(); + $rocket->setParams(['_config' => 'service_provider'])->setPayload(new Collection( [ + "out_refund_no" => "111", + ])); + + $result = $this->plugin->assembly($rocket, function ($rocket) { return $rocket; }); + + self::assertEquals('GET', $result->getPayload()->get('_method')); + self::assertEquals('v3/refund/domestic/refunds/111?sub_mchid=1600314070', $result->getPayload()->get('_service_url')); + } +} diff --git a/tests/Plugin/Wechat/Pay/Jsapi/RefundPluginTest.php b/tests/Plugin/Wechat/Pay/Jsapi/RefundPluginTest.php new file mode 100644 index 0000000..0c7600c --- /dev/null +++ b/tests/Plugin/Wechat/Pay/Jsapi/RefundPluginTest.php @@ -0,0 +1,110 @@ +plugin = new RefundPlugin(); + } + + public function testEmptyPayload() + { + $rocket = new Rocket(); + + self::expectException(InvalidParamsException::class); + self::expectExceptionCode(Exception::PARAMS_NECESSARY_PARAMS_MISSING); + self::expectExceptionMessage('参数异常: Jsapi 退款申请,参数为空'); + + $this->plugin->assembly($rocket, function ($rocket) { return $rocket; }); + } + + public function testNormalParams() + { + $rocket = new Rocket(); + $rocket->setPayload(new Collection( [ + "notify_url" => "111", + 'name' => '222', + ])); + + $result = $this->plugin->assembly($rocket, function ($rocket) { return $rocket; }); + + self::assertEquals([ + '_method' => 'POST', + '_url' => 'v3/refund/domestic/refunds', + '_service_url' => 'v3/refund/domestic/refunds', + 'notify_url' => '111', + 'name' => '222', + ], $result->getPayload()->all()); + } + + public function testNormal() + { + $rocket = new Rocket(); + $rocket->setPayload(new Collection( [ + "out_trade_no" => "111", + ])); + + $result = $this->plugin->assembly($rocket, function ($rocket) { return $rocket; }); + + self::assertEquals([ + '_method' => 'POST', + '_url' => 'v3/refund/domestic/refunds', + '_service_url' => 'v3/refund/domestic/refunds', + 'notify_url' => 'https://pay.yansongda.cn', + 'out_trade_no' => '111', + ], $result->getPayload()->all()); + } + + public function testServiceParams() + { + $rocket = new Rocket(); + $rocket->setParams(['_config' => 'service_provider'])->setPayload(new Collection( [ + "notify_url" => "111", + 'sub_mchid' => '222', + 'name' => 'yansongda', + ])); + + $result = $this->plugin->assembly($rocket, function ($rocket) { return $rocket; }); + + self::assertEquals([ + '_method' => 'POST', + '_url' => 'v3/refund/domestic/refunds', + '_service_url' => 'v3/refund/domestic/refunds', + 'notify_url' => '111', + 'sub_mchid' => '222', + 'name' => 'yansongda', + ], $result->getPayload()->all()); + } + + public function testService() + { + $rocket = new Rocket(); + $rocket->setParams(['_config' => 'service_provider'])->setPayload(new Collection([ + 'name' => 'yansongda', + ])); + + $result = $this->plugin->assembly($rocket, function ($rocket) { return $rocket; }); + + self::assertEquals([ + '_method' => 'POST', + '_url' => 'v3/refund/domestic/refunds', + '_service_url' => 'v3/refund/domestic/refunds', + 'name' => 'yansongda', + 'notify_url' => null, + 'sub_mchid' => '1600314070', + ], $result->getPayload()->all()); + } +} diff --git a/tests/Plugin/Wechat/Pay/Mini/ClosePluginTest.php b/tests/Plugin/Wechat/Pay/Mini/ClosePluginTest.php new file mode 100644 index 0000000..e8a35ed --- /dev/null +++ b/tests/Plugin/Wechat/Pay/Mini/ClosePluginTest.php @@ -0,0 +1,87 @@ +plugin = new ClosePlugin(); + } + + public function testEmptyPayload() + { + $rocket = new Rocket(); + + self::expectException(InvalidParamsException::class); + self::expectExceptionCode(Exception::PARAMS_NECESSARY_PARAMS_MISSING); + self::expectExceptionMessage('参数异常: Mini 关闭订单,参数缺少 `out_trade_no`'); + + $this->plugin->assembly($rocket, function ($rocket) { return $rocket; }); + } + + public function testNormal() + { + $rocket = new Rocket(); + $rocket->setPayload(new Collection( [ + "out_trade_no" => "111", + ])); + + $result = $this->plugin->assembly($rocket, function ($rocket) { return $rocket; }); + + self::assertEquals([ + '_method' => 'POST', + '_url' => 'v3/pay/transactions/out-trade-no/111/close', + '_service_url' => 'v3/pay/partner/transactions/out-trade-no/111/close', + 'mchid' => '1600314069', + ], $result->getPayload()->all()); + } + + public function testServiceParams() + { + $rocket = new Rocket(); + $rocket->setParams(['_config' => 'service_provider'])->setPayload(new Collection( [ + "out_trade_no" => "111", + 'sub_mchid' => '333', + ])); + + $result = $this->plugin->assembly($rocket, function ($rocket) { return $rocket; }); + + self::assertEquals([ + '_method' => 'POST', + '_url' => 'v3/pay/transactions/out-trade-no/111/close', + '_service_url' => 'v3/pay/partner/transactions/out-trade-no/111/close', + 'sp_mchid' => '1600314069', + 'sub_mchid' => '333', + ], $result->getPayload()->all()); + } + + public function testService() + { + $rocket = new Rocket(); + $rocket->setParams(['_config' => 'service_provider'])->setPayload(new Collection( [ + "out_trade_no" => "111", + ])); + + $result = $this->plugin->assembly($rocket, function ($rocket) { return $rocket; }); + + self::assertEquals([ + '_method' => 'POST', + '_url' => 'v3/pay/transactions/out-trade-no/111/close', + '_service_url' => 'v3/pay/partner/transactions/out-trade-no/111/close', + 'sp_mchid' => '1600314069', + 'sub_mchid' => '1600314070', + ], $result->getPayload()->all()); + } +} diff --git a/tests/Plugin/Wechat/Pay/Mini/DownloadBillPluginTest.php b/tests/Plugin/Wechat/Pay/Mini/DownloadBillPluginTest.php new file mode 100644 index 0000000..c211770 --- /dev/null +++ b/tests/Plugin/Wechat/Pay/Mini/DownloadBillPluginTest.php @@ -0,0 +1,49 @@ +plugin = new DownloadBillPlugin(); + } + + public function testEmptyPayload() + { + $rocket = new Rocket(); + + self::expectException(InvalidParamsException::class); + self::expectExceptionCode(Exception::PARAMS_NECESSARY_PARAMS_MISSING); + self::expectExceptionMessage('参数异常: Mini 下载交易对账单,参数缺少 `download_url`'); + + $this->plugin->assembly($rocket, function ($rocket) { return $rocket; }); + } + + public function testNormal() + { + $rocket = new Rocket(); + $rocket->setPayload(new Collection( [ + "download_url" => "111", + ])); + + $result = $this->plugin->assembly($rocket, function ($rocket) { return $rocket; }); + + self::assertEquals([ + '_method' => 'GET', + '_url' => '111', + '_service_url' => '111', + ], $result->getPayload()->all()); + } +} diff --git a/tests/Plugin/Wechat/Pay/Mini/GetFundBillPluginTest.php b/tests/Plugin/Wechat/Pay/Mini/GetFundBillPluginTest.php new file mode 100644 index 0000000..d502a35 --- /dev/null +++ b/tests/Plugin/Wechat/Pay/Mini/GetFundBillPluginTest.php @@ -0,0 +1,49 @@ +plugin = new GetFundBillPlugin(); + } + + public function testEmptyPayload() + { + $rocket = new Rocket(); + + self::expectException(InvalidParamsException::class); + self::expectExceptionCode(Exception::PARAMS_NECESSARY_PARAMS_MISSING); + self::expectExceptionMessage('参数异常: Mini 申请资金账单,参数为空'); + + $this->plugin->assembly($rocket, function ($rocket) { return $rocket; }); + } + + public function testNormal() + { + $rocket = new Rocket(); + $rocket->setPayload(new Collection( [ + "download_url" => "111", + ])); + + $result = $this->plugin->assembly($rocket, function ($rocket) { return $rocket; }); + + self::assertEquals([ + '_method' => 'GET', + '_url' => 'v3/bill/fundflowbill?download_url=111', + '_service_url' => 'v3/bill/fundflowbill?download_url=111', + ], $result->getPayload()->all()); + } +} diff --git a/tests/Plugin/Wechat/Pay/Mini/GetTradeBillPluginTest.php b/tests/Plugin/Wechat/Pay/Mini/GetTradeBillPluginTest.php new file mode 100644 index 0000000..90928c8 --- /dev/null +++ b/tests/Plugin/Wechat/Pay/Mini/GetTradeBillPluginTest.php @@ -0,0 +1,49 @@ +plugin = new GetTradeBillPlugin(); + } + + public function testEmptyPayload() + { + $rocket = new Rocket(); + + self::expectException(InvalidParamsException::class); + self::expectExceptionCode(Exception::PARAMS_NECESSARY_PARAMS_MISSING); + self::expectExceptionMessage('参数异常: Mini 申请交易账单,参数为空'); + + $this->plugin->assembly($rocket, function ($rocket) { return $rocket; }); + } + + public function testNormal() + { + $rocket = new Rocket(); + $rocket->setPayload(new Collection( [ + "download_url" => "111", + ])); + + $result = $this->plugin->assembly($rocket, function ($rocket) { return $rocket; }); + + self::assertEquals([ + '_method' => 'GET', + '_url' => 'v3/bill/tradebill?download_url=111', + '_service_url' => 'v3/bill/tradebill?download_url=111', + ], $result->getPayload()->all()); + } +} diff --git a/tests/Plugin/Wechat/Pay/Mini/InvokePluginTest.php b/tests/Plugin/Wechat/Pay/Mini/InvokePluginTest.php new file mode 100644 index 0000000..5d0670f --- /dev/null +++ b/tests/Plugin/Wechat/Pay/Mini/InvokePluginTest.php @@ -0,0 +1,104 @@ +plugin = new InvokePlugin(); + } + + public function testMissingPrepayId() + { + $rocket = new Rocket(); + + self::expectException(InvalidResponseException::class); + self::expectExceptionCode(Exception::RESPONSE_MISSING_NECESSARY_PARAMS); + self::expectExceptionMessage('预下单失败:响应缺少 `prepay_id` 参数,请自行检查参数是否符合微信要求'); + + $this->plugin->assembly($rocket, function ($rocket) { return $rocket; }); + } + + public function testNormalParams() + { + $rocket = (new Rocket()) + ->setDestination(new Collection(['prepay_id' => 'yansongda'])) + ->setPayload(['_invoke_appid' => '111']); + + $result = $this->plugin->assembly($rocket, function ($rocket) { return $rocket; }); + + $contents = $result->getDestination(); + + self::assertArrayHasKey('paySign', $contents->all()); + self::assertArrayHasKey('timeStamp', $contents->all()); + self::assertArrayHasKey('nonceStr', $contents->all()); + self::assertEquals('111', $contents->get('appId')); + self::assertEquals('prepay_id=yansongda', $contents->get('package')); + self::assertEquals('RSA', $contents->get('signType')); + } + + public function testNormal() + { + $rocket = (new Rocket())->setDestination(new Collection(['prepay_id' => 'yansongda'])); + + $result = $this->plugin->assembly($rocket, function ($rocket) { return $rocket; }); + + $contents = $result->getDestination(); + + self::assertArrayHasKey('paySign', $contents->all()); + self::assertArrayHasKey('timeStamp', $contents->all()); + self::assertArrayHasKey('nonceStr', $contents->all()); + self::assertEquals('wx55955316af4ef14', $contents->get('appId')); + self::assertEquals('prepay_id=yansongda', $contents->get('package')); + self::assertEquals('RSA', $contents->get('signType')); + } + + public function testServiceParams() + { + $rocket = (new Rocket()) + ->setParams(['_config' => 'service_provider4']) + ->setDestination(new Collection(['prepay_id' => 'yansongda'])) + ->setPayload(['_invoke_appid' => '111']); + + $result = $this->plugin->assembly($rocket, function ($rocket) { return $rocket; }); + + $contents = $result->getDestination(); + + self::assertArrayHasKey('paySign', $contents->all()); + self::assertArrayHasKey('timeStamp', $contents->all()); + self::assertArrayHasKey('nonceStr', $contents->all()); + self::assertEquals('111', $contents->get('appId')); + self::assertEquals('prepay_id=yansongda', $contents->get('package')); + self::assertEquals('RSA', $contents->get('signType')); + } + + public function testService() + { + $rocket = (new Rocket()) + ->setParams(['_config' => 'service_provider4']) + ->setDestination(new Collection(['prepay_id' => 'yansongda'])); + + $result = $this->plugin->assembly($rocket, function ($rocket) { return $rocket; }); + + $contents = $result->getDestination(); + + self::assertArrayHasKey('paySign', $contents->all()); + self::assertArrayHasKey('timeStamp', $contents->all()); + self::assertArrayHasKey('nonceStr', $contents->all()); + self::assertEquals('wx55955316af4ef17', $contents->get('appId')); + self::assertEquals('prepay_id=yansongda', $contents->get('package')); + self::assertEquals('RSA', $contents->get('signType')); + } +} \ No newline at end of file diff --git a/tests/Plugin/Wechat/Pay/Mini/InvokePrepayPluginTest.php b/tests/Plugin/Wechat/Pay/Mini/InvokePrepayPluginTest.php deleted file mode 100644 index 6411115..0000000 --- a/tests/Plugin/Wechat/Pay/Mini/InvokePrepayPluginTest.php +++ /dev/null @@ -1,75 +0,0 @@ -plugin = new InvokePrepayPlugin(); - } - - public function testNormal() - { - $rocket = (new Rocket())->setParams([])->setDestination(new Collection(['prepay_id' => 'yansongda anthony'])); - - $result = $this->plugin->assembly($rocket, function ($rocket) { return $rocket; }); - - $contents = $result->getDestination(); - $config = get_wechat_config($rocket->getParams()); - - self::assertArrayHasKey('appId', $contents->all()); - self::assertEquals($config['mini_app_id'], $contents->get('appId')); - self::assertArrayHasKey('nonceStr', $contents->all()); - self::assertArrayHasKey('package', $contents->all()); - self::assertArrayHasKey('signType', $contents->all()); - self::assertArrayHasKey('paySign', $contents->all()); - } - - public function testPartnerSpAppId() - { - $rocket = (new Rocket())->setParams(['_config' => 'service_provider']); - $rocket->setPayload(new Collection(['out_trade_no'=>'121218'])); - $rocket->setDestination(new Collection(['prepay_id' => 'yansongda anthony'])); - - $result = $this->plugin->assembly($rocket, function ($rocket) { return $rocket; }); - - $contents = $result->getDestination(); - $config = get_wechat_config($rocket->getParams()); - - self::assertArrayHasKey('appId', $contents->all()); - self::assertEquals($config['mini_app_id'], $contents->get('appId')); - self::assertArrayHasKey('nonceStr', $contents->all()); - self::assertArrayHasKey('package', $contents->all()); - self::assertArrayHasKey('signType', $contents->all()); - self::assertArrayHasKey('paySign', $contents->all()); - } - - public function testPartnerSubAppId() - { - $rocket = (new Rocket())->setParams(['_config' => 'service_provider']); - $rocket->setPayload(new Collection(['out_trade_no'=>'121218','sub_appid' =>'wx55955316af4ef88'])); - $rocket->setDestination(new Collection(['prepay_id' => 'yansongda anthony'])); - - $result = $this->plugin->assembly($rocket, function ($rocket) { return $rocket; }); - - $contents = $result->getDestination(); - - self::assertArrayHasKey('appId', $contents->all()); - self::assertEquals('wx55955316af4ef88', $contents->get('appId')); - self::assertArrayHasKey('nonceStr', $contents->all()); - self::assertArrayHasKey('package', $contents->all()); - self::assertArrayHasKey('signType', $contents->all()); - self::assertArrayHasKey('paySign', $contents->all()); - } -} diff --git a/tests/Plugin/Wechat/Pay/Mini/InvokePrepayV2PluginTest.php b/tests/Plugin/Wechat/Pay/Mini/InvokePrepayV2PluginTest.php deleted file mode 100644 index 68f932e..0000000 --- a/tests/Plugin/Wechat/Pay/Mini/InvokePrepayV2PluginTest.php +++ /dev/null @@ -1,38 +0,0 @@ -plugin = new InvokePrepayV2Plugin(); - } - - public function testNormal() - { - $rocket = (new Rocket())->setDestination(new Collection(['prepay_id' => 'yansongda'])); - $config = get_wechat_config($rocket->getParams()); - - $result = $this->plugin->assembly($rocket, function ($rocket) { return $rocket; }); - - $contents = $result->getDestination(); - - self::assertArrayHasKey('paySign', $contents->all()); - self::assertArrayHasKey('timeStamp', $contents->all()); - self::assertArrayHasKey('nonceStr', $contents->all()); - self::assertEquals('prepay_id=yansongda', $contents->get('package')); - self::assertEquals('MD5', $contents->get('signType')); - self::assertEquals($config['mini_app_id'], $contents->get('appId')); - } -} diff --git a/tests/Plugin/Wechat/Pay/Mini/PayPluginTest.php b/tests/Plugin/Wechat/Pay/Mini/PayPluginTest.php new file mode 100644 index 0000000..ac6540d --- /dev/null +++ b/tests/Plugin/Wechat/Pay/Mini/PayPluginTest.php @@ -0,0 +1,97 @@ +plugin = new PayPlugin(); + } + + public function testEmptyPayload() + { + $rocket = new Rocket(); + + self::expectException(InvalidParamsException::class); + self::expectExceptionCode(Exception::PARAMS_NECESSARY_PARAMS_MISSING); + self::expectExceptionMessage('参数异常: Mini 下单,参数为空'); + + $this->plugin->assembly($rocket, function ($rocket) { return $rocket; }); + } + + public function testNormal() + { + $rocket = new Rocket(); + $rocket->setPayload(new Collection( [ + "name" => "yansongda", + ])); + + $result = $this->plugin->assembly($rocket, function ($rocket) { return $rocket; }); + + self::assertEquals([ + '_method' => 'POST', + '_url' => 'v3/pay/transactions/jsapi', + '_service_url' => 'v3/pay/partner/transactions/jsapi', + "appid" => "wx55955316af4ef14", + 'mchid' => '1600314069', + 'notify_url' => 'https://pay.yansongda.cn', + 'name' => 'yansongda', + ], $result->getPayload()->all()); + } + + public function testServiceParams() + { + $rocket = new Rocket(); + $rocket->setParams(['_config' => 'service_provider'])->setPayload(new Collection( [ + 'sub_mchid' => '333', + 'notify_url' => '444', + 'name' => 'yansongda', + ])); + + $result = $this->plugin->assembly($rocket, function ($rocket) { return $rocket; }); + + self::assertEquals([ + '_method' => 'POST', + '_url' => 'v3/pay/transactions/jsapi', + '_service_url' => 'v3/pay/partner/transactions/jsapi', + "sp_appid" => "wx55955316af4ef14", + 'sp_mchid' => '1600314069', + 'sub_mchid' => '333', + 'notify_url' => '444', + 'name' => 'yansongda', + ], $result->getPayload()->all()); + } + + public function testService() + { + $rocket = new Rocket(); + $rocket->setParams(['_config' => 'service_provider'])->setPayload(new Collection( [ + 'name' => 'yansongda', + ])); + + $result = $this->plugin->assembly($rocket, function ($rocket) { return $rocket; }); + + self::assertEquals([ + '_method' => 'POST', + '_url' => 'v3/pay/transactions/jsapi', + '_service_url' => 'v3/pay/partner/transactions/jsapi', + "sp_appid" => "wx55955316af4ef14", + 'sp_mchid' => '1600314069', + 'sub_mchid' => '1600314070', + 'notify_url' => '', + 'name' => 'yansongda', + ], $result->getPayload()->all()); + } +} diff --git a/tests/Plugin/Wechat/Pay/Mini/PrepayPluginTest.php b/tests/Plugin/Wechat/Pay/Mini/PrepayPluginTest.php deleted file mode 100644 index a42de58..0000000 --- a/tests/Plugin/Wechat/Pay/Mini/PrepayPluginTest.php +++ /dev/null @@ -1,107 +0,0 @@ -plugin = new PrepayPlugin(); - } - - public function testWechatIdNormal() - { - $rocket = new Rocket(); - $rocket->setParams([])->setPayload(new Collection()); - - $result = $this->plugin->assembly($rocket, function ($rocket) { return $rocket; }); - - $payload = $result->getPayload(); - - self::assertEquals('wx55955316af4ef14', $payload->get('appid')); - self::assertEquals('1600314069', $payload->get('mchid')); - } - - public function testWechatIdNormalWithType() - { - $rocket = new Rocket(); - $rocket->setParams(['_type' => 'app'])->setPayload(new Collection()); - - $result = $this->plugin->assembly($rocket, function ($rocket) { return $rocket; }); - - $payload = $result->getPayload(); - - self::assertEquals('wx55955316af4ef14', $payload->get('appid')); - self::assertEquals('1600314069', $payload->get('mchid')); - } - - public function testWechatIdPartner() - { - $rocket = new Rocket(); - $rocket->setParams(['_config' => 'service_provider'])->setPayload(new Collection()); - - $result = $this->plugin->assembly($rocket, function ($rocket) { return $rocket; }); - - $payload = $result->getPayload(); - - self::assertEquals('wx55955316af4ef17', $payload->get('sub_appid')); - self::assertEquals('1600314070', $payload->get('sub_mchid')); - } - - public function testWechatIdPartnerDirect() - { - $rocket = new Rocket(); - $rocket->setParams(['_config' => 'service_provider'])->setPayload(new Collection(['sub_appid' => '123'])); - - $result = $this->plugin->assembly($rocket, function ($rocket) { return $rocket; }); - - $payload = $result->getPayload(); - - self::assertEquals('123', $payload->get('sub_appid')); - self::assertEquals('wx55955316af4ef14', $payload->get('sp_appid')); - self::assertEquals('1600314070', $payload->get('sub_mchid')); - self::assertEquals('1600314069', $payload->get('sp_mchid')); - } - - public function testWechatIdPartnerDirectMpAppId() - { - $rocket = new Rocket(); - $rocket->setParams(['_config' => 'service_provider2'])->setPayload(new Collection(['sub_appid' => '123'])); - - $result = $this->plugin->assembly($rocket, function ($rocket) { return $rocket; }); - - $payload = $result->getPayload(); - - self::assertEquals('123', $payload->get('sub_appid')); - self::assertEquals('wx55955316af4ef18', $payload->get('sp_appid')); - self::assertEquals('1600314072', $payload->get('sub_mchid')); - self::assertEquals('1600314071', $payload->get('sp_mchid')); - } - - public function testWechatIdPartnerWithoutSubAppId() - { - $rocket = new Rocket(); - $rocket->setParams(['_config' => 'service_provider3'])->setPayload(new Collection()); - - $result = $this->plugin->assembly($rocket, function ($rocket) { return $rocket; }); - - $payload = $result->getPayload(); - - self::assertArrayNotHasKey('sub_appid', $payload->all()); - self::assertEquals('wx55955316af4ef18', $payload->get('sp_appid')); - self::assertEquals('1600314072', $payload->get('sub_mchid')); - self::assertEquals('1600314071', $payload->get('sp_mchid')); - } -} diff --git a/tests/Plugin/Wechat/Pay/Mini/QueryByWxPluginTest.php b/tests/Plugin/Wechat/Pay/Mini/QueryByWxPluginTest.php new file mode 100644 index 0000000..c3430bf --- /dev/null +++ b/tests/Plugin/Wechat/Pay/Mini/QueryByWxPluginTest.php @@ -0,0 +1,73 @@ +plugin = new QueryByWxPlugin(); + } + + public function testEmptyPayload() + { + $rocket = new Rocket(); + + self::expectException(InvalidParamsException::class); + self::expectExceptionCode(Exception::PARAMS_NECESSARY_PARAMS_MISSING); + self::expectExceptionMessage('参数异常: Mini 通过微信订单号查询订单,参数缺少 `transaction_id`'); + + $this->plugin->assembly($rocket, function ($rocket) { return $rocket; }); + } + + public function testNormal() + { + $rocket = new Rocket(); + $rocket->setPayload(new Collection( [ + "transaction_id" => "111", + ])); + + $result = $this->plugin->assembly($rocket, function ($rocket) { return $rocket; }); + + self::assertEquals('GET', $result->getPayload()->get('_method')); + self::assertEquals('v3/pay/transactions/id/111?mchid=1600314069', $result->getPayload()->get('_url')); + } + + public function testServiceParams() + { + $rocket = new Rocket(); + $rocket->setPayload(new Collection( [ + "transaction_id" => "111", + 'sub_mchid' => '333', + ])); + + $result = $this->plugin->assembly($rocket, function ($rocket) { return $rocket; }); + + self::assertEquals('GET', $result->getPayload()->get('_method')); + self::assertEquals('v3/pay/partner/transactions/id/111?sp_mchid=1600314069&sub_mchid=333', $result->getPayload()->get('_service_url')); + } + + public function testService() + { + $rocket = new Rocket(); + $rocket->setParams(['_config' => 'service_provider'])->setPayload(new Collection( [ + "transaction_id" => "111", + ])); + + $result = $this->plugin->assembly($rocket, function ($rocket) { return $rocket; }); + + self::assertEquals('GET', $result->getPayload()->get('_method')); + self::assertEquals('v3/pay/partner/transactions/id/111?sp_mchid=1600314069&sub_mchid=1600314070', $result->getPayload()->get('_service_url')); + } +} diff --git a/tests/Plugin/Wechat/Pay/Mini/QueryPluginTest.php b/tests/Plugin/Wechat/Pay/Mini/QueryPluginTest.php new file mode 100644 index 0000000..8151b8d --- /dev/null +++ b/tests/Plugin/Wechat/Pay/Mini/QueryPluginTest.php @@ -0,0 +1,73 @@ +plugin = new QueryPlugin(); + } + + public function testEmptyPayload() + { + $rocket = new Rocket(); + + self::expectException(InvalidParamsException::class); + self::expectExceptionCode(Exception::PARAMS_NECESSARY_PARAMS_MISSING); + self::expectExceptionMessage('参数异常: Mini 通过商户订单号查询订单,参数缺少 `out_trade_no`'); + + $this->plugin->assembly($rocket, function ($rocket) { return $rocket; }); + } + + public function testNormal() + { + $rocket = new Rocket(); + $rocket->setPayload(new Collection( [ + "out_trade_no" => "111", + ])); + + $result = $this->plugin->assembly($rocket, function ($rocket) { return $rocket; }); + + self::assertEquals('GET', $result->getPayload()->get('_method')); + self::assertEquals('v3/pay/transactions/out-trade-no/111?mchid=1600314069', $result->getPayload()->get('_url')); + } + + public function testServiceParams() + { + $rocket = new Rocket(); + $rocket->setPayload(new Collection( [ + "out_trade_no" => "111", + 'sub_mchid' => '333', + ])); + + $result = $this->plugin->assembly($rocket, function ($rocket) { return $rocket; }); + + self::assertEquals('GET', $result->getPayload()->get('_method')); + self::assertEquals('v3/pay/partner/transactions/out-trade-no/111?sp_mchid=1600314069&sub_mchid=333', $result->getPayload()->get('_service_url')); + } + + public function testService() + { + $rocket = new Rocket(); + $rocket->setParams(['_config' => 'service_provider'])->setPayload(new Collection( [ + "out_trade_no" => "111", + ])); + + $result = $this->plugin->assembly($rocket, function ($rocket) { return $rocket; }); + + self::assertEquals('GET', $result->getPayload()->get('_method')); + self::assertEquals('v3/pay/partner/transactions/out-trade-no/111?sp_mchid=1600314069&sub_mchid=1600314070', $result->getPayload()->get('_service_url')); + } +} diff --git a/tests/Plugin/Wechat/Pay/Mini/QueryRefundPluginTest.php b/tests/Plugin/Wechat/Pay/Mini/QueryRefundPluginTest.php new file mode 100644 index 0000000..8d2680f --- /dev/null +++ b/tests/Plugin/Wechat/Pay/Mini/QueryRefundPluginTest.php @@ -0,0 +1,73 @@ +plugin = new QueryRefundPlugin(); + } + + public function testEmptyPayload() + { + $rocket = new Rocket(); + + self::expectException(InvalidParamsException::class); + self::expectExceptionCode(Exception::PARAMS_NECESSARY_PARAMS_MISSING); + self::expectExceptionMessage('参数异常: Mini 查询退款订单,参数缺少 `out_refund_no`'); + + $this->plugin->assembly($rocket, function ($rocket) { return $rocket; }); + } + + public function testNormal() + { + $rocket = new Rocket(); + $rocket->setPayload(new Collection( [ + "out_refund_no" => "111", + ])); + + $result = $this->plugin->assembly($rocket, function ($rocket) { return $rocket; }); + + self::assertEquals('GET', $result->getPayload()->get('_method')); + self::assertEquals('v3/refund/domestic/refunds/111', $result->getPayload()->get('_url')); + } + + public function testServiceParams() + { + $rocket = new Rocket(); + $rocket->setPayload(new Collection( [ + "out_refund_no" => "111", + 'sub_mchid' => '333', + ])); + + $result = $this->plugin->assembly($rocket, function ($rocket) { return $rocket; }); + + self::assertEquals('GET', $result->getPayload()->get('_method')); + self::assertEquals('v3/refund/domestic/refunds/111?sub_mchid=333', $result->getPayload()->get('_service_url')); + } + + public function testService() + { + $rocket = new Rocket(); + $rocket->setParams(['_config' => 'service_provider'])->setPayload(new Collection( [ + "out_refund_no" => "111", + ])); + + $result = $this->plugin->assembly($rocket, function ($rocket) { return $rocket; }); + + self::assertEquals('GET', $result->getPayload()->get('_method')); + self::assertEquals('v3/refund/domestic/refunds/111?sub_mchid=1600314070', $result->getPayload()->get('_service_url')); + } +} diff --git a/tests/Plugin/Wechat/Pay/Mini/RefundPluginTest.php b/tests/Plugin/Wechat/Pay/Mini/RefundPluginTest.php new file mode 100644 index 0000000..e9e9dd4 --- /dev/null +++ b/tests/Plugin/Wechat/Pay/Mini/RefundPluginTest.php @@ -0,0 +1,110 @@ +plugin = new RefundPlugin(); + } + + public function testEmptyPayload() + { + $rocket = new Rocket(); + + self::expectException(InvalidParamsException::class); + self::expectExceptionCode(Exception::PARAMS_NECESSARY_PARAMS_MISSING); + self::expectExceptionMessage('参数异常: Mini 退款申请,参数为空'); + + $this->plugin->assembly($rocket, function ($rocket) { return $rocket; }); + } + + public function testNormalParams() + { + $rocket = new Rocket(); + $rocket->setPayload(new Collection( [ + "notify_url" => "111", + 'name' => '222', + ])); + + $result = $this->plugin->assembly($rocket, function ($rocket) { return $rocket; }); + + self::assertEquals([ + '_method' => 'POST', + '_url' => 'v3/refund/domestic/refunds', + '_service_url' => 'v3/refund/domestic/refunds', + 'notify_url' => '111', + 'name' => '222', + ], $result->getPayload()->all()); + } + + public function testNormal() + { + $rocket = new Rocket(); + $rocket->setPayload(new Collection( [ + "out_trade_no" => "111", + ])); + + $result = $this->plugin->assembly($rocket, function ($rocket) { return $rocket; }); + + self::assertEquals([ + '_method' => 'POST', + '_url' => 'v3/refund/domestic/refunds', + '_service_url' => 'v3/refund/domestic/refunds', + 'notify_url' => 'https://pay.yansongda.cn', + 'out_trade_no' => '111', + ], $result->getPayload()->all()); + } + + public function testServiceParams() + { + $rocket = new Rocket(); + $rocket->setParams(['_config' => 'service_provider'])->setPayload(new Collection( [ + "notify_url" => "111", + 'sub_mchid' => '222', + 'name' => 'yansongda', + ])); + + $result = $this->plugin->assembly($rocket, function ($rocket) { return $rocket; }); + + self::assertEquals([ + '_method' => 'POST', + '_url' => 'v3/refund/domestic/refunds', + '_service_url' => 'v3/refund/domestic/refunds', + 'notify_url' => '111', + 'sub_mchid' => '222', + 'name' => 'yansongda', + ], $result->getPayload()->all()); + } + + public function testService() + { + $rocket = new Rocket(); + $rocket->setParams(['_config' => 'service_provider'])->setPayload(new Collection([ + 'name' => 'yansongda', + ])); + + $result = $this->plugin->assembly($rocket, function ($rocket) { return $rocket; }); + + self::assertEquals([ + '_method' => 'POST', + '_url' => 'v3/refund/domestic/refunds', + '_service_url' => 'v3/refund/domestic/refunds', + 'name' => 'yansongda', + 'notify_url' => null, + 'sub_mchid' => '1600314070', + ], $result->getPayload()->all()); + } +} diff --git a/tests/Plugin/Wechat/Pay/Native/ClosePluginTest.php b/tests/Plugin/Wechat/Pay/Native/ClosePluginTest.php new file mode 100644 index 0000000..09bea53 --- /dev/null +++ b/tests/Plugin/Wechat/Pay/Native/ClosePluginTest.php @@ -0,0 +1,87 @@ +plugin = new ClosePlugin(); + } + + public function testEmptyPayload() + { + $rocket = new Rocket(); + + self::expectException(InvalidParamsException::class); + self::expectExceptionCode(Exception::PARAMS_NECESSARY_PARAMS_MISSING); + self::expectExceptionMessage('参数异常: Native 关闭订单,参数缺少 `out_trade_no`'); + + $this->plugin->assembly($rocket, function ($rocket) { return $rocket; }); + } + + public function testNormal() + { + $rocket = new Rocket(); + $rocket->setPayload(new Collection( [ + "out_trade_no" => "111", + ])); + + $result = $this->plugin->assembly($rocket, function ($rocket) { return $rocket; }); + + self::assertEquals([ + '_method' => 'POST', + '_url' => 'v3/pay/transactions/out-trade-no/111/close', + '_service_url' => 'v3/pay/partner/transactions/out-trade-no/111/close', + 'mchid' => '1600314069', + ], $result->getPayload()->all()); + } + + public function testServiceParams() + { + $rocket = new Rocket(); + $rocket->setParams(['_config' => 'service_provider'])->setPayload(new Collection( [ + "out_trade_no" => "111", + 'sub_mchid' => '333', + ])); + + $result = $this->plugin->assembly($rocket, function ($rocket) { return $rocket; }); + + self::assertEquals([ + '_method' => 'POST', + '_url' => 'v3/pay/transactions/out-trade-no/111/close', + '_service_url' => 'v3/pay/partner/transactions/out-trade-no/111/close', + 'sp_mchid' => '1600314069', + 'sub_mchid' => '333', + ], $result->getPayload()->all()); + } + + public function testService() + { + $rocket = new Rocket(); + $rocket->setParams(['_config' => 'service_provider'])->setPayload(new Collection( [ + "out_trade_no" => "111", + ])); + + $result = $this->plugin->assembly($rocket, function ($rocket) { return $rocket; }); + + self::assertEquals([ + '_method' => 'POST', + '_url' => 'v3/pay/transactions/out-trade-no/111/close', + '_service_url' => 'v3/pay/partner/transactions/out-trade-no/111/close', + 'sp_mchid' => '1600314069', + 'sub_mchid' => '1600314070', + ], $result->getPayload()->all()); + } +} diff --git a/tests/Plugin/Wechat/Pay/Native/DownloadBillPluginTest.php b/tests/Plugin/Wechat/Pay/Native/DownloadBillPluginTest.php new file mode 100644 index 0000000..dd22b93 --- /dev/null +++ b/tests/Plugin/Wechat/Pay/Native/DownloadBillPluginTest.php @@ -0,0 +1,49 @@ +plugin = new DownloadBillPlugin(); + } + + public function testEmptyPayload() + { + $rocket = new Rocket(); + + self::expectException(InvalidParamsException::class); + self::expectExceptionCode(Exception::PARAMS_NECESSARY_PARAMS_MISSING); + self::expectExceptionMessage('参数异常: Native 下载交易对账单,参数缺少 `download_url`'); + + $this->plugin->assembly($rocket, function ($rocket) { return $rocket; }); + } + + public function testNormal() + { + $rocket = new Rocket(); + $rocket->setPayload(new Collection( [ + "download_url" => "111", + ])); + + $result = $this->plugin->assembly($rocket, function ($rocket) { return $rocket; }); + + self::assertEquals([ + '_method' => 'GET', + '_url' => '111', + '_service_url' => '111', + ], $result->getPayload()->all()); + } +} diff --git a/tests/Plugin/Wechat/Pay/Native/GetFundBillPluginTest.php b/tests/Plugin/Wechat/Pay/Native/GetFundBillPluginTest.php new file mode 100644 index 0000000..489f3f6 --- /dev/null +++ b/tests/Plugin/Wechat/Pay/Native/GetFundBillPluginTest.php @@ -0,0 +1,49 @@ +plugin = new GetFundBillPlugin(); + } + + public function testEmptyPayload() + { + $rocket = new Rocket(); + + self::expectException(InvalidParamsException::class); + self::expectExceptionCode(Exception::PARAMS_NECESSARY_PARAMS_MISSING); + self::expectExceptionMessage('参数异常: Native 申请资金账单,参数为空'); + + $this->plugin->assembly($rocket, function ($rocket) { return $rocket; }); + } + + public function testNormal() + { + $rocket = new Rocket(); + $rocket->setPayload(new Collection( [ + "download_url" => "111", + ])); + + $result = $this->plugin->assembly($rocket, function ($rocket) { return $rocket; }); + + self::assertEquals([ + '_method' => 'GET', + '_url' => 'v3/bill/fundflowbill?download_url=111', + '_service_url' => 'v3/bill/fundflowbill?download_url=111', + ], $result->getPayload()->all()); + } +} diff --git a/tests/Plugin/Wechat/Pay/Native/GetTradeBillPluginTest.php b/tests/Plugin/Wechat/Pay/Native/GetTradeBillPluginTest.php new file mode 100644 index 0000000..2966491 --- /dev/null +++ b/tests/Plugin/Wechat/Pay/Native/GetTradeBillPluginTest.php @@ -0,0 +1,49 @@ +plugin = new GetTradeBillPlugin(); + } + + public function testEmptyPayload() + { + $rocket = new Rocket(); + + self::expectException(InvalidParamsException::class); + self::expectExceptionCode(Exception::PARAMS_NECESSARY_PARAMS_MISSING); + self::expectExceptionMessage('参数异常: Native 申请交易账单,参数为空'); + + $this->plugin->assembly($rocket, function ($rocket) { return $rocket; }); + } + + public function testNormal() + { + $rocket = new Rocket(); + $rocket->setPayload(new Collection( [ + "download_url" => "111", + ])); + + $result = $this->plugin->assembly($rocket, function ($rocket) { return $rocket; }); + + self::assertEquals([ + '_method' => 'GET', + '_url' => 'v3/bill/tradebill?download_url=111', + '_service_url' => 'v3/bill/tradebill?download_url=111', + ], $result->getPayload()->all()); + } +} diff --git a/tests/Plugin/Wechat/Pay/Native/PayPluginTest.php b/tests/Plugin/Wechat/Pay/Native/PayPluginTest.php new file mode 100644 index 0000000..43b88f5 --- /dev/null +++ b/tests/Plugin/Wechat/Pay/Native/PayPluginTest.php @@ -0,0 +1,97 @@ +plugin = new PayPlugin(); + } + + public function testEmptyPayload() + { + $rocket = new Rocket(); + + self::expectException(InvalidParamsException::class); + self::expectExceptionCode(Exception::PARAMS_NECESSARY_PARAMS_MISSING); + self::expectExceptionMessage('参数异常: Native 下单,参数为空'); + + $this->plugin->assembly($rocket, function ($rocket) { return $rocket; }); + } + + public function testNormal() + { + $rocket = new Rocket(); + $rocket->setPayload(new Collection( [ + "name" => "yansongda", + ])); + + $result = $this->plugin->assembly($rocket, function ($rocket) { return $rocket; }); + + self::assertEquals([ + '_method' => 'POST', + '_url' => 'v3/pay/transactions/native', + '_service_url' => 'v3/pay/partner/transactions/native', + "appid" => "wx55955316af4ef13", + 'mchid' => '1600314069', + 'notify_url' => 'https://pay.yansongda.cn', + 'name' => 'yansongda', + ], $result->getPayload()->all()); + } + + public function testServiceParams() + { + $rocket = new Rocket(); + $rocket->setParams(['_config' => 'service_provider'])->setPayload(new Collection( [ + 'sub_mchid' => '333', + 'notify_url' => '444', + 'name' => 'yansongda', + ])); + + $result = $this->plugin->assembly($rocket, function ($rocket) { return $rocket; }); + + self::assertEquals([ + '_method' => 'POST', + '_url' => 'v3/pay/transactions/native', + '_service_url' => 'v3/pay/partner/transactions/native', + "sp_appid" => "wx55955316af4ef13", + 'sp_mchid' => '1600314069', + 'sub_mchid' => '333', + 'notify_url' => '444', + 'name' => 'yansongda', + ], $result->getPayload()->all()); + } + + public function testService() + { + $rocket = new Rocket(); + $rocket->setParams(['_config' => 'service_provider'])->setPayload(new Collection( [ + 'name' => 'yansongda', + ])); + + $result = $this->plugin->assembly($rocket, function ($rocket) { return $rocket; }); + + self::assertEquals([ + '_method' => 'POST', + '_url' => 'v3/pay/transactions/native', + '_service_url' => 'v3/pay/partner/transactions/native', + "sp_appid" => "wx55955316af4ef13", + 'sp_mchid' => '1600314069', + 'sub_mchid' => '1600314070', + 'notify_url' => '', + 'name' => 'yansongda', + ], $result->getPayload()->all()); + } +} diff --git a/tests/Plugin/Wechat/Pay/Native/PrepayPluginTest.php b/tests/Plugin/Wechat/Pay/Native/PrepayPluginTest.php deleted file mode 100644 index d0a359c..0000000 --- a/tests/Plugin/Wechat/Pay/Native/PrepayPluginTest.php +++ /dev/null @@ -1,145 +0,0 @@ -plugin = new PrepayPlugin(); - } - - public function testNormal() - { - $rocket = new Rocket(); - $rocket->setParams([])->setPayload(new Collection()); - - $result = $this->plugin->assembly($rocket, function ($rocket) { return $rocket; }); - - $radar = $result->getRadar(); - $payload = $result->getPayload(); - - self::assertInstanceOf(RequestInterface::class, $radar); - self::assertEquals('POST', $radar->getMethod()); - self::assertEquals(new Uri(Wechat::URL[Pay::MODE_NORMAL].'v3/pay/transactions/native'), $radar->getUri()); - self::assertArrayNotHasKey('sp_appid', $payload->all()); - self::assertArrayNotHasKey('sp_mchid', $payload->all()); - self::assertArrayNotHasKey('sub_appid', $payload->all()); - self::assertArrayNotHasKey('sub_mchid', $payload->all()); - self::assertEquals('wx55955316af4ef13', $payload->get('appid')); - self::assertEquals('1600314069', $payload->get('mchid')); - } - - public function testNormalType() - { - $rocket = new Rocket(); - $rocket->setParams(['_type' => 'mini'])->setPayload(new Collection()); - - $result = $this->plugin->assembly($rocket, function ($rocket) { return $rocket; }); - - $radar = $result->getRadar(); - $payload = $result->getPayload(); - - self::assertInstanceOf(RequestInterface::class, $radar); - self::assertEquals('POST', $radar->getMethod()); - self::assertEquals(new Uri(Wechat::URL[Pay::MODE_NORMAL].'v3/pay/transactions/native'), $radar->getUri()); - self::assertArrayNotHasKey('sp_appid', $payload->all()); - self::assertArrayNotHasKey('sp_mchid', $payload->all()); - self::assertArrayNotHasKey('sub_appid', $payload->all()); - self::assertArrayNotHasKey('sub_mchid', $payload->all()); - self::assertEquals('wx55955316af4ef14', $payload->get('appid')); - self::assertEquals('1600314069', $payload->get('mchid')); - } - - public function testNormalTypeApp() - { - $rocket = new Rocket(); - $rocket->setParams(['_type' => 'app'])->setPayload(new Collection()); - - $result = $this->plugin->assembly($rocket, function ($rocket) { return $rocket; }); - - $radar = $result->getRadar(); - $payload = $result->getPayload(); - - self::assertInstanceOf(RequestInterface::class, $radar); - self::assertEquals('POST', $radar->getMethod()); - self::assertEquals(new Uri(Wechat::URL[Pay::MODE_NORMAL].'v3/pay/transactions/native'), $radar->getUri()); - self::assertArrayNotHasKey('sp_appid', $payload->all()); - self::assertArrayNotHasKey('sp_mchid', $payload->all()); - self::assertArrayNotHasKey('sub_appid', $payload->all()); - self::assertArrayNotHasKey('sub_mchid', $payload->all()); - self::assertEquals('yansongda', $payload->get('appid')); - self::assertEquals('1600314069', $payload->get('mchid')); - } - - public function testPartner() - { - $rocket = new Rocket(); - $rocket->setParams(['_config' => 'service_provider'])->setPayload(new Collection()); - - $result = $this->plugin->assembly($rocket, function ($rocket) { return $rocket; }); - - $radar = $result->getRadar(); - $payload = $result->getPayload(); - - self::assertInstanceOf(RequestInterface::class, $radar); - self::assertEquals('POST', $radar->getMethod()); - self::assertEquals(new Uri(Wechat::URL[Pay::MODE_SERVICE].'v3/pay/partner/transactions/native'), $radar->getUri()); - self::assertArrayNotHasKey('appid', $payload->all()); - self::assertArrayNotHasKey('mchid', $payload->all()); - self::assertEquals('wx55955316af4ef13', $payload->get('sp_appid')); - self::assertEquals('1600314069', $payload->get('sp_mchid')); - self::assertEquals('wx55955316af4ef15', $payload->get('sub_appid')); - self::assertEquals('1600314070', $payload->get('sub_mchid')); - } - - public function testPartnerType() - { - $rocket = new Rocket(); - $rocket->setParams(['_config' => 'service_provider', '_type' => 'mini'])->setPayload(new Collection()); - - $result = $this->plugin->assembly($rocket, function ($rocket) { return $rocket; }); - - $radar = $result->getRadar(); - $payload = $result->getPayload(); - - self::assertInstanceOf(RequestInterface::class, $radar); - self::assertEquals('POST', $radar->getMethod()); - self::assertEquals(new Uri(Wechat::URL[Pay::MODE_SERVICE].'v3/pay/partner/transactions/native'), $radar->getUri()); - self::assertArrayNotHasKey('appid', $payload->all()); - self::assertArrayNotHasKey('mchid', $payload->all()); - self::assertEquals('wx55955316af4ef14', $payload->get('sp_appid')); - self::assertEquals('1600314069', $payload->get('sp_mchid')); - self::assertEquals('wx55955316af4ef17', $payload->get('sub_appid')); - self::assertEquals('1600314070', $payload->get('sub_mchid')); - } - - public function testPartnerDirectPayload() - { - $rocket = new Rocket(); - $rocket->setParams(['_config' => 'service_provider'])->setPayload(new Collection(['sub_appid' => '123'])); - - $result = $this->plugin->assembly($rocket, function ($rocket) { return $rocket; }); - - $payload = $result->getPayload(); - - self::assertEquals('123', $payload->get('sub_appid')); - self::assertEquals('1600314070', $payload->get('sub_mchid')); - } -} diff --git a/tests/Plugin/Wechat/Pay/Native/QueryByWxPluginTest.php b/tests/Plugin/Wechat/Pay/Native/QueryByWxPluginTest.php new file mode 100644 index 0000000..82ec228 --- /dev/null +++ b/tests/Plugin/Wechat/Pay/Native/QueryByWxPluginTest.php @@ -0,0 +1,73 @@ +plugin = new QueryByWxPlugin(); + } + + public function testEmptyPayload() + { + $rocket = new Rocket(); + + self::expectException(InvalidParamsException::class); + self::expectExceptionCode(Exception::PARAMS_NECESSARY_PARAMS_MISSING); + self::expectExceptionMessage('参数异常: Native 通过微信订单号查询订单,参数缺少 `transaction_id`'); + + $this->plugin->assembly($rocket, function ($rocket) { return $rocket; }); + } + + public function testNormal() + { + $rocket = new Rocket(); + $rocket->setPayload(new Collection( [ + "transaction_id" => "111", + ])); + + $result = $this->plugin->assembly($rocket, function ($rocket) { return $rocket; }); + + self::assertEquals('GET', $result->getPayload()->get('_method')); + self::assertEquals('v3/pay/transactions/id/111?mchid=1600314069', $result->getPayload()->get('_url')); + } + + public function testServiceParams() + { + $rocket = new Rocket(); + $rocket->setPayload(new Collection( [ + "transaction_id" => "111", + 'sub_mchid' => '333', + ])); + + $result = $this->plugin->assembly($rocket, function ($rocket) { return $rocket; }); + + self::assertEquals('GET', $result->getPayload()->get('_method')); + self::assertEquals('v3/pay/partner/transactions/id/111?sp_mchid=1600314069&sub_mchid=333', $result->getPayload()->get('_service_url')); + } + + public function testService() + { + $rocket = new Rocket(); + $rocket->setParams(['_config' => 'service_provider'])->setPayload(new Collection( [ + "transaction_id" => "111", + ])); + + $result = $this->plugin->assembly($rocket, function ($rocket) { return $rocket; }); + + self::assertEquals('GET', $result->getPayload()->get('_method')); + self::assertEquals('v3/pay/partner/transactions/id/111?sp_mchid=1600314069&sub_mchid=1600314070', $result->getPayload()->get('_service_url')); + } +} diff --git a/tests/Plugin/Wechat/Pay/Native/QueryPluginTest.php b/tests/Plugin/Wechat/Pay/Native/QueryPluginTest.php new file mode 100644 index 0000000..04375df --- /dev/null +++ b/tests/Plugin/Wechat/Pay/Native/QueryPluginTest.php @@ -0,0 +1,73 @@ +plugin = new QueryPlugin(); + } + + public function testEmptyPayload() + { + $rocket = new Rocket(); + + self::expectException(InvalidParamsException::class); + self::expectExceptionCode(Exception::PARAMS_NECESSARY_PARAMS_MISSING); + self::expectExceptionMessage('参数异常: Native 通过商户订单号查询订单,参数缺少 `out_trade_no`'); + + $this->plugin->assembly($rocket, function ($rocket) { return $rocket; }); + } + + public function testNormal() + { + $rocket = new Rocket(); + $rocket->setPayload(new Collection( [ + "out_trade_no" => "111", + ])); + + $result = $this->plugin->assembly($rocket, function ($rocket) { return $rocket; }); + + self::assertEquals('GET', $result->getPayload()->get('_method')); + self::assertEquals('v3/pay/transactions/out-trade-no/111?mchid=1600314069', $result->getPayload()->get('_url')); + } + + public function testServiceParams() + { + $rocket = new Rocket(); + $rocket->setPayload(new Collection( [ + "out_trade_no" => "111", + 'sub_mchid' => '333', + ])); + + $result = $this->plugin->assembly($rocket, function ($rocket) { return $rocket; }); + + self::assertEquals('GET', $result->getPayload()->get('_method')); + self::assertEquals('v3/pay/partner/transactions/out-trade-no/111?sp_mchid=1600314069&sub_mchid=333', $result->getPayload()->get('_service_url')); + } + + public function testService() + { + $rocket = new Rocket(); + $rocket->setParams(['_config' => 'service_provider'])->setPayload(new Collection( [ + "out_trade_no" => "111", + ])); + + $result = $this->plugin->assembly($rocket, function ($rocket) { return $rocket; }); + + self::assertEquals('GET', $result->getPayload()->get('_method')); + self::assertEquals('v3/pay/partner/transactions/out-trade-no/111?sp_mchid=1600314069&sub_mchid=1600314070', $result->getPayload()->get('_service_url')); + } +} diff --git a/tests/Plugin/Wechat/Pay/Native/QueryRefundPluginTest.php b/tests/Plugin/Wechat/Pay/Native/QueryRefundPluginTest.php new file mode 100644 index 0000000..b3b99f0 --- /dev/null +++ b/tests/Plugin/Wechat/Pay/Native/QueryRefundPluginTest.php @@ -0,0 +1,73 @@ +plugin = new QueryRefundPlugin(); + } + + public function testEmptyPayload() + { + $rocket = new Rocket(); + + self::expectException(InvalidParamsException::class); + self::expectExceptionCode(Exception::PARAMS_NECESSARY_PARAMS_MISSING); + self::expectExceptionMessage('参数异常: Native 查询退款订单,参数缺少 `out_refund_no`'); + + $this->plugin->assembly($rocket, function ($rocket) { return $rocket; }); + } + + public function testNormal() + { + $rocket = new Rocket(); + $rocket->setPayload(new Collection( [ + "out_refund_no" => "111", + ])); + + $result = $this->plugin->assembly($rocket, function ($rocket) { return $rocket; }); + + self::assertEquals('GET', $result->getPayload()->get('_method')); + self::assertEquals('v3/refund/domestic/refunds/111', $result->getPayload()->get('_url')); + } + + public function testServiceParams() + { + $rocket = new Rocket(); + $rocket->setPayload(new Collection( [ + "out_refund_no" => "111", + 'sub_mchid' => '333', + ])); + + $result = $this->plugin->assembly($rocket, function ($rocket) { return $rocket; }); + + self::assertEquals('GET', $result->getPayload()->get('_method')); + self::assertEquals('v3/refund/domestic/refunds/111?sub_mchid=333', $result->getPayload()->get('_service_url')); + } + + public function testService() + { + $rocket = new Rocket(); + $rocket->setParams(['_config' => 'service_provider'])->setPayload(new Collection( [ + "out_refund_no" => "111", + ])); + + $result = $this->plugin->assembly($rocket, function ($rocket) { return $rocket; }); + + self::assertEquals('GET', $result->getPayload()->get('_method')); + self::assertEquals('v3/refund/domestic/refunds/111?sub_mchid=1600314070', $result->getPayload()->get('_service_url')); + } +} diff --git a/tests/Plugin/Wechat/Pay/Native/RefundPluginTest.php b/tests/Plugin/Wechat/Pay/Native/RefundPluginTest.php new file mode 100644 index 0000000..8f80ebb --- /dev/null +++ b/tests/Plugin/Wechat/Pay/Native/RefundPluginTest.php @@ -0,0 +1,110 @@ +plugin = new RefundPlugin(); + } + + public function testEmptyPayload() + { + $rocket = new Rocket(); + + self::expectException(InvalidParamsException::class); + self::expectExceptionCode(Exception::PARAMS_NECESSARY_PARAMS_MISSING); + self::expectExceptionMessage('参数异常: Native 退款申请,参数为空'); + + $this->plugin->assembly($rocket, function ($rocket) { return $rocket; }); + } + + public function testNormalParams() + { + $rocket = new Rocket(); + $rocket->setPayload(new Collection( [ + "notify_url" => "111", + 'name' => '222', + ])); + + $result = $this->plugin->assembly($rocket, function ($rocket) { return $rocket; }); + + self::assertEquals([ + '_method' => 'POST', + '_url' => 'v3/refund/domestic/refunds', + '_service_url' => 'v3/refund/domestic/refunds', + 'notify_url' => '111', + 'name' => '222', + ], $result->getPayload()->all()); + } + + public function testNormal() + { + $rocket = new Rocket(); + $rocket->setPayload(new Collection( [ + "out_trade_no" => "111", + ])); + + $result = $this->plugin->assembly($rocket, function ($rocket) { return $rocket; }); + + self::assertEquals([ + '_method' => 'POST', + '_url' => 'v3/refund/domestic/refunds', + '_service_url' => 'v3/refund/domestic/refunds', + 'notify_url' => 'https://pay.yansongda.cn', + 'out_trade_no' => '111', + ], $result->getPayload()->all()); + } + + public function testServiceParams() + { + $rocket = new Rocket(); + $rocket->setParams(['_config' => 'service_provider'])->setPayload(new Collection( [ + "notify_url" => "111", + 'sub_mchid' => '222', + 'name' => 'yansongda', + ])); + + $result = $this->plugin->assembly($rocket, function ($rocket) { return $rocket; }); + + self::assertEquals([ + '_method' => 'POST', + '_url' => 'v3/refund/domestic/refunds', + '_service_url' => 'v3/refund/domestic/refunds', + 'notify_url' => '111', + 'sub_mchid' => '222', + 'name' => 'yansongda', + ], $result->getPayload()->all()); + } + + public function testService() + { + $rocket = new Rocket(); + $rocket->setParams(['_config' => 'service_provider'])->setPayload(new Collection([ + 'name' => 'yansongda', + ])); + + $result = $this->plugin->assembly($rocket, function ($rocket) { return $rocket; }); + + self::assertEquals([ + '_method' => 'POST', + '_url' => 'v3/refund/domestic/refunds', + '_service_url' => 'v3/refund/domestic/refunds', + 'name' => 'yansongda', + 'notify_url' => null, + 'sub_mchid' => '1600314070', + ], $result->getPayload()->all()); + } +} diff --git a/tests/Plugin/Wechat/Pay/Pos/PayPluginTest.php b/tests/Plugin/Wechat/Pay/Pos/PayPluginTest.php deleted file mode 100644 index fc6c12d..0000000 --- a/tests/Plugin/Wechat/Pay/Pos/PayPluginTest.php +++ /dev/null @@ -1,58 +0,0 @@ -plugin = new PayPlugin(); - } - - public function testNormal() - { - $rocket = new Rocket(); - $rocket->setParams([])->setPayload(new Collection(['out_trade_no' => '123'])); - - $result = $this->plugin->assembly($rocket, function ($rocket) { return $rocket; }); - - $radar = $result->getRadar(); - $payload = $result->getPayload(); - $params = $result->getParams(); - - self::assertEquals(new Uri(Wechat::URL[Pay::MODE_NORMAL].'pay/micropay'), $radar->getUri()); - self::assertEquals('POST', $radar->getMethod()); - self::assertEquals('1600314069', $payload->get('mch_id')); - self::assertEquals('wx55955316af4ef13', $payload->get('appid')); - self::assertEquals('v2', $params['_version']); - self::assertEquals('application/xml', $radar->getHeaderLine('Content-Type')); - self::assertEquals('yansongda/pay-v3', $radar->getHeaderLine('User-Agent')); - } - - public function testMultiType() - { - $rocket = new Rocket(); - $rocket->setParams(['_type' => 'app'])->setPayload(new Collection()); - - $result = $this->plugin->assembly($rocket, function ($rocket) { return $rocket; }); - - $radar = $result->getRadar(); - $payload = $result->getPayload(); - - self::assertEquals(new Uri(Wechat::URL[Pay::MODE_NORMAL].'pay/micropay'), $radar->getUri()); - self::assertEquals('POST', $radar->getMethod()); - self::assertEquals('1600314069', $payload->get('mch_id')); - self::assertEquals('yansongda', $payload->get('appid')); - } -} \ No newline at end of file diff --git a/tests/Plugin/Wechat/Pay/Pos/QueryPluginTest.php b/tests/Plugin/Wechat/Pay/Pos/QueryPluginTest.php deleted file mode 100644 index bc7caec..0000000 --- a/tests/Plugin/Wechat/Pay/Pos/QueryPluginTest.php +++ /dev/null @@ -1,34 +0,0 @@ -plugin = new QueryPlugin(); - } - - public function testNormal() - { - $rocket = new Rocket(); - $rocket->setParams([])->setPayload(new Collection(['out_trade_no' => '123'])); - - $result = $this->plugin->assembly($rocket, function ($rocket) { return $rocket; }); - - $radar = $result->getRadar(); - - self::assertEquals(new Uri(Wechat::URL[Pay::MODE_NORMAL].'pay/orderquery'), $radar->getUri()); - } -} \ No newline at end of file diff --git a/tests/Plugin/Wechat/Pay/Pos/QueryRefundPluginTest.php b/tests/Plugin/Wechat/Pay/Pos/QueryRefundPluginTest.php deleted file mode 100644 index 6d1a2bb..0000000 --- a/tests/Plugin/Wechat/Pay/Pos/QueryRefundPluginTest.php +++ /dev/null @@ -1,34 +0,0 @@ -plugin = new QueryRefundPlugin(); - } - - public function testNormal() - { - $rocket = new Rocket(); - $rocket->setParams([])->setPayload(new Collection(['out_trade_no' => '123'])); - - $result = $this->plugin->assembly($rocket, function ($rocket) { return $rocket; }); - - $radar = $result->getRadar(); - - self::assertEquals(new Uri(Wechat::URL[Pay::MODE_NORMAL].'pay/refundquery'), $radar->getUri()); - } -} \ No newline at end of file diff --git a/tests/Plugin/Wechat/Pay/Refund/RefundAbnormalPluginTest.php b/tests/Plugin/Wechat/Pay/Refund/RefundAbnormalPluginTest.php new file mode 100644 index 0000000..da979b6 --- /dev/null +++ b/tests/Plugin/Wechat/Pay/Refund/RefundAbnormalPluginTest.php @@ -0,0 +1,141 @@ +plugin = new RefundAbnormalPlugin(); + } + + public function testEmptyPayload() + { + $rocket = new Rocket(); + + self::expectException(InvalidParamsException::class); + self::expectExceptionCode(Exception::PARAMS_NECESSARY_PARAMS_MISSING); + self::expectExceptionMessage('参数异常: 发起异常退款,参数缺少 `refund_id`'); + + $this->plugin->assembly($rocket, function ($rocket) { return $rocket; }); + } + + public function testNormal() + { + $rocket = new Rocket(); + $rocket->setPayload(new Collection([ + 'refund_id' => '111', + "name" => "yansongda", + ])); + + $result = $this->plugin->assembly($rocket, function ($rocket) { return $rocket; }); + + self::assertEquals([ + '_method' => 'POST', + '_url' => 'v3/refund/domestic/refunds/111/apply-abnormal-refund', + '_service_url' => 'v3/refund/domestic/refunds/111/apply-abnormal-refund', + 'name' => 'yansongda', + ], $result->getPayload()->all()); + } + + public function testNormalWithName() + { + $rocket = new Rocket(); + $rocket->setPayload(new Collection([ + 'refund_id' => '111', + "name" => "yansongda", + 'bank_account' => '222', + 'real_name' => '333', + ])); + + $result = $this->plugin->assembly($rocket, function ($rocket) { return $rocket; }); + + $payload = $result->getPayload()->all(); + + self::assertEquals('POST', $payload['_method']); + self::assertEquals('v3/refund/domestic/refunds/111/apply-abnormal-refund', $payload['_url']); + self::assertEquals('v3/refund/domestic/refunds/111/apply-abnormal-refund', $payload['_service_url']); + self::assertEquals('yansongda', $payload['name']); + self::assertArrayHasKey('bank_account', $payload); + self::assertNotEquals('222', $payload['bank_account']); + self::assertArrayHasKey('real_name', $payload); + self::assertNotEquals('333', $payload['real_name']); + self::assertArrayHasKey('_serial_no', $payload); + } + + public function testServiceParams() + { + $rocket = new Rocket(); + $rocket->setParams(['_config' => 'service_provider'])->setPayload(new Collection( [ + 'sub_mchid' => '111', + 'refund_id' => '222', + 'name' => 'yansongda', + ])); + + $result = $this->plugin->assembly($rocket, function ($rocket) { return $rocket; }); + + self::assertEquals([ + '_method' => 'POST', + '_url' => 'v3/refund/domestic/refunds/222/apply-abnormal-refund', + '_service_url' => 'v3/refund/domestic/refunds/222/apply-abnormal-refund', + 'sub_mchid' => '111', + 'name' => 'yansongda', + ], $result->getPayload()->all()); + } + + public function testService() + { + $rocket = new Rocket(); + $rocket->setParams(['_config' => 'service_provider'])->setPayload(new Collection( [ + 'refund_id' => '222', + 'name' => 'yansongda', + ])); + + $result = $this->plugin->assembly($rocket, function ($rocket) { return $rocket; }); + + self::assertEquals([ + '_method' => 'POST', + '_url' => 'v3/refund/domestic/refunds/222/apply-abnormal-refund', + '_service_url' => 'v3/refund/domestic/refunds/222/apply-abnormal-refund', + 'sub_mchid' => '1600314070', + 'name' => 'yansongda', + ], $result->getPayload()->all()); + } + + public function testServiceWithName() + { + $rocket = new Rocket(); + $rocket->setParams(['_config' => 'service_provider'])->setPayload(new Collection([ + 'refund_id' => '111', + "name" => "yansongda", + 'bank_account' => '222', + 'real_name' => '333', + ])); + + $result = $this->plugin->assembly($rocket, function ($rocket) { return $rocket; }); + + $payload = $result->getPayload()->all(); + + self::assertEquals('POST', $payload['_method']); + self::assertEquals('v3/refund/domestic/refunds/111/apply-abnormal-refund', $payload['_url']); + self::assertEquals('v3/refund/domestic/refunds/111/apply-abnormal-refund', $payload['_service_url']); + self::assertEquals('1600314070', $payload['sub_mchid']); + self::assertEquals('yansongda', $payload['name']); + self::assertArrayHasKey('bank_account', $payload); + self::assertNotEquals('222', $payload['bank_account']); + self::assertArrayHasKey('real_name', $payload); + self::assertNotEquals('333', $payload['real_name']); + self::assertArrayHasKey('_serial_no', $payload); + } +} diff --git a/tests/Plugin/Wechat/LaunchPluginTest.php b/tests/Plugin/Wechat/ResponsePluginTest.php similarity index 62% rename from tests/Plugin/Wechat/LaunchPluginTest.php rename to tests/Plugin/Wechat/ResponsePluginTest.php index 04644ff..db55347 100644 --- a/tests/Plugin/Wechat/LaunchPluginTest.php +++ b/tests/Plugin/Wechat/ResponsePluginTest.php @@ -4,37 +4,23 @@ namespace Yansongda\Pay\Tests\Plugin\Wechat; use GuzzleHttp\Psr7\Response; use GuzzleHttp\Psr7\ServerRequest; +use Yansongda\Pay\Direction\OriginResponseDirection; use Yansongda\Pay\Exception\Exception; use Yansongda\Pay\Exception\InvalidResponseException; -use Yansongda\Pay\Direction\NoHttpRequestDirection; -use Yansongda\Pay\Direction\OriginResponseDirection; -use Yansongda\Pay\Plugin\Wechat\LaunchPlugin; +use Yansongda\Pay\Plugin\Wechat\ResponsePlugin; use Yansongda\Pay\Rocket; use Yansongda\Pay\Tests\TestCase; use Yansongda\Supports\Collection; -class LaunchPluginTest extends TestCase +class ResponsePluginTest extends TestCase { - /** - * @var \Yansongda\Pay\Plugin\Wechat\LaunchPlugin - */ - protected $plugin; + protected ResponsePlugin $plugin; protected function setUp(): void { parent::setUp(); - $this->plugin = new LaunchPlugin(); - } - - public function testShouldNotDoRequest() - { - $rocket = new Rocket(); - $rocket->setDirection(NoHttpRequestDirection::class); - - $result = $this->plugin->assembly($rocket, function ($rocket) { return $rocket; }); - - self::assertSame($rocket, $result); + $this->plugin = new ResponsePlugin(); } public function testOriginalResponseDestination() @@ -66,26 +52,11 @@ class LaunchPluginTest extends TestCase $this->plugin->assembly($rocket, function ($rocket) { return $rocket; }); } - public function testArrayDestination() - { - $destination = []; - - $rocket = new Rocket(); - $rocket->setDirection(OriginResponseDirection::class); - $rocket->setDestination(Collection::wrap($destination)); - $rocket->setDestinationOrigin(new ServerRequest('POST', 'http://localhost')); - - $result = $this->plugin->assembly($rocket, function ($rocket) { return $rocket; }); - - self::assertEquals($destination, $result->getDestination()->toArray()); - } - public function testCollectionDestination() { $destination = new Collection(); $rocket = new Rocket(); - $rocket->setDirection(OriginResponseDirection::class); $rocket->setDestination($destination); $rocket->setDestinationOrigin(new ServerRequest('POST', 'http://localhost')); diff --git a/tests/Plugin/Wechat/Risk/Complaints/CompleteComplaintPluginTest.php b/tests/Plugin/Wechat/Risk/Complaints/CompleteComplaintPluginTest.php deleted file mode 100644 index ffd0652..0000000 --- a/tests/Plugin/Wechat/Risk/Complaints/CompleteComplaintPluginTest.php +++ /dev/null @@ -1,69 +0,0 @@ -plugin = new CompleteComplaintPlugin(); - } - - public function testNormal() - { - $rocket = new Rocket(); - $rocket->setParams([])->setPayload(new Collection(['complaint_id' => '123', 'foo' => 'bar'])); - - $result = $this->plugin->assembly($rocket, function ($rocket) {return $rocket;}); - - $radar = $result->getRadar(); - - self::assertEquals(new Uri(Wechat::URL[Pay::MODE_NORMAL].'v3/merchant-service/complaints-v2/123/complete'), $radar->getUri()); - self::assertEquals(['complainted_mchid' => '1600314069'], $rocket->getPayload()->toArray()); - self::assertEquals('POST', $radar->getMethod()); - self::assertEquals(OriginResponseDirection::class, $result->getDirection()); - } - - public function testDirectMchId() - { - $rocket = new Rocket(); - $rocket->setParams([])->setPayload(new Collection(['complaint_id' => '456', 'complainted_mchid' => 'bar'])); - - $result = $this->plugin->assembly($rocket, function ($rocket) {return $rocket;}); - - $radar = $result->getRadar(); - - self::assertEquals(new Uri(Wechat::URL[Pay::MODE_NORMAL].'v3/merchant-service/complaints-v2/456/complete'), $radar->getUri()); - self::assertEquals(['complainted_mchid' => 'bar'], $rocket->getPayload()->toArray()); - self::assertEquals(OriginResponseDirection::class, $result->getDirection()); - } - - public function testMissingId() - { - $rocket = new Rocket(); - $rocket->setParams([])->setPayload(new Collection()); - - self::expectException(InvalidParamsException::class); - self::expectExceptionCode(Exception::PARAMS_NECESSARY_PARAMS_MISSING); - - $this->plugin->assembly($rocket, function ($rocket) {return $rocket;}); - } -} diff --git a/tests/Plugin/Wechat/Risk/Complaints/DeleteCallbackPluginTest.php b/tests/Plugin/Wechat/Risk/Complaints/DeleteCallbackPluginTest.php deleted file mode 100644 index fc53217..0000000 --- a/tests/Plugin/Wechat/Risk/Complaints/DeleteCallbackPluginTest.php +++ /dev/null @@ -1,42 +0,0 @@ -plugin = new DeleteCallbackPlugin(); - } - - public function testNormal() - { - $rocket = new Rocket(); - $rocket->setParams([])->setPayload(new Collection(['complaint_id' => '123', 'foo' => 'bar'])); - - $result = $this->plugin->assembly($rocket, function ($rocket) {return $rocket;}); - - $radar = $result->getRadar(); - - self::assertEquals(new Uri(Wechat::URL[Pay::MODE_NORMAL].'v3/merchant-service/complaint-notifications'), $radar->getUri()); - self::assertNull($rocket->getPayload()); - self::assertEquals('DELETE', $radar->getMethod()); - self::assertEquals(OriginResponseDirection::class, $rocket->getDirection()); - } -} diff --git a/tests/Plugin/Wechat/Risk/Complaints/DownloadMediaPluginTest.php b/tests/Plugin/Wechat/Risk/Complaints/DownloadMediaPluginTest.php deleted file mode 100644 index c198098..0000000 --- a/tests/Plugin/Wechat/Risk/Complaints/DownloadMediaPluginTest.php +++ /dev/null @@ -1,52 +0,0 @@ -plugin = new DownloadMediaPlugin(); - } - - public function testNormal() - { - $rocket = new Rocket(); - $rocket->setParams([])->setPayload(new Collection(['media_url' => 'https://yansongda.cn'])); - - $result = $this->plugin->assembly($rocket, function ($rocket) { return $rocket; }); - - $radar = $result->getRadar(); - - self::assertEquals(OriginResponseDirection::class, $result->getDirection()); - self::assertEquals('GET', $radar->getMethod()); - self::assertEquals(new Uri('https://yansongda.cn'), $radar->getUri()); - } - - public function testNormalNoDownloadUrl() - { - $rocket = new Rocket(); - $rocket->setParams([])->setPayload(new Collection()); - - self::expectException(InvalidParamsException::class); - self::expectExceptionCode(Exception::PARAMS_NECESSARY_PARAMS_MISSING); - - $this->plugin->assembly($rocket, function ($rocket) { return $rocket; }); - } -} diff --git a/tests/Plugin/Wechat/Risk/Complaints/QueryCallbackPluginTest.php b/tests/Plugin/Wechat/Risk/Complaints/QueryCallbackPluginTest.php deleted file mode 100644 index ea3d34b..0000000 --- a/tests/Plugin/Wechat/Risk/Complaints/QueryCallbackPluginTest.php +++ /dev/null @@ -1,40 +0,0 @@ -plugin = new QueryCallbackPlugin(); - } - - public function testNormal() - { - $rocket = new Rocket(); - $rocket->setParams([])->setPayload(new Collection(['complaint_id' => '123', 'foo' => 'bar'])); - - $result = $this->plugin->assembly($rocket, function ($rocket) {return $rocket;}); - - $radar = $result->getRadar(); - - self::assertEquals(new Uri(Wechat::URL[Pay::MODE_NORMAL].'v3/merchant-service/complaint-notifications'), $radar->getUri()); - self::assertNull($rocket->getPayload()); - self::assertEquals('GET', $radar->getMethod()); - } -} diff --git a/tests/Plugin/Wechat/Risk/Complaints/QueryComplaintDetailPluginTest.php b/tests/Plugin/Wechat/Risk/Complaints/QueryComplaintDetailPluginTest.php deleted file mode 100644 index 8071c92..0000000 --- a/tests/Plugin/Wechat/Risk/Complaints/QueryComplaintDetailPluginTest.php +++ /dev/null @@ -1,53 +0,0 @@ -plugin = new QueryComplaintDetailPlugin(); - } - - public function testNormal() - { - $rocket = new Rocket(); - $rocket->setParams([])->setPayload(new Collection(['complaint_id' => '123', 'foo' => 'bar'])); - - $result = $this->plugin->assembly($rocket, function ($rocket) {return $rocket;}); - - $radar = $result->getRadar(); - - self::assertEquals(new Uri(Wechat::URL[Pay::MODE_NORMAL].'v3/merchant-service/complaints-v2/123'), $radar->getUri()); - self::assertNull($rocket->getPayload()); - self::assertEquals('GET', $radar->getMethod()); - } - - public function testMissingId() - { - $rocket = new Rocket(); - $rocket->setParams([])->setPayload(new Collection()); - - self::expectException(InvalidParamsException::class); - self::expectExceptionCode(Exception::PARAMS_NECESSARY_PARAMS_MISSING); - - $this->plugin->assembly($rocket, function ($rocket) {return $rocket;}); - } -} diff --git a/tests/Plugin/Wechat/Risk/Complaints/QueryComplaintNegotiationPluginTest.php b/tests/Plugin/Wechat/Risk/Complaints/QueryComplaintNegotiationPluginTest.php deleted file mode 100644 index df95a13..0000000 --- a/tests/Plugin/Wechat/Risk/Complaints/QueryComplaintNegotiationPluginTest.php +++ /dev/null @@ -1,53 +0,0 @@ -plugin = new QueryComplaintNegotiationPlugin(); - } - - public function testNormal() - { - $rocket = new Rocket(); - $rocket->setParams([])->setPayload(new Collection(['complaint_id' => '123', 'foo' => 'bar'])); - - $result = $this->plugin->assembly($rocket, function ($rocket) {return $rocket;}); - - $radar = $result->getRadar(); - - self::assertEquals(new Uri(Wechat::URL[Pay::MODE_NORMAL].'v3/merchant-service/complaints-v2/123/negotiation-historys?foo=bar'), $radar->getUri()); - self::assertNull($rocket->getPayload()); - self::assertEquals('GET', $radar->getMethod()); - } - - public function testMissingId() - { - $rocket = new Rocket(); - $rocket->setParams([])->setPayload(new Collection()); - - self::expectException(InvalidParamsException::class); - self::expectExceptionCode(Exception::PARAMS_NECESSARY_PARAMS_MISSING); - - $this->plugin->assembly($rocket, function ($rocket) {return $rocket;}); - } -} diff --git a/tests/Plugin/Wechat/Risk/Complaints/QueryComplaintsPluginTest.php b/tests/Plugin/Wechat/Risk/Complaints/QueryComplaintsPluginTest.php deleted file mode 100644 index 77fdc25..0000000 --- a/tests/Plugin/Wechat/Risk/Complaints/QueryComplaintsPluginTest.php +++ /dev/null @@ -1,40 +0,0 @@ -plugin = new QueryComplaintsPlugin(); - } - - public function testNormal() - { - $rocket = new Rocket(); - $rocket->setParams([])->setPayload(new Collection(['foo' => 'bar', 'name' => 'yansongda'])); - - $result = $this->plugin->assembly($rocket, function ($rocket) {return $rocket;}); - - $radar = $result->getRadar(); - - self::assertEquals(new Uri(Wechat::URL[Pay::MODE_NORMAL].'v3/merchant-service/complaints-v2?foo=bar&name=yansongda'), $radar->getUri()); - self::assertNull($rocket->getPayload()); - self::assertEquals('GET', $radar->getMethod()); - } -} diff --git a/tests/Plugin/Wechat/Risk/Complaints/ResponseComplaintPluginTest.php b/tests/Plugin/Wechat/Risk/Complaints/ResponseComplaintPluginTest.php deleted file mode 100644 index 43a0a97..0000000 --- a/tests/Plugin/Wechat/Risk/Complaints/ResponseComplaintPluginTest.php +++ /dev/null @@ -1,69 +0,0 @@ -plugin = new ResponseComplaintPlugin(); - } - - public function testNormal() - { - $rocket = new Rocket(); - $rocket->setParams([])->setPayload(new Collection(['complaint_id' => '123', 'foo' => 'bar'])); - - $result = $this->plugin->assembly($rocket, function ($rocket) {return $rocket;}); - - $radar = $result->getRadar(); - - self::assertEquals(OriginResponseDirection::class, $result->getDirection()); - self::assertEquals(new Uri(Wechat::URL[Pay::MODE_NORMAL].'v3/merchant-service/complaints-v2/123/response'), $radar->getUri()); - self::assertEquals('POST', $radar->getMethod()); - self::assertEquals(['foo' => 'bar', 'complainted_mchid' => '1600314069'], $rocket->getPayload()->toArray()); - } - - public function testDirectMchId() - { - $rocket = new Rocket(); - $rocket->setParams([])->setPayload(new Collection(['complaint_id' => '456', 'complainted_mchid' => 'bar', 'u' => 'a'])); - - $result = $this->plugin->assembly($rocket, function ($rocket) {return $rocket;}); - - $radar = $result->getRadar(); - - self::assertEquals(OriginResponseDirection::class, $result->getDirection()); - self::assertEquals(new Uri(Wechat::URL[Pay::MODE_NORMAL].'v3/merchant-service/complaints-v2/456/response'), $radar->getUri()); - self::assertEquals(['complainted_mchid' => 'bar', 'u' => 'a'], $rocket->getPayload()->toArray()); - } - - public function testMissingId() - { - $rocket = new Rocket(); - $rocket->setParams([])->setPayload(new Collection()); - - self::expectException(InvalidParamsException::class); - self::expectExceptionCode(Exception::PARAMS_NECESSARY_PARAMS_MISSING); - - $this->plugin->assembly($rocket, function ($rocket) {return $rocket;}); - } -} diff --git a/tests/Plugin/Wechat/Risk/Complaints/SetCallbackPluginTest.php b/tests/Plugin/Wechat/Risk/Complaints/SetCallbackPluginTest.php deleted file mode 100644 index 908f0ac..0000000 --- a/tests/Plugin/Wechat/Risk/Complaints/SetCallbackPluginTest.php +++ /dev/null @@ -1,39 +0,0 @@ -plugin = new SetCallbackPlugin(); - } - - public function testNormal() - { - $rocket = new Rocket(); - $rocket->setParams([])->setPayload(new Collection(['url' => 'bar'])); - - $result = $this->plugin->assembly($rocket, function ($rocket) {return $rocket;}); - - $radar = $result->getRadar(); - - self::assertEquals(new Uri(Wechat::URL[Pay::MODE_NORMAL].'v3/merchant-service/complaint-notifications'), $radar->getUri()); - self::assertEquals(['url' => 'bar'], $rocket->getPayload()->toArray()); - } -} diff --git a/tests/Plugin/Wechat/Risk/Complaints/UpdateCallbackPluginTest.php b/tests/Plugin/Wechat/Risk/Complaints/UpdateCallbackPluginTest.php deleted file mode 100644 index 5ca04f6..0000000 --- a/tests/Plugin/Wechat/Risk/Complaints/UpdateCallbackPluginTest.php +++ /dev/null @@ -1,40 +0,0 @@ -plugin = new UpdateCallbackPlugin(); - } - - public function testNormal() - { - $rocket = new Rocket(); - $rocket->setParams([])->setPayload(new Collection(['url' => 'bar'])); - - $result = $this->plugin->assembly($rocket, function ($rocket) {return $rocket;}); - - $radar = $result->getRadar(); - - self::assertEquals(new Uri(Wechat::URL[Pay::MODE_NORMAL].'v3/merchant-service/complaint-notifications'), $radar->getUri()); - self::assertEquals(['url' => 'bar'], $rocket->getPayload()->toArray()); - self::assertEquals('PUT', $radar->getMethod()); - } -} diff --git a/tests/Plugin/Wechat/Risk/Complaints/UpdateRefundPluginTest.php b/tests/Plugin/Wechat/Risk/Complaints/UpdateRefundPluginTest.php deleted file mode 100644 index d9c73f0..0000000 --- a/tests/Plugin/Wechat/Risk/Complaints/UpdateRefundPluginTest.php +++ /dev/null @@ -1,53 +0,0 @@ -plugin = new UpdateRefundPlugin(); - } - - public function testNormal() - { - $rocket = new Rocket(); - $rocket->setParams([])->setPayload(new Collection(['complaint_id' => '123', 'foo' => 'bar'])); - - $result = $this->plugin->assembly($rocket, function ($rocket) {return $rocket;}); - - $radar = $result->getRadar(); - - self::assertEquals(new Uri(Wechat::URL[Pay::MODE_NORMAL].'v3/merchant-service/complaints-v2/123/update-refund-progress'), $radar->getUri()); - self::assertEquals('POST', $radar->getMethod()); - self::assertEquals(['foo' => 'bar'], $rocket->getPayload()->toArray()); - } - - public function testMissingId() - { - $rocket = new Rocket(); - $rocket->setParams([])->setPayload(new Collection()); - - self::expectException(InvalidParamsException::class); - self::expectExceptionCode(Exception::PARAMS_NECESSARY_PARAMS_MISSING); - - $this->plugin->assembly($rocket, function ($rocket) {return $rocket;}); - } -} diff --git a/tests/Plugin/Wechat/PreparePluginTest.php b/tests/Plugin/Wechat/StartPluginTest.php similarity index 69% rename from tests/Plugin/Wechat/PreparePluginTest.php rename to tests/Plugin/Wechat/StartPluginTest.php index 013a7ef..e3a66d6 100644 --- a/tests/Plugin/Wechat/PreparePluginTest.php +++ b/tests/Plugin/Wechat/StartPluginTest.php @@ -2,22 +2,19 @@ namespace Yansongda\Pay\Tests\Plugin\Wechat; -use Yansongda\Pay\Plugin\Wechat\PreparePlugin; +use Yansongda\Pay\Plugin\Wechat\StartPlugin; use Yansongda\Pay\Rocket; use Yansongda\Pay\Tests\TestCase; -class PreparePluginTest extends TestCase +class StartPluginTest extends TestCase { - /** - * @var \Yansongda\Pay\Plugin\Wechat\PreparePlugin - */ - protected $plugin; + protected StartPlugin $plugin; protected function setUp(): void { parent::setUp(); - $this->plugin = new PreparePlugin(); + $this->plugin = new StartPlugin(); } public function testNormal() @@ -34,6 +31,6 @@ class PreparePluginTest extends TestCase self::assertEquals('yansongda', $payload['name']); self::assertArrayNotHasKey('aaa', $payload); - self::assertArrayNotHasKey('_aaa', $payload); + self::assertArrayHasKey('_aaa', $payload); } } diff --git a/tests/Plugin/Wechat/VerifySignaturePluginTest.php b/tests/Plugin/Wechat/VerifySignaturePluginTest.php new file mode 100644 index 0000000..cada5c6 --- /dev/null +++ b/tests/Plugin/Wechat/VerifySignaturePluginTest.php @@ -0,0 +1,55 @@ +plugin = new VerifySignaturePlugin(); + } + + public function testShouldNotDoRequest() + { + $rocket = new Rocket(); + $rocket->setDirection(NoHttpRequestDirection::class)->setDestinationOrigin(new Response()); + $result = $this->plugin->assembly($rocket, function ($rocket) { return $rocket; }); + self::assertSame($rocket, $result); + + $rocket = new Rocket(); + $rocket->setDestinationOrigin(null); + $result = $this->plugin->assembly($rocket, function ($rocket) { return $rocket; }); + self::assertSame($rocket, $result); + } + + public function testNormal() + { + $response = new Response( + 200, + [ + 'Wechatpay-Nonce' => 'e59e78a6c3f7dfd7e84aabee71be0452', + 'Wechatpay-Signature' => 'Bb10ZUsON47E/qLjecjk6ESLt7obZCvCCAXAEoD1Q+K548fz9h6YBgR3PZzviTmjsA3/r22qEC3r/yelFAn4pl4rJBGqrjo4ODJkOPlaDnHZwYotDvf6RcASpKB9ExCb33hAijHCiMzr9V9skNrj5F9eXc96lNZN3R5MVLsTF97nV922JIzyCrZ668khYPrn1jl5pCBpYDQ3rskgmZ+nnjg7M9vRAfTowEydSEGtsKjXUSaaKui2RDUuX8ZwxVcBTRng978Gh9s4mdRxs+mlv3gP1xQHdpa0mYMG0yGzLcWOTgrkt27sAwFnuXj9WtlEAgz/1DYntujKPxilMVGRow==', + 'Wechatpay-Timestamp' => '1626444144', + 'Wechatpay-Serial' => '45F59D4DABF31918AFCEC556D5D2C6E376675D57', + ], + json_encode(['h5_url' => 'https://wx.tenpay.com/cgi-bin/mmpayweb-bin/checkmweb?prepay_id=wx16220223998099f898c5b24eed5c320000&package=4049184564'], JSON_UNESCAPED_SLASHES), + ); + + $rocket = new Rocket(); + $rocket->setDestinationOrigin($response); + + $this->plugin->assembly($rocket, function ($rocket) { return $rocket; }); + + self::assertTrue(true); + } +} diff --git a/tests/Plugin/Wechat/WechatPublicCertsPluginTest.php b/tests/Plugin/Wechat/WechatPublicCertsPluginTest.php new file mode 100644 index 0000000..3bd6928 --- /dev/null +++ b/tests/Plugin/Wechat/WechatPublicCertsPluginTest.php @@ -0,0 +1,33 @@ +plugin = new WechatPublicCertsPlugin(); + } + + public function testNormal() + { + $rocket = (new Rocket())->setParams(['aaa' => 'bbb'])->setPayload(['name' => 'yansongda']); + + $result = $this->plugin->assembly($rocket, function ($rocket) { return $rocket; }); + + $payload = $result->getPayload()->all(); + + self::assertEquals('GET', $payload['_method']); + self::assertEquals('v3/certificates', $payload['_url']); + self::assertArrayNotHasKey('aaa', $payload); + self::assertArrayNotHasKey('name', $payload); + } +} diff --git a/tests/Provider/AlipayTest.php b/tests/Provider/AlipayTest.php index e2566e0..da9191c 100644 --- a/tests/Provider/AlipayTest.php +++ b/tests/Provider/AlipayTest.php @@ -12,8 +12,8 @@ use Yansongda\Pay\Exception\Exception; use Yansongda\Pay\Exception\InvalidParamsException; use Yansongda\Pay\Pay; use Yansongda\Pay\Plugin\Alipay\AddRadarPlugin; -use Yansongda\Pay\Plugin\Alipay\AddSignaturePlugin; -use Yansongda\Pay\Plugin\Alipay\FormatBizContentPlugin; +use Yansongda\Pay\Plugin\Alipay\AddPayloadSignaturePlugin; +use Yansongda\Pay\Plugin\Alipay\FormatPayloadBizContentPlugin; use Yansongda\Pay\Plugin\Alipay\ResponsePlugin; use Yansongda\Pay\Plugin\Alipay\StartPlugin; use Yansongda\Pay\Plugin\Alipay\VerifySignaturePlugin; @@ -70,28 +70,81 @@ class AlipayTest extends TestCase self::assertEqualsCanonicalizing($response['alipay_trade_query_response'], $result->except('_sign')->all()); } - public function testQueryTransfer() + public function testTransfer() { $response = [ - "alipay_fund_trans_common_query_response" => [ + "alipay_fund_trans_uni_transfer_response" => [ "code" => "10000", "msg" => "Success", - "order_id" => "20231220110070000002150000657610", - "out_biz_no" => "2023122022560000", - "pay_date" => "2023-12-20 22:56:33", - "pay_fund_order_id" => "20231220110070001502150000660902", + "order_id" => "20231226110070000002150000683137", + "out_biz_no" => "2023122621450001", + "pay_fund_order_id" => "20231226110070001502150000685481", "status" => "SUCCESS", - "trans_amount" => "0.01", + "trans_date" => "2023-12-26 22:11:45", ], - "sign" => "eITxP5fZiJPB2+vZb90IRkv2iARxeNx/6Omxk7FStqflhG5lMoCvGjo2FZ6Szo1bGBMBReazZuqLaqsgomWAUO9onMVurB3enLbRvwUlpE7XEZaxk/sJYjgc2Y7pIAenvnLL9PEAiXmvUvuinUlvS9J2r1XysC0p/2wu7kEJ/GgZpFDIIYY9mdM6U1rGbi+RvirQXtQHmaEuuJWLA75NR1bvfG3L8znzW9xz1kOQqOWsQmD/bF1CDWbozNLwLCUmClRJz0Fj4mUYRF0zbW2VP8ZgHu1YvVKJ2+dWC9b+0o94URk7psIpc5NjiOM9Jsn6aoC2CfrJ/sqFMRCkYWzw6A==", + "sign" => "exg0CUSgsRvI+q/Qqyu+MJ17ao4+vnEUMRE4YNbN2H3K6iX3xBcZv9jTt6m6c9JLZIifbqkZU13PLa4zy1MaQnQKg676wbqpN7ybEVL7LMzAgXUFm3Dc0XL1minPie2XOtwIgEecoPwpEqvqjjdTXfaE7fT6ZLxFLMMlPAESGwDDnKQVUmWs/8oq/EdPDNtVMmoVbF4o9zizyHw/QHVpLYvt0DHNCZRLhY85V99W6CrHjkNTB1QzEb1vCe3okVT3UAq26sxpu46R5l3n0xKJiYrucs8Y6CEWmayTKmZou7WQdgKQJHC0x0OIN58zWBkAFwz9ZAGON/WO3YHWq6mi5A==", ]; $http = Mockery::mock(Client::class); $http->shouldReceive('sendRequest')->andReturn(new Response(200, [], json_encode($response))); Pay::set(HttpClientInterface::class, $http); - $result = Pay::alipay()->query(['out_biz_no' => '202209032319', '_action' => 'transfer']); - self::assertEqualsCanonicalizing($response['alipay_fund_trans_common_query_response'], $result->except('_sign')->all()); + $result = Pay::alipay()->transfer([ + 'out_biz_no' => '2023122621450001', + 'trans_amount' => '0.01', + 'product_code' => 'TRANS_ACCOUNT_NO_PWD', + 'biz_scene' => 'DIRECT_TRANSFER', + 'payee_info' => [ + 'identity' => 'ifvlwp1413@sandbox.com', + 'identity_type' => 'ALIPAY_LOGON_ID', + 'name' => 'ifvlwp1413' + ], + '_return_rocket' => true, + ]); + + // 支付宝参数里有实时时间,导致签名不一样,这里只验证签名之前的部分 + $body1 = 'app_id=9021000122682882&method=alipay.fund.trans.uni.transfer&format=JSON&return_url=https%3A%2F%2Fpay.yansongda.cn&charset=utf-8&sign_type=RSA2×tamp='; + $body2 = '&version=1.0¬ify_url=https%3A%2F%2Fpay.yansongda.cn&app_cert_sn=e90dd23a37c5c7b616e003970817ff82&alipay_root_cert_sn=687b59193f3f462dd5336e5abf83c5d8_02941eef3187dddf3d3b83462e1dfcf6&biz_content=%7B%22biz_scene%22%3A%22DIRECT_TRANSFER%22%2C%22product_code%22%3A%22TRANS_ACCOUNT_NO_PWD%22%2C%22out_biz_no%22%3A%222023122621450001%22%2C%22trans_amount%22%3A%220.01%22%2C%22payee_info%22%3A%7B%22identity%22%3A%22ifvlwp1413%40sandbox.com%22%2C%22identity_type%22%3A%22ALIPAY_LOGON_ID%22%2C%22name%22%3A%22ifvlwp1413%22%7D%7D&sign='; + + self::assertStringContainsString($body1, (string) $result->getRadar()->getBody()); + self::assertStringContainsString($body2, (string) $result->getRadar()->getBody()); + self::assertEqualsCanonicalizing($response['alipay_fund_trans_uni_transfer_response'], $result->getDestination()->except('_sign')->all()); + } + + public function testQueryTransfer() + { + $response = [ + "alipay_fund_trans_common_query_response" => [ + "code" => "10000", + "msg" => "Success", + "order_id" => "20231226110070000002150000683137", + "out_biz_no" => "2023122621450001", + "pay_date" => "2023-12-26 22:11:45", + "pay_fund_order_id" => "20231226110070001502150000685481", + "status" => "SUCCESS", + "trans_amount" => "0.01", + ], + "sign" => "AVEw2M/E95HJvcUVS05s/ABD96Hlw0IlGyjz36IjFMmb2u0Qviz/ZSBGnSdW4XH4Nda80h4hmiuslp7vnydeZKiyMUMms1wq8YZGYCjrBPs1pj898wPT22foVWEIAmwZYQ1ixJtmycYd8wZfg0y+fuLiSYifsik4OyQ8SGam1k0RqB1Qje0v8WKLtsrZszw0zDp9vYbPuCTLkgmT0gGRxHoUOP2JLfpK/uJs54tECVF9FUEVJmeBM8TvTxgMPB0b32MOzOtI1JB8qE/Gn7RaMbTVrQQZNCSEHhjhaCvHoBo3xVbx8Rcq6Xl2Nf0N8uEmK6UQqqLh//IW4nWs0T4HHQ==", + ]; + + $http = Mockery::mock(Client::class); + $http->shouldReceive('sendRequest')->andReturn(new Response(200, [], json_encode($response))); + Pay::set(HttpClientInterface::class, $http); + + $result = Pay::alipay()->query([ + 'out_biz_no' => '2023122621450001', + 'product_code' => 'TRANS_ACCOUNT_NO_PWD', + 'biz_scene' => 'DIRECT_TRANSFER', + '_action' => 'transfer', + '_return_rocket' => true, + ]); + + $body1 = 'app_id=9021000122682882&method=alipay.fund.trans.common.query&format=JSON&return_url=https%3A%2F%2Fpay.yansongda.cn&charset=utf-8&sign_type=RSA2×tamp='; + $body2 = '&version=1.0¬ify_url=https%3A%2F%2Fpay.yansongda.cn&app_cert_sn=e90dd23a37c5c7b616e003970817ff82&alipay_root_cert_sn=687b59193f3f462dd5336e5abf83c5d8_02941eef3187dddf3d3b83462e1dfcf6&biz_content=%7B%22out_biz_no%22%3A%222023122621450001%22%2C%22product_code%22%3A%22TRANS_ACCOUNT_NO_PWD%22%2C%22biz_scene%22%3A%22DIRECT_TRANSFER%22%7D&sign='; + + self::assertStringContainsString($body1, (string) $result->getRadar()->getBody()); + self::assertStringContainsString($body2, (string) $result->getRadar()->getBody()); + self::assertEqualsCanonicalizing($response['alipay_fund_trans_common_query_response'], $result->getDestination()->except('_sign')->all()); } public function testQueryRefund() @@ -200,7 +253,7 @@ class AlipayTest extends TestCase self::assertEquals(array_merge( [StartPlugin::class], $plugins, - [FormatBizContentPlugin::class, AddSignaturePlugin::class, AddRadarPlugin::class, VerifySignaturePlugin::class, ResponsePlugin::class, ParserPlugin::class], + [FormatPayloadBizContentPlugin::class, AddPayloadSignaturePlugin::class, AddRadarPlugin::class, VerifySignaturePlugin::class, ResponsePlugin::class, ParserPlugin::class], ), Pay::alipay()->mergeCommonPlugins($plugins)); } diff --git a/tests/Provider/WechatTest.php b/tests/Provider/WechatTest.php index 443d7b8..d0b36a8 100644 --- a/tests/Provider/WechatTest.php +++ b/tests/Provider/WechatTest.php @@ -12,9 +12,12 @@ use Yansongda\Pay\Exception\Exception; use Yansongda\Pay\Exception\InvalidParamsException; use Yansongda\Pay\Pay; use Yansongda\Pay\Plugin\ParserPlugin; -use Yansongda\Pay\Plugin\Wechat\LaunchPlugin; -use Yansongda\Pay\Plugin\Wechat\PreparePlugin; -use Yansongda\Pay\Plugin\Wechat\RadarSignPlugin; +use Yansongda\Pay\Plugin\Wechat\AddPayloadBodyPlugin; +use Yansongda\Pay\Plugin\Wechat\AddPayloadSignaturePlugin; +use Yansongda\Pay\Plugin\Wechat\AddRadarPlugin; +use Yansongda\Pay\Plugin\Wechat\ResponsePlugin; +use Yansongda\Pay\Plugin\Wechat\StartPlugin; +use Yansongda\Pay\Plugin\Wechat\VerifySignaturePlugin; use Yansongda\Pay\Tests\Stubs\Plugin\FooPluginStub; use Yansongda\Pay\Tests\TestCase; @@ -42,10 +45,9 @@ class WechatTest extends TestCase $plugins = [FooPluginStub::class]; self::assertEquals(array_merge( - [PreparePlugin::class], + [StartPlugin::class], $plugins, - [RadarSignPlugin::class], - [LaunchPlugin::class, ParserPlugin::class], + [AddPayloadBodyPlugin::class, AddPayloadSignaturePlugin::class, AddRadarPlugin::class, ResponsePlugin::class, VerifySignaturePlugin::class, ParserPlugin::class], ), Pay::wechat()->mergeCommonPlugins($plugins)); } diff --git a/tests/Shortcut/Alipay/AppShortcutTest.php b/tests/Shortcut/Alipay/AppShortcutTest.php index ab8f732..175f015 100644 --- a/tests/Shortcut/Alipay/AppShortcutTest.php +++ b/tests/Shortcut/Alipay/AppShortcutTest.php @@ -2,8 +2,8 @@ namespace Yansongda\Pay\Tests\Shortcut\Alipay; -use Yansongda\Pay\Plugin\Alipay\AddSignaturePlugin; -use Yansongda\Pay\Plugin\Alipay\FormatBizContentPlugin; +use Yansongda\Pay\Plugin\Alipay\AddPayloadSignaturePlugin; +use Yansongda\Pay\Plugin\Alipay\FormatPayloadBizContentPlugin; use Yansongda\Pay\Plugin\Alipay\Pay\App\PayPlugin; use Yansongda\Pay\Plugin\Alipay\ResponseInvokeStringPlugin; use Yansongda\Pay\Plugin\Alipay\StartPlugin; @@ -29,8 +29,8 @@ class AppShortcutTest extends TestCase self::assertEquals([ StartPlugin::class, PayPlugin::class, - FormatBizContentPlugin::class, - AddSignaturePlugin::class, + FormatPayloadBizContentPlugin::class, + AddPayloadSignaturePlugin::class, ResponseInvokeStringPlugin::class, ParserPlugin::class, ], $result); diff --git a/tests/Shortcut/Alipay/CancelShortcutTest.php b/tests/Shortcut/Alipay/CancelShortcutTest.php index 19627e0..507b09a 100644 --- a/tests/Shortcut/Alipay/CancelShortcutTest.php +++ b/tests/Shortcut/Alipay/CancelShortcutTest.php @@ -5,8 +5,8 @@ namespace Yansongda\Pay\Tests\Shortcut\Alipay; use Yansongda\Pay\Exception\Exception; use Yansongda\Pay\Exception\InvalidParamsException; use Yansongda\Pay\Plugin\Alipay\AddRadarPlugin; -use Yansongda\Pay\Plugin\Alipay\AddSignaturePlugin; -use Yansongda\Pay\Plugin\Alipay\FormatBizContentPlugin; +use Yansongda\Pay\Plugin\Alipay\AddPayloadSignaturePlugin; +use Yansongda\Pay\Plugin\Alipay\FormatPayloadBizContentPlugin; use Yansongda\Pay\Plugin\Alipay\Pay\Agreement\CancelPlugin as AgreementCancelPlugin; use Yansongda\Pay\Plugin\Alipay\Pay\Authorization\CancelPlugin as AuthorizationCancelPlugin; use Yansongda\Pay\Plugin\Alipay\Pay\Mini\CancelPlugin as MiniCancelPlugin; @@ -45,8 +45,8 @@ class CancelShortcutTest extends TestCase self::assertEquals([ StartPlugin::class, PosCancelPlugin::class, - FormatBizContentPlugin::class, - AddSignaturePlugin::class, + FormatPayloadBizContentPlugin::class, + AddPayloadSignaturePlugin::class, AddRadarPlugin::class, VerifySignaturePlugin::class, ResponsePlugin::class, @@ -61,8 +61,8 @@ class CancelShortcutTest extends TestCase self::assertEquals([ StartPlugin::class, AgreementCancelPlugin::class, - FormatBizContentPlugin::class, - AddSignaturePlugin::class, + FormatPayloadBizContentPlugin::class, + AddPayloadSignaturePlugin::class, AddRadarPlugin::class, VerifySignaturePlugin::class, ResponsePlugin::class, @@ -77,8 +77,8 @@ class CancelShortcutTest extends TestCase self::assertEquals([ StartPlugin::class, AuthorizationCancelPlugin::class, - FormatBizContentPlugin::class, - AddSignaturePlugin::class, + FormatPayloadBizContentPlugin::class, + AddPayloadSignaturePlugin::class, AddRadarPlugin::class, VerifySignaturePlugin::class, ResponsePlugin::class, @@ -93,8 +93,8 @@ class CancelShortcutTest extends TestCase self::assertEquals([ StartPlugin::class, MiniCancelPlugin::class, - FormatBizContentPlugin::class, - AddSignaturePlugin::class, + FormatPayloadBizContentPlugin::class, + AddPayloadSignaturePlugin::class, AddRadarPlugin::class, VerifySignaturePlugin::class, ResponsePlugin::class, @@ -109,8 +109,8 @@ class CancelShortcutTest extends TestCase self::assertEquals([ StartPlugin::class, PosCancelPlugin::class, - FormatBizContentPlugin::class, - AddSignaturePlugin::class, + FormatPayloadBizContentPlugin::class, + AddPayloadSignaturePlugin::class, AddRadarPlugin::class, VerifySignaturePlugin::class, ResponsePlugin::class, @@ -125,8 +125,8 @@ public function testScan() self::assertEquals([ StartPlugin::class, ScanCancelPlugin::class, - FormatBizContentPlugin::class, - AddSignaturePlugin::class, + FormatPayloadBizContentPlugin::class, + AddPayloadSignaturePlugin::class, AddRadarPlugin::class, VerifySignaturePlugin::class, ResponsePlugin::class, diff --git a/tests/Shortcut/Alipay/CloseShortcutTest.php b/tests/Shortcut/Alipay/CloseShortcutTest.php index 6324d14..23540d7 100644 --- a/tests/Shortcut/Alipay/CloseShortcutTest.php +++ b/tests/Shortcut/Alipay/CloseShortcutTest.php @@ -5,15 +5,15 @@ namespace Yansongda\Pay\Tests\Shortcut\Alipay; use Yansongda\Pay\Exception\Exception; use Yansongda\Pay\Exception\InvalidParamsException; use Yansongda\Pay\Plugin\Alipay\AddRadarPlugin; -use Yansongda\Pay\Plugin\Alipay\AddSignaturePlugin; -use Yansongda\Pay\Plugin\Alipay\FormatBizContentPlugin; +use Yansongda\Pay\Plugin\Alipay\AddPayloadSignaturePlugin; +use Yansongda\Pay\Plugin\Alipay\FormatPayloadBizContentPlugin; use Yansongda\Pay\Plugin\Alipay\Pay\Agreement\ClosePlugin as AgreementClosePlugin; use Yansongda\Pay\Plugin\Alipay\Pay\App\ClosePlugin as AppClosePlugin; use Yansongda\Pay\Plugin\Alipay\Pay\Authorization\ClosePlugin as AuthorizationClosePlugin; use Yansongda\Pay\Plugin\Alipay\Pay\Mini\ClosePlugin as MiniClosePlugin; use Yansongda\Pay\Plugin\Alipay\Pay\Pos\ClosePlugin as PosClosePlugin; use Yansongda\Pay\Plugin\Alipay\Pay\Scan\ClosePlugin as ScanClosePlugin; -use Yansongda\Pay\Plugin\Alipay\Pay\Wap\ClosePlugin as WapClosePlugin; +use Yansongda\Pay\Plugin\Alipay\Pay\H5\ClosePlugin as WapClosePlugin; use Yansongda\Pay\Plugin\Alipay\Pay\Web\ClosePlugin as WebClosePlugin; use Yansongda\Pay\Plugin\Alipay\ResponsePlugin; use Yansongda\Pay\Plugin\Alipay\StartPlugin; @@ -48,8 +48,8 @@ class CloseShortcutTest extends TestCase self::assertEquals([ StartPlugin::class, WebClosePlugin::class, - FormatBizContentPlugin::class, - AddSignaturePlugin::class, + FormatPayloadBizContentPlugin::class, + AddPayloadSignaturePlugin::class, AddRadarPlugin::class, VerifySignaturePlugin::class, ResponsePlugin::class, @@ -64,8 +64,8 @@ class CloseShortcutTest extends TestCase self::assertEquals([ StartPlugin::class, AgreementClosePlugin::class, - FormatBizContentPlugin::class, - AddSignaturePlugin::class, + FormatPayloadBizContentPlugin::class, + AddPayloadSignaturePlugin::class, AddRadarPlugin::class, VerifySignaturePlugin::class, ResponsePlugin::class, @@ -80,8 +80,8 @@ class CloseShortcutTest extends TestCase self::assertEquals([ StartPlugin::class, AppClosePlugin::class, - FormatBizContentPlugin::class, - AddSignaturePlugin::class, + FormatPayloadBizContentPlugin::class, + AddPayloadSignaturePlugin::class, AddRadarPlugin::class, VerifySignaturePlugin::class, ResponsePlugin::class, @@ -96,8 +96,8 @@ class CloseShortcutTest extends TestCase self::assertEquals([ StartPlugin::class, AuthorizationClosePlugin::class, - FormatBizContentPlugin::class, - AddSignaturePlugin::class, + FormatPayloadBizContentPlugin::class, + AddPayloadSignaturePlugin::class, AddRadarPlugin::class, VerifySignaturePlugin::class, ResponsePlugin::class, @@ -112,8 +112,8 @@ class CloseShortcutTest extends TestCase self::assertEquals([ StartPlugin::class, MiniClosePlugin::class, - FormatBizContentPlugin::class, - AddSignaturePlugin::class, + FormatPayloadBizContentPlugin::class, + AddPayloadSignaturePlugin::class, AddRadarPlugin::class, VerifySignaturePlugin::class, ResponsePlugin::class, @@ -128,8 +128,8 @@ class CloseShortcutTest extends TestCase self::assertEquals([ StartPlugin::class, PosClosePlugin::class, - FormatBizContentPlugin::class, - AddSignaturePlugin::class, + FormatPayloadBizContentPlugin::class, + AddPayloadSignaturePlugin::class, AddRadarPlugin::class, VerifySignaturePlugin::class, ResponsePlugin::class, @@ -144,8 +144,8 @@ class CloseShortcutTest extends TestCase self::assertEquals([ StartPlugin::class, ScanClosePlugin::class, - FormatBizContentPlugin::class, - AddSignaturePlugin::class, + FormatPayloadBizContentPlugin::class, + AddPayloadSignaturePlugin::class, AddRadarPlugin::class, VerifySignaturePlugin::class, ResponsePlugin::class, @@ -160,8 +160,8 @@ class CloseShortcutTest extends TestCase self::assertEquals([ StartPlugin::class, WapClosePlugin::class, - FormatBizContentPlugin::class, - AddSignaturePlugin::class, + FormatPayloadBizContentPlugin::class, + AddPayloadSignaturePlugin::class, AddRadarPlugin::class, VerifySignaturePlugin::class, ResponsePlugin::class, @@ -176,8 +176,8 @@ class CloseShortcutTest extends TestCase self::assertEquals([ StartPlugin::class, WebClosePlugin::class, - FormatBizContentPlugin::class, - AddSignaturePlugin::class, + FormatPayloadBizContentPlugin::class, + AddPayloadSignaturePlugin::class, AddRadarPlugin::class, VerifySignaturePlugin::class, ResponsePlugin::class, diff --git a/tests/Shortcut/Alipay/MiniShortcutTest.php b/tests/Shortcut/Alipay/MiniShortcutTest.php index e7b5c4d..b0e06d5 100644 --- a/tests/Shortcut/Alipay/MiniShortcutTest.php +++ b/tests/Shortcut/Alipay/MiniShortcutTest.php @@ -3,8 +3,8 @@ namespace Yansongda\Pay\Tests\Shortcut\Alipay; use Yansongda\Pay\Plugin\Alipay\AddRadarPlugin; -use Yansongda\Pay\Plugin\Alipay\AddSignaturePlugin; -use Yansongda\Pay\Plugin\Alipay\FormatBizContentPlugin; +use Yansongda\Pay\Plugin\Alipay\AddPayloadSignaturePlugin; +use Yansongda\Pay\Plugin\Alipay\FormatPayloadBizContentPlugin; use Yansongda\Pay\Plugin\Alipay\Pay\Mini\PayPlugin; use Yansongda\Pay\Plugin\Alipay\ResponsePlugin; use Yansongda\Pay\Plugin\Alipay\StartPlugin; @@ -31,8 +31,8 @@ class MiniShortcutTest extends TestCase self::assertEquals([ StartPlugin::class, PayPlugin::class, - FormatBizContentPlugin::class, - AddSignaturePlugin::class, + FormatPayloadBizContentPlugin::class, + AddPayloadSignaturePlugin::class, AddRadarPlugin::class, VerifySignaturePlugin::class, ResponsePlugin::class, diff --git a/tests/Shortcut/Alipay/PosShortcutTest.php b/tests/Shortcut/Alipay/PosShortcutTest.php index 29ada45..1ec5bec 100644 --- a/tests/Shortcut/Alipay/PosShortcutTest.php +++ b/tests/Shortcut/Alipay/PosShortcutTest.php @@ -3,13 +3,13 @@ namespace Yansongda\Pay\Tests\Shortcut\Alipay; use Yansongda\Pay\Plugin\Alipay\AddRadarPlugin; -use Yansongda\Pay\Plugin\Alipay\AddSignaturePlugin; -use Yansongda\Pay\Plugin\Alipay\FormatBizContentPlugin; +use Yansongda\Pay\Plugin\Alipay\AddPayloadSignaturePlugin; +use Yansongda\Pay\Plugin\Alipay\FormatPayloadBizContentPlugin; use Yansongda\Pay\Plugin\Alipay\ResponsePlugin; use Yansongda\Pay\Plugin\Alipay\StartPlugin; use Yansongda\Pay\Plugin\Alipay\VerifySignaturePlugin; use Yansongda\Pay\Plugin\ParserPlugin; -use Yansongda\Pay\Plugin\Wechat\Pay\Pos\PayPlugin; +use Yansongda\Pay\Plugin\Alipay\Pay\Pos\PayPlugin; use Yansongda\Pay\Shortcut\Alipay\PosShortcut; use Yansongda\Pay\Tests\TestCase; @@ -31,8 +31,8 @@ class PosShortcutTest extends TestCase self::assertEquals([ StartPlugin::class, PayPlugin::class, - FormatBizContentPlugin::class, - AddSignaturePlugin::class, + FormatPayloadBizContentPlugin::class, + AddPayloadSignaturePlugin::class, AddRadarPlugin::class, VerifySignaturePlugin::class, ResponsePlugin::class, diff --git a/tests/Shortcut/Alipay/QueryShortcutTest.php b/tests/Shortcut/Alipay/QueryShortcutTest.php index d95d49f..106a684 100644 --- a/tests/Shortcut/Alipay/QueryShortcutTest.php +++ b/tests/Shortcut/Alipay/QueryShortcutTest.php @@ -5,8 +5,8 @@ namespace Yansongda\Pay\Tests\Shortcut\Alipay; use Yansongda\Pay\Exception\Exception; use Yansongda\Pay\Exception\InvalidParamsException; use Yansongda\Pay\Plugin\Alipay\AddRadarPlugin; -use Yansongda\Pay\Plugin\Alipay\AddSignaturePlugin; -use Yansongda\Pay\Plugin\Alipay\FormatBizContentPlugin; +use Yansongda\Pay\Plugin\Alipay\AddPayloadSignaturePlugin; +use Yansongda\Pay\Plugin\Alipay\FormatPayloadBizContentPlugin; use Yansongda\Pay\Plugin\Alipay\Fund\Transfer\QueryPlugin as TransferQueryPlugin; use Yansongda\Pay\Plugin\Alipay\Pay\Agreement\QueryPlugin as AgreementQueryPlugin; use Yansongda\Pay\Plugin\Alipay\Pay\App\QueryPlugin as AppQueryPlugin; @@ -20,8 +20,8 @@ use Yansongda\Pay\Plugin\Alipay\Pay\Pos\QueryPlugin as PosQueryPlugin; use Yansongda\Pay\Plugin\Alipay\Pay\Pos\QueryRefundPlugin as PosQueryRefundPlugin; use Yansongda\Pay\Plugin\Alipay\Pay\Scan\QueryPlugin as ScanQueryPlugin; use Yansongda\Pay\Plugin\Alipay\Pay\Scan\QueryRefundPlugin as ScanQueryRefundPlugin; -use Yansongda\Pay\Plugin\Alipay\Pay\Wap\QueryPlugin as WapQueryPlugin; -use Yansongda\Pay\Plugin\Alipay\Pay\Wap\QueryRefundPlugin as WapQueryRefundPlugin; +use Yansongda\Pay\Plugin\Alipay\Pay\H5\QueryPlugin as WapQueryPlugin; +use Yansongda\Pay\Plugin\Alipay\Pay\H5\QueryRefundPlugin as WapQueryRefundPlugin; use Yansongda\Pay\Plugin\Alipay\Pay\Web\QueryPlugin as WebQueryPlugin; use Yansongda\Pay\Plugin\Alipay\Pay\Web\QueryRefundPlugin as WebQueryRefundPlugin; use Yansongda\Pay\Plugin\Alipay\ResponsePlugin; @@ -57,8 +57,8 @@ class QueryShortcutTest extends TestCase self::assertEquals([ StartPlugin::class, WebQueryPlugin::class, - FormatBizContentPlugin::class, - AddSignaturePlugin::class, + FormatPayloadBizContentPlugin::class, + AddPayloadSignaturePlugin::class, AddRadarPlugin::class, VerifySignaturePlugin::class, ResponsePlugin::class, @@ -73,8 +73,8 @@ class QueryShortcutTest extends TestCase self::assertEquals([ StartPlugin::class, AgreementQueryPlugin::class, - FormatBizContentPlugin::class, - AddSignaturePlugin::class, + FormatPayloadBizContentPlugin::class, + AddPayloadSignaturePlugin::class, AddRadarPlugin::class, VerifySignaturePlugin::class, ResponsePlugin::class, @@ -89,8 +89,8 @@ class QueryShortcutTest extends TestCase self::assertEquals([ StartPlugin::class, AppQueryPlugin::class, - FormatBizContentPlugin::class, - AddSignaturePlugin::class, + FormatPayloadBizContentPlugin::class, + AddPayloadSignaturePlugin::class, AddRadarPlugin::class, VerifySignaturePlugin::class, ResponsePlugin::class, @@ -105,8 +105,8 @@ class QueryShortcutTest extends TestCase self::assertEquals([ StartPlugin::class, AuthorizationQueryPlugin::class, - FormatBizContentPlugin::class, - AddSignaturePlugin::class, + FormatPayloadBizContentPlugin::class, + AddPayloadSignaturePlugin::class, AddRadarPlugin::class, VerifySignaturePlugin::class, ResponsePlugin::class, @@ -121,8 +121,8 @@ class QueryShortcutTest extends TestCase self::assertEquals([ StartPlugin::class, FaceQueryPlugin::class, - FormatBizContentPlugin::class, - AddSignaturePlugin::class, + FormatPayloadBizContentPlugin::class, + AddPayloadSignaturePlugin::class, AddRadarPlugin::class, VerifySignaturePlugin::class, ResponsePlugin::class, @@ -137,8 +137,8 @@ class QueryShortcutTest extends TestCase self::assertEquals([ StartPlugin::class, MiniQueryPlugin::class, - FormatBizContentPlugin::class, - AddSignaturePlugin::class, + FormatPayloadBizContentPlugin::class, + AddPayloadSignaturePlugin::class, AddRadarPlugin::class, VerifySignaturePlugin::class, ResponsePlugin::class, @@ -153,8 +153,8 @@ class QueryShortcutTest extends TestCase self::assertEquals([ StartPlugin::class, PosQueryPlugin::class, - FormatBizContentPlugin::class, - AddSignaturePlugin::class, + FormatPayloadBizContentPlugin::class, + AddPayloadSignaturePlugin::class, AddRadarPlugin::class, VerifySignaturePlugin::class, ResponsePlugin::class, @@ -169,8 +169,8 @@ class QueryShortcutTest extends TestCase self::assertEquals([ StartPlugin::class, ScanQueryPlugin::class, - FormatBizContentPlugin::class, - AddSignaturePlugin::class, + FormatPayloadBizContentPlugin::class, + AddPayloadSignaturePlugin::class, AddRadarPlugin::class, VerifySignaturePlugin::class, ResponsePlugin::class, @@ -185,8 +185,8 @@ class QueryShortcutTest extends TestCase self::assertEquals([ StartPlugin::class, WapQueryPlugin::class, - FormatBizContentPlugin::class, - AddSignaturePlugin::class, + FormatPayloadBizContentPlugin::class, + AddPayloadSignaturePlugin::class, AddRadarPlugin::class, VerifySignaturePlugin::class, ResponsePlugin::class, @@ -201,8 +201,8 @@ class QueryShortcutTest extends TestCase self::assertEquals([ StartPlugin::class, WebQueryPlugin::class, - FormatBizContentPlugin::class, - AddSignaturePlugin::class, + FormatPayloadBizContentPlugin::class, + AddPayloadSignaturePlugin::class, AddRadarPlugin::class, VerifySignaturePlugin::class, ResponsePlugin::class, @@ -217,8 +217,8 @@ class QueryShortcutTest extends TestCase self::assertEquals([ StartPlugin::class, TransferQueryPlugin::class, - FormatBizContentPlugin::class, - AddSignaturePlugin::class, + FormatPayloadBizContentPlugin::class, + AddPayloadSignaturePlugin::class, AddRadarPlugin::class, VerifySignaturePlugin::class, ResponsePlugin::class, @@ -233,8 +233,8 @@ class QueryShortcutTest extends TestCase self::assertEquals([ StartPlugin::class, WebQueryRefundPlugin::class, - FormatBizContentPlugin::class, - AddSignaturePlugin::class, + FormatPayloadBizContentPlugin::class, + AddPayloadSignaturePlugin::class, AddRadarPlugin::class, VerifySignaturePlugin::class, ResponsePlugin::class, @@ -249,8 +249,8 @@ class QueryShortcutTest extends TestCase self::assertEquals([ StartPlugin::class, AppQueryRefundPlugin::class, - FormatBizContentPlugin::class, - AddSignaturePlugin::class, + FormatPayloadBizContentPlugin::class, + AddPayloadSignaturePlugin::class, AddRadarPlugin::class, VerifySignaturePlugin::class, ResponsePlugin::class, @@ -265,8 +265,8 @@ class QueryShortcutTest extends TestCase self::assertEquals([ StartPlugin::class, AuthorizationQueryRefundPlugin::class, - FormatBizContentPlugin::class, - AddSignaturePlugin::class, + FormatPayloadBizContentPlugin::class, + AddPayloadSignaturePlugin::class, AddRadarPlugin::class, VerifySignaturePlugin::class, ResponsePlugin::class, @@ -281,8 +281,8 @@ class QueryShortcutTest extends TestCase self::assertEquals([ StartPlugin::class, MiniQueryRefundPlugin::class, - FormatBizContentPlugin::class, - AddSignaturePlugin::class, + FormatPayloadBizContentPlugin::class, + AddPayloadSignaturePlugin::class, AddRadarPlugin::class, VerifySignaturePlugin::class, ResponsePlugin::class, @@ -297,8 +297,8 @@ class QueryShortcutTest extends TestCase self::assertEquals([ StartPlugin::class, PosQueryRefundPlugin::class, - FormatBizContentPlugin::class, - AddSignaturePlugin::class, + FormatPayloadBizContentPlugin::class, + AddPayloadSignaturePlugin::class, AddRadarPlugin::class, VerifySignaturePlugin::class, ResponsePlugin::class, @@ -313,8 +313,8 @@ class QueryShortcutTest extends TestCase self::assertEquals([ StartPlugin::class, ScanQueryRefundPlugin::class, - FormatBizContentPlugin::class, - AddSignaturePlugin::class, + FormatPayloadBizContentPlugin::class, + AddPayloadSignaturePlugin::class, AddRadarPlugin::class, VerifySignaturePlugin::class, ResponsePlugin::class, @@ -329,8 +329,8 @@ class QueryShortcutTest extends TestCase self::assertEquals([ StartPlugin::class, WapQueryRefundPlugin::class, - FormatBizContentPlugin::class, - AddSignaturePlugin::class, + FormatPayloadBizContentPlugin::class, + AddPayloadSignaturePlugin::class, AddRadarPlugin::class, VerifySignaturePlugin::class, ResponsePlugin::class, @@ -345,8 +345,8 @@ class QueryShortcutTest extends TestCase self::assertEquals([ StartPlugin::class, WebQueryRefundPlugin::class, - FormatBizContentPlugin::class, - AddSignaturePlugin::class, + FormatPayloadBizContentPlugin::class, + AddPayloadSignaturePlugin::class, AddRadarPlugin::class, VerifySignaturePlugin::class, ResponsePlugin::class, diff --git a/tests/Shortcut/Alipay/RefundShortcutTest.php b/tests/Shortcut/Alipay/RefundShortcutTest.php index 60f0ee3..fa64788 100644 --- a/tests/Shortcut/Alipay/RefundShortcutTest.php +++ b/tests/Shortcut/Alipay/RefundShortcutTest.php @@ -5,8 +5,8 @@ namespace Yansongda\Pay\Tests\Shortcut\Alipay; use Yansongda\Pay\Exception\Exception; use Yansongda\Pay\Exception\InvalidParamsException; use Yansongda\Pay\Plugin\Alipay\AddRadarPlugin; -use Yansongda\Pay\Plugin\Alipay\AddSignaturePlugin; -use Yansongda\Pay\Plugin\Alipay\FormatBizContentPlugin; +use Yansongda\Pay\Plugin\Alipay\AddPayloadSignaturePlugin; +use Yansongda\Pay\Plugin\Alipay\FormatPayloadBizContentPlugin; use Yansongda\Pay\Plugin\Alipay\Fund\Transfer\RefundPlugin as FundTransferRefundPlugin; use Yansongda\Pay\Plugin\Alipay\Pay\Agreement\RefundPlugin as AgreementRefundPlugin; use Yansongda\Pay\Plugin\Alipay\Pay\App\RefundPlugin as AppRefundPlugin; @@ -14,7 +14,7 @@ use Yansongda\Pay\Plugin\Alipay\Pay\Authorization\RefundPlugin as AuthorizationR use Yansongda\Pay\Plugin\Alipay\Pay\Mini\RefundPlugin as MiniRefundPlugin; use Yansongda\Pay\Plugin\Alipay\Pay\Pos\RefundPlugin as PosRefundPlugin; use Yansongda\Pay\Plugin\Alipay\Pay\Scan\RefundPlugin as ScanRefundPlugin; -use Yansongda\Pay\Plugin\Alipay\Pay\Wap\RefundPlugin as WapRefundPlugin; +use Yansongda\Pay\Plugin\Alipay\Pay\H5\RefundPlugin as WapRefundPlugin; use Yansongda\Pay\Plugin\Alipay\Pay\Web\RefundPlugin as WebRefundPlugin; use Yansongda\Pay\Plugin\Alipay\ResponsePlugin; use Yansongda\Pay\Plugin\Alipay\StartPlugin; @@ -49,8 +49,8 @@ class RefundShortcutTest extends TestCase self::assertEquals([ StartPlugin::class, WebRefundPlugin::class, - FormatBizContentPlugin::class, - AddSignaturePlugin::class, + FormatPayloadBizContentPlugin::class, + AddPayloadSignaturePlugin::class, AddRadarPlugin::class, VerifySignaturePlugin::class, ResponsePlugin::class, @@ -65,8 +65,8 @@ class RefundShortcutTest extends TestCase self::assertEquals([ StartPlugin::class, AgreementRefundPlugin::class, - FormatBizContentPlugin::class, - AddSignaturePlugin::class, + FormatPayloadBizContentPlugin::class, + AddPayloadSignaturePlugin::class, AddRadarPlugin::class, VerifySignaturePlugin::class, ResponsePlugin::class, @@ -81,8 +81,8 @@ class RefundShortcutTest extends TestCase self::assertEquals([ StartPlugin::class, AppRefundPlugin::class, - FormatBizContentPlugin::class, - AddSignaturePlugin::class, + FormatPayloadBizContentPlugin::class, + AddPayloadSignaturePlugin::class, AddRadarPlugin::class, VerifySignaturePlugin::class, ResponsePlugin::class, @@ -97,8 +97,8 @@ class RefundShortcutTest extends TestCase self::assertEquals([ StartPlugin::class, AuthorizationRefundPlugin::class, - FormatBizContentPlugin::class, - AddSignaturePlugin::class, + FormatPayloadBizContentPlugin::class, + AddPayloadSignaturePlugin::class, AddRadarPlugin::class, VerifySignaturePlugin::class, ResponsePlugin::class, @@ -113,8 +113,8 @@ class RefundShortcutTest extends TestCase self::assertEquals([ StartPlugin::class, MiniRefundPlugin::class, - FormatBizContentPlugin::class, - AddSignaturePlugin::class, + FormatPayloadBizContentPlugin::class, + AddPayloadSignaturePlugin::class, AddRadarPlugin::class, VerifySignaturePlugin::class, ResponsePlugin::class, @@ -129,8 +129,8 @@ class RefundShortcutTest extends TestCase self::assertEquals([ StartPlugin::class, PosRefundPlugin::class, - FormatBizContentPlugin::class, - AddSignaturePlugin::class, + FormatPayloadBizContentPlugin::class, + AddPayloadSignaturePlugin::class, AddRadarPlugin::class, VerifySignaturePlugin::class, ResponsePlugin::class, @@ -145,8 +145,8 @@ class RefundShortcutTest extends TestCase self::assertEquals([ StartPlugin::class, ScanRefundPlugin::class, - FormatBizContentPlugin::class, - AddSignaturePlugin::class, + FormatPayloadBizContentPlugin::class, + AddPayloadSignaturePlugin::class, AddRadarPlugin::class, VerifySignaturePlugin::class, ResponsePlugin::class, @@ -161,8 +161,8 @@ class RefundShortcutTest extends TestCase self::assertEquals([ StartPlugin::class, WapRefundPlugin::class, - FormatBizContentPlugin::class, - AddSignaturePlugin::class, + FormatPayloadBizContentPlugin::class, + AddPayloadSignaturePlugin::class, AddRadarPlugin::class, VerifySignaturePlugin::class, ResponsePlugin::class, @@ -177,8 +177,8 @@ class RefundShortcutTest extends TestCase self::assertEquals([ StartPlugin::class, WebRefundPlugin::class, - FormatBizContentPlugin::class, - AddSignaturePlugin::class, + FormatPayloadBizContentPlugin::class, + AddPayloadSignaturePlugin::class, AddRadarPlugin::class, VerifySignaturePlugin::class, ResponsePlugin::class, @@ -193,8 +193,8 @@ class RefundShortcutTest extends TestCase self::assertEquals([ StartPlugin::class, FundTransferRefundPlugin::class, - FormatBizContentPlugin::class, - AddSignaturePlugin::class, + FormatPayloadBizContentPlugin::class, + AddPayloadSignaturePlugin::class, AddRadarPlugin::class, VerifySignaturePlugin::class, ResponsePlugin::class, diff --git a/tests/Shortcut/Alipay/ScanShortcutTest.php b/tests/Shortcut/Alipay/ScanShortcutTest.php index 25b6a31..97facf6 100644 --- a/tests/Shortcut/Alipay/ScanShortcutTest.php +++ b/tests/Shortcut/Alipay/ScanShortcutTest.php @@ -3,8 +3,8 @@ namespace Yansongda\Pay\Tests\Shortcut\Alipay; use Yansongda\Pay\Plugin\Alipay\AddRadarPlugin; -use Yansongda\Pay\Plugin\Alipay\AddSignaturePlugin; -use Yansongda\Pay\Plugin\Alipay\FormatBizContentPlugin; +use Yansongda\Pay\Plugin\Alipay\AddPayloadSignaturePlugin; +use Yansongda\Pay\Plugin\Alipay\FormatPayloadBizContentPlugin; use Yansongda\Pay\Plugin\Alipay\Pay\Scan\PayPlugin; use Yansongda\Pay\Plugin\Alipay\ResponsePlugin; use Yansongda\Pay\Plugin\Alipay\StartPlugin; @@ -31,8 +31,8 @@ class ScanShortcutTest extends TestCase self::assertEquals([ StartPlugin::class, PayPlugin::class, - FormatBizContentPlugin::class, - AddSignaturePlugin::class, + FormatPayloadBizContentPlugin::class, + AddPayloadSignaturePlugin::class, AddRadarPlugin::class, VerifySignaturePlugin::class, ResponsePlugin::class, diff --git a/tests/Shortcut/Alipay/TransferShortcutTest.php b/tests/Shortcut/Alipay/TransferShortcutTest.php index babbc78..590c1e1 100644 --- a/tests/Shortcut/Alipay/TransferShortcutTest.php +++ b/tests/Shortcut/Alipay/TransferShortcutTest.php @@ -3,8 +3,8 @@ namespace Yansongda\Pay\Tests\Shortcut\Alipay; use Yansongda\Pay\Plugin\Alipay\AddRadarPlugin; -use Yansongda\Pay\Plugin\Alipay\AddSignaturePlugin; -use Yansongda\Pay\Plugin\Alipay\FormatBizContentPlugin; +use Yansongda\Pay\Plugin\Alipay\AddPayloadSignaturePlugin; +use Yansongda\Pay\Plugin\Alipay\FormatPayloadBizContentPlugin; use Yansongda\Pay\Plugin\Alipay\Fund\Transfer\TransferPlugin; use Yansongda\Pay\Plugin\Alipay\ResponsePlugin; use Yansongda\Pay\Plugin\Alipay\StartPlugin; @@ -31,8 +31,8 @@ class TransferShortcutTest extends TestCase self::assertEquals([ StartPlugin::class, TransferPlugin::class, - FormatBizContentPlugin::class, - AddSignaturePlugin::class, + FormatPayloadBizContentPlugin::class, + AddPayloadSignaturePlugin::class, AddRadarPlugin::class, VerifySignaturePlugin::class, ResponsePlugin::class, diff --git a/tests/Shortcut/Alipay/WapShortcutTest.php b/tests/Shortcut/Alipay/WapShortcutTest.php index c8cf740..3dd6468 100644 --- a/tests/Shortcut/Alipay/WapShortcutTest.php +++ b/tests/Shortcut/Alipay/WapShortcutTest.php @@ -2,9 +2,9 @@ namespace Yansongda\Pay\Tests\Shortcut\Alipay; -use Yansongda\Pay\Plugin\Alipay\AddSignaturePlugin; -use Yansongda\Pay\Plugin\Alipay\FormatBizContentPlugin; -use Yansongda\Pay\Plugin\Alipay\Pay\Wap\PayPlugin; +use Yansongda\Pay\Plugin\Alipay\AddPayloadSignaturePlugin; +use Yansongda\Pay\Plugin\Alipay\FormatPayloadBizContentPlugin; +use Yansongda\Pay\Plugin\Alipay\Pay\H5\PayPlugin; use Yansongda\Pay\Plugin\Alipay\ResponseHtmlPlugin; use Yansongda\Pay\Plugin\Alipay\StartPlugin; use Yansongda\Pay\Plugin\ParserPlugin; @@ -29,8 +29,8 @@ class WapShortcutTest extends TestCase self::assertEquals([ StartPlugin::class, PayPlugin::class, - FormatBizContentPlugin::class, - AddSignaturePlugin::class, + FormatPayloadBizContentPlugin::class, + AddPayloadSignaturePlugin::class, ResponseHtmlPlugin::class, ParserPlugin::class, ], $result); diff --git a/tests/Shortcut/Alipay/WebShortcutTest.php b/tests/Shortcut/Alipay/WebShortcutTest.php index 9f8ba82..6b3a442 100644 --- a/tests/Shortcut/Alipay/WebShortcutTest.php +++ b/tests/Shortcut/Alipay/WebShortcutTest.php @@ -3,8 +3,8 @@ namespace Yansongda\Pay\Tests\Shortcut\Alipay; use Yansongda\Pay\Plugin\Alipay\AddRadarPlugin; -use Yansongda\Pay\Plugin\Alipay\AddSignaturePlugin; -use Yansongda\Pay\Plugin\Alipay\FormatBizContentPlugin; +use Yansongda\Pay\Plugin\Alipay\AddPayloadSignaturePlugin; +use Yansongda\Pay\Plugin\Alipay\FormatPayloadBizContentPlugin; use Yansongda\Pay\Plugin\Alipay\Pay\Web\PayPlugin; use Yansongda\Pay\Plugin\Alipay\ResponseHtmlPlugin; use Yansongda\Pay\Plugin\Alipay\StartPlugin; @@ -30,8 +30,8 @@ class WebShortcutTest extends TestCase self::assertEquals([ StartPlugin::class, PayPlugin::class, - FormatBizContentPlugin::class, - AddSignaturePlugin::class, + FormatPayloadBizContentPlugin::class, + AddPayloadSignaturePlugin::class, AddRadarPlugin::class, ResponseHtmlPlugin::class, ParserPlugin::class, diff --git a/tests/Shortcut/Wechat/AppShortcutTest.php b/tests/Shortcut/Wechat/AppShortcutTest.php new file mode 100644 index 0000000..d8b8e79 --- /dev/null +++ b/tests/Shortcut/Wechat/AppShortcutTest.php @@ -0,0 +1,44 @@ +plugin = new AppShortcut(); + } + + public function testDefault() + { + self::assertEquals([ + StartPlugin::class, + PayPlugin::class, + AddPayloadBodyPlugin::class, + AddPayloadSignaturePlugin::class, + AddRadarPlugin::class, + InvokePlugin::class, + ResponsePlugin::class, + VerifySignaturePlugin::class, + ParserPlugin::class, + ], $this->plugin->getPlugins([])); + } +} diff --git a/tests/Shortcut/Wechat/CloseShortcutTest.php b/tests/Shortcut/Wechat/CloseShortcutTest.php index 7fa6383..db551ea 100644 --- a/tests/Shortcut/Wechat/CloseShortcutTest.php +++ b/tests/Shortcut/Wechat/CloseShortcutTest.php @@ -6,12 +6,15 @@ namespace Yansongda\Pay\Tests\Shortcut\Wechat; use Yansongda\Pay\Exception\Exception; use Yansongda\Pay\Exception\InvalidParamsException; -use Yansongda\Pay\Plugin\Alipay\Fund\TransCommonQueryPlugin; use Yansongda\Pay\Plugin\ParserPlugin; -use Yansongda\Pay\Plugin\Wechat\LaunchPlugin; -use Yansongda\Pay\Plugin\Wechat\Pay\Common\ClosePlugin; -use Yansongda\Pay\Plugin\Wechat\PreparePlugin; -use Yansongda\Pay\Plugin\Wechat\RadarSignPlugin; +use Yansongda\Pay\Plugin\Wechat\AddPayloadBodyPlugin; +use Yansongda\Pay\Plugin\Wechat\AddPayloadSignaturePlugin; +use Yansongda\Pay\Plugin\Wechat\AddRadarPlugin; +use Yansongda\Pay\Plugin\Wechat\Pay\Combine\ClosePlugin as CombineClosePlugin; +use Yansongda\Pay\Plugin\Wechat\Pay\Jsapi\ClosePlugin as JsapiClosePlugin; +use Yansongda\Pay\Plugin\Wechat\ResponsePlugin; +use Yansongda\Pay\Plugin\Wechat\StartPlugin; +use Yansongda\Pay\Plugin\Wechat\VerifySignaturePlugin; use Yansongda\Pay\Shortcut\Wechat\CloseShortcut; use Yansongda\Pay\Tests\TestCase; @@ -29,10 +32,13 @@ class CloseShortcutTest extends TestCase public function testDefault() { self::assertEquals([ - PreparePlugin::class, - ClosePlugin::class, - RadarSignPlugin::class, - LaunchPlugin::class, + StartPlugin::class, + JsapiClosePlugin::class, + AddPayloadBodyPlugin::class, + AddPayloadSignaturePlugin::class, + AddRadarPlugin::class, + ResponsePlugin::class, + VerifySignaturePlugin::class, ParserPlugin::class, ], $this->plugin->getPlugins([])); } @@ -40,10 +46,13 @@ class CloseShortcutTest extends TestCase public function testCombine() { self::assertEquals([ - PreparePlugin::class, - \Yansongda\Pay\Plugin\Wechat\Pay\Combine\ClosePlugin::class, - RadarSignPlugin::class, - LaunchPlugin::class, + StartPlugin::class, + CombineClosePlugin::class, + AddPayloadBodyPlugin::class, + AddPayloadSignaturePlugin::class, + AddRadarPlugin::class, + ResponsePlugin::class, + VerifySignaturePlugin::class, ParserPlugin::class, ], $this->plugin->getPlugins(['_action' => 'combine'])); } @@ -51,18 +60,24 @@ class CloseShortcutTest extends TestCase public function testCombineParams() { self::assertEquals([ - PreparePlugin::class, - \Yansongda\Pay\Plugin\Wechat\Pay\Combine\ClosePlugin::class, - RadarSignPlugin::class, - LaunchPlugin::class, + StartPlugin::class, + CombineClosePlugin::class, + AddPayloadBodyPlugin::class, + AddPayloadSignaturePlugin::class, + AddRadarPlugin::class, + ResponsePlugin::class, + VerifySignaturePlugin::class, ParserPlugin::class, ], $this->plugin->getPlugins(['combine_out_trade_no' => '123abc'])); self::assertEquals([ - PreparePlugin::class, - \Yansongda\Pay\Plugin\Wechat\Pay\Combine\ClosePlugin::class, - RadarSignPlugin::class, - LaunchPlugin::class, + StartPlugin::class, + CombineClosePlugin::class, + AddPayloadBodyPlugin::class, + AddPayloadSignaturePlugin::class, + AddRadarPlugin::class, + ResponsePlugin::class, + VerifySignaturePlugin::class, ParserPlugin::class, ], $this->plugin->getPlugins(['sub_orders' => '123abc'])); } @@ -71,7 +86,7 @@ class CloseShortcutTest extends TestCase { self::expectException(InvalidParamsException::class); self::expectExceptionCode(Exception::PARAMS_SHORTCUT_ACTION_INVALID); - self::expectExceptionMessage('Query action [fooPlugins] not supported'); + self::expectExceptionMessage('Close action [fooPlugins] not supported'); $this->plugin->getPlugins(['_action' => 'foo']); } diff --git a/tests/Shortcut/Wechat/MiniShortcutTest.php b/tests/Shortcut/Wechat/MiniShortcutTest.php new file mode 100644 index 0000000..b8b4d9f --- /dev/null +++ b/tests/Shortcut/Wechat/MiniShortcutTest.php @@ -0,0 +1,42 @@ +plugin = new MiniShortcut(); + } + + public function testDefault() + { + self::assertEquals([ + StartPlugin::class, + PayPlugin::class, + AddPayloadBodyPlugin::class, + AddPayloadSignaturePlugin::class, + AddRadarPlugin::class, + ResponsePlugin::class, + VerifySignaturePlugin::class, + ParserPlugin::class, + ], $this->plugin->getPlugins([])); + } +} diff --git a/tests/Shortcut/Wechat/MpShortcutTest.php b/tests/Shortcut/Wechat/MpShortcutTest.php new file mode 100644 index 0000000..cd89d07 --- /dev/null +++ b/tests/Shortcut/Wechat/MpShortcutTest.php @@ -0,0 +1,42 @@ +plugin = new MpShortcut(); + } + + public function testDefault() + { + self::assertEquals([ + StartPlugin::class, + PayPlugin::class, + AddPayloadBodyPlugin::class, + AddPayloadSignaturePlugin::class, + AddRadarPlugin::class, + ResponsePlugin::class, + VerifySignaturePlugin::class, + ParserPlugin::class, + ], $this->plugin->getPlugins([])); + } +} diff --git a/tests/Shortcut/Wechat/PapayShortcutTest.php b/tests/Shortcut/Wechat/PapayShortcutTest.php deleted file mode 100644 index 88908a2..0000000 --- a/tests/Shortcut/Wechat/PapayShortcutTest.php +++ /dev/null @@ -1,89 +0,0 @@ -plugin = new PapayShortcut(); - } - - public function testDefault() - { - self::assertEquals([ - PreparePlugin::class, - ContractOrderPlugin::class, - RadarSignPlugin::class, - InvokePrepayV2Plugin::class, - ParserPlugin::class, - ], $this->plugin->getPlugins([])); - } - - public function testDefaultMini() - { - self::assertEquals([ - PreparePlugin::class, - ContractOrderPlugin::class, - RadarSignPlugin::class, - \Yansongda\Pay\Plugin\Wechat\Pay\Mini\InvokePrepayV2Plugin::class, - ParserPlugin::class, - ], $this->plugin->getPlugins(['_type' => 'mini'])); - } - - public function testDefaultApp() - { - self::assertEquals([ - PreparePlugin::class, - ContractOrderPlugin::class, - RadarSignPlugin::class, - \Yansongda\Pay\Plugin\Wechat\Pay\App\InvokePrepayV2Plugin::class, - ParserPlugin::class, - ], $this->plugin->getPlugins(['_type' => 'app'])); - } - - public function testContract() - { - self::assertEquals([ - PreparePlugin::class, - OnlyContractPlugin::class, - ], $this->plugin->getPlugins(['_action' => 'contract'])); - } - - public function testApply() - { - self::assertEquals([ - PreparePlugin::class, - ApplyPlugin::class, - RadarSignPlugin::class, - ParserPlugin::class, - ], $this->plugin->getPlugins(['_action' => 'apply'])); - } - - public function testFoo() - { - self::expectException(InvalidParamsException::class); - self::expectExceptionCode(Exception::PARAMS_SHORTCUT_ACTION_INVALID); - self::expectExceptionMessage('Papay action [fooPlugins] not supported'); - - $this->plugin->getPlugins(['_action' => 'foo']); - } -} diff --git a/tests/Shortcut/Wechat/PosShortcutTest.php b/tests/Shortcut/Wechat/PosShortcutTest.php deleted file mode 100644 index 8f16ad8..0000000 --- a/tests/Shortcut/Wechat/PosShortcutTest.php +++ /dev/null @@ -1,28 +0,0 @@ -plugin = new PosShortcut(); - } - - public function testDefault() - { - self::assertEquals([ - PayPlugin::class, - ], $this->plugin->getPlugins([])); - } -} diff --git a/tests/Shortcut/Wechat/QueryShortcutTest.php b/tests/Shortcut/Wechat/QueryShortcutTest.php index 7baca01..bbae246 100644 --- a/tests/Shortcut/Wechat/QueryShortcutTest.php +++ b/tests/Shortcut/Wechat/QueryShortcutTest.php @@ -7,11 +7,16 @@ namespace Yansongda\Pay\Tests\Shortcut\Wechat; use Yansongda\Pay\Exception\Exception; use Yansongda\Pay\Exception\InvalidParamsException; use Yansongda\Pay\Plugin\ParserPlugin; -use Yansongda\Pay\Plugin\Wechat\LaunchPlugin; -use Yansongda\Pay\Plugin\Wechat\Pay\Common\QueryPlugin; -use Yansongda\Pay\Plugin\Wechat\Pay\Common\QueryRefundPlugin; -use Yansongda\Pay\Plugin\Wechat\PreparePlugin; -use Yansongda\Pay\Plugin\Wechat\RadarSignPlugin; +use Yansongda\Pay\Plugin\Wechat\AddPayloadBodyPlugin; +use Yansongda\Pay\Plugin\Wechat\AddPayloadSignaturePlugin; +use Yansongda\Pay\Plugin\Wechat\AddRadarPlugin; +use Yansongda\Pay\Plugin\Wechat\Marketing\Transfer\QueryDetailPlugin as TransferQueryPlugin; +use Yansongda\Pay\Plugin\Wechat\Pay\Combine\QueryPlugin as CombineQueryPlugin; +use Yansongda\Pay\Plugin\Wechat\Pay\Jsapi\QueryPlugin as JsapiQueryPlugin; +use Yansongda\Pay\Plugin\Wechat\Pay\Jsapi\RefundPlugin as JsapiRefundPlugin; +use Yansongda\Pay\Plugin\Wechat\ResponsePlugin; +use Yansongda\Pay\Plugin\Wechat\StartPlugin; +use Yansongda\Pay\Plugin\Wechat\VerifySignaturePlugin; use Yansongda\Pay\Shortcut\Wechat\QueryShortcut; use Yansongda\Pay\Tests\TestCase; @@ -29,10 +34,13 @@ class QueryShortcutTest extends TestCase public function testDefault() { self::assertEquals([ - PreparePlugin::class, - QueryPlugin::class, - RadarSignPlugin::class, - LaunchPlugin::class, + StartPlugin::class, + JsapiQueryPlugin::class, + AddPayloadBodyPlugin::class, + AddPayloadSignaturePlugin::class, + AddRadarPlugin::class, + ResponsePlugin::class, + VerifySignaturePlugin::class, ParserPlugin::class, ], $this->plugin->getPlugins([])); } @@ -40,10 +48,13 @@ class QueryShortcutTest extends TestCase public function testRefund() { self::assertEquals([ - PreparePlugin::class, - QueryRefundPlugin::class, - RadarSignPlugin::class, - LaunchPlugin::class, + StartPlugin::class, + JsapiRefundPlugin::class, + AddPayloadBodyPlugin::class, + AddPayloadSignaturePlugin::class, + AddRadarPlugin::class, + ResponsePlugin::class, + VerifySignaturePlugin::class, ParserPlugin::class, ], $this->plugin->getPlugins(['_action' => 'refund'])); } @@ -51,10 +62,13 @@ class QueryShortcutTest extends TestCase public function testCombine() { self::assertEquals([ - PreparePlugin::class, - \Yansongda\Pay\Plugin\Wechat\Pay\Combine\QueryPlugin::class, - RadarSignPlugin::class, - LaunchPlugin::class, + StartPlugin::class, + CombineQueryPlugin::class, + AddPayloadBodyPlugin::class, + AddPayloadSignaturePlugin::class, + AddRadarPlugin::class, + ResponsePlugin::class, + VerifySignaturePlugin::class, ParserPlugin::class, ], $this->plugin->getPlugins(['_action' => 'combine'])); } @@ -62,14 +76,31 @@ class QueryShortcutTest extends TestCase public function testCombineParams() { self::assertEquals([ - PreparePlugin::class, - \Yansongda\Pay\Plugin\Wechat\Pay\Combine\QueryPlugin::class, - RadarSignPlugin::class, - LaunchPlugin::class, + StartPlugin::class, + CombineQueryPlugin::class, + AddPayloadBodyPlugin::class, + AddPayloadSignaturePlugin::class, + AddRadarPlugin::class, + ResponsePlugin::class, + VerifySignaturePlugin::class, ParserPlugin::class, ], $this->plugin->getPlugins(['combine_out_trade_no' => '123abc'])); } + public function testTransfer() + { + self::assertEquals([ + StartPlugin::class, + TransferQueryPlugin::class, + AddPayloadBodyPlugin::class, + AddPayloadSignaturePlugin::class, + AddRadarPlugin::class, + ResponsePlugin::class, + VerifySignaturePlugin::class, + ParserPlugin::class, + ], $this->plugin->getPlugins(['_action' => 'transfer'])); + } + public function testFoo() { self::expectException(InvalidParamsException::class); diff --git a/tests/Shortcut/Wechat/RefundShortcutTest.php b/tests/Shortcut/Wechat/RefundShortcutTest.php new file mode 100644 index 0000000..454b401 --- /dev/null +++ b/tests/Shortcut/Wechat/RefundShortcutTest.php @@ -0,0 +1,143 @@ +plugin = new RefundShortcut(); + } + + public function testDefault() + { + self::assertEquals([ + StartPlugin::class, + JsapiRefundPlugin::class, + AddPayloadBodyPlugin::class, + AddPayloadSignaturePlugin::class, + AddRadarPlugin::class, + ResponsePlugin::class, + VerifySignaturePlugin::class, + ParserPlugin::class, + ], $this->plugin->getPlugins([])); + } + + public function testApp() + { + self::assertEquals([ + StartPlugin::class, + AppRefundPlugin::class, + AddPayloadBodyPlugin::class, + AddPayloadSignaturePlugin::class, + AddRadarPlugin::class, + ResponsePlugin::class, + VerifySignaturePlugin::class, + ParserPlugin::class, + ], $this->plugin->getPlugins(['_action' => 'app'])); + } + + public function testCombine() + { + self::assertEquals([ + StartPlugin::class, + CombineRefundPlugin::class, + AddPayloadBodyPlugin::class, + AddPayloadSignaturePlugin::class, + AddRadarPlugin::class, + ResponsePlugin::class, + VerifySignaturePlugin::class, + ParserPlugin::class, + ], $this->plugin->getPlugins(['_action' => 'combine'])); + } + + public function testH5() + { + self::assertEquals([ + StartPlugin::class, + H5RefundPlugin::class, + AddPayloadBodyPlugin::class, + AddPayloadSignaturePlugin::class, + AddRadarPlugin::class, + ResponsePlugin::class, + VerifySignaturePlugin::class, + ParserPlugin::class, + ], $this->plugin->getPlugins(['_action' => 'h5'])); + } + + public function testJsapi() + { + self::assertEquals([ + StartPlugin::class, + JsapiRefundPlugin::class, + AddPayloadBodyPlugin::class, + AddPayloadSignaturePlugin::class, + AddRadarPlugin::class, + ResponsePlugin::class, + VerifySignaturePlugin::class, + ParserPlugin::class, + ], $this->plugin->getPlugins(['_action' => 'jsapi'])); + } + + public function testMini() + { + self::assertEquals([ + StartPlugin::class, + MiniRefundPlugin::class, + AddPayloadBodyPlugin::class, + AddPayloadSignaturePlugin::class, + AddRadarPlugin::class, + ResponsePlugin::class, + VerifySignaturePlugin::class, + ParserPlugin::class, + ], $this->plugin->getPlugins(['_action' => 'mini'])); + } + + public function testNative() + { + self::assertEquals([ + StartPlugin::class, + NativeRefundPlugin::class, + AddPayloadBodyPlugin::class, + AddPayloadSignaturePlugin::class, + AddRadarPlugin::class, + ResponsePlugin::class, + VerifySignaturePlugin::class, + ParserPlugin::class, + ], $this->plugin->getPlugins(['_action' => 'native'])); + } + + + public function testFoo() + { + self::expectException(InvalidParamsException::class); + self::expectExceptionCode(Exception::PARAMS_SHORTCUT_ACTION_INVALID); + self::expectExceptionMessage('Refund action [fooPlugins] not supported'); + + $this->plugin->getPlugins(['_action' => 'foo']); + } +} diff --git a/tests/Shortcut/Wechat/ScanShortcutTest.php b/tests/Shortcut/Wechat/ScanShortcutTest.php new file mode 100644 index 0000000..c30753b --- /dev/null +++ b/tests/Shortcut/Wechat/ScanShortcutTest.php @@ -0,0 +1,42 @@ +plugin = new ScanShortcut(); + } + + public function testDefault() + { + self::assertEquals([ + StartPlugin::class, + PayPlugin::class, + AddPayloadBodyPlugin::class, + AddPayloadSignaturePlugin::class, + AddRadarPlugin::class, + ResponsePlugin::class, + VerifySignaturePlugin::class, + ParserPlugin::class, + ], $this->plugin->getPlugins([])); + } +} diff --git a/tests/Shortcut/Wechat/TransferShortcutTest.php b/tests/Shortcut/Wechat/TransferShortcutTest.php new file mode 100644 index 0000000..55c415b --- /dev/null +++ b/tests/Shortcut/Wechat/TransferShortcutTest.php @@ -0,0 +1,42 @@ +plugin = new TransferShortcut(); + } + + public function testDefault() + { + self::assertEquals([ + StartPlugin::class, + CreatePlugin::class, + AddPayloadBodyPlugin::class, + AddPayloadSignaturePlugin::class, + AddRadarPlugin::class, + ResponsePlugin::class, + VerifySignaturePlugin::class, + ParserPlugin::class, + ], $this->plugin->getPlugins([])); + } +} diff --git a/tests/Shortcut/Wechat/WapShortcutTest.php b/tests/Shortcut/Wechat/WapShortcutTest.php new file mode 100644 index 0000000..b2d0420 --- /dev/null +++ b/tests/Shortcut/Wechat/WapShortcutTest.php @@ -0,0 +1,42 @@ +plugin = new WapShortcut(); + } + + public function testDefault() + { + self::assertEquals([ + StartPlugin::class, + PayPlugin::class, + AddPayloadBodyPlugin::class, + AddPayloadSignaturePlugin::class, + AddRadarPlugin::class, + ResponsePlugin::class, + VerifySignaturePlugin::class, + ParserPlugin::class, + ], $this->plugin->getPlugins([])); + } +} diff --git a/tests/TestCase.php b/tests/TestCase.php index c21552e..f39366a 100644 --- a/tests/TestCase.php +++ b/tests/TestCase.php @@ -13,12 +13,14 @@ class TestCase extends \PHPUnit\Framework\TestCase $config = [ 'alipay' => [ 'default' => [ - 'app_id' => 'yansongda', + 'app_id' => '9021000122682882', 'app_secret_cert' => 'MIIEpAIBAAKCAQEApSA9oxvcqfbgpgkxXvyCpnxaR6TPaEMh/ij+PhF8180zL82ic4whkrRlcu1Y179AKEZNar71Ugi37fKcXWLerjPOeb8WHnZgNG19gkAcOIqZPRPpJ1eRtwKEclIzt+j3H/wgXWkD7BTr61RjuAcviyvDVbAJ/TPlMqXdJFIuJwZblN2WblIv+4Dm1iPOB+fVCU3rsgg4eajf3HrZ7sq6fBhQhO5krDmIIYGsFZ+fohEgnLkBaF0gqNUb5Yb4PBfaEcu8Hcwq+XyBSMOVOIABRPQVDedW2sE/2NsLkR62DaEe/Ri9VUDJe0pE39P+X22DicJ3E3yrxvdioMnLtDqEuwIDAQABAoIBAQCSHZ1tH9J7c8IGKkxNyROzToZ0rxn5IK6LwKp5MfBO5X1N56DArldnAcpjkDL1dn7HJK6Mrr1WAfD/1ZcX680wSReEE9r2ybkHq3tMLn7KaZp/uYavEYYXc1rP7n1lV/iVjPz2q16VIU5Bx0MWLQWdGPSYdlXggHNoBe1RnobIcCGOVe9HlzCBtWzGpCZvMlqRbCuWAdp14aCkaJqpRxG4PY9Kd/NzELvhnCd9k8e7G2qcwx6gAoXN8OXO8jmZg/6fOvFnrGl6CBp8sioe5F3R023fDum546IqS8EZdCl5T0gW/boTbSV8luitab65xBO3PmUI+V2OEFCL6WcJxawBAoGBAOZoft6/LatdoXzr8vh+rKzacUHw246fpacbgx0B5DDymM7hbhXbY/NoCWPgBJtV3XI3DtMJ5yvlEVDQvPfbSHRPx2XQknwrM7ly2SLbaC+tuhcvoG6F1RLWFx+y/583seSlVNuWC9KdpLTKzo8wl8Z4/kheLTBxTxL20NZu79XBAoGBALd3fNoXk5V+T16hnSinPtt2NEsZpn+4w07DikzcpdyjCL5PYjp/BppmX3xly96fCZh3MO3Vkuya1xgauMzxVKQlR/aD5yVmsqK7wxNTY1ZQM74B44/4Mks/8MG2r7o3DElA4/qIeMP4CwkWmYcuij7npm2bgIqFzS+4aGZfDRF7AoGAKMO2Jpy2bMo9BwgLzdFDpbVkMmF1xu8R9NXWRayO/eX+CSQzQOS281qlxqjcx8rSSiHZmpb28notrRmxRTzjvchbo/TZ5eQS262pIxSkg0L+WJnRjZxaDWIZZz9ZIIdPDv/9WnhakSHZAS+cihLz12aSvqUC4744WkeWvUmVX0ECgYAGLDoCKHrps7c96tgbzwy5W4/E2xcUAwZnNwMHNQFLnBymMouOhkmVlk4uJEqosdcjzxbRWbc4yLjl8bg4BQKhBzQVojh7tKnb+c9Fbi/QbqBfCzc519LxXzRdgCUHceSy7kD9Y+wUQ9szMhR2TOWP2kFqPKolfvz5Vw4EK7yH0wKBgQDerq9Pthbii7lNt528/q0cH9vOMn9z76o6jMMea9EibclVHtdcQBWLOn8Yw97k+WSXYGuUrQUWWQbyabZqWkkS4cEjJf5/DiwOuYdNVXg7FK56ucTczBA7lR4dnunPW6U1HbSWf0Cn4Y/cl/z7B5QBSQt0W38IYHSaf6/sqsV6SA==', - 'app_auth_token' => 'yansongda_token', + 'app_auth_token' => '', 'app_public_cert_path' => __DIR__ . '/Cert/alipayAppPublicCert.crt', 'alipay_public_cert_path' => __DIR__ . '/Cert/alipayPublicCert.crt', 'alipay_root_cert_path' => __DIR__ . '/Cert/alipayRootCert.crt', + 'notify_url' => 'https://pay.yansongda.cn', + 'return_url' => 'https://pay.yansongda.cn', ], ], 'wechat' => [ @@ -31,7 +33,7 @@ class TestCase extends \PHPUnit\Framework\TestCase 'mch_secret_key' => '53D67FCB97E68F9998CBD17ED7A8D1E2', 'mch_secret_cert' => __DIR__.'/Cert/wechatAppPrivateKey.pem', 'mch_public_cert_path' => __DIR__.'/Cert/wechatAppPublicKey.pem', - 'notify_url' => 'pay.yansongda.cn', + 'notify_url' => 'https://pay.yansongda.cn', 'wechat_public_cert_path' => [ '45F59D4DABF31918AFCEC556D5D2C6E376675D57' => __DIR__.'/Cert/wechatPublicKey.crt', 'yansongda' => __DIR__.'/Cert/wechatPublicKey.crt', @@ -39,6 +41,7 @@ class TestCase extends \PHPUnit\Framework\TestCase 'mode' => Pay::MODE_NORMAL, ], 'service_provider' => [ + 'app_id' => 'yansongdaa', 'mp_app_id' => 'wx55955316af4ef13', 'mch_id' => '1600314069', 'mini_app_id' => 'wx55955316af4ef14', @@ -123,16 +126,16 @@ class TestCase extends \PHPUnit\Framework\TestCase 'mch_cert_path' => __DIR__.'/Cert/unipayAppCert.pfx', 'mch_cert_password' => '000000', 'unipay_public_cert_path' => __DIR__.'/Cert/unipayCertPublicKey.cer', - 'return_url' => 'https://yansongda.cn/unipay/return', - 'notify_url' => 'https://yansongda.cn/unipay/notify', + 'return_url' => 'https://pay.yansongda.cn', + 'notify_url' => 'https://pay.yansongda.cn', ], 'sandbox' => [ 'mch_id' => '777290058167151', 'mch_cert_path' => __DIR__.'/Cert/unipayAppCert.pfx', 'mch_cert_password' => '000000', 'unipay_public_cert_path' => __DIR__.'/Cert/unipayCertPublicKey.cer', - 'return_url' => 'https://yansongda.cn/unipay/return', - 'notify_url' => 'https://yansongda.cn/unipay/notify', + 'return_url' => 'https://pay.yansongda.cn', + 'notify_url' => 'https://pay.yansongda.cn', 'mode' => Pay::MODE_SANDBOX, ] ] diff --git a/tests/Traits/GetUnipayCertsTest.php b/tests/Traits/GetUnipayCertsTest.php index fd49d32..7849147 100644 --- a/tests/Traits/GetUnipayCertsTest.php +++ b/tests/Traits/GetUnipayCertsTest.php @@ -42,7 +42,7 @@ class GetUnipayCertsTest extends TestCase $this->expectException(InvalidConfigException::class); self::expectExceptionCode(Exception::CONFIG_UNIPAY_INVALID); - $this->expectExceptionMessage('Missing Unipay Config -- [mch_cert_path] or [mch_cert_password]'); + $this->expectExceptionMessage('配置异常: 缺少银联配置 -- [mch_cert_path] or [mch_cert_password]'); $this->trait->getCertId('default', get_unipay_config([])); } @@ -54,7 +54,7 @@ class GetUnipayCertsTest extends TestCase $this->expectException(InvalidConfigException::class); self::expectExceptionCode(Exception::CONFIG_UNIPAY_INVALID); - $this->expectExceptionMessage('Missing Unipay Config -- [mch_cert_path] or [mch_cert_password]'); + $this->expectExceptionMessage('配置异常: 缺少银联配置 -- [mch_cert_path] or [mch_cert_password]'); $this->trait->getCertId('default', get_unipay_config([])); } @@ -67,7 +67,7 @@ class GetUnipayCertsTest extends TestCase self::expectException(InvalidConfigException::class); self::expectExceptionCode(Exception::CONFIG_UNIPAY_INVALID); - self::expectExceptionMessage('Read `mch_cert_path` Error'); + self::expectExceptionMessage('配置异常: 读取银联 `mch_cert_path` 失败,请确认参数是否正确'); $this->trait->getCertId('default', get_unipay_config([])); } diff --git a/tests/Traits/HasWechatEncryptionTest.php b/tests/Traits/HasWechatEncryptionTest.php deleted file mode 100644 index 619d2ff..0000000 --- a/tests/Traits/HasWechatEncryptionTest.php +++ /dev/null @@ -1,85 +0,0 @@ -trait = new HasWechatEncryptionStub(); - } - - public function testLoadSerialNo() - { - // 不传证书 - $params = []; - $result = $this->trait->loadSerialNo($params); - self::assertTrue(in_array($result['_serial_no'], ['45F59D4DABF31918AFCEC556D5D2C6E376675D57', 'yansongda'])); - - // 传证书 - $params = ['_serial_no' => 'yansongda',]; - $result = $this->trait->loadSerialNo($params); - self::assertEquals('yansongda', $result['_serial_no']); - } - - public function testLoadSerialNoWithRequestWechat() - { - $response = new Response( - 200, - [], - json_encode([ - 'data' => [ - [ - 'effective_time' => '2021-07-16T17:51:10+08:00', - 'encrypt_certificate' => [ - 'algorithm' => 'AEAD_AES_256_GCM', - 'associated_data' => 'certificate', - 'ciphertext' => 'kbbHAUhBwdjYZkHPW149MW/8WNpxQo1Gyp4kVNVjd+zrXnyOFhgZic2U2+tobFAgfdr93zr0JZF3FdbxgkaOAV2NAeCfU8jsUYXSfn7fM8487jXMVXKKEneGiiv1/bDLkz7KFsTfu2y5Rv+igWQ+bvCUQAwoNzjupTXnnDR5hBiofZcFLHL45govyYE2o0qD5SLiJHcFS4pg/IOx8SIqUFNepr3piKXUxKowU8/kNxXyRzL8yp7XnhrzAzclupvjveNwZyiw3TqlLZdR5TbEFLCogWaRHZRqz3vKEfgRaUYUtXCtQVrm+adbSDBFIq34v+XfeIHMz9pKhH/m80N5Hx69hPzbvIdBhzwaEDyN3h8gaeYKFyW9xIAs5jCrzzUEkKyMzOKzx7XA+1HRakSyvs6RlkRTa/ztBy6aZL0nxK6XMZ9tA7zdf2VnBX/7WPQYRzoky0cVyH1KRZxI7In2hfvpjSvl6P7Adzp+EZXYM/dINTrrg+RQRe60tPy7vgE8PZZf+SAWzSZPWIm7Lx6GksJX0vnT4gOeTAPw6EeFsYU/ZD7fYslJOEbA14yHBrJFkwDpSI8aSHp2nZYbruM0y8IKr0p3vjN80Ko3jiRPxj4uNdJliR9WDCV22b9JeadAaJhO9+oSNbbtFnFTCZjXbf8rMz5KCGVrGRvUyB70zhRxYIOdTYKAEkmbU7jcMLd0aufuQqIw0WviQHB+ztrkjBCFwPu5/hlRVj9opNFnzYNltfVGrA1XW3NQ4FaMNah95ahomAG/+S7zJqq4Gvk1O/PgQ9kMP0adY3GlrHUNqr2zC709IervMQ1pEdcuNEln3V5TSDiE0x7BjoMoN2m+MKAIhw59VxzHGNmJELbkKsZUhKKXFFyEXFsw143/9IYOyanmHQxujdIBKI0rxYkVz9QgaajisCzdnRf0ymnkceGGnYsP7VTYBnuCncjgHxbEn3emlTRygEjgj/epupsQL2tfW+snxnafEM+Pc079pUYmKeCUEUoX/FUmdFIf8hlSHBTjEVMGsNUI/u2W781RBDfk2X/2QQQm3NOjgZ3le6hxEQqc12yANTvdq7cFVllWqMHBsXPCjpHWIHcS5BMkImoD7s6WItq60yJA8ioGJf3Rba+Yb/YeBBNxjDnXtAmX/2hJIsxEFLTYGUvdmFC5jeb5ifrOuxnLciKM8y4nLZ28dDsvVsaBBAMAFYfWb5NymKUDhhngR5bDuW4sKccZ6DmYQeStHT1fn2yoSneGA70HctQSWZ2roTdNihPTCs7rYD0dFeQ+SfLOJzMN4c5GbJ6n5tdCjERcLGIaXEKacfySo7e4VZtHeHowvlvBclS9pooZqzHd+EFlJEYywEs9jURgsJY2yHJt2zTZeIdsvM8KK5v0NkH8FiPbWqFG8LaRmUrqhJGLuLLRTcJnt6YVYESxUVTb3pmriUbXfg/ThHF/y0THyrM6bVDNOwNWZOpMYPPNaVmOTX39JdYayWl2HX0n8AsIRmevXzD4N9iDh2HGwie4gh92Qdcogwua++uhkhSsLFuWBpJiaPdxVtzz3E3jHfy+yryfh6msaXc/jmhwqBm/ii3j76lDP5YaRv4+JWZmom72+pmZuKD8qPKrPRxI2/aGiKEqgs25knpLLnbAhWAEYeIzVK1sQkjc5JFss1Std8FdDrHeM6agAB+MWncK1LloXZmiwz/6WmlwSDepnGHqLEciXThAZq6FwunJZTcHY9LamJgIY81c9t/KHlSFqlc/9mW4OZHM4BOZQ5sTj5PWE+OP2Aq9CKdJqoK3OmphBg2ewjrZt5/tSn9jpk6NlVrHD7MsJcKi5a0he4qvNPh1cHqUqWcF4rBFmfPptdHIBV77LXnizJZMUAwf16KsmJpwJg==', - 'nonce' => '4196a5b75276', - ], - 'expire_time' => '2026-07-15T17:51:10+08:00', - 'serial_no' => 'test-45F59D4DABF31918AFCEC556D5D2C6E376675D57', - ] - ] - ]) - ); - - $http = Mockery::mock(Client::class); - $http->shouldReceive('sendRequest')->andReturn($response); - - Pay::set(HttpClientInterface::class, $http); - - $params = ['_config' => 'empty_wechat_public_cert']; - $result = $this->trait->loadSerialNo($params); - self::assertEquals('test-45F59D4DABF31918AFCEC556D5D2C6E376675D57', $result['_serial_no']); - } - - public function testGetPublicKey() - { - $serialNo = '45F59D4DABF31918AFCEC556D5D2C6E376675D57'; - $result = $this->trait->getPublicKey([], $serialNo); - self::assertIsString($result); - - $serialNo = 'non-exist'; - self::expectException(InvalidParamsException::class); - self::expectExceptionCode(Exception::PARAMS_WECHAT_SERIAL_NOT_FOUND); - $this->trait->getPublicKey([], $serialNo); - } -}