From 955cb284276a4081e46fc9c1ce99d12c5cafb7e3 Mon Sep 17 00:00:00 2001 From: Anyon Date: Thu, 11 Dec 2025 16:23:29 +0800 Subject: [PATCH] =?UTF-8?q?fix:=20=E6=89=B9=E9=87=8F=E6=9B=B4=E6=96=B0?= =?UTF-8?q?=E4=BB=A3=E7=A0=81=EF=BC=8C=E5=90=8C=E6=97=B6=E5=A2=9E=E5=8A=A0?= =?UTF-8?q?=E9=80=9A=E7=94=A8=E6=8E=A5=E5=8F=A3=E8=B0=83=E7=94=A8?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- AliPay/App.php | 9 +- AliPay/Bill.php | 9 +- AliPay/Pos.php | 9 +- AliPay/Scan.php | 9 +- AliPay/Trade.php | 21 +- AliPay/Transfer.php | 27 +- AliPay/Wap.php | 9 +- AliPay/Web.php | 9 +- We.php | 5 +- WeChat/Card.php | 221 ++- WeChat/Contracts/BasicAliPay.php | 535 ++++---- WeChat/Contracts/BasicPushEvent.php | 51 +- WeChat/Contracts/BasicWeChat.php | 185 ++- WeChat/Contracts/BasicWePay.php | 172 ++- WeChat/Contracts/BasicWeWork.php | 3 +- WeChat/Contracts/DataArray.php | 62 +- WeChat/Contracts/DataError.php | 3 +- WeChat/Contracts/MyCurlFile.php | 3 +- WeChat/Contracts/Tools.php | 266 ++-- WeChat/Custom.php | 49 +- WeChat/Draft.php | 29 +- .../Exceptions/InvalidArgumentException.php | 5 +- WeChat/Exceptions/InvalidDecryptException.php | 5 +- .../Exceptions/InvalidInstanceException.php | 3 +- .../Exceptions/InvalidResponseException.php | 5 +- WeChat/Exceptions/LocalCacheException.php | 5 +- WeChat/Freepublish.php | 33 +- WeChat/Limit.php | 11 +- WeChat/Media.php | 45 +- WeChat/Menu.php | 35 +- WeChat/Oauth.php | 35 +- WeChat/Pay.php | 65 +- WeChat/Product.php | 31 +- WeChat/Prpcrypt/ErrorCode.php | 1 - WeChat/Prpcrypt/PKCS7Encoder.php | 1 - WeChat/Prpcrypt/Prpcrypt.php | 31 +- WeChat/Qrcode.php | 21 +- WeChat/Receive.php | 37 +- WeChat/Scan.php | 35 +- WeChat/Script.php | 71 +- WeChat/Shake.php | 95 +- WeChat/Tags.php | 32 +- WeChat/Template.php | 25 +- WeChat/User.php | 57 +- WeChat/Wifi.php | 91 +- WeMini/Crypt.php | 96 +- WeMini/Custom.php | 41 +- WeMini/Delivery.php | 43 +- WeMini/Guide.php | 136 +- WeMini/Image.php | 21 +- WeMini/Insurance.php | 51 +- WeMini/Live.php | 125 +- WeMini/Logistics.php | 45 +- WeMini/Market.php | 13 +- WeMini/Media.php | 7 +- WeMini/Message.php | 15 +- WeMini/Newtmpl.php | 39 +- WeMini/Ocr.php | 27 +- WeMini/Operation.php | 17 +- WeMini/Plugs.php | 30 +- WeMini/Poi.php | 29 +- WeMini/Qrcode.php | 43 +- WeMini/Scheme.php | 11 +- WeMini/Search.php | 7 +- WeMini/Security.php | 17 +- WeMini/Shipping.php | 35 +- WeMini/Shopping.php | 17 +- WeMini/Soter.php | 7 +- WeMini/Template.php | 27 +- WeMini/Total.php | 49 +- WeMini/crypt/wxBizDataCrypt.php | 1 - WePay/Bill.php | 15 +- WePay/Coupon.php | 19 +- WePay/Custom.php | 21 +- WePay/Order.php | 61 +- WePay/ProfitSharing.php | 43 +- WePay/Redpack.php | 19 +- WePay/Refund.php | 21 +- WePay/Transfers.php | 15 +- WePay/TransfersBank.php | 47 +- WePayV3/Cert.php | 5 +- WePayV3/Complaints.php | 39 +- WePayV3/Contracts/BasicWePay.php | 319 ++--- WePayV3/Contracts/DecryptAes.php | 6 +- WePayV3/Coupon.php | 31 +- WePayV3/Ecommerce.php | 157 ++- WePayV3/Order.php | 85 +- WePayV3/ProfitSharing.php | 21 +- WePayV3/Refund.php | 20 +- WePayV3/Transfers.php | 39 +- _test/alipay-app.php | 4 +- _test/alipay-bill.php | 2 +- _test/alipay-callapi-test.php | 163 +++ _test/alipay-notify.php | 2 +- _test/alipay-pos.php | 2 +- _test/alipay-refund.php | 2 +- _test/alipay-scan.php | 2 +- _test/alipay-transfer-account.php | 2 +- _test/alipay-transfer-create.php | 2 +- _test/alipay-transfer-query.php | 2 +- _test/alipay-transfer.php | 2 +- _test/alipay-wap.php | 2 +- _test/alipay-web.php | 2 +- _test/alipay.php | 2 +- _test/alipay2.php | 2 +- _test/config.php | 2 +- _test/mini-login.php | 2 +- _test/mini-qrc.php | 2 +- _test/pay-callapi-test.php | 169 +++ _test/pay-config.php | 2 +- _test/pay-download-bill.php | 2 +- _test/pay-order-close.php | 2 +- _test/pay-order-create.php | 2 +- _test/pay-order-notify.php | 2 +- _test/pay-order-query.php | 2 +- _test/pay-redpack-create.php | 2 +- _test/pay-refund-create.php | 2 +- _test/pay-refund-query.php | 2 +- _test/pay-transfers-create.php | 2 +- _test/pay-transfersbank-create.php | 2 +- _test/pay-v3-callapi-test.php | 205 +++ _test/pay-v3-config-cert.php | 2 +- _test/pay-v3-config.php | 2 +- _test/pay-v3-order-app.php | 2 +- _test/pay-v3-order-h5.php | 2 +- _test/pay-v3-order-jsapi.php | 2 +- _test/pay-v3-order-native.php | 2 +- _test/pay-v3-transfer.php | 2 +- _test/wechat-callapi-test.php | 139 ++ _test/wechat-jssdk-sign.php | 2 +- _test/wechat-menu-get.php | 2 +- _test/wechat-qrcode-create.php | 2 +- _test/wechat-user-get.php | 2 +- _test/work-config.php | 2 +- _test/work-department.php | 2 +- include.php | 2 +- readme.md | 1202 +++++++++++++---- 137 files changed, 3898 insertions(+), 2459 deletions(-) create mode 100644 _test/alipay-callapi-test.php create mode 100644 _test/pay-callapi-test.php create mode 100644 _test/pay-v3-callapi-test.php create mode 100644 _test/wechat-callapi-test.php diff --git a/AliPay/App.php b/AliPay/App.php index 0eba717..24f6f43 100644 --- a/AliPay/App.php +++ b/AliPay/App.php @@ -3,7 +3,7 @@ // +---------------------------------------------------------------------- // | WeChatDeveloper // +---------------------------------------------------------------------- -// | 版权所有 2014~2025 ThinkAdmin [ thinkadmin.top ] +// | 版权所有 2014~2026 ThinkAdmin [ thinkadmin.top ] // +---------------------------------------------------------------------- // | 官方网站: https://thinkadmin.top // +---------------------------------------------------------------------- @@ -20,7 +20,6 @@ use WeChat\Contracts\BasicAliPay; /** * 支付宝App支付网关 - * Class App * @package AliPay */ class App extends BasicAliPay @@ -38,9 +37,9 @@ class App extends BasicAliPay } /** - * 创建数据操作 - * @param array $options - * @return string + * 生成APP支付参数字符串 + * @param array $options 订单参数(out_trade_no, total_amount, subject等) + * @return string URL编码后的参数字符串(用于APP调起支付) */ public function apply($options) { diff --git a/AliPay/Bill.php b/AliPay/Bill.php index 3d7c8b2..5dcf921 100644 --- a/AliPay/Bill.php +++ b/AliPay/Bill.php @@ -3,7 +3,7 @@ // +---------------------------------------------------------------------- // | WeChatDeveloper // +---------------------------------------------------------------------- -// | 版权所有 2014~2025 ThinkAdmin [ thinkadmin.top ] +// | 版权所有 2014~2026 ThinkAdmin [ thinkadmin.top ] // +---------------------------------------------------------------------- // | 官方网站: https://thinkadmin.top // +---------------------------------------------------------------------- @@ -20,7 +20,6 @@ use WeChat\Contracts\BasicAliPay; /** * 支付宝电子面单下载 - * Class Bill * @package AliPay */ class Bill extends BasicAliPay @@ -36,9 +35,9 @@ class Bill extends BasicAliPay } /** - * 创建数据操作 - * @param array $options - * @return array|bool + * 获取账单下载地址 + * @param array $options 账单参数(bill_type, bill_date 等) + * @return array|bool 包含 bill_download_url * @throws \WeChat\Exceptions\InvalidResponseException * @throws \WeChat\Exceptions\LocalCacheException */ diff --git a/AliPay/Pos.php b/AliPay/Pos.php index 0a2e13a..73d114c 100644 --- a/AliPay/Pos.php +++ b/AliPay/Pos.php @@ -3,7 +3,7 @@ // +---------------------------------------------------------------------- // | WeChatDeveloper // +---------------------------------------------------------------------- -// | 版权所有 2014~2025 ThinkAdmin [ thinkadmin.top ] +// | 版权所有 2014~2026 ThinkAdmin [ thinkadmin.top ] // +---------------------------------------------------------------------- // | 官方网站: https://thinkadmin.top // +---------------------------------------------------------------------- @@ -20,7 +20,6 @@ use WeChat\Contracts\BasicAliPay; /** * 支付宝刷卡支付 - * Class Pos * @package AliPay */ class Pos extends BasicAliPay @@ -37,9 +36,9 @@ class Pos extends BasicAliPay } /** - * 创建数据操作 - * @param array $options - * @return array|bool + * 刷卡支付(条码/声波)下单 + * @param array $options 订单参数(out_trade_no, auth_code, subject, total_amount 等) + * @return array|bool 支付结果 * @throws \WeChat\Exceptions\InvalidResponseException * @throws \WeChat\Exceptions\LocalCacheException */ diff --git a/AliPay/Scan.php b/AliPay/Scan.php index efa185e..efba5b5 100644 --- a/AliPay/Scan.php +++ b/AliPay/Scan.php @@ -3,7 +3,7 @@ // +---------------------------------------------------------------------- // | WeChatDeveloper // +---------------------------------------------------------------------- -// | 版权所有 2014~2025 ThinkAdmin [ thinkadmin.top ] +// | 版权所有 2014~2026 ThinkAdmin [ thinkadmin.top ] // +---------------------------------------------------------------------- // | 官方网站: https://thinkadmin.top // +---------------------------------------------------------------------- @@ -20,7 +20,6 @@ use WeChat\Contracts\BasicAliPay; /** * 支付宝扫码支付 - * Class Scan * @package AliPay */ class Scan extends BasicAliPay @@ -36,9 +35,9 @@ class Scan extends BasicAliPay } /** - * 创建数据操作 - * @param array $options - * @return array|bool + * 预创建扫码支付订单(返回二维码地址) + * @param array $options 订单参数(out_trade_no, subject, total_amount 等) + * @return array|bool 包含 qr_code 的预下单结果 * @throws \WeChat\Exceptions\InvalidResponseException * @throws \WeChat\Exceptions\LocalCacheException */ diff --git a/AliPay/Trade.php b/AliPay/Trade.php index 2057c2d..76b783a 100644 --- a/AliPay/Trade.php +++ b/AliPay/Trade.php @@ -3,7 +3,7 @@ // +---------------------------------------------------------------------- // | WeChatDeveloper // +---------------------------------------------------------------------- -// | 版权所有 2014~2025 ThinkAdmin [ thinkadmin.top ] +// | 版权所有 2014~2026 ThinkAdmin [ thinkadmin.top ] // +---------------------------------------------------------------------- // | 官方网站: https://thinkadmin.top // +---------------------------------------------------------------------- @@ -20,15 +20,14 @@ use WeChat\Contracts\BasicAliPay; /** * 支付宝标准接口 - * Class Trade * @package AliPay */ class Trade extends BasicAliPay { /** - * 设置交易接口地址 - * @param string $method + * 设置交易接口方法名 + * @param string $method 如 alipay.trade.close 等 * @return $this */ public function setMethod($method) @@ -38,7 +37,7 @@ class Trade extends BasicAliPay } /** - * 获取交易接口地址 + * 获取当前交易接口方法名 * @return string */ public function getMethod() @@ -47,8 +46,8 @@ class Trade extends BasicAliPay } /** - * 设置接口公共参数 - * @param array $option + * 设置公共参数(透传到 options) + * @param array $option key-value 公共参数 * @return Trade */ public function setOption($option = []) @@ -60,7 +59,7 @@ class Trade extends BasicAliPay } /** - * 获取接口公共参数 + * 获取当前公共参数 * @return array|string|null */ public function getOption() @@ -69,9 +68,9 @@ class Trade extends BasicAliPay } /** - * 执行通过接口 - * @param array $options - * @return array|boolean + * 执行当前设置的交易接口 + * @param array $options 业务参数(写入 biz_content) + * @return array|boolean 接口返回结果 * @throws \WeChat\Exceptions\InvalidResponseException * @throws \WeChat\Exceptions\LocalCacheException */ diff --git a/AliPay/Transfer.php b/AliPay/Transfer.php index cdbcb80..837deac 100644 --- a/AliPay/Transfer.php +++ b/AliPay/Transfer.php @@ -3,7 +3,7 @@ // +---------------------------------------------------------------------- // | WeChatDeveloper // +---------------------------------------------------------------------- -// | 版权所有 2014~2025 ThinkAdmin [ thinkadmin.top ] +// | 版权所有 2014~2026 ThinkAdmin [ thinkadmin.top ] // +---------------------------------------------------------------------- // | 官方网站: https://thinkadmin.top // +---------------------------------------------------------------------- @@ -20,16 +20,15 @@ use WeChat\Contracts\BasicAliPay; /** * 支付宝转账到账户 - * Class Transfer * @package AliPay */ class Transfer extends BasicAliPay { /** - * 旧版 向指定支付宝账户转账 - * @param array $options - * @return array|bool + * 旧版:向支付宝账户转账(toaccount.transfer) + * @param array $options 转账参数(out_biz_no, payee_type, payee_account, amount, remark 等) + * @return array|bool 转账结果 * @throws \WeChat\Exceptions\InvalidResponseException * @throws \WeChat\Exceptions\LocalCacheException */ @@ -40,9 +39,9 @@ class Transfer extends BasicAliPay } /** - * 新版 向指定支付宝账户转账 - * @param array $options - * @return array|bool + * 新版:统一转账接口(uni.transfer) + * @param array $options 转账参数(out_biz_no, trans_amount, product_code, payee_info 等) + * @return array|bool 转账结果 * @throws \WeChat\Exceptions\InvalidResponseException * @throws \WeChat\Exceptions\LocalCacheException */ @@ -53,9 +52,9 @@ class Transfer extends BasicAliPay } /** - * 新版 转账业务单据查询接口 - * @param array $options - * @return array|bool + * 新版:转账业务单据查询 + * @param array $options 查询参数(out_biz_no 或 order_id) + * @return array|bool 查询结果 * @throws \WeChat\Exceptions\InvalidResponseException * @throws \WeChat\Exceptions\LocalCacheException */ @@ -66,9 +65,9 @@ class Transfer extends BasicAliPay } /** - * 新版 支付宝资金账户资产查询接口 - * @param array $options - * @return array|bool + * 新版:资金账户余额查询 + * @param array $options 查询参数(alipay_user_id 或 user_id,可选 account_type) + * @return array|bool 账户余额等信息 * @throws \WeChat\Exceptions\InvalidResponseException * @throws \WeChat\Exceptions\LocalCacheException */ diff --git a/AliPay/Wap.php b/AliPay/Wap.php index 4eaea4f..2c6b8ef 100644 --- a/AliPay/Wap.php +++ b/AliPay/Wap.php @@ -3,7 +3,7 @@ // +---------------------------------------------------------------------- // | WeChatDeveloper // +---------------------------------------------------------------------- -// | 版权所有 2014~2025 ThinkAdmin [ thinkadmin.top ] +// | 版权所有 2014~2026 ThinkAdmin [ thinkadmin.top ] // +---------------------------------------------------------------------- // | 官方网站: https://thinkadmin.top // +---------------------------------------------------------------------- @@ -20,7 +20,6 @@ use WeChat\Contracts\BasicAliPay; /** * 手机WAP网站支付支持 - * Class Wap * @package AliPay */ class Wap extends BasicAliPay @@ -37,9 +36,9 @@ class Wap extends BasicAliPay } /** - * 创建数据操作 - * @param array $options - * @return string + * 生成 WAP 支付表单 HTML + * @param array $options 订单参数(out_trade_no, total_amount, subject, quit_url, return_url 等) + * @return string 自动提交的支付表单 HTML */ public function apply($options) { diff --git a/AliPay/Web.php b/AliPay/Web.php index 5ee7f59..9b65df5 100644 --- a/AliPay/Web.php +++ b/AliPay/Web.php @@ -3,7 +3,7 @@ // +---------------------------------------------------------------------- // | WeChatDeveloper // +---------------------------------------------------------------------- -// | 版权所有 2014~2025 ThinkAdmin [ thinkadmin.top ] +// | 版权所有 2014~2026 ThinkAdmin [ thinkadmin.top ] // +---------------------------------------------------------------------- // | 官方网站: https://thinkadmin.top // +---------------------------------------------------------------------- @@ -20,7 +20,6 @@ use WeChat\Contracts\BasicAliPay; /** * 支付宝网站支付 - * Class Web * @package AliPay */ class Web extends BasicAliPay @@ -37,9 +36,9 @@ class Web extends BasicAliPay } /** - * 创建数据操作 - * @param array $options - * @return string + * 生成网站支付表单HTML + * @param array $options 订单参数(out_trade_no, total_amount, subject等) + * @return string 支付表单HTML(自动提交到支付宝) */ public function apply($options) { diff --git a/We.php b/We.php index 126f4b9..5bcb5d8 100644 --- a/We.php +++ b/We.php @@ -3,7 +3,7 @@ // +---------------------------------------------------------------------- // | WeChatDeveloper // +---------------------------------------------------------------------- -// | 版权所有 2014~2025 ThinkAdmin [ thinkadmin.top ] +// | 版权所有 2014~2026 ThinkAdmin [ thinkadmin.top ] // +---------------------------------------------------------------------- // | 官方网站: https://thinkadmin.top // +---------------------------------------------------------------------- @@ -20,7 +20,6 @@ use WeChat\Exceptions\InvalidInstanceException; /** * 加载缓存器 * - * Class We * @library WeChatDeveloper * @author Anyon * @date 2018/05/24 13:23 @@ -59,7 +58,7 @@ use WeChat\Exceptions\InvalidInstanceException; * ----- WeMini ----- * @method \WeMini\Crypt WeMiniCrypt($options = []) static 小程序数据加密处理 * @method \WeMini\Delivery WeMiniDelivery($options = []) static 小程序即时配送 - * @method \WeMini\Shipping WeMiniShipping($options = []) satic 小程序发货信息 + * @method \WeMini\Shipping WeMiniShipping($options = []) static 小程序发货信息 * @method \WeMini\Guide WeMiniGuide($options = []) static 小程序导购助手 * @method \WeMini\Image WeMiniImage($options = []) static 小程序图像处理 * @method \WeMini\Live WeMiniLive($options = []) static 小程序直播接口 diff --git a/WeChat/Card.php b/WeChat/Card.php index a19a9a5..a2224a9 100644 --- a/WeChat/Card.php +++ b/WeChat/Card.php @@ -3,7 +3,7 @@ // +---------------------------------------------------------------------- // | WeChatDeveloper // +---------------------------------------------------------------------- -// | 版权所有 2014~2025 ThinkAdmin [ thinkadmin.top ] +// | 版权所有 2014~2026 ThinkAdmin [ thinkadmin.top ] // +---------------------------------------------------------------------- // | 官方网站: https://thinkadmin.top // +---------------------------------------------------------------------- @@ -20,14 +20,13 @@ use WeChat\Contracts\BasicWeChat; /** * 卡券管理 - * Class Card * @package WeChat */ class Card extends BasicWeChat { /** * 创建卡券 - * @param array $data + * @param array $data 卡券数据(card 对象) * @return array * @throws Exceptions\InvalidResponseException * @throws Exceptions\LocalCacheException @@ -39,9 +38,9 @@ class Card extends BasicWeChat } /** - * 设置买单接口 - * @param string $cardId - * @param bool $isOpen + * 设置买单开关 + * @param string $cardId 卡券ID + * @param bool $isOpen 是否开启 * @return array * @throws Exceptions\InvalidResponseException * @throws Exceptions\LocalCacheException @@ -53,9 +52,9 @@ class Card extends BasicWeChat } /** - * 设置自助核销接口 - * @param string $cardId - * @param bool $isOpen + * 设置自助核销 + * @param string $cardId 卡券ID + * @param bool $isOpen 是否开启 * @return array * @throws Exceptions\InvalidResponseException * @throws Exceptions\LocalCacheException @@ -67,8 +66,8 @@ class Card extends BasicWeChat } /** - * 创建二维码接口 - * @param array $data + * 创建卡券二维码 + * @param array $data 二维码参数(action_name, card 等) * @return array * @throws Exceptions\InvalidResponseException * @throws Exceptions\LocalCacheException @@ -80,8 +79,8 @@ class Card extends BasicWeChat } /** - * 创建货架接口 - * @param array $data + * 创建卡券货架 + * @param array $data 货架参数 * @return array * @throws Exceptions\InvalidResponseException * @throws Exceptions\LocalCacheException @@ -93,9 +92,9 @@ class Card extends BasicWeChat } /** - * 导入自定义code - * @param string $cardId - * @param array $code + * 导入自定义 code + * @param string $cardId 卡券ID + * @param array $code code 列表(最多10万) * @return array * @throws Exceptions\InvalidResponseException * @throws Exceptions\LocalCacheException @@ -107,8 +106,8 @@ class Card extends BasicWeChat } /** - * 查询导入code数目 - * @param string $cardId + * 查询已导入 code 数量 + * @param string $cardId 卡券ID * @return array * @throws Exceptions\InvalidResponseException * @throws Exceptions\LocalCacheException @@ -120,9 +119,9 @@ class Card extends BasicWeChat } /** - * 核查code接口 - * @param string $cardId 进行导入code的卡券ID - * @param array $code 已经微信卡券后台的自定义code,上限为100个 + * 校验导入的 code + * @param string $cardId 卡券ID + * @param array $code 自定义 code 列表(<=100) * @return array * @throws Exceptions\InvalidResponseException * @throws Exceptions\LocalCacheException @@ -134,8 +133,8 @@ class Card extends BasicWeChat } /** - * 图文消息群发卡券 - * @param string $cardId + * 获取图文群发卡券的 HTML + * @param string $cardId 卡券ID * @return array * @throws Exceptions\InvalidResponseException * @throws Exceptions\LocalCacheException @@ -148,8 +147,8 @@ class Card extends BasicWeChat /** * 设置测试白名单 - * @param array $openids - * @param array $usernames + * @param array $openids 测试 openid 列表 + * @param array $usernames 测试微信号列表 * @return array * @throws Exceptions\InvalidResponseException * @throws Exceptions\LocalCacheException @@ -161,10 +160,10 @@ class Card extends BasicWeChat } /** - * 线下核销查询Code - * @param string $code 单张卡券的唯一标准 - * @param string $cardId 卡券ID代表一类卡券。自定义code卡券必填 - * @param bool $checkConsume 是否校验code核销状态,填入true和false时的code异常状态返回数据不同 + * 查询 Code 状态 + * @param string $code 卡券 code + * @param string $cardId 卡券ID(自定义 code 必填) + * @param bool $checkConsume 是否校验核销状态 * @return array * @throws Exceptions\InvalidResponseException * @throws Exceptions\LocalCacheException @@ -179,9 +178,9 @@ class Card extends BasicWeChat } /** - * 线下核销核销Code - * @param string $code 需核销的Code码 - * @param null $card_id 券ID。创建卡券时use_custom_code填写true时必填。非自定义Code不必填写 + * 核销 Code + * @param string $code 待核销的 code + * @param null|string $card_id 卡券ID(自定义 code 必填) * @return array * @throws Exceptions\InvalidResponseException * @throws Exceptions\LocalCacheException @@ -195,8 +194,8 @@ class Card extends BasicWeChat } /** - * Code解码接口 - * @param string $encryptCode + * 解码加密 Code + * @param string $encryptCode 加密 code * @return array * @throws Exceptions\InvalidResponseException * @throws Exceptions\LocalCacheException @@ -208,9 +207,9 @@ class Card extends BasicWeChat } /** - * 获取用户已领取卡券接口 - * @param string $openid - * @param null|string $cardId + * 获取用户已领取卡券 + * @param string $openid 用户 openid + * @param null|string $cardId 卡券ID(可选) * @return array * @throws Exceptions\InvalidResponseException * @throws Exceptions\LocalCacheException @@ -225,7 +224,7 @@ class Card extends BasicWeChat /** * 查看卡券详情 - * @param string $cardId + * @param string $cardId 卡券ID * @return array * @throws Exceptions\InvalidResponseException * @throws Exceptions\LocalCacheException @@ -237,10 +236,10 @@ class Card extends BasicWeChat } /** - * 批量查询卡券列表 - * @param int $offset 查询卡列表的起始偏移量,从0开始,即offset: 5是指从从列表里的第六个开始读取 - * @param int $count 需要查询的卡片的数量(数量最大50) - * @param array $statusList 支持开发者拉出指定状态的卡券列表 + * 批量查询卡券 + * @param int $offset 起始偏移量 + * @param int $count 拉取数量(<=50) + * @param array $statusList 状态过滤 * @return array * @throws Exceptions\InvalidResponseException * @throws Exceptions\LocalCacheException @@ -254,9 +253,9 @@ class Card extends BasicWeChat } /** - * 更改卡券信息接口 - * @param string $cardId - * @param array $memberCard + * 更新会员卡信息 + * @param string $cardId 卡券ID + * @param array $memberCard 会员卡内容 * @return array * @throws Exceptions\InvalidResponseException * @throws Exceptions\LocalCacheException @@ -268,10 +267,10 @@ class Card extends BasicWeChat } /** - * 修改库存接口 + * 修改库存 * @param string $card_id 卡券ID - * @param null|integer $increase_stock_value 增加多少库存,支持不填或填0 - * @param null|integer $reduce_stock_value 减少多少库存,可以不填或填0 + * @param int|null $increase_stock_value 增加库存 + * @param int|null $reduce_stock_value 减少库存 * @return array * @throws Exceptions\InvalidResponseException * @throws Exceptions\LocalCacheException @@ -286,9 +285,9 @@ class Card extends BasicWeChat } /** - * 更改Code接口 - * @param string $code 需变更的Code码 - * @param string $new_code 变更后的有效Code码 + * 变更 Code + * @param string $code 原 code + * @param string $new_code 新 code * @param null|string $card_id 卡券ID * @return array * @throws Exceptions\InvalidResponseException @@ -303,8 +302,8 @@ class Card extends BasicWeChat } /** - * 删除卡券接口 - * @param string $cardId + * 删除卡券 + * @param string $cardId 卡券ID * @return array * @throws Exceptions\InvalidResponseException * @throws Exceptions\LocalCacheException @@ -316,10 +315,10 @@ class Card extends BasicWeChat } /** - * 设置卡券失效接口 - * @param string $code - * @param string $cardId - * @param null|string $reason + * 设置卡券失效 + * @param string $code 卡券 code + * @param string $cardId 卡券ID + * @param null|string $reason 失效原因 * @return array * @throws Exceptions\InvalidResponseException * @throws Exceptions\LocalCacheException @@ -333,10 +332,10 @@ class Card extends BasicWeChat } /** - * 拉取卡券概况数据接口 - * @param string $beginDate 查询数据的起始时间 - * @param string $endDate 查询数据的截至时间 - * @param string $condSource 卡券来源(0为公众平台创建的卡券数据 1是API创建的卡券数据) + * 拉取卡券概况数据 + * @param string $beginDate 开始日期 + * @param string $endDate 结束日期 + * @param string $condSource 卡券来源 0|1 * @return array * @throws Exceptions\InvalidResponseException * @throws Exceptions\LocalCacheException @@ -349,11 +348,11 @@ class Card extends BasicWeChat } /** - * 获取免费券数据接口 - * @param string $beginDate 查询数据的起始时间 - * @param string $endDate 查询数据的截至时间 - * @param integer $condSource 卡券来源,0为公众平台创建的卡券数据、1是API创建的卡券数据 - * @param null $cardId 卡券ID + * 获取免费券数据 + * @param string $beginDate 开始日期 + * @param string $endDate 结束日期 + * @param int $condSource 卡券来源 0|1 + * @param null|string $cardId 卡券ID * @return array * @throws Exceptions\InvalidResponseException * @throws Exceptions\LocalCacheException @@ -369,7 +368,7 @@ class Card extends BasicWeChat /** * 激活会员卡 - * @param array $data + * @param array $data 激活参数 * @return array * @throws Exceptions\InvalidResponseException * @throws Exceptions\LocalCacheException @@ -381,9 +380,8 @@ class Card extends BasicWeChat } /** - * 设置开卡字段接口 - * 用户激活时需要填写的选项 - * @param array $data + * 设置开卡字段(激活表单) + * @param array $data 表单字段 * @return array * @throws Exceptions\InvalidResponseException * @throws Exceptions\LocalCacheException @@ -395,9 +393,8 @@ class Card extends BasicWeChat } /** - * 获取用户提交资料 - * 根据activate_ticket获取到用户填写的信息 - * @param string $activateTicket + * 获取用户提交的激活资料 + * @param string $activateTicket 激活 ticket * @return array * @throws Exceptions\InvalidResponseException * @throws Exceptions\LocalCacheException @@ -410,7 +407,7 @@ class Card extends BasicWeChat /** * 更新会员信息 - * @param array $data + * @param array $data 更新参数 * @return array * @throws Exceptions\InvalidResponseException * @throws Exceptions\LocalCacheException @@ -422,10 +419,10 @@ class Card extends BasicWeChat } /** - * 拉取会员卡概况数据接口 - * @param string $beginDate 查询数据的起始时间 - * @param string $endDate 查询数据的截至时间 - * @param string $condSource 卡券来源(0为公众平台创建的卡券数据 1是API创建的卡券数据) + * 拉取会员卡概况数据 + * @param string $beginDate 开始日期 + * @param string $endDate 结束日期 + * @param string $condSource 卡券来源 0|1 * @return array * @throws Exceptions\InvalidResponseException * @throws Exceptions\LocalCacheException @@ -438,10 +435,10 @@ class Card extends BasicWeChat } /** - * 拉取单张会员卡数据接口 - * @param string $beginDate 查询数据的起始时间 - * @param string $endDate 查询数据的截至时间 - * @param string $cardId 卡券id + * 拉取单张会员卡数据 + * @param string $beginDate 开始日期 + * @param string $endDate 结束日期 + * @param string $cardId 卡券ID * @return array * @throws Exceptions\InvalidResponseException * @throws Exceptions\LocalCacheException @@ -454,9 +451,9 @@ class Card extends BasicWeChat } /** - * 拉取会员信息(积分查询)接口 - * @param string $cardId 查询会员卡的cardid - * @param string $code 所查询用户领取到的code值 + * 查询会员信息(积分) + * @param string $cardId 会员卡ID + * @param string $code 用户 code * @return array * @throws Exceptions\InvalidResponseException * @throws Exceptions\LocalCacheException @@ -469,8 +466,8 @@ class Card extends BasicWeChat } /** - * 设置支付后投放卡券接口 - * @param array $data + * 支付后投放卡券规则 + * @param array $data 规则参数 * @return array * @throws Exceptions\InvalidResponseException * @throws Exceptions\LocalCacheException @@ -483,7 +480,7 @@ class Card extends BasicWeChat /** * 删除支付后投放卡券规则 - * @param integer $ruleId 支付即会员的规则名称 + * @param int $ruleId 规则ID * @return array * @throws Exceptions\InvalidResponseException * @throws Exceptions\LocalCacheException @@ -495,8 +492,8 @@ class Card extends BasicWeChat } /** - * 查询支付后投放卡券规则详情 - * @param integer $ruleId 要查询规则id + * 查询支付后投放卡券规则 + * @param int $ruleId 规则ID * @return array * @throws Exceptions\InvalidResponseException * @throws Exceptions\LocalCacheException @@ -508,10 +505,10 @@ class Card extends BasicWeChat } /** - * 批量查询支付后投放卡券规则 - * @param integer $offset 起始偏移量 - * @param integer $count 查询的数量 - * @param bool $effective 是否仅查询生效的规则 + * 批量查询支付后投放规则 + * @param int $offset 起始偏移 + * @param int $count 数量 + * @param bool $effective 是否仅查询生效规则 * @return array * @throws Exceptions\InvalidResponseException * @throws Exceptions\LocalCacheException @@ -524,8 +521,8 @@ class Card extends BasicWeChat } /** - * 创建支付后领取立减金活动 - * @param array $data + * 创建支付后立减金活动 + * @param array $data 活动参数 * @return array * @throws Exceptions\InvalidResponseException * @throws Exceptions\LocalCacheException @@ -537,7 +534,7 @@ class Card extends BasicWeChat } /** - * 开通券点账户接口 + * 开通券点账户 * @return array * @throws Exceptions\InvalidResponseException * @throws Exceptions\LocalCacheException @@ -549,9 +546,9 @@ class Card extends BasicWeChat } /** - * 对优惠券批价 - * @param string $cardId 需要来配置库存的card_id - * @param integer $quantity 本次需要兑换的库存数目 + * 预估优惠券库存价格 + * @param string $cardId 卡券ID + * @param int $quantity 兑换数量 * @return array * @throws Exceptions\InvalidResponseException * @throws Exceptions\LocalCacheException @@ -563,7 +560,7 @@ class Card extends BasicWeChat } /** - * 查询券点余额接口 + * 查询券点余额 * @return array * @throws Exceptions\InvalidResponseException * @throws Exceptions\LocalCacheException @@ -575,10 +572,10 @@ class Card extends BasicWeChat } /** - * 确认兑换库存接口 - * @param string $cardId 需要来兑换库存的card_id - * @param integer $quantity 本次需要兑换的库存数目 - * @param string $orderId 仅可以使用上面得到的订单号,保证批价有效性 + * 确认兑换库存 + * @param string $cardId 卡券ID + * @param int $quantity 数量 + * @param string $orderId 批价返回的订单号 * @return array * @throws Exceptions\InvalidResponseException * @throws Exceptions\LocalCacheException @@ -591,8 +588,8 @@ class Card extends BasicWeChat } /** - * 充值券点接口 - * @param integer $coinCount + * 充值券点 + * @param int $coinCount 充值数量 * @return array * @throws Exceptions\InvalidResponseException * @throws Exceptions\LocalCacheException @@ -604,8 +601,8 @@ class Card extends BasicWeChat } /** - * 查询订单详情接口 - * @param string $orderId + * 查询券点订单详情 + * @param string $orderId 订单号 * @return array * @throws Exceptions\InvalidResponseException * @throws Exceptions\LocalCacheException @@ -617,8 +614,8 @@ class Card extends BasicWeChat } /** - * 查询券点流水详情接口 - * @param array $data + * 查询券点流水 + * @param array $data 查询参数 * @return array * @throws Exceptions\InvalidResponseException * @throws Exceptions\LocalCacheException @@ -631,7 +628,7 @@ class Card extends BasicWeChat /** * 获取开卡插件参数 - * @param array $data + * @param array $data 入口参数 * @return array * @throws Exceptions\InvalidResponseException * @throws Exceptions\LocalCacheException diff --git a/WeChat/Contracts/BasicAliPay.php b/WeChat/Contracts/BasicAliPay.php index cd6be48..9c072f7 100644 --- a/WeChat/Contracts/BasicAliPay.php +++ b/WeChat/Contracts/BasicAliPay.php @@ -3,7 +3,7 @@ // +---------------------------------------------------------------------- // | WeChatDeveloper // +---------------------------------------------------------------------- -// | 版权所有 2014~2025 ThinkAdmin [ thinkadmin.top ] +// | 版权所有 2014~2026 ThinkAdmin [ thinkadmin.top ] // +---------------------------------------------------------------------- // | 官方网站: https://thinkadmin.top // +---------------------------------------------------------------------- @@ -21,36 +21,31 @@ use WeChat\Exceptions\InvalidResponseException; /** * 支付宝支付基类 - * Class AliPay - * @package AliPay\Contracts + * @package WeChat\Contracts */ abstract class BasicAliPay { - /** - * 支持配置 - * @var DataArray - */ - protected $config; - - /** - * 当前请求数据 - * @var DataArray - */ - protected $options; - - /** - * DzContent数据 - * @var DataArray - */ - protected $params; - /** * 静态缓存 * @var static */ protected static $cache; - + /** + * 支持配置 + * @var DataArray + */ + protected $config; + /** + * 当前请求数据 + * @var DataArray + */ + protected $options; + /** + * DzContent数据 + * @var DataArray + */ + protected $params; /** * 正常请求网关 * @var string @@ -137,6 +132,188 @@ abstract class BasicAliPay return $this->getResult(['out_trade_no' => $outTradeNo]); } + /** + * 请求接口并验证访问数据 + * @param array $options + * @return array|boolean + * @throws \WeChat\Exceptions\InvalidResponseException + * @throws \WeChat\Exceptions\LocalCacheException + */ + protected function getResult($options) + { + $this->applyData($options); + $method = str_replace('.', '_', $this->options['method']) . '_response'; + $data = json_decode(Tools::get($this->gateway, $this->options->get()), true); + if (!isset($data[$method]['code']) || $data[$method]['code'] !== '10000') { + throw new InvalidResponseException( + "Error: " . + (empty($data[$method]['code']) ? '' : "{$data[$method]['msg']} [{$data[$method]['code']}]\r\n") . + (empty($data[$method]['sub_code']) ? '' : "{$data[$method]['sub_msg']} [{$data[$method]['sub_code']}]\r\n"), + $data[$method]['code'], $data + ); + } + return $data[$method]; + // 返回结果签名检查 + // return $this->verify($data[$method], $data['sign']); + } + + /** + * 数据包生成及数据签名 + * @param array $options + */ + protected function applyData($options) + { + if ($this->config->get('app_cert') && $this->config->get('root_cert')) { + $this->setAppCertSnAndRootCertSn(); + } + $this->options->set('biz_content', json_encode($this->params->merge($options), 256)); + $this->options->set('sign', $this->getSign()); + } + + /** + * 新版 设置网关应用公钥证书SN、支付宝根证书SN + */ + protected function setAppCertSnAndRootCertSn() + { + if (!($appCert = $this->config->get('app_cert'))) { + throw new InvalidArgumentException('Missing Config -- [app_cert|app_cert_path]'); + } + if (!($rootCert = $this->config->get('root_cert'))) { + throw new InvalidArgumentException('Missing Config -- [root_cert|alipay_root_path]'); + } + $this->options->set('app_cert_sn', $this->getAppCertSN($appCert)); + $this->options->set('alipay_root_cert_sn', $this->getRootCertSN($rootCert)); + if (!$this->options->get('app_cert_sn')) { + throw new InvalidArgumentException('Missing options -- [app_cert_sn]'); + } + if (!$this->options->get('alipay_root_cert_sn')) { + throw new InvalidArgumentException('Missing options -- [alipay_root_cert_sn]'); + } + } + + /** + * 新版 从证书中提取序列号 + * @param string $sign + * @return string + */ + private function getAppCertSN($sign) + { + $ssl = openssl_x509_parse($sign, true); + $issuer = isset($ssl['issuer']) && is_array($ssl['issuer']) ? $ssl['issuer'] : []; + return md5($this->_arr2str(array_reverse($issuer)) . $ssl['serialNumber']); + } + + /** + * 新版 数组转字符串 + * @param array $array + * @return string + */ + private function _arr2str($array) + { + $string = []; + if ($array && is_array($array)) { + foreach ($array as $key => $value) { + $string[] = $key . '=' . $value; + } + } + return join(',', $string); + } + + /** + * 新版 提取根证书序列号 + * @param string $sign + * @return string|null + */ + private function getRootCertSN($sign) + { + if (strlen($sign) < 500 && file_exists($sign)) { + $sign = file_get_contents($sign); + } + $sn = null; + $array = explode('-----END CERTIFICATE-----', $sign); + for ($i = 0; $i < count($array) - 1; $i++) { + $ssl[$i] = openssl_x509_parse($array[$i] . '-----END CERTIFICATE-----', true); + if (strpos($ssl[$i]['serialNumber'], '0x') === 0) { + $ssl[$i]['serialNumber'] = $this->_hex2dec($ssl[$i]['serialNumberHex']); + } + if ($ssl[$i]['signatureTypeLN'] == 'sha1WithRSAEncryption' || $ssl[$i]['signatureTypeLN'] == 'sha256WithRSAEncryption') { + $issuer = isset($ssl[$i]['issuer']) && is_array($ssl[$i]['issuer']) ? $ssl[$i]['issuer'] : []; + if ($sn == null) { + $sn = md5($this->_arr2str(array_reverse($issuer)) . $ssl[$i]['serialNumber']); + } else { + $sn = $sn . '_' . md5($this->_arr2str(array_reverse($issuer)) . $ssl[$i]['serialNumber']); + } + } + } + return $sn; + } + + /** + * 新版 0x转高精度数字 + * @param string $hex + * @return int|string + */ + private function _hex2dec($hex) + { + list($dec, $len) = [0, strlen($hex)]; + for ($i = 1; $i <= $len; $i++) { + $dec = bcadd($dec, bcmul(strval(hexdec($hex[$i - 1])), bcpow('16', strval($len - $i)))); + } + return $dec; + } + + /** + * 获取数据签名 + * @return string + */ + protected function getSign() + { + if ($this->options->get('sign_type') === 'RSA2') { + openssl_sign($this->getSignContent($this->options->get(), true), $sign, $this->getAppPrivateKey(), OPENSSL_ALGO_SHA256); + } else { + openssl_sign($this->getSignContent($this->options->get(), true), $sign, $this->getAppPrivateKey(), OPENSSL_ALGO_SHA1); + } + return base64_encode($sign); + } + + /** + * 数据签名处理 + * @param array $data 需要进行签名数据 + * @param boolean $needSignType 是否需要sign_type字段 + * @return string + */ + private function getSignContent(array $data, $needSignType = false) + { + list($attrs,) = [[], ksort($data)]; + if (isset($data['sign'])) unset($data['sign']); + if (empty($needSignType)) unset($data['sign_type']); + foreach ($data as $key => $value) { + if ($value === '' || is_null($value)) continue; + $attrs[] = "{$key}={$value}"; + } + return join('&', $attrs); + } + + /** + * 获取应用私钥内容 + * @return string + */ + private function getAppPrivateKey() + { + $content = wordwrap($this->trimCert($this->config->get('private_key')), 64, "\n", true); + return "-----BEGIN RSA PRIVATE KEY-----\n{$content}\n-----END RSA PRIVATE KEY-----"; + } + + /** + * 去除证书前后内容及空白 + * @param string $sign + * @return string + */ + protected function trimCert($sign) + { + return preg_replace(['/\s+/', '/-{5}.*?-{5}/'], '', $sign); + } + /** * 支付宝订单退款操作 * @param array|string $options 退款参数或退款商户订单号 @@ -204,6 +381,116 @@ abstract class BasicAliPay return $data; } + /** + * 获取支付公钥内容 + * @return string + */ + public function getAliPublicKey() + { + $cert = $this->config->get('public_key'); + if (strpos(trim($cert), '-----BEGIN CERTIFICATE-----') !== false) { + $pkey = openssl_pkey_get_public($cert); + $keyData = openssl_pkey_get_details($pkey); + return trim($keyData['key']); + } else { + $content = wordwrap($this->trimCert($cert), 64, "\n", true); + return "-----BEGIN PUBLIC KEY-----\n{$content}\n-----END PUBLIC KEY-----"; + } + } + + /** + * 应用数据操作 + * @param array $options + * @return mixed + */ + abstract public function apply($options); + + /** + * 通用接口调用(支付宝开放平台) + * @param string $apiMethod API 方法名(如 alipay.trade.query),必填 + * @param array|string $data 业务参数,数组会写入 biz_content;字符串尝试解析为 JSON + * @param string $method GET|POST|PUT|DELETE|PATCH,默认 GET(POST 会放入表单) + * @param bool $verify 是否验证返回签名 + * @return array 返回解析后的响应体 + * @throws \WeChat\Exceptions\InvalidResponseException + * @throws \WeChat\Exceptions\LocalCacheException + */ + public function callApi($apiMethod, $data = [], $method = 'GET', $verify = false) + { + $method = strtoupper($method); + + // 验证API方法名(必填) + if (empty($apiMethod)) { + throw new \WeChat\Exceptions\InvalidArgumentException("Missing required parameter -- [apiMethod]"); + } + + // 使用gateway作为URL + $url = $this->gateway; + + // 设置API方法 + $this->options->set('method', $apiMethod); + + // 处理数据格式并合并参数 + $params = []; + if (is_array($data)) { + $params = $data; + } elseif (is_string($data) && !empty($data)) { + $decoded = json_decode($data, true); + if (json_last_error() === JSON_ERROR_NONE) { + $params = $decoded; + } + } + if (!empty($params)) { + $this->params->merge($params); + } + + // 处理签名(默认自动签名) + if ($this->config->get('app_cert') && $this->config->get('root_cert')) { + $this->setAppCertSnAndRootCertSn(); + } + $this->options->set('biz_content', json_encode($this->params->get(), 256)); + $this->options->set('sign', $this->getSign()); + + // 统一处理响应(减少重复代码) + $methodKey = str_replace('.', '_', $this->options->get('method')) . '_response'; + $self = $this; + $processResponse = function ($response) use ($verify, $methodKey, $self) { + $data = json_decode($response, true); + if (json_last_error() !== JSON_ERROR_NONE) { + return $response; // JSON解析失败,返回原始响应 + } + + // 验证响应签名 + if ($verify && isset($data['sign']) && isset($data[$methodKey])) { + return $self->verify($data[$methodKey], $data['sign']); + } + + // 检查错误 + if (isset($data[$methodKey])) { + if (isset($data[$methodKey]['code']) && $data[$methodKey]['code'] !== '10000') { + $msg = isset($data[$methodKey]['msg']) ? "{$data[$methodKey]['msg']} [{$data[$methodKey]['code']}]\r\n" : ''; + $subMsg = isset($data[$methodKey]['sub_msg']) ? "{$data[$methodKey]['sub_msg']} [{$data[$methodKey]['sub_code']}]\r\n" : ''; + throw new InvalidResponseException("Error: " . $msg . $subMsg, $data[$methodKey]['code'], $data); + } + return $data[$methodKey]; + } + + return $data; + }; + + // GET/HEAD/OPTIONS请求 + if (in_array($method, ['GET', 'HEAD', 'OPTIONS'])) { + $queryParams = array_merge($this->options->get(), $params); + $response = Tools::get($url, $queryParams); + return $processResponse($response); + } + + // POST/PUT/PATCH/DELETE请求 + $postData = array_merge($this->options->get(), $params); + $response = Tools::doRequest($method, $url, ['data' => $postData]); + return $processResponse($response); + } + /** * 验证接口返回的数据签名 * @param array $data 通知数据 @@ -226,86 +513,6 @@ abstract class BasicAliPay return $data; } - /** - * 获取数据签名 - * @return string - */ - protected function getSign() - { - if ($this->options->get('sign_type') === 'RSA2') { - openssl_sign($this->getSignContent($this->options->get(), true), $sign, $this->getAppPrivateKey(), OPENSSL_ALGO_SHA256); - } else { - openssl_sign($this->getSignContent($this->options->get(), true), $sign, $this->getAppPrivateKey(), OPENSSL_ALGO_SHA1); - } - return base64_encode($sign); - } - - /** - * 去除证书前后内容及空白 - * @param string $sign - * @return string - */ - protected function trimCert($sign) - { - return preg_replace(['/\s+/', '/-{5}.*?-{5}/'], '', $sign); - } - - /** - * 数据签名处理 - * @param array $data 需要进行签名数据 - * @param boolean $needSignType 是否需要sign_type字段 - * @return string - */ - private function getSignContent(array $data, $needSignType = false) - { - list($attrs,) = [[], ksort($data)]; - if (isset($data['sign'])) unset($data['sign']); - if (empty($needSignType)) unset($data['sign_type']); - foreach ($data as $key => $value) { - if ($value === '' || is_null($value)) continue; - $attrs[] = "{$key}={$value}"; - } - return join('&', $attrs); - } - - /** - * 数据包生成及数据签名 - * @param array $options - */ - protected function applyData($options) - { - if ($this->config->get('app_cert') && $this->config->get('root_cert')) { - $this->setAppCertSnAndRootCertSn(); - } - $this->options->set('biz_content', json_encode($this->params->merge($options), 256)); - $this->options->set('sign', $this->getSign()); - } - - /** - * 请求接口并验证访问数据 - * @param array $options - * @return array|boolean - * @throws \WeChat\Exceptions\InvalidResponseException - * @throws \WeChat\Exceptions\LocalCacheException - */ - protected function getResult($options) - { - $this->applyData($options); - $method = str_replace('.', '_', $this->options['method']) . '_response'; - $data = json_decode(Tools::get($this->gateway, $this->options->get()), true); - if (!isset($data[$method]['code']) || $data[$method]['code'] !== '10000') { - throw new InvalidResponseException( - "Error: " . - (empty($data[$method]['code']) ? '' : "{$data[$method]['msg']} [{$data[$method]['code']}]\r\n") . - (empty($data[$method]['sub_code']) ? '' : "{$data[$method]['sub_msg']} [{$data[$method]['sub_code']}]\r\n"), - $data[$method]['code'], $data - ); - } - return $data[$method]; - // 返回结果签名检查 - // return $this->verify($data[$method], $data['sign']); - } - /** * 生成支付HTML代码 * @return string @@ -320,128 +527,4 @@ abstract class BasicAliPay $html .= ""; return "{$html}"; } - - /** - * 获取应用私钥内容 - * @return string - */ - private function getAppPrivateKey() - { - $content = wordwrap($this->trimCert($this->config->get('private_key')), 64, "\n", true); - return "-----BEGIN RSA PRIVATE KEY-----\n{$content}\n-----END RSA PRIVATE KEY-----"; - } - - /** - * 获取支付公钥内容 - * @return string - */ - public function getAliPublicKey() - { - $cert = $this->config->get('public_key'); - if (strpos(trim($cert), '-----BEGIN CERTIFICATE-----') !== false) { - $pkey = openssl_pkey_get_public($cert); - $keyData = openssl_pkey_get_details($pkey); - return trim($keyData['key']); - } else { - $content = wordwrap($this->trimCert($cert), 64, "\n", true); - return "-----BEGIN PUBLIC KEY-----\n{$content}\n-----END PUBLIC KEY-----"; - } - } - - /** - * 新版 从证书中提取序列号 - * @param string $sign - * @return string - */ - private function getAppCertSN($sign) - { - $ssl = openssl_x509_parse($sign, true); - return md5($this->_arr2str(array_reverse($ssl['issuer'])) . $ssl['serialNumber']); - } - - /** - * 新版 提取根证书序列号 - * @param string $sign - * @return string|null - */ - private function getRootCertSN($sign) - { - if (strlen($sign) < 500 && file_exists($sign)) { - $sign = file_get_contents($sign); - } - $sn = null; - $array = explode('-----END CERTIFICATE-----', $sign); - for ($i = 0; $i < count($array) - 1; $i++) { - $ssl[$i] = openssl_x509_parse($array[$i] . '-----END CERTIFICATE-----', true); - if (strpos($ssl[$i]['serialNumber'], '0x') === 0) { - $ssl[$i]['serialNumber'] = $this->_hex2dec($ssl[$i]['serialNumberHex']); - } - if ($ssl[$i]['signatureTypeLN'] == 'sha1WithRSAEncryption' || $ssl[$i]['signatureTypeLN'] == 'sha256WithRSAEncryption') { - if ($sn == null) { - $sn = md5($this->_arr2str(array_reverse($ssl[$i]['issuer'])) . $ssl[$i]['serialNumber']); - } else { - $sn = $sn . '_' . md5($this->_arr2str(array_reverse($ssl[$i]['issuer'])) . $ssl[$i]['serialNumber']); - } - } - } - return $sn; - } - - /** - * 新版 设置网关应用公钥证书SN、支付宝根证书SN - */ - protected function setAppCertSnAndRootCertSn() - { - if (!($appCert = $this->config->get('app_cert'))) { - throw new InvalidArgumentException('Missing Config -- [app_cert|app_cert_path]'); - } - if (!($rootCert = $this->config->get('root_cert'))) { - throw new InvalidArgumentException('Missing Config -- [root_cert|alipay_root_path]'); - } - $this->options->set('app_cert_sn', $this->getAppCertSN($appCert)); - $this->options->set('alipay_root_cert_sn', $this->getRootCertSN($rootCert)); - if (!$this->options->get('app_cert_sn')) { - throw new InvalidArgumentException('Missing options -- [app_cert_sn]'); - } - if (!$this->options->get('alipay_root_cert_sn')) { - throw new InvalidArgumentException('Missing options -- [alipay_root_cert_sn]'); - } - } - - /** - * 新版 数组转字符串 - * @param array $array - * @return string - */ - private function _arr2str($array) - { - $string = []; - if ($array && is_array($array)) { - foreach ($array as $key => $value) { - $string[] = $key . '=' . $value; - } - } - return join(',', $string); - } - - /** - * 新版 0x转高精度数字 - * @param string $hex - * @return int|string - */ - private function _hex2dec($hex) - { - list($dec, $len) = [0, strlen($hex)]; - for ($i = 1; $i <= $len; $i++) { - $dec = bcadd($dec, bcmul(strval(hexdec($hex[$i - 1])), bcpow('16', strval($len - $i)))); - } - return $dec; - } - - /** - * 应用数据操作 - * @param array $options - * @return mixed - */ - abstract public function apply($options); } \ No newline at end of file diff --git a/WeChat/Contracts/BasicPushEvent.php b/WeChat/Contracts/BasicPushEvent.php index ac277a2..ddf5e77 100644 --- a/WeChat/Contracts/BasicPushEvent.php +++ b/WeChat/Contracts/BasicPushEvent.php @@ -3,7 +3,7 @@ // +---------------------------------------------------------------------- // | WeChatDeveloper // +---------------------------------------------------------------------- -// | 版权所有 2014~2025 ThinkAdmin [ thinkadmin.top ] +// | 版权所有 2014~2026 ThinkAdmin [ thinkadmin.top ] // +---------------------------------------------------------------------- // | 官方网站: https://thinkadmin.top // +---------------------------------------------------------------------- @@ -23,7 +23,6 @@ use WeChat\Prpcrypt\Prpcrypt; /** * 微信通知处理基本类 - * Class BasicPushEvent * @package WeChat\Contracts */ class BasicPushEvent @@ -118,6 +117,30 @@ class BasicPushEvent } } + /** + * 消息是否需要加密 + * @return boolean + */ + public function isEncrypt() + { + return $this->encryptType === 'aes'; + } + + /** + * 验证来自微信服务器 + * @return bool + */ + private function checkSignature() + { + $nonce = $this->input->get('nonce'); + $timestamp = $this->input->get('timestamp'); + $msg_signature = $this->input->get('msg_signature'); + $signature = empty($msg_signature) ? $this->input->get('signature') : $msg_signature; + $tmpArr = [$this->config->get('token'), $timestamp, $nonce, '']; + sort($tmpArr, SORT_STRING); + return sha1(implode($tmpArr)) === $signature; + } + /** * 获取回显字串 * @return string @@ -131,15 +154,6 @@ class BasicPushEvent } } - /** - * 消息是否需要加密 - * @return boolean - */ - public function isEncrypt() - { - return $this->encryptType === 'aes'; - } - /** * 回复消息 * @param array $data 消息内容 @@ -171,21 +185,6 @@ class BasicPushEvent echo $xml; } - /** - * 验证来自微信服务器 - * @return bool - */ - private function checkSignature() - { - $nonce = $this->input->get('nonce'); - $timestamp = $this->input->get('timestamp'); - $msg_signature = $this->input->get('msg_signature'); - $signature = empty($msg_signature) ? $this->input->get('signature') : $msg_signature; - $tmpArr = [$this->config->get('token'), $timestamp, $nonce, '']; - sort($tmpArr, SORT_STRING); - return sha1(implode($tmpArr)) === $signature; - } - /** * 获取公众号推送对象 * @param null|string $field 指定获取字段 diff --git a/WeChat/Contracts/BasicWeChat.php b/WeChat/Contracts/BasicWeChat.php index 9738dd5..3cd256e 100644 --- a/WeChat/Contracts/BasicWeChat.php +++ b/WeChat/Contracts/BasicWeChat.php @@ -3,7 +3,7 @@ // +---------------------------------------------------------------------- // | WeChatDeveloper // +---------------------------------------------------------------------- -// | 版权所有 2014~2025 ThinkAdmin [ thinkadmin.top ] +// | 版权所有 2014~2026 ThinkAdmin [ thinkadmin.top ] // +---------------------------------------------------------------------- // | 官方网站: https://thinkadmin.top // +---------------------------------------------------------------------- @@ -20,42 +20,37 @@ use WeChat\Exceptions\InvalidArgumentException; use WeChat\Exceptions\InvalidResponseException; /** - * Class BasicWeChat + * 微信基础类 * @package WeChat\Contracts */ class BasicWeChat { + /** + * 静态缓存 + * @var static + */ + protected static $cache; /** * 当前微信配置 * @var DataArray */ public $config; - /** * 访问AccessToken * @var string */ public $access_token = ''; - /** * 当前请求方法参数 * @var array */ protected $currentMethod = []; - /** * 当前模式 * @var bool */ protected $isTry = false; - - /** - * 静态缓存 - * @var static - */ - protected static $cache; - /** * 注册代替函数 * @var string @@ -85,7 +80,7 @@ class BasicWeChat /** * 静态创建对象 - * @param array $config + * @param array $config 配置(appid、appsecret 等) * @return static */ public static function instance(array $config) @@ -95,6 +90,37 @@ class BasicWeChat return self::$cache[$key] = new static($config); } + /** + * 接口通用POST请求方法 + * @param string $url 接口URL + * @param array $data POST提交接口参数 + * @param bool $toJson 是否转换为JSON参数 + * @return array + * @throws \WeChat\Exceptions\InvalidResponseException + * @throws \WeChat\Exceptions\LocalCacheException + */ + public function callPostApi($url, array $data, $toJson = true, array $options = []) + { + $this->registerApi($url, __FUNCTION__, func_get_args()); + return $this->httpPostForJson($url, $data, $toJson, $options); + } + + /** + * 注册当前请求接口 + * @param string $url 接口地址 + * @param string $method 当前接口方法 + * @param array $arguments 请求参数 + * @return string + * @throws \WeChat\Exceptions\InvalidResponseException + * @throws \WeChat\Exceptions\LocalCacheException + */ + protected function registerApi(&$url, $method, $arguments = []) + { + $this->currentMethod = ['method' => $method, 'arguments' => $arguments]; + if (empty($this->access_token)) $this->access_token = $this->getAccessToken(); + return $url = str_replace('ACCESS_TOKEN', urlencode($this->access_token), $url); + } + /** * 获取访问 AccessToken * @return string @@ -147,38 +173,6 @@ class BasicWeChat Tools::setCache($cache, $this->access_token = $accessToken); } - /** - * 清理删除 AccessToken - * @return bool - */ - public function delAccessToken() - { - $this->access_token = ''; - return Tools::delCache($this->config->get('appid') . '_access_token'); - } - - /** - * 以GET获取接口数据并转为数组 - * @param string $url 接口地址 - * @return array - * @throws \WeChat\Exceptions\InvalidResponseException - * @throws \WeChat\Exceptions\LocalCacheException - */ - protected function httpGetForJson($url) - { - try { - return Tools::json2arr(Tools::get($url)); - } catch (InvalidResponseException $exception) { - if (isset($this->currentMethod['method']) && empty($this->isTry)) { - if (in_array($exception->getCode(), ['40014', '40001', '41001', '42001'])) { - [$this->delAccessToken(), $this->isTry = true]; - return call_user_func_array([$this, $this->currentMethod['method']], $this->currentMethod['arguments']); - } - } - throw new InvalidResponseException($exception->getMessage(), $exception->getCode()); - } - } - /** * 以POST获取接口数据并转为数组 * @param string $url 接口地址 @@ -205,39 +199,18 @@ class BasicWeChat } /** - * 注册当前请求接口 - * @param string $url 接口地址 - * @param string $method 当前接口方法 - * @param array $arguments 请求参数 - * @return string - * @throws \WeChat\Exceptions\InvalidResponseException - * @throws \WeChat\Exceptions\LocalCacheException + * 清理删除 AccessToken + * @return bool */ - protected function registerApi(&$url, $method, $arguments = []) + public function delAccessToken() { - $this->currentMethod = ['method' => $method, 'arguments' => $arguments]; - if (empty($this->access_token)) $this->access_token = $this->getAccessToken(); - return $url = str_replace('ACCESS_TOKEN', urlencode($this->access_token), $url); + $this->access_token = ''; + return Tools::delCache($this->config->get('appid') . '_access_token'); } /** - * 接口通用POST请求方法 - * @param string $url 接口URL - * @param array $data POST提交接口参数 - * @param bool $toJson 是否转换为JSON参数 - * @return array - * @throws \WeChat\Exceptions\InvalidResponseException - * @throws \WeChat\Exceptions\LocalCacheException - */ - public function callPostApi($url, array $data, $toJson = true, array $options = []) - { - $this->registerApi($url, __FUNCTION__, func_get_args()); - return $this->httpPostForJson($url, $data, $toJson, $options); - } - - /** - * 接口通用GET请求方法 - * @param string $url 接口URL + * 通用 GET 请求(自动处理 ACCESS_TOKEN) + * @param string $url 接口 URL * @return array * @throws \WeChat\Exceptions\InvalidResponseException * @throws \WeChat\Exceptions\LocalCacheException @@ -248,4 +221,70 @@ class BasicWeChat return $this->httpGetForJson($url); } + /** + * 以GET获取接口数据并转为数组 + * @param string $url 接口地址 + * @return array + * @throws \WeChat\Exceptions\InvalidResponseException + * @throws \WeChat\Exceptions\LocalCacheException + */ + protected function httpGetForJson($url) + { + try { + return Tools::json2arr(Tools::get($url)); + } catch (InvalidResponseException $exception) { + if (isset($this->currentMethod['method']) && empty($this->isTry)) { + if (in_array($exception->getCode(), ['40014', '40001', '41001', '42001'])) { + [$this->delAccessToken(), $this->isTry = true]; + return call_user_func_array([$this, $this->currentMethod['method']], $this->currentMethod['arguments']); + } + } + throw new InvalidResponseException($exception->getMessage(), $exception->getCode()); + } + } + + /** + * 通用接口调用 + * @param string $url 完整 URL 或相对路径,支持 ACCESS_TOKEN 占位符自动替换 + * @param array|string $data GET 参数或请求体,数组自动 JSON;字符串原样发送 + * @param string $method GET|POST|PUT|DELETE|PATCH|HEAD|OPTIONS,默认 GET + * @return array 解析后的数组 + * @throws \WeChat\Exceptions\InvalidResponseException + * @throws \WeChat\Exceptions\LocalCacheException + */ + public function callApi($url, $data = [], $method = 'GET') + { + $method = strtoupper($method); + + // 自动处理ACCESS_TOKEN + if (strpos($url, 'ACCESS_TOKEN') !== false) { + if (empty($this->access_token)) { + $this->access_token = $this->getAccessToken(); + } + $url = str_replace('ACCESS_TOKEN', urlencode($this->access_token), $url); + } + + // GET/HEAD/OPTIONS请求(无请求体) + if (in_array($method, ['GET', 'HEAD', 'OPTIONS'])) { + if (!empty($data) && is_array($data)) { + $url .= (strpos($url, '?') !== false ? '&' : '?') . http_build_query($data); + } + return $this->httpGetForJson($url); + } + + // POST/PUT/PATCH/DELETE请求(有请求体) + $postData = is_array($data) ? $data : []; + $toJson = is_array($data); + + // POST请求使用原有方法(支持自动重试) + if ($method === 'POST') { + return $this->httpPostForJson($url, $postData, $toJson, []); + } + + // PUT/PATCH/DELETE请求直接调用 + $requestData = is_string($data) ? $data : Tools::arr2json($postData); + $response = Tools::doRequest($method, $url, ['data' => $requestData]); + return Tools::json2arr($response); + } + } \ No newline at end of file diff --git a/WeChat/Contracts/BasicWePay.php b/WeChat/Contracts/BasicWePay.php index 13aab0d..6edbb35 100644 --- a/WeChat/Contracts/BasicWePay.php +++ b/WeChat/Contracts/BasicWePay.php @@ -3,7 +3,7 @@ // +---------------------------------------------------------------------- // | WeChatDeveloper // +---------------------------------------------------------------------- -// | 版权所有 2014~2025 ThinkAdmin [ thinkadmin.top ] +// | 版权所有 2014~2026 ThinkAdmin [ thinkadmin.top ] // +---------------------------------------------------------------------- // | 官方网站: https://thinkadmin.top // +---------------------------------------------------------------------- @@ -21,17 +21,20 @@ use WeChat\Exceptions\InvalidResponseException; /** * 微信支付基础类 - * Class BasicPay * @package WeChat\Contracts */ class BasicWePay { + /** + * 静态缓存 + * @var static + */ + protected static $cache; /** * 商户配置 * @var DataArray */ protected $config; - /** * 当前请求数据 * @var DataArray @@ -39,14 +42,8 @@ class BasicWePay protected $params; /** - * 静态缓存 - * @var static - */ - protected static $cache; - - /** - * WeChat constructor. - * @param array $options + * 构造函数 + * @param array $options 必填:appid、mch_id、mch_key,可选:sub_appid、sub_mch_id、cache_path */ public function __construct(array $options) { @@ -80,7 +77,7 @@ class BasicWePay /** * 静态创建对象 - * @param array $config + * @param array $config 商户配置 * @return static */ public static function instance(array $config) @@ -91,9 +88,9 @@ class BasicWePay } /** - * 获取微信支付通知 - * @param string|array $xml - * @return array + * 获取微信支付异步通知并验签 + * @param string|array $xml 可选,默认读取原始输入 + * @return array 验签通过的通知数据 * @throws \WeChat\Exceptions\InvalidResponseException */ public function getNotify($xml = '') @@ -105,21 +102,12 @@ class BasicWePay throw new InvalidResponseException('Invalid Notify.', '0'); } - /** - * 获取微信支付通知回复内容 - * @return string - */ - public function getNotifySuccessReply() - { - return Tools::arr2xml(['return_code' => 'SUCCESS', 'return_msg' => 'OK']); - } - /** * 生成支付签名 - * @param array $data 参与签名的数据 - * @param string $signType 参与签名的类型 - * @param string $buff 参与签名字符串前缀 - * @return string + * @param array $data 待签名数据 + * @param string $signType MD5|HMAC-SHA256 + * @param string $buff 签名前缀(内部使用) + * @return string 大写签名 */ public function getPaySign(array $data, $signType = 'MD5', $buff = '') { @@ -137,8 +125,17 @@ class BasicWePay } /** - * 转换短链接 - * @param string $longUrl 需要转换的URL,签名用原串,传输需URLencode + * 获取微信支付通知成功回复 XML + * @return string + */ + public function getNotifySuccessReply() + { + return Tools::arr2xml(['return_code' => 'SUCCESS', 'return_msg' => 'OK']); + } + + /** + * 转换短链接(tools/shorturl) + * @param string $longUrl 需转换的URL,签名用原串,传输需URLencode * @return array * @throws \WeChat\Exceptions\InvalidResponseException * @throws \WeChat\Exceptions\LocalCacheException @@ -150,27 +147,14 @@ class BasicWePay } /** - * 数组直接转xml数据输出 - * @param array $data - * @param bool $isReturn - * @return string|void - */ - public function toXml(array $data, $isReturn = false) - { - $xml = Tools::arr2xml($data); - if ($isReturn) return $xml; - echo $xml; - } - - /** - * 以 Post 请求接口 - * @param string $url 请求 + * 基础 POST 调用(自动签名,可选双向证书) + * @param string $url 请求地址 * @param array $data 接口参数 - * @param bool $isCert 是否需要使用双向证书 - * @param string $signType 数据签名类型 MD5|SHA256 - * @param bool $needSignType 是否需要传签名类型参数 - * @param bool $needNonceStr - * @return array + * @param bool $isCert 是否需要双向证书(退款等场景) + * @param string $signType MD5|HMAC-SHA256 + * @param bool $needSignType 是否追加 sign_type 字段 + * @param bool $needNonceStr 是否自动附加 nonce_str + * @return array XML 解析结果 * @throws \WeChat\Exceptions\InvalidResponseException * @throws \WeChat\Exceptions\LocalCacheException */ @@ -205,4 +189,92 @@ class BasicWePay } return $result; } + + /** + * 数组转 XML 输出 + * @param array $data 待转换数据 + * @param bool $isReturn true 返回字符串,false 直接输出 + * @return string|void + */ + public function toXml(array $data, $isReturn = false) + { + $xml = Tools::arr2xml($data); + if ($isReturn) return $xml; + echo $xml; + } + + /** + * 通用接口(V2)调用 + * @param string $url 完整 URL + * @param array|string $data 请求参数,数组自动补全商户参数并签名;字符串原样发送 + * @param string $method GET|POST|PUT|DELETE|PATCH,默认 POST(GET/HEAD/OPTIONS 不带签名) + * @param bool $isCert 是否启用双向证书 + * @param string $signType MD5|HMAC-SHA256,默认 HMAC-SHA256 + * @return array XML 解析结果 + * @throws \WeChat\Exceptions\InvalidArgumentException + * @throws \WeChat\Exceptions\InvalidResponseException + * @throws \WeChat\Exceptions\LocalCacheException + */ + public function callApi($url, $data = [], $method = 'POST', $isCert = false, $signType = 'HMAC-SHA256') + { + $method = strtoupper($method); + + // 处理数据格式 + $requestData = is_array($data) ? $data : (is_string($data) ? $data : []); + + // GET/HEAD/OPTIONS请求(无请求体,不签名) + if (in_array($method, ['GET', 'HEAD', 'OPTIONS'])) { + if (!empty($requestData) && is_array($requestData)) { + $url .= (strpos($url, '?') !== false ? '&' : '?') . http_build_query($requestData); + } + $response = Tools::get($url); + $result = Tools::xml2arr($response); + if (isset($result['return_code']) && $result['return_code'] !== 'SUCCESS') { + throw new InvalidResponseException($result['return_msg'], '0'); + } + return $result; + } + + // POST/PUT/PATCH/DELETE请求(有请求体) + $option = []; + if ($isCert) { + $option['ssl_p12'] = $this->config->get('ssl_p12'); + $option['ssl_cer'] = $this->config->get('ssl_cer'); + $option['ssl_key'] = $this->config->get('ssl_key'); + if (is_string($option['ssl_p12']) && file_exists($option['ssl_p12'])) { + $content = file_get_contents($option['ssl_p12']); + if (openssl_pkcs12_read($content, $certs, $this->config->get('mch_id'))) { + $option['ssl_key'] = Tools::pushFile(md5($certs['pkey']) . '.pem', $certs['pkey']); + $option['ssl_cer'] = Tools::pushFile(md5($certs['cert']) . '.pem', $certs['cert']); + } else { + throw new InvalidArgumentException("P12 certificate does not match MCH_ID --- ssl_p12"); + } + } + if (empty($option['ssl_cer']) || !file_exists($option['ssl_cer'])) { + throw new InvalidArgumentException("Missing Config -- ssl_cer", '0'); + } + if (empty($option['ssl_key']) || !file_exists($option['ssl_key'])) { + throw new InvalidArgumentException("Missing Config -- ssl_key", '0'); + } + } + + // 合并参数并处理签名(默认自动签名) + if (is_array($requestData)) { + $params = $this->params->merge($requestData); + $params['sign_type'] = strtoupper($signType); + $params['sign'] = $this->getPaySign($params, $signType); + $option['data'] = Tools::arr2xml($params); + } else { + $option['data'] = $requestData; + } + + // 使用doRequest支持PUT/DELETE/PATCH + $response = Tools::doRequest($method, $url, $option); + + $result = Tools::xml2arr($response); + if (isset($result['return_code']) && $result['return_code'] !== 'SUCCESS') { + throw new InvalidResponseException($result['return_msg'], '0'); + } + return $result; + } } diff --git a/WeChat/Contracts/BasicWeWork.php b/WeChat/Contracts/BasicWeWork.php index eac8cfc..8b701a1 100644 --- a/WeChat/Contracts/BasicWeWork.php +++ b/WeChat/Contracts/BasicWeWork.php @@ -3,7 +3,7 @@ // +---------------------------------------------------------------------- // | WeChatDeveloper // +---------------------------------------------------------------------- -// | 版权所有 2014~2025 ThinkAdmin [ thinkadmin.top ] +// | 版权所有 2014~2026 ThinkAdmin [ thinkadmin.top ] // +---------------------------------------------------------------------- // | 官方网站: https://thinkadmin.top // +---------------------------------------------------------------------- @@ -18,7 +18,6 @@ namespace WeChat\Contracts; /** * 企业微信基础类 - * Class BasicWeWork * @package WeChat\Contracts */ class BasicWeWork extends BasicWeChat diff --git a/WeChat/Contracts/DataArray.php b/WeChat/Contracts/DataArray.php index cc800d8..a8fa8da 100644 --- a/WeChat/Contracts/DataArray.php +++ b/WeChat/Contracts/DataArray.php @@ -3,7 +3,7 @@ // +---------------------------------------------------------------------- // | WeChatDeveloper // +---------------------------------------------------------------------- -// | 版权所有 2014~2025 ThinkAdmin [ thinkadmin.top ] +// | 版权所有 2014~2026 ThinkAdmin [ thinkadmin.top ] // +---------------------------------------------------------------------- // | 官方网站: https://thinkadmin.top // +---------------------------------------------------------------------- @@ -19,8 +19,8 @@ namespace WeChat\Contracts; use ArrayAccess; /** - * Class DataArray - * @package WeChat + * 数据处理类 + * @package WeChat\Contracts */ class DataArray implements ArrayAccess { @@ -50,6 +50,22 @@ class DataArray implements ArrayAccess $this->offsetSet($offset, $value); } + /** + * 设置配置项值 + * @param string $offset + * @param string|array|null|integer $value + * @return void + */ + #[\ReturnTypeWillChange] + public function offsetSet($offset, $value) + { + if (is_null($offset)) { + $this->config[] = $value; + } else { + $this->config[$offset] = $value; + } + } + /** * 获取配置项参数 * @param string|null $offset @@ -60,6 +76,18 @@ class DataArray implements ArrayAccess return $this->offsetGet($offset); } + /** + * 获取配置项参数 + * @param string|null $offset + * @return mixed + */ + #[\ReturnTypeWillChange] + public function offsetGet($offset = null) + { + if (is_null($offset)) return $this->config; + return isset($this->config[$offset]) ? $this->config[$offset] : null; + } + /** * 合并数据到对象 * @param array $data 需要合并的数据 @@ -74,22 +102,6 @@ class DataArray implements ArrayAccess return array_merge($this->config, $data); } - /** - * 设置配置项值 - * @param string $offset - * @param string|array|null|integer $value - * @return void - */ - #[\ReturnTypeWillChange] - public function offsetSet($offset, $value) - { - if (is_null($offset)) { - $this->config[] = $value; - } else { - $this->config[$offset] = $value; - } - } - /** * 判断配置Key是否存在 * @param string $offset @@ -115,16 +127,4 @@ class DataArray implements ArrayAccess unset($this->config[$offset]); } } - - /** - * 获取配置项参数 - * @param string|null $offset - * @return mixed - */ - #[\ReturnTypeWillChange] - public function offsetGet($offset = null) - { - if (is_null($offset)) return $this->config; - return isset($this->config[$offset]) ? $this->config[$offset] : null; - } } \ No newline at end of file diff --git a/WeChat/Contracts/DataError.php b/WeChat/Contracts/DataError.php index 430fb8c..75638e9 100644 --- a/WeChat/Contracts/DataError.php +++ b/WeChat/Contracts/DataError.php @@ -3,7 +3,7 @@ // +---------------------------------------------------------------------- // | WeChatDeveloper // +---------------------------------------------------------------------- -// | 版权所有 2014~2025 ThinkAdmin [ thinkadmin.top ] +// | 版权所有 2014~2026 ThinkAdmin [ thinkadmin.top ] // +---------------------------------------------------------------------- // | 官方网站: https://thinkadmin.top // +---------------------------------------------------------------------- @@ -18,7 +18,6 @@ namespace WeChat\Contracts; /** * 错误消息处理 - * Class DataError * @package WeChat\Contracts */ class DataError diff --git a/WeChat/Contracts/MyCurlFile.php b/WeChat/Contracts/MyCurlFile.php index 78f2a7f..485283d 100644 --- a/WeChat/Contracts/MyCurlFile.php +++ b/WeChat/Contracts/MyCurlFile.php @@ -3,7 +3,7 @@ // +---------------------------------------------------------------------- // | WeChatDeveloper // +---------------------------------------------------------------------- -// | 版权所有 2014~2025 ThinkAdmin [ thinkadmin.top ] +// | 版权所有 2014~2026 ThinkAdmin [ thinkadmin.top ] // +---------------------------------------------------------------------- // | 官方网站: https://thinkadmin.top // +---------------------------------------------------------------------- @@ -18,7 +18,6 @@ namespace WeChat\Contracts; /** * 自定义CURL文件类 - * Class MyCurlFile * @package WeChat\Contracts */ class MyCurlFile extends \stdClass diff --git a/WeChat/Contracts/Tools.php b/WeChat/Contracts/Tools.php index d3bdbbc..fe148e3 100644 --- a/WeChat/Contracts/Tools.php +++ b/WeChat/Contracts/Tools.php @@ -3,7 +3,7 @@ // +---------------------------------------------------------------------- // | WeChatDeveloper // +---------------------------------------------------------------------- -// | 版权所有 2014~2025 ThinkAdmin [ thinkadmin.top ] +// | 版权所有 2014~2026 ThinkAdmin [ thinkadmin.top ] // +---------------------------------------------------------------------- // | 官方网站: https://thinkadmin.top // +---------------------------------------------------------------------- @@ -48,7 +48,6 @@ use WeChat\Exceptions\LocalCacheException; /** * 网络请求支持 - * Class Tools * @package WeChat\Contracts */ class Tools @@ -114,61 +113,6 @@ class Tools $GLOBALS['HTTP_RAW_POST_DATA'] = $rawInput; } - /** - * 根据文件后缀获取文件类型 - * @param string|array $ext 文件后缀 - * @param array $mine 文件后缀MINE信息 - * @return string - * @throws \WeChat\Exceptions\LocalCacheException - */ - public static function getExtMine($ext, $mine = []) - { - $mines = self::getMines(); - foreach (is_string($ext) ? explode(',', $ext) : $ext as $e) { - $mine[] = isset($mines[strtolower($e)]) ? $mines[strtolower($e)] : 'application/octet-stream'; - } - return join(',', array_unique($mine)); - } - - /** - * 获取所有文件扩展的类型 - * @return array - * @throws \WeChat\Exceptions\LocalCacheException - */ - private static function getMines() - { - $mines = self::getCache('all_ext_mine'); - if (empty($mines)) { - $content = file_get_contents('http://svn.apache.org/repos/asf/httpd/httpd/trunk/docs/conf/mime.types'); - preg_match_all('#^([^\s]{2,}?)\s+(.+?)$#ism', $content, $matches, PREG_SET_ORDER); - foreach ($matches as $match) foreach (explode(" ", $match[2]) as $ext) $mines[$ext] = $match[1]; - self::setCache('all_ext_mine', $mines); - } - return $mines; - } - - /** - * 创建CURL文件对象 - * @param mixed $filename - * @param string $mimetype - * @param string $postname - * @return \CURLFile|string - * @throws \WeChat\Exceptions\LocalCacheException - */ - public static function createCurlFile($filename, $mimetype = null, $postname = null) - { - if (is_string($filename) && file_exists($filename)) { - if (is_null($postname)) $postname = basename($filename); - if (is_null($mimetype)) $mimetype = self::getExtMine(pathinfo($filename, 4)); - if (class_exists('CURLFile')) { - return new \CURLFile($filename, $mimetype, $postname); - } else { - return "@{$filename};filename={$postname};type={$mimetype}"; - } - } - return $filename; - } - /** * 数组转XML内容 * @param array $data @@ -202,6 +146,17 @@ class Tools return $content; } + /** + * 解析XML文本内容 + * @param string $xml + * @return array|false + */ + public static function xml3arr($xml) + { + $state = xml_parse($parser = xml_parser_create(), $xml, true); + return xml_parser_free($parser) && $state ? self::xml2arr($xml) : false; + } + /** * 解析XML内容到数组 * @param string $xml @@ -219,17 +174,6 @@ class Tools return json_decode(json_encode($data), true); } - /** - * 解析XML文本内容 - * @param string $xml - * @return array|false - */ - public static function xml3arr($xml) - { - $state = xml_parse($parser = xml_parser_create(), $xml, true); - return xml_parser_free($parser) && $state ? self::xml2arr($xml) : false; - } - /** * 数组转xml内容 * @param array $data @@ -260,6 +204,18 @@ class Tools return $data; } + /** + * Emoji原形转换为String + * @param string $content + * @return string + */ + public static function emojiEncode($content) + { + return json_decode(preg_replace_callback("/(\\\u[ed][0-9a-f]{3})/i", function ($string) { + return addslashes($string[0]); + }, json_encode($content))); + } + /** * 数组对象Emoji反解析处理 * @param array $data @@ -279,18 +235,6 @@ class Tools return $data; } - /** - * Emoji原形转换为String - * @param string $content - * @return string - */ - public static function emojiEncode($content) - { - return json_decode(preg_replace_callback("/(\\\u[ed][0-9a-f]{3})/i", function ($string) { - return addslashes($string[0]); - }, json_encode($content))); - } - /** * Emoji字符串转换为原形 * @param string $content @@ -335,20 +279,6 @@ class Tools return self::doRequest('get', $url, $options); } - /** - * 以post访问模拟访问 - * @param string $url 访问URL - * @param array $data POST数据 - * @param array $options - * @return boolean|string - * @throws \WeChat\Exceptions\LocalCacheException - */ - public static function post($url, $data = [], $options = []) - { - $options['data'] = $data; - return self::doRequest('post', $url, $options); - } - /** * CURL模拟网络请求 * @param string $method 请求方法 @@ -368,9 +298,14 @@ class Tools if (!empty($options['headers'])) { curl_setopt($curl, CURLOPT_HTTPHEADER, $options['headers']); } - // POST数据设置 - if (strtolower($method) === 'post') { - curl_setopt($curl, CURLOPT_POST, true); + // POST/PUT/PATCH/DELETE数据设置 + $methodLower = strtolower($method); + if (in_array($methodLower, ['post', 'put', 'patch', 'delete'])) { + if ($methodLower === 'post') { + curl_setopt($curl, CURLOPT_POST, true); + } else { + curl_setopt($curl, CURLOPT_CUSTOMREQUEST, strtoupper($method)); + } curl_setopt($curl, CURLOPT_POSTFIELDS, self::_buildHttpData($options['data'])); } // 证书文件设置 @@ -384,7 +319,7 @@ class Tools curl_setopt($curl, CURLOPT_SSLKEY, $options['ssl_key']); } else throw new InvalidArgumentException("Certificate files that do not exist. --- [ssl_key]"); curl_setopt($curl, CURLOPT_URL, $url); - curl_setopt($curl, CURLOPT_TIMEOUT, 60); + curl_setopt($curl, CURLOPT_TIMEOUT, isset($options['timeout']) ? intval($options['timeout']) : 60); curl_setopt($curl, CURLOPT_HEADER, false); curl_setopt($curl, CURLOPT_RETURNTRANSFER, true); curl_setopt($curl, CURLOPT_SSL_VERIFYPEER, false); @@ -431,43 +366,58 @@ class Tools } /** - * 写入文件 - * @param string $name 文件名称 - * @param string $content 文件内容 - * @return string + * 创建CURL文件对象 + * @param mixed $filename + * @param string $mimetype + * @param string $postname + * @return \CURLFile|string * @throws \WeChat\Exceptions\LocalCacheException */ - public static function pushFile($name, $content) + public static function createCurlFile($filename, $mimetype = null, $postname = null) { - if (is_callable(self::$cache_callable['put'])) { - return call_user_func_array(self::$cache_callable['put'], func_get_args()); + if (is_string($filename) && file_exists($filename)) { + if (is_null($postname)) $postname = basename($filename); + if (is_null($mimetype)) $mimetype = self::getExtMine(pathinfo($filename, 4)); + if (class_exists('CURLFile')) { + return new \CURLFile($filename, $mimetype, $postname); + } else { + return "@{$filename};filename={$postname};type={$mimetype}"; + } } - $file = self::_getCacheName($name); - if (!file_put_contents($file, $content)) { - throw new LocalCacheException('local file write error.', '0'); - } - return $file; + return $filename; } /** - * 缓存配置与存储 - * @param string $name 缓存名称 - * @param string $value 缓存内容 - * @param int $expired 缓存时间(0表示永久缓存) + * 根据文件后缀获取文件类型 + * @param string|array $ext 文件后缀 + * @param array $mine 文件后缀MINE信息 * @return string * @throws \WeChat\Exceptions\LocalCacheException */ - public static function setCache($name, $value = '', $expired = 3600) + public static function getExtMine($ext, $mine = []) { - if (is_callable(self::$cache_callable['set'])) { - return call_user_func_array(self::$cache_callable['set'], func_get_args()); + $mines = self::getMines(); + foreach (is_string($ext) ? explode(',', $ext) : $ext as $e) { + $mine[] = isset($mines[strtolower($e)]) ? $mines[strtolower($e)] : 'application/octet-stream'; } - $file = self::_getCacheName($name); - $data = ['name' => $name, 'value' => $value, 'expired' => time() + intval($expired)]; - if (!file_put_contents($file, serialize($data))) { - throw new LocalCacheException('local cache error.', '0'); + return join(',', array_unique($mine)); + } + + /** + * 获取所有文件扩展的类型 + * @return array + * @throws \WeChat\Exceptions\LocalCacheException + */ + private static function getMines() + { + $mines = self::getCache('all_ext_mine'); + if (empty($mines)) { + $content = file_get_contents('http://svn.apache.org/repos/asf/httpd/httpd/trunk/docs/conf/mime.types'); + preg_match_all('#^([^\s]{2,}?)\s+(.+?)$#ism', $content, $matches, PREG_SET_ORDER); + foreach ($matches as $match) foreach (explode(" ", $match[2]) as $ext) $mines[$ext] = $match[1]; + self::setCache('all_ext_mine', $mines); } - return $file; + return $mines; } /** @@ -491,6 +441,23 @@ class Tools return null; } + /** + * 应用缓存目录 + * @param string $name + * @return string + */ + private static function _getCacheName($name) + { + if (empty(self::$cache_path)) { + self::$cache_path = dirname(dirname(__DIR__)) . DIRECTORY_SEPARATOR . 'Cache' . DIRECTORY_SEPARATOR; + } + $cachePath = rtrim((string)self::$cache_path, '/\\') . DIRECTORY_SEPARATOR; + if (!file_exists($cachePath)) { + mkdir($cachePath, 0755, true); + } + return $cachePath . $name; + } + /** * 移除缓存文件 * @param string $name 缓存名称 @@ -506,17 +473,56 @@ class Tools } /** - * 应用缓存目录 - * @param string $name + * 缓存配置与存储 + * @param string $name 缓存名称 + * @param string $value 缓存内容 + * @param int $expired 缓存时间(0表示永久缓存) * @return string + * @throws \WeChat\Exceptions\LocalCacheException */ - private static function _getCacheName($name) + public static function setCache($name, $value = '', $expired = 3600) { - if (empty(self::$cache_path)) { - self::$cache_path = dirname(dirname(__DIR__)) . DIRECTORY_SEPARATOR . 'Cache' . DIRECTORY_SEPARATOR; + if (is_callable(self::$cache_callable['set'])) { + return call_user_func_array(self::$cache_callable['set'], func_get_args()); } - self::$cache_path = rtrim(self::$cache_path, '/\\') . DIRECTORY_SEPARATOR; - file_exists(self::$cache_path) || mkdir(self::$cache_path, 0755, true); - return self::$cache_path . $name; + $file = self::_getCacheName($name); + $data = ['name' => $name, 'value' => $value, 'expired' => time() + intval($expired)]; + if (!file_put_contents($file, serialize($data))) { + throw new LocalCacheException('local cache error.', '0'); + } + return $file; + } + + /** + * 以post访问模拟访问 + * @param string $url 访问URL + * @param array $data POST数据 + * @param array $options + * @return boolean|string + * @throws \WeChat\Exceptions\LocalCacheException + */ + public static function post($url, $data = [], $options = []) + { + $options['data'] = $data; + return self::doRequest('post', $url, $options); + } + + /** + * 写入文件 + * @param string $name 文件名称 + * @param string $content 文件内容 + * @return string + * @throws \WeChat\Exceptions\LocalCacheException + */ + public static function pushFile($name, $content) + { + if (is_callable(self::$cache_callable['put'])) { + return call_user_func_array(self::$cache_callable['put'], func_get_args()); + } + $file = self::_getCacheName($name); + if (!file_put_contents($file, $content)) { + throw new LocalCacheException('local file write error.', '0'); + } + return $file; } } diff --git a/WeChat/Custom.php b/WeChat/Custom.php index 36810f5..4773ce2 100644 --- a/WeChat/Custom.php +++ b/WeChat/Custom.php @@ -3,7 +3,7 @@ // +---------------------------------------------------------------------- // | WeChatDeveloper // +---------------------------------------------------------------------- -// | 版权所有 2014~2025 ThinkAdmin [ thinkadmin.top ] +// | 版权所有 2014~2026 ThinkAdmin [ thinkadmin.top ] // +---------------------------------------------------------------------- // | 官方网站: https://thinkadmin.top // +---------------------------------------------------------------------- @@ -21,14 +21,13 @@ use WeChat\Contracts\Tools; /** * 客服消息处理 - * Class Custom * @package WeChat */ class Custom extends BasicWeChat { /** * 添加客服帐号 - * @param string $kf_account 客服账号 + * @param string $kf_account 客服账号,格式 账号前缀@公众号微信号 * @param string $nickname 客服昵称 * @return array * @throws Exceptions\InvalidResponseException @@ -69,7 +68,7 @@ class Custom extends BasicWeChat /** * 邀请绑定客服帐号 - * @param string $kfAccount 完整客服帐号,格式为:帐号前缀@公众号微信号 + * @param string $kfAccount 客服账号,格式 账号前缀@公众号微信号 * @param string $invite_wx 接收绑定邀请的客服微信号 * @return array * @throws Exceptions\InvalidResponseException @@ -82,7 +81,7 @@ class Custom extends BasicWeChat } /** - * 获取所有客服账号 + * 获取客服账号列表 * @return array * @throws Exceptions\InvalidResponseException * @throws Exceptions\LocalCacheException @@ -94,9 +93,9 @@ class Custom extends BasicWeChat } /** - * 设置客服帐号的头像 - * @param string $kf_account 客户账号 - * @param string $image 头像文件位置 + * 设置客服头像 + * @param string $kf_account 客服账号 + * @param string $image 本地图片路径 * @return array * @throws Exceptions\InvalidResponseException * @throws Exceptions\LocalCacheException @@ -108,8 +107,8 @@ class Custom extends BasicWeChat } /** - * 客服接口-发消息 - * @param array $data + * 发送客服消息 + * @param array $data 消息体(touser, msgtype, content 等) * @return array * @throws Exceptions\InvalidResponseException * @throws Exceptions\LocalCacheException @@ -121,9 +120,9 @@ class Custom extends BasicWeChat } /** - * 客服输入状态 - * @param string $openid 普通用户(openid) - * @param string $command Typing:正在输入,CancelTyping:取消正在输入 + * 设置客服输入状态 + * @param string $openid 用户 openid + * @param string $command Typing|CancelTyping * @return array * @throws Exceptions\InvalidResponseException * @throws Exceptions\LocalCacheException @@ -135,8 +134,8 @@ class Custom extends BasicWeChat } /** - * 根据标签进行群发【订阅号与服务号认证后均可用】 - * @param array $data + * 根据标签群发 + * @param array $data 群发参数 * @return array * @throws Exceptions\InvalidResponseException * @throws Exceptions\LocalCacheException @@ -148,8 +147,8 @@ class Custom extends BasicWeChat } /** - * 根据OpenID列表群发【订阅号不可用,服务号认证后可用】 - * @param array $data + * 根据 OpenID 列表群发 + * @param array $data 群发参数 * @return array * @throws Exceptions\InvalidResponseException * @throws Exceptions\LocalCacheException @@ -161,9 +160,9 @@ class Custom extends BasicWeChat } /** - * 删除群发【订阅号与服务号认证后均可用】 - * @param integer $msg_id 发送出去的消息ID - * @param null|integer $article_idx 要删除的文章在图文消息中的位置,第一篇编号为1,该字段不填或填0会删除全部文章 + * 删除群发 + * @param int $msg_id 群发消息ID + * @param null|int $article_idx 图文位置,0 删除全部 * @return array * @throws Exceptions\InvalidResponseException * @throws Exceptions\LocalCacheException @@ -177,8 +176,8 @@ class Custom extends BasicWeChat } /** - * 预览接口【订阅号与服务号认证后均可用】 - * @param array $data + * 群发预览 + * @param array $data 预览参数 * @return array * @throws Exceptions\InvalidResponseException * @throws Exceptions\LocalCacheException @@ -190,8 +189,8 @@ class Custom extends BasicWeChat } /** - * 查询群发消息发送状态【订阅号与服务号认证后均可用】 - * @param integer $msgId 群发消息后返回的消息id + * 查询群发状态 + * @param int $msgId 群发消息ID * @return array * @throws Exceptions\InvalidResponseException * @throws Exceptions\LocalCacheException @@ -216,7 +215,7 @@ class Custom extends BasicWeChat /** * 设置群发速度 - * @param integer $speed 群发速度的级别 + * @param int $speed 速度级别 * @return array * @throws Exceptions\InvalidResponseException * @throws Exceptions\LocalCacheException diff --git a/WeChat/Draft.php b/WeChat/Draft.php index 264a8f0..28fb20d 100644 --- a/WeChat/Draft.php +++ b/WeChat/Draft.php @@ -3,7 +3,7 @@ // +---------------------------------------------------------------------- // | WeChatDeveloper // +---------------------------------------------------------------------- -// | 版权所有 2014~2025 ThinkAdmin [ thinkadmin.top ] +// | 版权所有 2014~2026 ThinkAdmin [ thinkadmin.top ] // +---------------------------------------------------------------------- // | 官方网站: https://thinkadmin.top // +---------------------------------------------------------------------- @@ -20,7 +20,6 @@ use WeChat\Contracts\BasicWeChat; /** * 微信草稿箱管理 - * Class Draft * @author taoxin * @package WeChat */ @@ -28,8 +27,8 @@ class Draft extends BasicWeChat { /** * 新建草稿 - * @param $articles - * @return array + * @param array $articles 图文数组 articles + * @return array 草稿 media_id * @throws \WeChat\Exceptions\InvalidResponseException * @throws \WeChat\Exceptions\LocalCacheException */ @@ -41,9 +40,9 @@ class Draft extends BasicWeChat /** * 获取草稿 - * @param string $mediaId - * @param string $outType 返回处理函数 - * @return array + * @param string $mediaId 草稿 media_id + * @param string $outType 可选回调处理 + * @return array 草稿内容 * @throws \WeChat\Exceptions\InvalidResponseException * @throws \WeChat\Exceptions\LocalCacheException */ @@ -55,7 +54,7 @@ class Draft extends BasicWeChat /** * 删除草稿 - * @param string $mediaId + * @param string $mediaId 草稿 media_id * @return array * @throws \WeChat\Exceptions\InvalidResponseException * @throws \WeChat\Exceptions\LocalCacheException @@ -68,7 +67,7 @@ class Draft extends BasicWeChat /** * 新增图文素材 - * @param array $data 文件名称 + * @param array $data 图文 articles * @return array * @throws \WeChat\Exceptions\InvalidResponseException * @throws \WeChat\Exceptions\LocalCacheException @@ -81,9 +80,9 @@ class Draft extends BasicWeChat /** * 修改草稿 - * @param string $media_id 要修改的图文消息的id - * @param int $index 要更新的文章在图文消息中的位置(多图文消息时,此字段才有意义),第一篇为0 - * @param $articles + * @param string $media_id 草稿 media_id + * @param int $index 文章序号(0 开始) + * @param array $articles 文章内容 * @return array * @throws \WeChat\Exceptions\InvalidResponseException * @throws \WeChat\Exceptions\LocalCacheException @@ -109,9 +108,9 @@ class Draft extends BasicWeChat /** * 获取草稿列表 - * @param int $offset 从全部素材的该偏移位置开始返回,0表示从第一个素材返回 - * @param int $count 返回素材的数量,取值在1到20之间 - * @param int $noContent 1 表示不返回 content 字段,0 表示正常返回,默认为 0 + * @param int $offset 起始位置 + * @param int $count 拉取数量 1-20 + * @param int $noContent 1 不返回 content,0 返回 * @return array * @throws \WeChat\Exceptions\InvalidResponseException * @throws \WeChat\Exceptions\LocalCacheException diff --git a/WeChat/Exceptions/InvalidArgumentException.php b/WeChat/Exceptions/InvalidArgumentException.php index 1776ce1..5def2af 100644 --- a/WeChat/Exceptions/InvalidArgumentException.php +++ b/WeChat/Exceptions/InvalidArgumentException.php @@ -3,7 +3,7 @@ // +---------------------------------------------------------------------- // | WeChatDeveloper // +---------------------------------------------------------------------- -// | 版权所有 2014~2025 ThinkAdmin [ thinkadmin.top ] +// | 版权所有 2014~2026 ThinkAdmin [ thinkadmin.top ] // +---------------------------------------------------------------------- // | 官方网站: https://thinkadmin.top // +---------------------------------------------------------------------- @@ -18,8 +18,7 @@ namespace WeChat\Exceptions; /** * 接口参数异常 - * Class InvalidArgumentException - * @package WeChat + * @package WeChat\Exceptions */ class InvalidArgumentException extends \InvalidArgumentException { diff --git a/WeChat/Exceptions/InvalidDecryptException.php b/WeChat/Exceptions/InvalidDecryptException.php index 29ecfaf..c561aa9 100644 --- a/WeChat/Exceptions/InvalidDecryptException.php +++ b/WeChat/Exceptions/InvalidDecryptException.php @@ -3,7 +3,7 @@ // +---------------------------------------------------------------------- // | WeChatDeveloper // +---------------------------------------------------------------------- -// | 版权所有 2014~2025 ThinkAdmin [ thinkadmin.top ] +// | 版权所有 2014~2026 ThinkAdmin [ thinkadmin.top ] // +---------------------------------------------------------------------- // | 官方网站: https://thinkadmin.top // +---------------------------------------------------------------------- @@ -18,8 +18,7 @@ namespace WeChat\Exceptions; /** * 加密解密异常 - * Class InvalidResponseException - * @package WeChat + * @package WeChat\Exceptions */ class InvalidDecryptException extends \Exception { diff --git a/WeChat/Exceptions/InvalidInstanceException.php b/WeChat/Exceptions/InvalidInstanceException.php index ab7b9e0..710d317 100644 --- a/WeChat/Exceptions/InvalidInstanceException.php +++ b/WeChat/Exceptions/InvalidInstanceException.php @@ -3,7 +3,7 @@ // +---------------------------------------------------------------------- // | WeChatDeveloper // +---------------------------------------------------------------------- -// | 版权所有 2014~2025 ThinkAdmin [ thinkadmin.top ] +// | 版权所有 2014~2026 ThinkAdmin [ thinkadmin.top ] // +---------------------------------------------------------------------- // | 官方网站: https://thinkadmin.top // +---------------------------------------------------------------------- @@ -18,7 +18,6 @@ namespace WeChat\Exceptions; /** * 加载类异常 - * Class InvalidInstanceException * @package WeChat\Exceptions */ class InvalidInstanceException extends \Exception diff --git a/WeChat/Exceptions/InvalidResponseException.php b/WeChat/Exceptions/InvalidResponseException.php index 33e9350..20f3824 100644 --- a/WeChat/Exceptions/InvalidResponseException.php +++ b/WeChat/Exceptions/InvalidResponseException.php @@ -3,7 +3,7 @@ // +---------------------------------------------------------------------- // | WeChatDeveloper // +---------------------------------------------------------------------- -// | 版权所有 2014~2025 ThinkAdmin [ thinkadmin.top ] +// | 版权所有 2014~2026 ThinkAdmin [ thinkadmin.top ] // +---------------------------------------------------------------------- // | 官方网站: https://thinkadmin.top // +---------------------------------------------------------------------- @@ -18,8 +18,7 @@ namespace WeChat\Exceptions; /** * 返回异常 - * Class InvalidResponseException - * @package WeChat + * @package WeChat\Exceptions */ class InvalidResponseException extends \Exception { diff --git a/WeChat/Exceptions/LocalCacheException.php b/WeChat/Exceptions/LocalCacheException.php index d56a78b..e0d5cb6 100644 --- a/WeChat/Exceptions/LocalCacheException.php +++ b/WeChat/Exceptions/LocalCacheException.php @@ -3,7 +3,7 @@ // +---------------------------------------------------------------------- // | WeChatDeveloper // +---------------------------------------------------------------------- -// | 版权所有 2014~2025 ThinkAdmin [ thinkadmin.top ] +// | 版权所有 2014~2026 ThinkAdmin [ thinkadmin.top ] // +---------------------------------------------------------------------- // | 官方网站: https://thinkadmin.top // +---------------------------------------------------------------------- @@ -18,8 +18,7 @@ namespace WeChat\Exceptions; /*** * 本地缓存异常 - * Class LocalCacheException - * @package WeChat + * @package WeChat\Exceptions */ class LocalCacheException extends \Exception { diff --git a/WeChat/Freepublish.php b/WeChat/Freepublish.php index eb95f55..d60c150 100644 --- a/WeChat/Freepublish.php +++ b/WeChat/Freepublish.php @@ -3,7 +3,7 @@ // +---------------------------------------------------------------------- // | WeChatDeveloper // +---------------------------------------------------------------------- -// | 版权所有 2014~2025 ThinkAdmin [ thinkadmin.top ] +// | 版权所有 2014~2026 ThinkAdmin [ thinkadmin.top ] // +---------------------------------------------------------------------- // | 官方网站: https://thinkadmin.top // +---------------------------------------------------------------------- @@ -20,17 +20,15 @@ use WeChat\Contracts\BasicWeChat; /** * 发布能力 - * Class Freepublish * @author taoxin * @package WeChat */ class Freepublish extends BasicWeChat { /** - * 发布接口 - * 开发者需要先将图文素材以草稿的形式保存(见“草稿箱/新建草稿”,如需从已保存的草稿中选择,见“草稿箱/获取草稿列表”) - * @param mixed $mediaId 选择要发布的草稿的media_id - * @return array + * 提交发布 + * @param string $mediaId 草稿 media_id + * @return array 含 publish_id * @throws \WeChat\Exceptions\InvalidResponseException * @throws \WeChat\Exceptions\LocalCacheException */ @@ -41,8 +39,8 @@ class Freepublish extends BasicWeChat } /** - * 发布状态轮询接口 - * @param mixed $publishId + * 查询发布状态 + * @param string $publishId 发布任务 ID * @return array * @throws \WeChat\Exceptions\InvalidResponseException * @throws \WeChat\Exceptions\LocalCacheException @@ -54,10 +52,9 @@ class Freepublish extends BasicWeChat } /** - * 删除发布 - * 发布成功之后,随时可以通过该接口删除。此操作不可逆,请谨慎操作。 - * @param mixed $articleId 成功发布时返回的 article_id - * @param int $index 要删除的文章在图文消息中的位置,第一篇编号为1,该字段不填或填0会删除全部文章 + * 删除已发布文章 + * @param string $articleId 发布返回的 article_id + * @param int $index 图文序号,1 开始,0 删除全部 * @return array * @throws \WeChat\Exceptions\InvalidResponseException * @throws \WeChat\Exceptions\LocalCacheException @@ -69,8 +66,8 @@ class Freepublish extends BasicWeChat } /** - * 通过 article_id 获取已发布文章 - * @param mixed $articleId 要获取的草稿的article_id + * 获取已发布文章 + * @param string $articleId article_id * @return array * @throws \WeChat\Exceptions\InvalidResponseException * @throws \WeChat\Exceptions\LocalCacheException @@ -82,10 +79,10 @@ class Freepublish extends BasicWeChat } /** - * 获取成功发布列表 - * @param int $offset 从全部素材的该偏移位置开始返回,0表示从第一个素材返回 - * @param int $count 返回素材的数量,取值在1到20之间 - * @param int $noContent 1 表示不返回 content 字段,0 表示正常返回,默认为 0 + * 获取已发布列表 + * @param int $offset 起始偏移 + * @param int $count 数量 1-20 + * @param int $noContent 1 不返回 content * @return array * @throws \WeChat\Exceptions\InvalidResponseException * @throws \WeChat\Exceptions\LocalCacheException diff --git a/WeChat/Limit.php b/WeChat/Limit.php index 0bb2205..85eeb24 100644 --- a/WeChat/Limit.php +++ b/WeChat/Limit.php @@ -3,7 +3,7 @@ // +---------------------------------------------------------------------- // | WeChatDeveloper // +---------------------------------------------------------------------- -// | 版权所有 2014~2025 ThinkAdmin [ thinkadmin.top ] +// | 版权所有 2014~2026 ThinkAdmin [ thinkadmin.top ] // +---------------------------------------------------------------------- // | 官方网站: https://thinkadmin.top // +---------------------------------------------------------------------- @@ -20,14 +20,13 @@ use WeChat\Contracts\BasicWeChat; /** * 接口调用频次限制 - * Class Limit * @package WeChat */ class Limit extends BasicWeChat { /** - * 公众号调用或第三方平台帮公众号调用对公众号的所有api调用(包括第三方帮其调用)次数进行清零 + * 清空公众号 API 调用次数 * @return array * @throws \WeChat\Exceptions\InvalidResponseException * @throws \WeChat\Exceptions\LocalCacheException @@ -40,8 +39,8 @@ class Limit extends BasicWeChat /** * 网络检测 - * @param string $action 执行的检测动作 - * @param string $operator 指定平台从某个运营商进行检测 + * @param string $action ping|dns|all + * @param string $operator DEFAULT|CT|CU|CM * @return array * @throws \WeChat\Exceptions\InvalidResponseException * @throws \WeChat\Exceptions\LocalCacheException @@ -53,7 +52,7 @@ class Limit extends BasicWeChat } /** - * 获取微信服务器IP地址 + * 获取微信服务器 IP * @return array * @throws \WeChat\Exceptions\InvalidResponseException * @throws \WeChat\Exceptions\LocalCacheException diff --git a/WeChat/Media.php b/WeChat/Media.php index e8a1db1..2b3e8f3 100644 --- a/WeChat/Media.php +++ b/WeChat/Media.php @@ -3,7 +3,7 @@ // +---------------------------------------------------------------------- // | WeChatDeveloper // +---------------------------------------------------------------------- -// | 版权所有 2014~2025 ThinkAdmin [ thinkadmin.top ] +// | 版权所有 2014~2026 ThinkAdmin [ thinkadmin.top ] // +---------------------------------------------------------------------- // | 官方网站: https://thinkadmin.top // +---------------------------------------------------------------------- @@ -22,16 +22,15 @@ use WeChat\Exceptions\InvalidResponseException; /** * 微信素材管理 - * Class Media * @package WeChat */ class Media extends BasicWeChat { /** * 新增临时素材 - * @param string $filename 文件名称 - * @param string $type 媒体文件类型(image|voice|video|thumb) - * @return array + * @param string $filename 本地文件路径 + * @param string $type 媒体类型 image|voice|video|thumb + * @return array 上传结果(media_id 等) * @throws \WeChat\Exceptions\InvalidResponseException * @throws \WeChat\Exceptions\LocalCacheException */ @@ -46,8 +45,8 @@ class Media extends BasicWeChat /** * 获取临时素材 - * @param string $media_id - * @param string $outType 返回处理函数 + * @param string $media_id 媒体 ID + * @param string $outType 可选:回调处理或 'url' 仅返回 URL * @return array|string * @throws \WeChat\Exceptions\InvalidResponseException * @throws \WeChat\Exceptions\LocalCacheException @@ -69,8 +68,8 @@ class Media extends BasicWeChat } /** - * 新增图文素材 - * @param array $data 文件名称 + * 新增永久图文素材 + * @param array $data 图文列表 articles * @return array * @throws \WeChat\Exceptions\InvalidResponseException * @throws \WeChat\Exceptions\LocalCacheException @@ -83,8 +82,8 @@ class Media extends BasicWeChat /** * 更新图文素材 - * @param string $media_id 要修改的图文消息的id - * @param int $index 要更新的文章在图文消息中的位置(多图文消息时,此字段才有意义),第一篇为0 + * @param string $media_id 图文 media_id + * @param int $index 文章位置(0 开始) * @param array $news 文章内容 * @return array * @throws \WeChat\Exceptions\InvalidResponseException @@ -97,9 +96,9 @@ class Media extends BasicWeChat } /** - * 上传图文消息内的图片获取URL - * @param mixed $filename - * @return array + * 上传图文消息内的图片,获取 URL + * @param string $filename 本地文件 + * @return array 含 url * @throws \WeChat\Exceptions\InvalidResponseException * @throws \WeChat\Exceptions\LocalCacheException */ @@ -111,9 +110,9 @@ class Media extends BasicWeChat /** * 新增其他类型永久素材 - * @param mixed $filename 文件名称 - * @param string $type 媒体文件类型(image|voice|video|thumb) - * @param array $description 包含素材的描述信息 + * @param string $filename 本地文件路径 + * @param string $type 媒体类型 image|voice|video|thumb + * @param array $description 视频描述等 * @return array * @throws \WeChat\Exceptions\InvalidResponseException * @throws \WeChat\Exceptions\LocalCacheException @@ -129,8 +128,8 @@ class Media extends BasicWeChat /** * 获取永久素材 - * @param string $media_id - * @param null|string $outType 输出类型 + * @param string $media_id 媒体 ID + * @param null|string $outType 回调处理或 'url' 返回地址 * @return array|string * @throws \WeChat\Exceptions\InvalidResponseException * @throws \WeChat\Exceptions\LocalCacheException @@ -153,7 +152,7 @@ class Media extends BasicWeChat /** * 删除永久素材 - * @param string $mediaId + * @param string $mediaId 媒体 ID * @return array * @throws \WeChat\Exceptions\InvalidResponseException * @throws \WeChat\Exceptions\LocalCacheException @@ -178,9 +177,9 @@ class Media extends BasicWeChat /** * 获取素材列表 - * @param string $type - * @param int $offset - * @param int $count + * @param string $type image|voice|video|news + * @param int $offset 起始位置 + * @param int $count 拉取数量 * @return array * @throws \WeChat\Exceptions\InvalidResponseException * @throws \WeChat\Exceptions\LocalCacheException diff --git a/WeChat/Menu.php b/WeChat/Menu.php index 1697bff..81124f7 100644 --- a/WeChat/Menu.php +++ b/WeChat/Menu.php @@ -3,7 +3,7 @@ // +---------------------------------------------------------------------- // | WeChatDeveloper // +---------------------------------------------------------------------- -// | 版权所有 2014~2025 ThinkAdmin [ thinkadmin.top ] +// | 版权所有 2014~2026 ThinkAdmin [ thinkadmin.top ] // +---------------------------------------------------------------------- // | 官方网站: https://thinkadmin.top // +---------------------------------------------------------------------- @@ -20,15 +20,14 @@ use WeChat\Contracts\BasicWeChat; /** * 微信菜单管理 - * Class Menu * @package WeChat */ class Menu extends BasicWeChat { /** - * 自定义菜单查询接口 - * @return array + * 查询自定义菜单接口 + * @return array 菜单配置信息 * @throws \WeChat\Exceptions\InvalidResponseException * @throws \WeChat\Exceptions\LocalCacheException */ @@ -39,8 +38,8 @@ class Menu extends BasicWeChat } /** - * 自定义菜单删除接口 - * @return array + * 删除自定义菜单接口 + * @return array 操作结果 * @throws \WeChat\Exceptions\InvalidResponseException * @throws \WeChat\Exceptions\LocalCacheException */ @@ -51,9 +50,9 @@ class Menu extends BasicWeChat } /** - * 自定义菜单创建 - * @param array $data - * @return array + * 创建自定义菜单接口 + * @param array $data 菜单配置(button数组,最多3个一级菜单,每个一级菜单最多5个二级菜单) + * @return array 操作结果 * @throws \WeChat\Exceptions\InvalidResponseException * @throws \WeChat\Exceptions\LocalCacheException */ @@ -64,9 +63,9 @@ class Menu extends BasicWeChat } /** - * 创建个性化菜单 - * @param array $data - * @return array + * 创建个性化菜单接口 + * @param array $data 菜单配置(button数组和matchrule匹配规则) + * @return array 返回menuid * @throws \WeChat\Exceptions\InvalidResponseException * @throws \WeChat\Exceptions\LocalCacheException */ @@ -77,9 +76,9 @@ class Menu extends BasicWeChat } /** - * 删除个性化菜单 - * @param string $menuid - * @return array + * 删除个性化菜单接口 + * @param string $menuid 菜单ID + * @return array 操作结果 * @throws \WeChat\Exceptions\InvalidResponseException * @throws \WeChat\Exceptions\LocalCacheException */ @@ -90,9 +89,9 @@ class Menu extends BasicWeChat } /** - * 测试个性化菜单匹配结果 - * @param string $openid - * @return array + * 测试个性化菜单匹配结果接口 + * @param string $openid 用户openid + * @return array 该用户匹配的菜单配置 * @throws \WeChat\Exceptions\InvalidResponseException * @throws \WeChat\Exceptions\LocalCacheException */ diff --git a/WeChat/Oauth.php b/WeChat/Oauth.php index 13986ed..1a13e3a 100644 --- a/WeChat/Oauth.php +++ b/WeChat/Oauth.php @@ -3,7 +3,7 @@ // +---------------------------------------------------------------------- // | WeChatDeveloper // +---------------------------------------------------------------------- -// | 版权所有 2014~2025 ThinkAdmin [ thinkadmin.top ] +// | 版权所有 2014~2026 ThinkAdmin [ thinkadmin.top ] // +---------------------------------------------------------------------- // | 官方网站: https://thinkadmin.top // +---------------------------------------------------------------------- @@ -20,18 +20,17 @@ use WeChat\Contracts\BasicWeChat; /** * 微信网页授权 - * Class Oauth * @package WeChat */ class Oauth extends BasicWeChat { /** - * Oauth 授权跳转接口 - * @param string $redirect_url 授权回跳地址 - * @param string $state 为重定向后会带上state参数(填写a-zA-Z0-9的参数值,最多128字节) - * @param string $scope 授权类类型(可选值snsapi_base|snsapi_userinfo) - * @return string + * 构造网页授权跳转链接 + * @param string $redirect_url 回调地址 + * @param string $state 自定义状态(<=128 字节) + * @param string $scope snsapi_base|snsapi_userinfo + * @return string 跳转 URL */ public function getOauthRedirect($redirect_url, $state = '', $scope = 'snsapi_base') { @@ -41,8 +40,8 @@ class Oauth extends BasicWeChat } /** - * 通过 code 获取 AccessToken 和 openid - * @param string $code 授权Code值,不传则取GET参数 + * 通过 code 换取 access_token/refresh_token/openid + * @param string $code 授权 code,不传则取 GET 参数 * @return array * @throws \WeChat\Exceptions\InvalidResponseException * @throws \WeChat\Exceptions\LocalCacheException @@ -57,8 +56,8 @@ class Oauth extends BasicWeChat } /** - * 刷新AccessToken并续期 - * @param string $refresh_token + * 刷新网页授权 access_token + * @param string $refresh_token 刷新 token * @return array * @throws \WeChat\Exceptions\InvalidResponseException * @throws \WeChat\Exceptions\LocalCacheException @@ -71,9 +70,9 @@ class Oauth extends BasicWeChat } /** - * 检验授权凭证(access_token)是否有效 - * @param string $accessToken 网页授权接口调用凭证,注意:此access_token与基础支持的access_token不同 - * @param string $openid 用户的唯一标识 + * 校验网页授权 access_token 是否有效 + * @param string $accessToken 网页授权 access_token + * @param string $openid 用户 openid * @return array * @throws \WeChat\Exceptions\InvalidResponseException * @throws \WeChat\Exceptions\LocalCacheException @@ -85,10 +84,10 @@ class Oauth extends BasicWeChat } /** - * 拉取用户信息(需scope为 snsapi_userinfo) - * @param string $accessToken 网页授权接口调用凭证,注意:此access_token与基础支持的access_token不同 - * @param string $openid 用户的唯一标识 - * @param string $lang 返回国家地区语言版本,zh_CN 简体,zh_TW 繁体,en 英语 + * 拉取用户信息(snsapi_userinfo) + * @param string $accessToken 网页授权 access_token + * @param string $openid 用户 openid + * @param string $lang zh_CN|zh_TW|en * @return array * @throws \WeChat\Exceptions\InvalidResponseException * @throws \WeChat\Exceptions\LocalCacheException diff --git a/WeChat/Pay.php b/WeChat/Pay.php index 6acb0cb..c463698 100644 --- a/WeChat/Pay.php +++ b/WeChat/Pay.php @@ -3,7 +3,7 @@ // +---------------------------------------------------------------------- // | WeChatDeveloper // +---------------------------------------------------------------------- -// | 版权所有 2014~2025 ThinkAdmin [ thinkadmin.top ] +// | 版权所有 2014~2026 ThinkAdmin [ thinkadmin.top ] // +---------------------------------------------------------------------- // | 官方网站: https://thinkadmin.top // +---------------------------------------------------------------------- @@ -24,8 +24,7 @@ use WePay\Transfers; use WePay\TransfersBank; /** - * 微信支付商户 - * Class Pay + * 微信支付商户聚合入口(V2) * @package WeChat\Contracts */ class Pay extends BasicWePay @@ -33,8 +32,8 @@ class Pay extends BasicWePay /** * 统一下单 - * @param array $options - * @return array + * @param array $options 下单参数(out_trade_no, body, total_fee, notify_url, trade_type 等) + * @return array 预支付信息 * @throws \WeChat\Exceptions\InvalidResponseException * @throws \WeChat\Exceptions\LocalCacheException */ @@ -44,8 +43,8 @@ class Pay extends BasicWePay } /** - * 刷卡支付 - * @param array $options + * 刷卡支付(被扫) + * @param array $options 支付参数(auth_code, out_trade_no, total_fee 等) * @return array * @throws \WeChat\Exceptions\InvalidResponseException * @throws \WeChat\Exceptions\LocalCacheException @@ -56,9 +55,9 @@ class Pay extends BasicWePay } /** - * 创建JsApi及H5支付参数 - * @param string $prepay_id 统一下单预支付码 - * @return array + * 生成 JSAPI/H5 支付参数 + * @param string $prepay_id 统一下单返回的 prepay_id + * @return array 前端调起参数 */ public function createParamsForJsApi($prepay_id) { @@ -66,9 +65,9 @@ class Pay extends BasicWePay } /** - * 获取APP支付参数 - * @param string $prepay_id 统一下单预支付码 - * @return array + * 生成 APP 支付参数 + * @param string $prepay_id 统一下单返回的 prepay_id + * @return array APP 支付参数 */ public function createParamsForApp($prepay_id) { @@ -76,8 +75,8 @@ class Pay extends BasicWePay } /** - * 获取支付规则二维码 - * @param string $product_id 商户定义的商品id 或者订单号 + * 生成 Native 支付二维码 URL + * @param string $product_id 商品 ID 或订单号 * @return string */ public function createParamsForRuleQrc($product_id) @@ -87,8 +86,8 @@ class Pay extends BasicWePay /** * 查询订单 - * @param array $options - * @return array + * @param array $options 查询参数(transaction_id 或 out_trade_no) + * @return array 订单详情 * @throws \WeChat\Exceptions\InvalidResponseException * @throws \WeChat\Exceptions\LocalCacheException */ @@ -111,7 +110,7 @@ class Pay extends BasicWePay /** * 申请退款 - * @param array $options + * @param array $options 退款参数(out_trade_no/transaction_id,out_refund_no,total_fee,refund_fee 等) * @return array * @throws \WeChat\Exceptions\InvalidResponseException * @throws \WeChat\Exceptions\LocalCacheException @@ -123,7 +122,7 @@ class Pay extends BasicWePay /** * 查询退款 - * @param array $options + * @param array $options 查询参数(transaction_id/out_trade_no/out_refund_no/refund_id 四选一) * @return array * @throws \WeChat\Exceptions\InvalidResponseException * @throws \WeChat\Exceptions\LocalCacheException @@ -134,8 +133,8 @@ class Pay extends BasicWePay } /** - * 交易保障 - * @param array $options + * 交易保障上报 + * @param array $options 上报参数(interface_url, execute_time, return_code 等) * @return array * @throws \WeChat\Exceptions\InvalidResponseException * @throws \WeChat\Exceptions\LocalCacheException @@ -146,9 +145,9 @@ class Pay extends BasicWePay } /** - * 授权码查询openid - * @param string $authCode 扫码支付授权码,设备读取用户微信中的条码或者二维码信息 - * @return array + * 授权码查询 openid + * @param string $authCode 扫码支付授权码 + * @return array 含 openid * @throws \WeChat\Exceptions\InvalidResponseException * @throws \WeChat\Exceptions\LocalCacheException */ @@ -159,8 +158,8 @@ class Pay extends BasicWePay /** * 下载对账单 - * @param array $options 静音参数 - * @param null|string $outType 输出类型 + * @param array $options 账单参数(bill_date, bill_type 等) + * @param null|string $outType 输出处理回调,为 null 返回原始内容 * @return bool|string * @throws \WeChat\Exceptions\InvalidResponseException * @throws \WeChat\Exceptions\LocalCacheException @@ -171,8 +170,8 @@ class Pay extends BasicWePay } /** - * 拉取订单评价数据 - * @param array $options + * 拉取订单评价数据(需证书) + * @param array $options 查询参数(bill_date, offset, limit 等) * @return array * @throws \WeChat\Exceptions\InvalidResponseException * @throws \WeChat\Exceptions\LocalCacheException @@ -184,7 +183,7 @@ class Pay extends BasicWePay /** * 企业付款到零钱 - * @param array $options + * @param array $options 付款参数(partner_trade_no, openid, amount, desc 等) * @return array * @throws \WeChat\Exceptions\InvalidResponseException * @throws \WeChat\Exceptions\LocalCacheException @@ -196,7 +195,7 @@ class Pay extends BasicWePay /** * 查询企业付款到零钱 - * @param string $partner_trade_no 商户调用企业付款API时使用的商户订单号 + * @param string $partner_trade_no 商户付款单号 * @return array * @throws \WeChat\Exceptions\InvalidResponseException * @throws \WeChat\Exceptions\LocalCacheException @@ -208,7 +207,7 @@ class Pay extends BasicWePay /** * 企业付款到银行卡 - * @param array $options + * @param array $options 付款参数(partner_trade_no, enc_bank_no, enc_true_name, bank_code, amount 等) * @return array * @throws \WeChat\Exceptions\InvalidDecryptException * @throws \WeChat\Exceptions\InvalidResponseException @@ -220,8 +219,8 @@ class Pay extends BasicWePay } /** - * 商户企业付款到银行卡操作进行结果查询 - * @param string $partner_trade_no 商户订单号,需保持唯一 + * 查询企业付款到银行卡结果 + * @param string $partner_trade_no 商户付款单号 * @return array * @throws \WeChat\Exceptions\InvalidResponseException * @throws \WeChat\Exceptions\LocalCacheException diff --git a/WeChat/Product.php b/WeChat/Product.php index 3be309e..9d6d6a7 100644 --- a/WeChat/Product.php +++ b/WeChat/Product.php @@ -3,7 +3,7 @@ // +---------------------------------------------------------------------- // | WeChatDeveloper // +---------------------------------------------------------------------- -// | 版权所有 2014~2025 ThinkAdmin [ thinkadmin.top ] +// | 版权所有 2014~2026 ThinkAdmin [ thinkadmin.top ] // +---------------------------------------------------------------------- // | 官方网站: https://thinkadmin.top // +---------------------------------------------------------------------- @@ -20,7 +20,6 @@ use WeChat\Contracts\BasicWeChat; /** * 商店管理 - * Class Product * @package WeChat */ class Product extends BasicWeChat @@ -29,7 +28,7 @@ class Product extends BasicWeChat * 提交审核/取消发布商品 * @param string $keystandard 商品编码标准 * @param string $keystr 商品编码内容 - * @param string $status 设置发布状态。on为提交审核,off为取消发布 + * @param string $status on 提交审核 | off 取消发布 * @return array * @throws \WeChat\Exceptions\InvalidResponseException * @throws \WeChat\Exceptions\LocalCacheException @@ -43,8 +42,8 @@ class Product extends BasicWeChat /** * 设置测试人员白名单 - * @param array $openids 测试人员的openid列表 - * @param array $usernames 测试人员的微信号列表 + * @param array $openids openid 列表 + * @param array $usernames 微信号列表 * @return array * @throws \WeChat\Exceptions\InvalidResponseException * @throws \WeChat\Exceptions\LocalCacheException @@ -57,10 +56,10 @@ class Product extends BasicWeChat /** * 获取商品二维码 - * @param string $keystandard 商品编码标准 - * @param string $keystr 商品编码内容 - * @param integer $qrcode_size 二维码的尺寸(整型),数值代表边长像素数,不填写默认值为100 - * @param array $extinfo 由商户自定义传入,建议仅使用大小写字母、数字及-_().*这6个常用字符 + * @param string $keystandard 编码标准 + * @param string $keystr 编码内容 + * @param int $qrcode_size 边长像素,默认100 + * @param array $extinfo 自定义扩展 * @return array * @throws \WeChat\Exceptions\InvalidResponseException * @throws \WeChat\Exceptions\LocalCacheException @@ -91,10 +90,10 @@ class Product extends BasicWeChat /** * 批量查询商品信息 - * @param integer $offset 批量查询的起始位置,从0开始,包含该起始位置 - * @param integer $limit 批量查询的数量 - * @param null|string $status 支持按状态拉取。on为发布状态,off为未发布状态,check为审核中状态,reject为审核未通过状态,all为所有状态 - * @param string $keystr 支持按部分编码内容拉取。填写该参数后,可将编码内容中包含所传参数的商品信息拉出。类似关键词搜索 + * @param int $offset 起始位置 + * @param int $limit 数量 + * @param null|string $status on|off|check|reject|all + * @param string $keystr 模糊编码过滤 * @return array * @throws \WeChat\Exceptions\InvalidResponseException * @throws \WeChat\Exceptions\LocalCacheException @@ -110,7 +109,7 @@ class Product extends BasicWeChat /** * 更新商品信息 - * @param array $data + * @param array $data 商品数据 * @return array * @throws \WeChat\Exceptions\InvalidResponseException * @throws \WeChat\Exceptions\LocalCacheException @@ -136,7 +135,7 @@ class Product extends BasicWeChat } /** - * 检查wxticket参数 + * 检查 wxticket 参数 * @param string $ticket * @return array * @throws \WeChat\Exceptions\InvalidResponseException @@ -152,7 +151,7 @@ class Product extends BasicWeChat * 清除扫码记录 * @param string $keystandard 商品编码标准 * @param string $keystr 商品编码内容 - * @param string $extinfo 调用“获取商品二维码接口”时传入的extinfo,为标识参数 + * @param string $extinfo 获取二维码时的 extinfo * @return array * @throws \WeChat\Exceptions\InvalidResponseException * @throws \WeChat\Exceptions\LocalCacheException diff --git a/WeChat/Prpcrypt/ErrorCode.php b/WeChat/Prpcrypt/ErrorCode.php index d11e4eb..fb1be61 100644 --- a/WeChat/Prpcrypt/ErrorCode.php +++ b/WeChat/Prpcrypt/ErrorCode.php @@ -5,7 +5,6 @@ namespace WeChat\Prpcrypt; /** * 仅用作类内部使用 * 不用于官方API接口的errCode码 - * Class ErrorCode */ class ErrorCode { diff --git a/WeChat/Prpcrypt/PKCS7Encoder.php b/WeChat/Prpcrypt/PKCS7Encoder.php index bac5ab0..3192446 100644 --- a/WeChat/Prpcrypt/PKCS7Encoder.php +++ b/WeChat/Prpcrypt/PKCS7Encoder.php @@ -4,7 +4,6 @@ namespace WeChat\Prpcrypt; /** * PKCS7算法 - 加解密 - * Class PKCS7Encoder */ class PKCS7Encoder { diff --git a/WeChat/Prpcrypt/Prpcrypt.php b/WeChat/Prpcrypt/Prpcrypt.php index cec9af7..f61482d 100644 --- a/WeChat/Prpcrypt/Prpcrypt.php +++ b/WeChat/Prpcrypt/Prpcrypt.php @@ -16,7 +16,6 @@ namespace WeChat\Prpcrypt; /** * 公众号消息 - 加解密 - * Class Prpcrypt */ class Prpcrypt { @@ -52,6 +51,21 @@ class Prpcrypt } } + /** + * 随机生成16位字符串 + * @param string $str + * @return string 生成的字符串 + */ + function getRandomStr($str = "") + { + $str_pol = "ABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789abcdefghijklmnopqrstuvwxyz"; + $max = strlen($str_pol) - 1; + for ($i = 0; $i < 16; $i++) { + $str .= $str_pol[mt_rand(0, $max)]; + } + return $str; + } + /** * 对密文进行解密 * @param string $encrypted 需要解密的密文 @@ -80,19 +94,4 @@ class Prpcrypt } } - /** - * 随机生成16位字符串 - * @param string $str - * @return string 生成的字符串 - */ - function getRandomStr($str = "") - { - $str_pol = "ABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789abcdefghijklmnopqrstuvwxyz"; - $max = strlen($str_pol) - 1; - for ($i = 0; $i < 16; $i++) { - $str .= $str_pol[mt_rand(0, $max)]; - } - return $str; - } - } diff --git a/WeChat/Qrcode.php b/WeChat/Qrcode.php index 958d8b6..51efb9f 100644 --- a/WeChat/Qrcode.php +++ b/WeChat/Qrcode.php @@ -3,7 +3,7 @@ // +---------------------------------------------------------------------- // | WeChatDeveloper // +---------------------------------------------------------------------- -// | 版权所有 2014~2025 ThinkAdmin [ thinkadmin.top ] +// | 版权所有 2014~2026 ThinkAdmin [ thinkadmin.top ] // +---------------------------------------------------------------------- // | 官方网站: https://thinkadmin.top // +---------------------------------------------------------------------- @@ -20,17 +20,16 @@ use WeChat\Contracts\BasicWeChat; /** * 二维码管理 - * Class Qrcode * @package WeChat */ class Qrcode extends BasicWeChat { /** - * 创建二维码ticket - * @param string|integer $scene 场景 - * @param int $expire_seconds 有效时间 - * @return array + * 创建二维码 ticket + * @param string|int $scene 场景值(字符串或数字) + * @param int $expire_seconds 过期时间,0 表示永久 + * @return array 含 ticket、url * @throws \WeChat\Exceptions\InvalidResponseException * @throws \WeChat\Exceptions\LocalCacheException */ @@ -52,9 +51,9 @@ class Qrcode extends BasicWeChat } /** - * 通过ticket换取二维码 - * @param string $ticket 获取的二维码ticket,凭借此ticket可以在有效时间内换取二维码。 - * @return string + * 通过 ticket 换取二维码 URL + * @param string $ticket 二维码 ticket + * @return string 图片 URL */ public function url($ticket) { @@ -62,8 +61,8 @@ class Qrcode extends BasicWeChat } /** - * 长链接转短链接接口 - * @param string $longUrl 需要转换的长链接 + * 长链接转短链接 + * @param string $longUrl 长链接 * @return array * @throws \WeChat\Exceptions\InvalidResponseException * @throws \WeChat\Exceptions\LocalCacheException diff --git a/WeChat/Receive.php b/WeChat/Receive.php index 6661cbc..b1d68c8 100644 --- a/WeChat/Receive.php +++ b/WeChat/Receive.php @@ -3,7 +3,7 @@ // +---------------------------------------------------------------------- // | WeChatDeveloper // +---------------------------------------------------------------------- -// | 版权所有 2014~2025 ThinkAdmin [ thinkadmin.top ] +// | 版权所有 2014~2026 ThinkAdmin [ thinkadmin.top ] // +---------------------------------------------------------------------- // | 官方网站: https://thinkadmin.top // +---------------------------------------------------------------------- @@ -20,15 +20,14 @@ use WeChat\Contracts\BasicPushEvent; /** * 公众号推送管理 - * Class Receive * @package WeChat */ class Receive extends BasicPushEvent { /** - * 转发多客服消息 - * @param string $account + * 转发到多客服 + * @param string $account 可选客服账号 * @return $this */ public function transferCustomerService($account = '') @@ -61,8 +60,8 @@ class Receive extends BasicPushEvent } /** - * 设置回复图文 - * @param array $newsData + * 设置图文消息 + * @param array $newsData Articles 列表 * @return $this */ public function news($newsData = []) @@ -80,7 +79,7 @@ class Receive extends BasicPushEvent /** * 设置图片消息 - * @param string $mediaId 图片媒体ID + * @param string $mediaId 图片 media_id * @return $this */ public function image($mediaId = '') @@ -96,8 +95,8 @@ class Receive extends BasicPushEvent } /** - * 设置语音回复消息 - * @param string $mediaid 语音媒体ID + * 设置语音消息 + * @param string $mediaid 语音 media_id * @return $this */ public function voice($mediaid = '') @@ -113,10 +112,10 @@ class Receive extends BasicPushEvent } /** - * 设置视频回复消息 - * @param string $mediaid 视频媒体ID - * @param string $title 视频标题 - * @param string $description 视频描述 + * 设置视频消息 + * @param string $mediaid 视频 media_id + * @param string $title 标题 + * @param string $description 描述 * @return $this */ public function video($mediaid = '', $title = '', $description = '') @@ -136,12 +135,12 @@ class Receive extends BasicPushEvent } /** - * 设置音乐回复消息 - * @param string $title 音乐标题 - * @param string $desc 音乐描述 - * @param string $musicurl 音乐地址 - * @param string $hgmusicurl 高清音乐地址 - * @param string $thumbmediaid 音乐图片缩略图的媒体id(可选) + * 设置音乐消息 + * @param string $title 标题 + * @param string $desc 描述 + * @param string $musicurl 音乐链接 + * @param string $hgmusicurl 高清链接 + * @param string $thumbmediaid 缩略图 media_id * @return $this */ public function music($title, $desc, $musicurl, $hgmusicurl = '', $thumbmediaid = '') diff --git a/WeChat/Scan.php b/WeChat/Scan.php index ce6a5e6..6f5df49 100644 --- a/WeChat/Scan.php +++ b/WeChat/Scan.php @@ -3,7 +3,7 @@ // +---------------------------------------------------------------------- // | WeChatDeveloper // +---------------------------------------------------------------------- -// | 版权所有 2014~2025 ThinkAdmin [ thinkadmin.top ] +// | 版权所有 2014~2026 ThinkAdmin [ thinkadmin.top ] // +---------------------------------------------------------------------- // | 官方网站: https://thinkadmin.top // +---------------------------------------------------------------------- @@ -20,7 +20,6 @@ use WeChat\Contracts\BasicWeChat; /** * 扫一扫接入管理 - * Class Scan * @package WeChat */ class Scan extends BasicWeChat @@ -39,7 +38,7 @@ class Scan extends BasicWeChat /** * 创建商品 - * @param array $data + * @param array $data 商品数据 * @return array * @throws \WeChat\Exceptions\InvalidResponseException * @throws \WeChat\Exceptions\LocalCacheException @@ -51,10 +50,10 @@ class Scan extends BasicWeChat } /** - * 商品发布 + * 商品发布/取消 * @param string $keystandard 商品编码标准 * @param string $keystr 商品编码内容 - * @param string $status 设置发布状态。on为提交审核,off为取消发布 + * @param string $status on 提交审核 | off 取消 * @return array * @throws \WeChat\Exceptions\InvalidResponseException * @throws \WeChat\Exceptions\LocalCacheException @@ -68,8 +67,8 @@ class Scan extends BasicWeChat /** * 设置测试人员白名单 - * @param array $openids 测试人员的openid列表 - * @param array $usernames 测试人员的微信号列表 + * @param array $openids openid 列表 + * @param array $usernames 微信号列表 * @return array * @throws \WeChat\Exceptions\InvalidResponseException * @throws \WeChat\Exceptions\LocalCacheException @@ -82,10 +81,10 @@ class Scan extends BasicWeChat /** * 获取商品二维码 - * @param string $keystandard - * @param string $keystr - * @param null|string $extinfo - * @param integer $qrcode_size + * @param string $keystandard 编码标准 + * @param string $keystr 编码内容 + * @param null|string $extinfo 自定义标识 + * @param int $qrcode_size 边长像素 * @return array * @throws \WeChat\Exceptions\InvalidResponseException * @throws \WeChat\Exceptions\LocalCacheException @@ -114,10 +113,10 @@ class Scan extends BasicWeChat /** * 批量查询商品信息 - * @param integer $offset 批量查询的起始位置,从0开始,包含该起始位置。 - * @param integer $limit 批量查询的数量。 - * @param string $status 支持按状态拉取。on为发布状态,off为未发布状态,check为审核中状态,reject为审核未通过状态,all为所有状态。 - * @param string $keystr 支持按部分编码内容拉取。填写该参数后,可将编码内容中包含所传参数的商品信息拉出。类似关键词搜索。 + * @param int $offset 起始位置 + * @param int $limit 数量 + * @param string $status on|off|check|reject|all + * @param string $keystr 关键词过滤 * @return array * @throws \WeChat\Exceptions\InvalidResponseException * @throws \WeChat\Exceptions\LocalCacheException @@ -133,7 +132,7 @@ class Scan extends BasicWeChat /** * 更新商品信息 - * @param array $data + * @param array $data 商品数据 * @return array * @throws \WeChat\Exceptions\InvalidResponseException * @throws \WeChat\Exceptions\LocalCacheException @@ -159,7 +158,7 @@ class Scan extends BasicWeChat } /** - * 检查wxticket参数 + * 检查 wxticket 参数 * @param string $ticket * @return array * @throws \WeChat\Exceptions\InvalidResponseException @@ -175,7 +174,7 @@ class Scan extends BasicWeChat * 清除扫码记录 * @param string $keystandard 商品编码标准 * @param string $keystr 商品编码内容 - * @param string $extinfo 调用“获取商品二维码接口”时传入的extinfo,为标识参数 + * @param string $extinfo 二维码接口时的 extinfo * @return array * @throws \WeChat\Exceptions\InvalidResponseException * @throws \WeChat\Exceptions\LocalCacheException diff --git a/WeChat/Script.php b/WeChat/Script.php index 98b25b2..243012a 100644 --- a/WeChat/Script.php +++ b/WeChat/Script.php @@ -3,7 +3,7 @@ // +---------------------------------------------------------------------- // | WeChatDeveloper // +---------------------------------------------------------------------- -// | 版权所有 2014~2025 ThinkAdmin [ thinkadmin.top ] +// | 版权所有 2014~2026 ThinkAdmin [ thinkadmin.top ] // +---------------------------------------------------------------------- // | 官方网站: https://thinkadmin.top // +---------------------------------------------------------------------- @@ -22,7 +22,6 @@ use WeChat\Exceptions\InvalidResponseException; /** * 微信前端支持 - * Class Script * @package WeChat */ class Script extends BasicWeChat @@ -42,37 +41,11 @@ class Script extends BasicWeChat } /** - * 获取JSAPI_TICKET接口 - * @param string $type TICKET类型(wx_card|jsapi) - * @param string $appid 强制指定有效APPID - * @return string - * @throws \WeChat\Exceptions\InvalidResponseException - * @throws \WeChat\Exceptions\LocalCacheException - */ - public function getTicket($type = 'jsapi', $appid = null) - { - is_null($appid) && $appid = $this->config->get('appid'); - $cache_name = "{$appid}_ticket_{$type}"; - $ticket = Tools::getCache($cache_name); - if (empty($ticket)) { - $url = "https://api.weixin.qq.com/cgi-bin/ticket/getticket?access_token=ACCESS_TOKEN&type={$type}"; - $this->registerApi($url, __FUNCTION__, func_get_args()); - $result = $this->httpGetForJson($url); - if (empty($result['ticket'])) { - throw new InvalidResponseException('Invalid Resoponse Ticket.', '0'); - } - $ticket = $result['ticket']; - Tools::setCache($cache_name, $ticket, 7000); - } - return $ticket; - } - - /** - * 获取JsApi使用签名 - * @param string $url 网页的URL - * @param string $appid 用于多个appid时使用(可空) - * @param string $ticket 强制指定ticket - * @param array $jsApiList 需初始化的 jsApiList + * 获取 JSAPI 签名 + * @param string $url 当前页面 URL(不含 #) + * @param string $appid 可选指定 appid + * @param string $ticket 可选指定 ticket + * @param array $jsApiList 需注入的 API 列表 * @return array * @throws \WeChat\Exceptions\InvalidResponseException * @throws \WeChat\Exceptions\LocalCacheException @@ -100,12 +73,38 @@ class Script extends BasicWeChat ]; } + /** + * 获取 JSAPI_TICKET + * @param string $type jsapi|wx_card + * @param string $appid 可选指定 appid + * @return string ticket + * @throws \WeChat\Exceptions\InvalidResponseException + * @throws \WeChat\Exceptions\LocalCacheException + */ + public function getTicket($type = 'jsapi', $appid = null) + { + is_null($appid) && $appid = $this->config->get('appid'); + $cache_name = "{$appid}_ticket_{$type}"; + $ticket = Tools::getCache($cache_name); + if (empty($ticket)) { + $url = "https://api.weixin.qq.com/cgi-bin/ticket/getticket?access_token=ACCESS_TOKEN&type={$type}"; + $this->registerApi($url, __FUNCTION__, func_get_args()); + $result = $this->httpGetForJson($url); + if (empty($result['ticket'])) { + throw new InvalidResponseException('Invalid Resoponse Ticket.', '0'); + } + $ticket = $result['ticket']; + Tools::setCache($cache_name, $ticket, 7000); + } + return $ticket; + } + /** * 数据生成签名 - * @param array $data 签名数组 + * @param array $data 待签名数据 * @param string $method 签名方法 - * @param array $params 签名参数 - * @return bool|string 签名值 + * @param array $params 额外参数 + * @return bool|string */ protected function getSignature($data, $method = "sha1", $params = []) { diff --git a/WeChat/Shake.php b/WeChat/Shake.php index 09e95e1..2b10278 100644 --- a/WeChat/Shake.php +++ b/WeChat/Shake.php @@ -3,7 +3,7 @@ // +---------------------------------------------------------------------- // | WeChatDeveloper // +---------------------------------------------------------------------- -// | 版权所有 2014~2025 ThinkAdmin [ thinkadmin.top ] +// | 版权所有 2014~2026 ThinkAdmin [ thinkadmin.top ] // +---------------------------------------------------------------------- // | 官方网站: https://thinkadmin.top // +---------------------------------------------------------------------- @@ -21,14 +21,13 @@ use WeChat\Contracts\Tools; /** * 揺一揺周边 - * Class Shake * @package WeChat */ class Shake extends BasicWeChat { /** - * 申请开通功能 - * @param array $data + * 申请开通摇一摇 + * @param array $data 资质信息 * @return array * @throws \WeChat\Exceptions\InvalidResponseException * @throws \WeChat\Exceptions\LocalCacheException @@ -52,11 +51,11 @@ class Shake extends BasicWeChat } /** - * 申请设备ID - * @param string $quantity 申请的设备ID的数量,单次新增设备超过500个,需走人工审核流程 - * @param string $apply_reason 申请理由,不超过100个汉字或200个英文字母 - * @param null|string $comment 备注,不超过15个汉字或30个英文字母 - * @param null|string $poi_id 设备关联的门店ID,关联门店后,在门店1KM的范围内有优先摇出信息的机会。 + * 申请设备 ID + * @param string $quantity 数量(>500 走人工审核) + * @param string $apply_reason 理由 + * @param null|string $comment 备注 + * @param null|string $poi_id 门店ID * @return array * @throws \WeChat\Exceptions\InvalidResponseException * @throws \WeChat\Exceptions\LocalCacheException @@ -71,8 +70,8 @@ class Shake extends BasicWeChat } /** - * 查询设备ID申请审核状态 - * @param integer $applyId 批次ID,申请设备ID时所返回的批次ID + * 查询设备 ID 申请状态 + * @param int $applyId 批次ID * @return array * @throws \WeChat\Exceptions\InvalidResponseException * @throws \WeChat\Exceptions\LocalCacheException @@ -85,7 +84,7 @@ class Shake extends BasicWeChat /** * 编辑设备信息 - * @param array $data + * @param array $data 设备参数 * @return array * @throws \WeChat\Exceptions\InvalidResponseException * @throws \WeChat\Exceptions\LocalCacheException @@ -97,8 +96,8 @@ class Shake extends BasicWeChat } /** - * 配置设备与门店的关联关系 - * @param array $data + * 设备绑定门店 + * @param array $data 绑定参数 * @return array * @throws \WeChat\Exceptions\InvalidResponseException * @throws \WeChat\Exceptions\LocalCacheException @@ -111,7 +110,7 @@ class Shake extends BasicWeChat /** * 查询设备列表 - * @param array $data + * @param array $data 查询参数 * @return array * @throws \WeChat\Exceptions\InvalidResponseException * @throws \WeChat\Exceptions\LocalCacheException @@ -123,8 +122,8 @@ class Shake extends BasicWeChat } /** - * 页面管理 - * @param array $data + * 创建页面 + * @param array $data 页面参数 * @return array * @throws \WeChat\Exceptions\InvalidResponseException * @throws \WeChat\Exceptions\LocalCacheException @@ -136,8 +135,8 @@ class Shake extends BasicWeChat } /** - * 编辑页面信息 - * @param array $data + * 编辑页面 + * @param array $data 页面参数 * @return array * @throws \WeChat\Exceptions\InvalidResponseException * @throws \WeChat\Exceptions\LocalCacheException @@ -150,7 +149,7 @@ class Shake extends BasicWeChat /** * 查询页面列表 - * @param array $data + * @param array $data 查询参数 * @return array * @throws \WeChat\Exceptions\InvalidResponseException * @throws \WeChat\Exceptions\LocalCacheException @@ -163,7 +162,7 @@ class Shake extends BasicWeChat /** * 删除页面 - * @param integer $pageId 指定页面的id + * @param int $pageId 页面ID * @return array * @throws \WeChat\Exceptions\InvalidResponseException * @throws \WeChat\Exceptions\LocalCacheException @@ -176,8 +175,8 @@ class Shake extends BasicWeChat /** * 上传图片素材 - * @param string $filename 图片名字 - * @param string $type Icon:摇一摇页面展示的icon图;License:申请开通摇一摇周边功能时需上传的资质文件;若不传type,则默认type=icon + * @param string $filename 图片路径 + * @param string $type icon|license * @return array * @throws \WeChat\Exceptions\InvalidResponseException * @throws \WeChat\Exceptions\LocalCacheException @@ -189,8 +188,8 @@ class Shake extends BasicWeChat } /** - * 配置设备与页面的关联关系 - * @param array $data + * 配置设备与页面关联 + * @param array $data 关联参数 * @return array * @throws \WeChat\Exceptions\InvalidResponseException * @throws \WeChat\Exceptions\LocalCacheException @@ -202,8 +201,8 @@ class Shake extends BasicWeChat } /** - * 查询设备与页面的关联关系 - * @param array $data + * 查询设备与页面关联 + * @param array $data 查询参数 * @return array * @throws \WeChat\Exceptions\InvalidResponseException * @throws \WeChat\Exceptions\LocalCacheException @@ -215,8 +214,8 @@ class Shake extends BasicWeChat } /** - * 以设备为维度的数据统计接口 - * @param array $data + * 设备维度数据统计 + * @param array $data 查询参数 * @return array * @throws \WeChat\Exceptions\InvalidResponseException * @throws \WeChat\Exceptions\LocalCacheException @@ -228,9 +227,9 @@ class Shake extends BasicWeChat } /** - * 批量查询设备统计数据接口 - * @param integer $date 指定查询日期时间戳,单位为秒 - * @param integer $pageIndex 指定查询的结果页序号;返回结果按摇周边人数降序排序,每50条记录为一页 + * 批量查询设备统计 + * @param int $date 日期时间戳(秒) + * @param int $pageIndex 页码 * @return array * @throws \WeChat\Exceptions\InvalidResponseException * @throws \WeChat\Exceptions\LocalCacheException @@ -242,10 +241,10 @@ class Shake extends BasicWeChat } /** - * 以页面为维度的数据统计接口 - * @param integer $pageId 指定页面的设备ID - * @param integer $beginDate 起始日期时间戳,最长时间跨度为30天,单位为秒 - * @param integer $endDate 结束日期时间戳,最长时间跨度为30天,单位为秒 + * 页面维度数据统计 + * @param int $pageId 页面ID + * @param int $beginDate 起始时间戳 + * @param int $endDate 结束时间戳 * @return array * @throws \WeChat\Exceptions\InvalidResponseException * @throws \WeChat\Exceptions\LocalCacheException @@ -258,8 +257,8 @@ class Shake extends BasicWeChat /** * 编辑分组信息 - * @param integer $groupId 分组唯一标识,全局唯一 - * @param string $groupName 分组名称,不超过100汉字或200个英文字母 + * @param int $groupId 分组ID + * @param string $groupName 分组名称 * @return array * @throws \WeChat\Exceptions\InvalidResponseException * @throws \WeChat\Exceptions\LocalCacheException @@ -272,7 +271,7 @@ class Shake extends BasicWeChat /** * 删除分组 - * @param integer $groupId 分组唯一标识,全局唯一 + * @param int $groupId 分组ID * @return array * @throws \WeChat\Exceptions\InvalidResponseException * @throws \WeChat\Exceptions\LocalCacheException @@ -285,8 +284,8 @@ class Shake extends BasicWeChat /** * 查询分组列表 - * @param integer $begin 分组列表的起始索引值 - * @param integer $count 待查询的分组数量,不能超过1000个 + * @param int $begin 起始索引 + * @param int $count 数量(<=1000) * @return array * @throws \WeChat\Exceptions\InvalidResponseException * @throws \WeChat\Exceptions\LocalCacheException @@ -300,9 +299,9 @@ class Shake extends BasicWeChat /** * 查询分组详情 - * @param integer $group_id 分组唯一标识,全局唯一 - * @param integer $begin 分组里设备的起始索引值 - * @param integer $count 待查询的分组里设备的数量,不能超过1000个 + * @param int $group_id 分组ID + * @param int $begin 设备起始索引 + * @param int $count 数量(<=1000) * @return array * @throws \WeChat\Exceptions\InvalidResponseException * @throws \WeChat\Exceptions\LocalCacheException @@ -314,8 +313,8 @@ class Shake extends BasicWeChat } /** - * 添加设备到分组 - * @param array $data + * 分组添加设备 + * @param array $data 设备参数 * @return array * @throws \WeChat\Exceptions\InvalidResponseException * @throws \WeChat\Exceptions\LocalCacheException @@ -327,8 +326,8 @@ class Shake extends BasicWeChat } /** - * 从分组中移除设备 - * @param array $data + * 分组移除设备 + * @param array $data 设备参数 * @return array * @throws \WeChat\Exceptions\InvalidResponseException * @throws \WeChat\Exceptions\LocalCacheException diff --git a/WeChat/Tags.php b/WeChat/Tags.php index 5b4f656..268a417 100644 --- a/WeChat/Tags.php +++ b/WeChat/Tags.php @@ -3,7 +3,7 @@ // +---------------------------------------------------------------------- // | WeChatDeveloper // +---------------------------------------------------------------------- -// | 版权所有 2014~2025 ThinkAdmin [ thinkadmin.top ] +// | 版权所有 2014~2026 ThinkAdmin [ thinkadmin.top ] // +---------------------------------------------------------------------- // | 官方网站: https://thinkadmin.top // +---------------------------------------------------------------------- @@ -20,13 +20,13 @@ use WeChat\Contracts\BasicWeChat; /** * 用户标签管理 - * Class Tags * @package WeChat */ class Tags extends BasicWeChat { /** - * 获取粉丝标签列表 + * 获取标签列表 + * @return array * @throws Exceptions\InvalidResponseException * @throws Exceptions\LocalCacheException */ @@ -37,8 +37,8 @@ class Tags extends BasicWeChat } /** - * 创建粉丝标签 - * @param string $name + * 创建标签 + * @param string $name 标签名称 * @return array * @throws Exceptions\InvalidResponseException * @throws Exceptions\LocalCacheException @@ -50,8 +50,8 @@ class Tags extends BasicWeChat } /** - * 更新粉丝标签 - * @param integer $id 标签ID + * 更新标签 + * @param int $id 标签ID * @param string $name 标签名称 * @return array * @throws Exceptions\InvalidResponseException @@ -64,8 +64,8 @@ class Tags extends BasicWeChat } /** - * 删除粉丝标签 - * @param int $tagId + * 删除标签 + * @param int $tagId 标签ID * @return array * @throws Exceptions\InvalidResponseException * @throws Exceptions\LocalCacheException @@ -78,8 +78,8 @@ class Tags extends BasicWeChat /** * 批量为用户打标签 - * @param array $openids - * @param integer $tagId + * @param array $openids openid 列表 + * @param int $tagId 标签ID * @return array * @throws Exceptions\InvalidResponseException * @throws Exceptions\LocalCacheException @@ -91,9 +91,9 @@ class Tags extends BasicWeChat } /** - * 批量为用户取消标签 - * @param array $openids - * @param integer $tagId + * 批量取消用户标签 + * @param array $openids openid 列表 + * @param int $tagId 标签ID * @return array * @throws Exceptions\InvalidResponseException * @throws Exceptions\LocalCacheException @@ -105,8 +105,8 @@ class Tags extends BasicWeChat } /** - * 获取用户身上的标签列表 - * @param string $openid + * 获取用户标签列表 + * @param string $openid 用户 openid * @return array * @throws Exceptions\InvalidResponseException * @throws Exceptions\LocalCacheException diff --git a/WeChat/Template.php b/WeChat/Template.php index 666e43e..5cbe498 100644 --- a/WeChat/Template.php +++ b/WeChat/Template.php @@ -3,7 +3,7 @@ // +---------------------------------------------------------------------- // | WeChatDeveloper // +---------------------------------------------------------------------- -// | 版权所有 2014~2025 ThinkAdmin [ thinkadmin.top ] +// | 版权所有 2014~2026 ThinkAdmin [ thinkadmin.top ] // +---------------------------------------------------------------------- // | 官方网站: https://thinkadmin.top // +---------------------------------------------------------------------- @@ -20,15 +20,14 @@ use WeChat\Contracts\BasicWeChat; /** * 模板消息 - * Class Template * @package WeChat */ class Template extends BasicWeChat { /** - * 设置所属行业 - * @param string $industryId1 公众号模板消息所属行业编号 - * @param string $industryId2 公众号模板消息所属行业编号 + * 设置模板消息所属行业 + * @param string $industryId1 行业编号 + * @param string $industryId2 行业编号 * @return array * @throws Exceptions\InvalidResponseException * @throws Exceptions\LocalCacheException @@ -40,7 +39,7 @@ class Template extends BasicWeChat } /** - * 获取设置的行业信息 + * 获取已设置的行业信息 * @return array * @throws Exceptions\InvalidResponseException * @throws Exceptions\LocalCacheException @@ -52,9 +51,9 @@ class Template extends BasicWeChat } /** - * 获得模板ID - * @param string $templateIdShort 板库中模板的编号,有“TM**”和“OPENTMTM**”等形式 - * @param array $keywordNameList 选用的类目模板的关键词 + * 领取模板 ID + * @param string $templateIdShort 模板编号(如 TM** 或 OPENTMTM**) + * @param array $keywordNameList 选用关键词 * @return array * @throws Exceptions\InvalidResponseException * @throws Exceptions\LocalCacheException @@ -66,7 +65,7 @@ class Template extends BasicWeChat } /** - * 获取模板列表 + * 获取私有模板列表 * @return array * @throws Exceptions\InvalidResponseException * @throws Exceptions\LocalCacheException @@ -78,8 +77,8 @@ class Template extends BasicWeChat } /** - * 删除模板ID - * @param string $tplId 公众帐号下模板消息ID + * 删除模板 + * @param string $tplId 模板 ID * @return array * @throws Exceptions\InvalidResponseException * @throws Exceptions\LocalCacheException @@ -92,7 +91,7 @@ class Template extends BasicWeChat /** * 发送模板消息 - * @param array $data + * @param array $data 消息内容(touser, template_id, data 等) * @return array * @throws Exceptions\InvalidResponseException * @throws Exceptions\LocalCacheException diff --git a/WeChat/User.php b/WeChat/User.php index 38dca45..49155bf 100644 --- a/WeChat/User.php +++ b/WeChat/User.php @@ -3,7 +3,7 @@ // +---------------------------------------------------------------------- // | WeChatDeveloper // +---------------------------------------------------------------------- -// | 版权所有 2014~2025 ThinkAdmin [ thinkadmin.top ] +// | 版权所有 2014~2026 ThinkAdmin [ thinkadmin.top ] // +---------------------------------------------------------------------- // | 官方网站: https://thinkadmin.top // +---------------------------------------------------------------------- @@ -20,17 +20,16 @@ use WeChat\Contracts\BasicWeChat; /** * 微信粉丝管理 - * Class User * @package WeChat */ class User extends BasicWeChat { /** - * 设置用户备注名 - * @param string $openid - * @param string $remark - * @return array + * 设置用户备注名接口 + * @param string $openid 用户openid + * @param string $remark 备注名(长度不超过30字符) + * @return array 操作结果 * @throws Exceptions\InvalidResponseException * @throws \WeChat\Exceptions\LocalCacheException */ @@ -41,10 +40,10 @@ class User extends BasicWeChat } /** - * 获取用户基本信息(包括UnionID机制) - * @param string $openid - * @param string $lang - * @return array + * 获取用户基本信息接口(包括UnionID) + * @param string $openid 用户openid + * @param string $lang 返回国家地区语言版本(zh_CN, zh_TW, en) + * @return array 用户信息(nickname, headimgurl, sex, province, city, country, unionid等) * @throws Exceptions\InvalidResponseException * @throws Exceptions\LocalCacheException */ @@ -55,10 +54,10 @@ class User extends BasicWeChat } /** - * 批量获取用户基本信息 - * @param array $openids - * @param string $lang - * @return array + * 批量获取用户基本信息接口 + * @param array $openids 用户openid列表(最多100个) + * @param string $lang 返回国家地区语言版本 + * @return array 用户信息列表 * @throws Exceptions\InvalidResponseException * @throws Exceptions\LocalCacheException */ @@ -73,9 +72,9 @@ class User extends BasicWeChat } /** - * 获取用户列表 - * @param string $next_openid - * @return array + * 获取用户列表接口 + * @param string $next_openid 第一个拉取的openid,不填默认从头开始拉取 + * @return array 用户列表(total, count, data.openid, next_openid) * @throws Exceptions\InvalidResponseException * @throws Exceptions\LocalCacheException */ @@ -86,10 +85,10 @@ class User extends BasicWeChat } /** - * 获取标签下粉丝列表 + * 获取标签下粉丝列表接口 * @param integer $tagid 标签ID - * @param string $nextOpenid 第一个拉取的OPENID - * @return array + * @param string $nextOpenid 第一个拉取的openid,不填默认从头开始拉取 + * @return array 粉丝列表(count, data.openid, next_openid) * @throws Exceptions\InvalidResponseException * @throws Exceptions\LocalCacheException */ @@ -100,9 +99,9 @@ class User extends BasicWeChat } /** - * 获取公众号的黑名单列表 - * @param string $beginOpenid - * @return array + * 获取公众号黑名单列表接口 + * @param string $beginOpenid 第一个拉取的openid,不填默认从头开始拉取 + * @return array 黑名单列表(total, count, data.openid, next_openid) * @throws Exceptions\InvalidResponseException * @throws Exceptions\LocalCacheException */ @@ -113,9 +112,9 @@ class User extends BasicWeChat } /** - * 批量拉黑用户 - * @param array $openids - * @return array + * 批量拉黑用户接口 + * @param array $openids 用户openid列表(最多20个) + * @return array 操作结果 * @throws Exceptions\InvalidResponseException * @throws Exceptions\LocalCacheException */ @@ -126,9 +125,9 @@ class User extends BasicWeChat } /** - * 批量取消拉黑用户 - * @param array $openids - * @return array + * 批量取消拉黑用户接口 + * @param array $openids 用户openid列表(最多20个) + * @return array 操作结果 * @throws Exceptions\InvalidResponseException * @throws Exceptions\LocalCacheException */ diff --git a/WeChat/Wifi.php b/WeChat/Wifi.php index 06b6b7d..c8386fc 100644 --- a/WeChat/Wifi.php +++ b/WeChat/Wifi.php @@ -3,7 +3,7 @@ // +---------------------------------------------------------------------- // | WeChatDeveloper // +---------------------------------------------------------------------- -// | 版权所有 2014~2025 ThinkAdmin [ thinkadmin.top ] +// | 版权所有 2014~2026 ThinkAdmin [ thinkadmin.top ] // +---------------------------------------------------------------------- // | 官方网站: https://thinkadmin.top // +---------------------------------------------------------------------- @@ -20,7 +20,6 @@ use WeChat\Contracts\BasicWeChat; /** * 门店 WIFI 管理 - * Class Wifi * @package WeChat */ class Wifi extends BasicWeChat @@ -28,8 +27,8 @@ class Wifi extends BasicWeChat /** * 获取 Wi-Fi 门店列表 - * @param integer $pageindex 分页下标,默认从1开始 - * @param integer $pagesize 每页的个数,默认10个,最大20个 + * @param int $pageindex 页码(从1开始) + * @param int $pagesize 每页数量(<=20) * @return array * @throws Exceptions\InvalidResponseException * @throws Exceptions\LocalCacheException @@ -42,8 +41,8 @@ class Wifi extends BasicWeChat } /** - * 查询门店Wi-Fi信息 - * @param integer $shop_id 门店ID + * 查询门店 Wi-Fi 信息 + * @param int $shop_id 门店ID * @return array * @throws Exceptions\InvalidResponseException * @throws Exceptions\LocalCacheException @@ -56,11 +55,11 @@ class Wifi extends BasicWeChat } /** - * 修改门店网络信息 - * @param integer $shop_id 门店ID - * @param string $old_ssid 旧的无线网络设备的ssid - * @param string $ssid 新的无线网络设备的ssid - * @param string $password 无线网络设备的密码(可选) + * 修改门店 Wi-Fi + * @param int $shop_id 门店ID + * @param string $old_ssid 原 SSID + * @param string $ssid 新 SSID + * @param string $password 可选密码 * @return array * @throws Exceptions\InvalidResponseException * @throws Exceptions\LocalCacheException @@ -75,8 +74,8 @@ class Wifi extends BasicWeChat } /** - * 清空门店网络及设备 - * @param integer $shop_id + * 清空门店网络与设备 + * @param int $shop_id 门店ID * @return array * @throws Exceptions\InvalidResponseException * @throws Exceptions\LocalCacheException @@ -90,9 +89,9 @@ class Wifi extends BasicWeChat /** * 添加密码型设备 - * @param integer $shop_id 门店ID - * @param string $ssid 无线网络设备的ssid - * @param null|string $password 无线网络设备的密码 + * @param int $shop_id 门店ID + * @param string $ssid SSID + * @param null|string $password 密码 * @return array * @throws Exceptions\InvalidResponseException * @throws Exceptions\LocalCacheException @@ -106,10 +105,10 @@ class Wifi extends BasicWeChat } /** - * 添加portal型设备 - * @param integer $shop_id 门店ID - * @param string $ssid 无线网络设备的ssid - * @param bool $reset 重置secretkey,false-不重置,true-重置,默认为false + * 添加 portal 型设备 + * @param int $shop_id 门店ID + * @param string $ssid SSID + * @param bool $reset 是否重置 secretkey * @return array * @throws Exceptions\InvalidResponseException * @throws Exceptions\LocalCacheException @@ -124,9 +123,9 @@ class Wifi extends BasicWeChat /** * 查询设备 - * @param null|integer $shop_id 根据门店id查询 - * @param null|integer $pageindex 分页下标,默认从1开始 - * @param null|integer $pagesize 每页的个数,默认10个,最大20个 + * @param int|null $shop_id 门店ID + * @param int|null $pageindex 页码 + * @param int|null $pagesize 数量 * @return array * @throws Exceptions\InvalidResponseException * @throws Exceptions\LocalCacheException @@ -144,7 +143,7 @@ class Wifi extends BasicWeChat /** * 删除设备 - * @param string $bssid 需要删除的无线网络设备无线mac地址,格式冒号分隔,字符长度17个,并且字母小写,例如:00:1f:7a:ad:5c:a8 + * @param string $bssid 设备 MAC,冒号分隔小写 * @return array * @throws Exceptions\InvalidResponseException * @throws Exceptions\LocalCacheException @@ -158,9 +157,9 @@ class Wifi extends BasicWeChat /** * 获取物料二维码 - * @param integer $shop_id 门店ID - * @param string $ssid 已添加到门店下的无线网络名称 - * @param integer $img_id 物料样式编号:0-纯二维码,可用于自由设计宣传材料;1-二维码物料,155mm×215mm(宽×高),可直接张贴 + * @param int $shop_id 门店ID + * @param string $ssid SSID + * @param int $img_id 物料样式 0|1 * @return array * @throws Exceptions\InvalidResponseException * @throws Exceptions\LocalCacheException @@ -174,9 +173,9 @@ class Wifi extends BasicWeChat /** * 设置商家主页 - * @param integer $shop_id 门店ID - * @param integer $template_id 模板ID,0-默认模板,1-自定义url - * @param null|string $url 自定义链接,当template_id为1时必填 + * @param int $shop_id 门店ID + * @param int $template_id 0 默认 | 1 自定义链接 + * @param null|string $url 自定义链接(template_id=1 必填) * @return array * @throws Exceptions\InvalidResponseException * @throws Exceptions\LocalCacheException @@ -192,7 +191,7 @@ class Wifi extends BasicWeChat /** * 查询商家主页 - * @param integer $shop_id 查询的门店id + * @param int $shop_id 门店ID * @return array * @throws Exceptions\InvalidResponseException * @throws Exceptions\LocalCacheException @@ -206,8 +205,8 @@ class Wifi extends BasicWeChat /** * 设置微信首页欢迎语 - * @param integer $shop_id 门店ID - * @param integer $bar_type 微信首页欢迎语的文本内容:0--欢迎光临+公众号名称;1--欢迎光临+门店名称;2--已连接+公众号名称+WiFi;3--已连接+门店名称+Wi-Fi。 + * @param int $shop_id 门店ID + * @param int $bar_type 0|1|2|3 * @return array * @throws Exceptions\InvalidResponseException * @throws Exceptions\LocalCacheException @@ -221,8 +220,8 @@ class Wifi extends BasicWeChat /** * 设置连网完成页 - * @param integer $shop_id 门店ID - * @param string $finishpage_url 连网完成页URL + * @param int $shop_id 门店ID + * @param string $finishpage_url 完成页 URL * @return array * @throws Exceptions\InvalidResponseException * @throws Exceptions\LocalCacheException @@ -236,9 +235,9 @@ class Wifi extends BasicWeChat /** * Wi-Fi 数据统计 - * @param string $begin_date 起始日期时间,格式yyyy-mm-dd,最长时间跨度为30天 - * @param string $end_date 结束日期时间戳,格式yyyy-mm-dd,最长时间跨度为30天 - * @param integer $shop_id 按门店ID搜索,-1为总统计 + * @param string $begin_date 开始日期 yyyy-mm-dd + * @param string $end_date 结束日期 yyyy-mm-dd + * @param int $shop_id 门店ID,-1 总统计 * @return array * @throws Exceptions\InvalidResponseException * @throws Exceptions\LocalCacheException @@ -251,12 +250,12 @@ class Wifi extends BasicWeChat } /** - * 设置门店卡券投放信息 - * @param integer $shop_id 门店ID,可设置为0,表示所有门店 - * @param integer $card_id 卡券ID - * @param string $card_describe 卡券描述,不能超过18个字符 - * @param string $start_time 卡券投放开始时间(单位是秒) - * @param string $end_time 卡券投放结束时间(单位是秒) 注:不能超过卡券的有效期时间 + * 设置门店卡券投放 + * @param int $shop_id 门店ID,0 表示全部 + * @param int $card_id 卡券ID + * @param string $card_describe 描述(<=18 字符) + * @param string $start_time 开始时间戳 + * @param string $end_time 结束时间戳 * @return array * @throws Exceptions\InvalidResponseException * @throws Exceptions\LocalCacheException @@ -270,8 +269,8 @@ class Wifi extends BasicWeChat } /** - * 查询门店卡券投放信息 - * @param integer $shop_id 门店ID,可设置为0,表示所有门店 + * 查询门店卡券投放 + * @param int $shop_id 门店ID,0 表示全部 * @return array * @throws Exceptions\InvalidResponseException * @throws Exceptions\LocalCacheException diff --git a/WeMini/Crypt.php b/WeMini/Crypt.php index fd716a3..139d1fc 100644 --- a/WeMini/Crypt.php +++ b/WeMini/Crypt.php @@ -3,7 +3,7 @@ // +---------------------------------------------------------------------- // | WeChatDeveloper // +---------------------------------------------------------------------- -// | 版权所有 2014~2025 ThinkAdmin [ thinkadmin.top ] +// | 版权所有 2014~2026 ThinkAdmin [ thinkadmin.top ] // +---------------------------------------------------------------------- // | 官方网站: https://thinkadmin.top // +---------------------------------------------------------------------- @@ -24,50 +24,17 @@ use WXBizDataCrypt; /** - * 数据加密处理 - * Class Crypt + * 小程序数据加解密 * @package WeMini */ class Crypt extends BasicWeChat { /** - * 数据签名校验 - * @param string $iv - * @param string $sessionKey - * @param string $encryptedData - * @return bool|array - */ - public function decode($iv, $sessionKey, $encryptedData) - { - require_once __DIR__ . DIRECTORY_SEPARATOR . 'crypt' . DIRECTORY_SEPARATOR . 'wxBizDataCrypt.php'; - $pc = new WXBizDataCrypt($this->config->get('appid'), $sessionKey); - $errCode = $pc->decryptData($encryptedData, $iv, $data); - if ($errCode == 0) { - return json_decode($data, true); - } - return false; - } - - /** - * 登录凭证校验 - * @param string $code 登录时获取的 code - * @return array - * @throws \WeChat\Exceptions\LocalCacheException - */ - public function session($code) - { - $appid = $this->config->get('appid'); - $secret = $this->config->get('appsecret'); - $url = "https://api.weixin.qq.com/sns/jscode2session?appid={$appid}&secret={$secret}&js_code={$code}&grant_type=authorization_code"; - return json_decode(Tools::get($url), true); - } - - /** - * 换取用户信息 - * @param string $code 用户登录凭证(有效期五分钟) - * @param string $iv 加密算法的初始向量 - * @param string $encryptedData 加密数据( encryptedData ) + * 通过 code 解密用户信息 + * @param string $code 登录凭证 + * @param string $iv 初始向量 + * @param string $encryptedData 加密数据 * @return array * @throws \WeChat\Exceptions\InvalidDecryptException * @throws \WeChat\Exceptions\InvalidResponseException @@ -87,8 +54,41 @@ class Crypt extends BasicWeChat } /** - * 通过授权码换取手机号 - * @param string $code + * code 换取 session_key + * @param string $code 登录 code + * @return array + * @throws \WeChat\Exceptions\LocalCacheException + */ + public function session($code) + { + $appid = $this->config->get('appid'); + $secret = $this->config->get('appsecret'); + $url = "https://api.weixin.qq.com/sns/jscode2session?appid={$appid}&secret={$secret}&js_code={$code}&grant_type=authorization_code"; + return json_decode(Tools::get($url), true); + } + + /** + * 解密数据 + * @param string $iv 初始向量 + * @param string $sessionKey 会话密钥 + * @param string $encryptedData 加密数据 + * @return bool|array + */ + public function decode($iv, $sessionKey, $encryptedData) + { + require_once __DIR__ . DIRECTORY_SEPARATOR . 'crypt' . DIRECTORY_SEPARATOR . 'wxBizDataCrypt.php'; + $pc = new WXBizDataCrypt($this->config->get('appid'), $sessionKey); + $data = ''; + $errCode = $pc->decryptData($encryptedData, $iv, $data); + if ($errCode == 0) { + return json_decode($data, true); + } + return false; + } + + /** + * 通过 code 获取手机号 + * @param string $code 授权码 * @return array * @throws \WeChat\Exceptions\InvalidResponseException * @throws \WeChat\Exceptions\LocalCacheException @@ -101,11 +101,11 @@ class Crypt extends BasicWeChat } /** - * 用户支付完成后,获取该用户的 UnionId - * @param string $openid 支付用户唯一标识 + * 支付后获取用户 UnionId + * @param string $openid 用户 openid * @param null|string $transaction_id 微信支付订单号 - * @param null|string $mch_id 微信支付分配的商户号,和商户订单号配合使用 - * @param null|string $out_trade_no 微信支付商户订单号,和商户号配合使用 + * @param null|string $mch_id 商户号 + * @param null|string $out_trade_no 商户订单号 * @return array * @throws \WeChat\Exceptions\InvalidResponseException * @throws \WeChat\Exceptions\LocalCacheException @@ -113,9 +113,9 @@ class Crypt extends BasicWeChat public function getPaidUnionId($openid, $transaction_id = null, $mch_id = null, $out_trade_no = null) { $url = "https://api.weixin.qq.com/wxa/getpaidunionid?access_token=ACCESS_TOKEN&openid={$openid}"; - if (is_null($mch_id)) $url .= "&mch_id={$mch_id}"; - if (is_null($out_trade_no)) $url .= "&out_trade_no={$out_trade_no}"; - if (is_null($transaction_id)) $url .= "&transaction_id={$transaction_id}"; + if (!is_null($mch_id)) $url .= "&mch_id={$mch_id}"; + if (!is_null($out_trade_no)) $url .= "&out_trade_no={$out_trade_no}"; + if (!is_null($transaction_id)) $url .= "&transaction_id={$transaction_id}"; $this->registerApi($url, __FUNCTION__, func_get_args()); return $this->callGetApi($url); } diff --git a/WeMini/Custom.php b/WeMini/Custom.php index e8c7c12..9c518f0 100644 --- a/WeMini/Custom.php +++ b/WeMini/Custom.php @@ -3,7 +3,7 @@ // +---------------------------------------------------------------------- // | WeChatDeveloper // +---------------------------------------------------------------------- -// | 版权所有 2014~2025 ThinkAdmin [ thinkadmin.top ] +// | 版权所有 2014~2026 ThinkAdmin [ thinkadmin.top ] // +---------------------------------------------------------------------- // | 官方网站: https://thinkadmin.top // +---------------------------------------------------------------------- @@ -20,7 +20,6 @@ use WeChat\Contracts\BasicWeChat; /** * 小程序客服服务 - * Class Custom * @package WeMini */ class Custom extends BasicWeChat @@ -28,7 +27,7 @@ class Custom extends BasicWeChat /** * 创建商户 - * @param array $data + * @param array $data 商户资料 * @return array * @throws \WeChat\Exceptions\InvalidResponseException * @throws \WeChat\Exceptions\LocalCacheException @@ -41,7 +40,7 @@ class Custom extends BasicWeChat /** * 更新商户信息 - * @param array $data + * @param array $data 商户资料 * @return array * @throws \WeChat\Exceptions\InvalidResponseException * @throws \WeChat\Exceptions\LocalCacheException @@ -54,8 +53,8 @@ class Custom extends BasicWeChat /** - * 拉取单个商户信息 - * @param array $data + * 查询单个商户 + * @param array $data 查询参数 * @return array * @throws \WeChat\Exceptions\InvalidResponseException * @throws \WeChat\Exceptions\LocalCacheException @@ -68,8 +67,8 @@ class Custom extends BasicWeChat /** - * 拉取多个商户信息 - * @param array $data + * 查询商户列表 + * @param array $data 查询参数 * @return array * @throws \WeChat\Exceptions\InvalidResponseException * @throws \WeChat\Exceptions\LocalCacheException @@ -82,7 +81,7 @@ class Custom extends BasicWeChat /** * 发送客服消息 - * @param array $data + * @param array $data 消息体(touser, msgtype, content 等) * @return array * @throws \WeChat\Exceptions\InvalidResponseException * @throws \WeChat\Exceptions\LocalCacheException @@ -95,7 +94,7 @@ class Custom extends BasicWeChat /** * 客服输入状态 - * @param array $data + * @param array $data 输入状态参数 * @return array * @throws \WeChat\Exceptions\InvalidResponseException * @throws \WeChat\Exceptions\LocalCacheException @@ -108,8 +107,8 @@ class Custom extends BasicWeChat /** - * 获取客服基本信息 - * @param string $business_id 客服子商户的business_id,对于普通小程序客服不需要填business_id + * 获取客服列表 + * @param string $business_id 子商户 business_id,普通小程序可为空 * @return array * @throws \WeChat\Exceptions\InvalidResponseException * @throws \WeChat\Exceptions\LocalCacheException @@ -126,7 +125,7 @@ class Custom extends BasicWeChat /** * 获取在线客服列表 - * @param string $business_id 客服子商户的business_id,对于普通小程序客服不需要填business_id + * @param string $business_id 子商户 business_id,普通小程序可为空 * @return array * @throws \WeChat\Exceptions\InvalidResponseException * @throws \WeChat\Exceptions\LocalCacheException @@ -142,8 +141,8 @@ class Custom extends BasicWeChat /** - * 客服输入状态 - * @param array $data + * 新增客服账号 + * @param array $data 账号参数 * @return array * @throws \WeChat\Exceptions\InvalidResponseException * @throws \WeChat\Exceptions\LocalCacheException @@ -157,8 +156,8 @@ class Custom extends BasicWeChat /** * 删除客服账号 - * @param string $kf_openid 客服openid - * @param string $business_id 客服子商户的business_id,对于普通小程序客服不需要填business_id + * @param string $kf_openid 客服 openid + * @param string $business_id 子商户 business_id,可为空 * @return array * @throws \WeChat\Exceptions\InvalidResponseException * @throws \WeChat\Exceptions\LocalCacheException @@ -174,8 +173,8 @@ class Custom extends BasicWeChat /** * 设置客服管理员 - * @param string $kf_openid 客服openid - * @param string $business_id 客服子商户的business_id,对于普通小程序客服不需要填business_id + * @param string $kf_openid 客服 openid + * @param string $business_id 子商户 business_id,可为空 * @return array * @throws \WeChat\Exceptions\InvalidResponseException * @throws \WeChat\Exceptions\LocalCacheException @@ -192,8 +191,8 @@ class Custom extends BasicWeChat /** * 取消客服管理员 - * @param string $kf_openid 客服openid - * @param string $business_id 客服子商户的business_id,对于普通小程序客服不需要填business_id + * @param string $kf_openid 客服 openid + * @param string $business_id 子商户 business_id,可为空 * @return array * @throws \WeChat\Exceptions\InvalidResponseException * @throws \WeChat\Exceptions\LocalCacheException diff --git a/WeMini/Delivery.php b/WeMini/Delivery.php index d2fa925..ad97902 100644 --- a/WeMini/Delivery.php +++ b/WeMini/Delivery.php @@ -3,7 +3,7 @@ // +---------------------------------------------------------------------- // | WeChatDeveloper // +---------------------------------------------------------------------- -// | 版权所有 2014~2025 ThinkAdmin [ thinkadmin.top ] +// | 版权所有 2014~2026 ThinkAdmin [ thinkadmin.top ] // +---------------------------------------------------------------------- // | 官方网站: https://thinkadmin.top // +---------------------------------------------------------------------- @@ -20,15 +20,14 @@ use WeChat\Contracts\BasicWeChat; /** * 小程序即时配送 - * Class Delivery * @package WeMini */ class Delivery extends BasicWeChat { /** - * 异常件退回商家商家确认收货接口 - * @param array $data + * 异常件退回确认收货 + * @param array $data 请求参数 * @return array * @throws \WeChat\Exceptions\InvalidResponseException * @throws \WeChat\Exceptions\LocalCacheException @@ -40,8 +39,8 @@ class Delivery extends BasicWeChat } /** - * 下配送单接口 - * @param array $data + * 下配送单 + * @param array $data 订单信息 * @return array * @throws \WeChat\Exceptions\InvalidResponseException * @throws \WeChat\Exceptions\LocalCacheException @@ -53,8 +52,8 @@ class Delivery extends BasicWeChat } /** - * 可以对待接单状态的订单增加小费 - * @param array $data + * 待接单订单加小费 + * @param array $data 订单与小费信息 * @return array * @throws \WeChat\Exceptions\InvalidResponseException * @throws \WeChat\Exceptions\LocalCacheException @@ -66,8 +65,8 @@ class Delivery extends BasicWeChat } /** - * 取消配送单接口 - * @param array $data + * 取消配送单 + * @param array $data 订单信息 * @return array * @throws \WeChat\Exceptions\InvalidResponseException * @throws \WeChat\Exceptions\LocalCacheException @@ -79,8 +78,8 @@ class Delivery extends BasicWeChat } /** - * 获取已支持的配送公司列表接口 - * @param array $data + * 获取配送公司列表 + * @param array $data 请求参数 * @return array * @throws \WeChat\Exceptions\InvalidResponseException * @throws \WeChat\Exceptions\LocalCacheException @@ -93,7 +92,7 @@ class Delivery extends BasicWeChat /** * 拉取已绑定账号 - * @param array $data + * @param array $data 请求参数 * @return array * @throws \WeChat\Exceptions\InvalidResponseException * @throws \WeChat\Exceptions\LocalCacheException @@ -105,8 +104,8 @@ class Delivery extends BasicWeChat } /** - * 拉取配送单信息 - * @param array $data + * 查询配送单 + * @param array $data 订单信息 * @return array * @throws \WeChat\Exceptions\InvalidResponseException * @throws \WeChat\Exceptions\LocalCacheException @@ -118,8 +117,8 @@ class Delivery extends BasicWeChat } /** - * 模拟配送公司更新配送单状态 - * @param array $data + * 模拟更新配送单状态 + * @param array $data 模拟参数 * @return array * @throws \WeChat\Exceptions\InvalidResponseException * @throws \WeChat\Exceptions\LocalCacheException @@ -131,8 +130,8 @@ class Delivery extends BasicWeChat } /** - * 预下配送单接口 - * @param array $data + * 预下单 + * @param array $data 订单信息 * @return array * @throws \WeChat\Exceptions\InvalidResponseException * @throws \WeChat\Exceptions\LocalCacheException @@ -144,8 +143,8 @@ class Delivery extends BasicWeChat } /** - * 预取消配送单接口 - * @param array $data + * 预取消配送单 + * @param array $data 订单信息 * @return array * @throws \WeChat\Exceptions\InvalidResponseException * @throws \WeChat\Exceptions\LocalCacheException @@ -158,7 +157,7 @@ class Delivery extends BasicWeChat /** * 重新下单 - * @param array $data + * @param array $data 订单信息 * @return array * @throws \WeChat\Exceptions\InvalidResponseException * @throws \WeChat\Exceptions\LocalCacheException diff --git a/WeMini/Guide.php b/WeMini/Guide.php index 2e146f5..c0a2241 100644 --- a/WeMini/Guide.php +++ b/WeMini/Guide.php @@ -3,7 +3,7 @@ // +---------------------------------------------------------------------- // | WeChatDeveloper // +---------------------------------------------------------------------- -// | 版权所有 2014~2025 ThinkAdmin [ thinkadmin.top ] +// | 版权所有 2014~2026 ThinkAdmin [ thinkadmin.top ] // +---------------------------------------------------------------------- // | 官方网站: https://thinkadmin.top // +---------------------------------------------------------------------- @@ -20,14 +20,13 @@ use WeChat\Contracts\BasicWeChat; /** * 小程序导购助手 - * Class Guide * @package WeMini */ class Guide extends BasicWeChat { /** - * 服务号添加导购 - * @param array $data + * 添加导购 + * @param array $data 导购账号信息 * @return array * @throws \WeChat\Exceptions\InvalidResponseException * @throws \WeChat\Exceptions\LocalCacheException @@ -39,8 +38,8 @@ class Guide extends BasicWeChat } /** - * 服务号删除导购 - * @param array $data + * 删除导购 + * @param array $data 导购账号 * @return array * @throws \WeChat\Exceptions\InvalidResponseException * @throws \WeChat\Exceptions\LocalCacheException @@ -52,8 +51,8 @@ class Guide extends BasicWeChat } /** - * 服务号获取导购信息 - * @param array $data + * 获取导购信息 + * @param array $data 导购账号 * @return array * @throws \WeChat\Exceptions\InvalidResponseException * @throws \WeChat\Exceptions\LocalCacheException @@ -65,7 +64,7 @@ class Guide extends BasicWeChat } /** - * 获取服务号的敏感词信息与自动回复信息 + * 获取敏感词与自动回复配置 * @return array * @throws \WeChat\Exceptions\InvalidResponseException * @throws \WeChat\Exceptions\LocalCacheException @@ -77,9 +76,9 @@ class Guide extends BasicWeChat } /** - * 服务号拉取导购列表 - * @param integer $page - * @param integer $num + * 拉取导购列表 + * @param int $page 页码 + * @param int $num 数量 * @return array * @throws \WeChat\Exceptions\InvalidResponseException * @throws \WeChat\Exceptions\LocalCacheException @@ -92,7 +91,7 @@ class Guide extends BasicWeChat /** * 获取导购聊天记录 - * @param array $data + * @param array $data 查询条件 * @return array * @throws \WeChat\Exceptions\InvalidResponseException * @throws \WeChat\Exceptions\LocalCacheException @@ -104,8 +103,8 @@ class Guide extends BasicWeChat } /** - * 获取导购快捷回复信息 - * @param array $data + * 获取导购快捷回复 + * @param array $data 导购信息 * @return array * @throws \WeChat\Exceptions\InvalidResponseException * @throws \WeChat\Exceptions\LocalCacheException @@ -118,7 +117,7 @@ class Guide extends BasicWeChat /** * 生成导购二维码 - * @param array $data + * @param array $data 导购信息 * @return array * @throws \WeChat\Exceptions\InvalidResponseException * @throws \WeChat\Exceptions\LocalCacheException @@ -130,7 +129,8 @@ class Guide extends BasicWeChat } /** - * @param array $data + * 推送小程序路径菜单 + * @param array $data 请求参数 * @return array * @throws \WeChat\Exceptions\InvalidResponseException * @throws \WeChat\Exceptions\LocalCacheException @@ -142,8 +142,8 @@ class Guide extends BasicWeChat } /** - * 为服务号设置敏感词与自动回复 - * @param array $data + * 设置敏感词与自动回复 + * @param array $data 配置数据 * @return array * @throws \WeChat\Exceptions\InvalidResponseException * @throws \WeChat\Exceptions\LocalCacheException @@ -155,8 +155,8 @@ class Guide extends BasicWeChat } /** - * 设置导购快捷回复信息 - * @param array $data + * 设置导购快捷回复 + * @param array $data 快捷回复数据 * @return array * @throws \WeChat\Exceptions\InvalidResponseException * @throws \WeChat\Exceptions\LocalCacheException @@ -168,8 +168,8 @@ class Guide extends BasicWeChat } /** - * 更新导购昵称或者头像 - * @param array $data + * 更新导购昵称或头像 + * @param array $data 导购信息 * @return array * @throws \WeChat\Exceptions\InvalidResponseException * @throws \WeChat\Exceptions\LocalCacheException @@ -181,8 +181,8 @@ class Guide extends BasicWeChat } /** - * 添加展示标签信息 - * @param array $data + * 添加展示标签 + * @param array $data 标签数据 * @return array * @throws \WeChat\Exceptions\InvalidResponseException * @throws \WeChat\Exceptions\LocalCacheException @@ -195,7 +195,7 @@ class Guide extends BasicWeChat /** * 为粉丝添加可查询标签 - * @param array $data + * @param array $data 标签数据 * @return array * @throws \WeChat\Exceptions\InvalidResponseException * @throws \WeChat\Exceptions\LocalCacheException @@ -208,7 +208,7 @@ class Guide extends BasicWeChat /** * 添加标签可选值 - * @param array $data + * @param array $data 选项数据 * @return array * @throws \WeChat\Exceptions\InvalidResponseException * @throws \WeChat\Exceptions\LocalCacheException @@ -221,7 +221,7 @@ class Guide extends BasicWeChat /** * 删除粉丝标签 - * @param array $data + * @param array $data 标签数据 * @return array * @throws \WeChat\Exceptions\InvalidResponseException * @throws \WeChat\Exceptions\LocalCacheException @@ -233,8 +233,8 @@ class Guide extends BasicWeChat } /** - * 查询展示标签信息 - * @param array $data + * 查询展示标签 + * @param array $data 查询参数 * @return array * @throws \WeChat\Exceptions\InvalidResponseException * @throws \WeChat\Exceptions\LocalCacheException @@ -247,7 +247,7 @@ class Guide extends BasicWeChat /** * 查询粉丝标签 - * @param array $data + * @param array $data 查询参数 * @return array * @throws \WeChat\Exceptions\InvalidResponseException * @throws \WeChat\Exceptions\LocalCacheException @@ -259,7 +259,7 @@ class Guide extends BasicWeChat } /** - * 查询标签可选值信息 + * 查询标签可选值 * @return array * @throws \WeChat\Exceptions\InvalidResponseException * @throws \WeChat\Exceptions\LocalCacheException @@ -271,8 +271,8 @@ class Guide extends BasicWeChat } /** - * 新建可查询标签类型,支持新建4类可查询标签 - * @param array $data + * 新建可查询标签类型 + * @param array $data 标签数据 * @return array * @throws \WeChat\Exceptions\InvalidResponseException * @throws \WeChat\Exceptions\LocalCacheException @@ -284,8 +284,8 @@ class Guide extends BasicWeChat } /** - * 根据标签值筛选粉丝 - * @param array $data + * 标签筛选粉丝 + * @param array $data 标签查询条件 * @return array * @throws \WeChat\Exceptions\InvalidResponseException * @throws \WeChat\Exceptions\LocalCacheException @@ -298,8 +298,8 @@ class Guide extends BasicWeChat } /** - * 为服务号导购添加粉丝 - * @param array $data + * 导购添加粉丝 + * @param array $data 绑定数据 * @return array * @throws \WeChat\Exceptions\InvalidResponseException * @throws \WeChat\Exceptions\LocalCacheException @@ -312,8 +312,8 @@ class Guide extends BasicWeChat } /** - * 删除导购的粉丝 - * @param array $data + * 删除导购粉丝 + * @param array $data 解绑数据 * @return array * @throws \WeChat\Exceptions\InvalidResponseException * @throws \WeChat\Exceptions\LocalCacheException @@ -326,8 +326,8 @@ class Guide extends BasicWeChat } /** - * 查询某一个粉丝与导购的绑定关系 - * @param array $data + * 查询粉丝绑定关系 + * @param array $data 查询参数 * @return array * @throws \WeChat\Exceptions\InvalidResponseException * @throws \WeChat\Exceptions\LocalCacheException @@ -340,8 +340,8 @@ class Guide extends BasicWeChat } /** - * 通过粉丝信息查询该粉丝与导购的绑定关系 - * @param string $openid + * 通过粉丝查询绑定关系 + * @param string $openid 粉丝 openid * @return array * @throws \WeChat\Exceptions\InvalidResponseException * @throws \WeChat\Exceptions\LocalCacheException @@ -354,8 +354,8 @@ class Guide extends BasicWeChat } /** - * 拉取导购的粉丝列表 - * @param array $data + * 拉取导购粉丝列表 + * @param array $data 查询参数 * @return array * @throws \WeChat\Exceptions\InvalidResponseException * @throws \WeChat\Exceptions\LocalCacheException @@ -368,8 +368,8 @@ class Guide extends BasicWeChat } /** - * 将粉丝从一个导购迁移到另外一个导购下 - * @param array $data + * 粉丝迁移导购 + * @param array $data 迁移数据 * @return array * @throws \WeChat\Exceptions\InvalidResponseException * @throws \WeChat\Exceptions\LocalCacheException @@ -383,7 +383,7 @@ class Guide extends BasicWeChat /** * 更新粉丝昵称 - * @param array $data + * @param array $data 昵称数据 * @return array * @throws \WeChat\Exceptions\InvalidResponseException * @throws \WeChat\Exceptions\LocalCacheException @@ -396,8 +396,8 @@ class Guide extends BasicWeChat } /** - * 删除小程序卡片素材 - * @param array $data + * 删除卡片素材 + * @param array $data 素材信息 * @return array * @throws \WeChat\Exceptions\InvalidResponseException * @throws \WeChat\Exceptions\LocalCacheException @@ -411,7 +411,7 @@ class Guide extends BasicWeChat /** * 删除图片素材 - * @param array $data + * @param array $data 素材信息 * @return array * @throws \WeChat\Exceptions\InvalidResponseException * @throws \WeChat\Exceptions\LocalCacheException @@ -425,7 +425,7 @@ class Guide extends BasicWeChat /** * 删除文字素材 - * @param array $data + * @param array $data 素材信息 * @return array * @throws \WeChat\Exceptions\InvalidResponseException * @throws \WeChat\Exceptions\LocalCacheException @@ -438,8 +438,8 @@ class Guide extends BasicWeChat } /** - * 获取小程序卡片素材信息 - * @param integer $type + * 获取卡片素材 + * @param int $type 类型 * @return array * @throws \WeChat\Exceptions\InvalidResponseException * @throws \WeChat\Exceptions\LocalCacheException @@ -452,10 +452,10 @@ class Guide extends BasicWeChat } /** - * 获取图片素材信息 - * @param integer $type 操作类型 - * @param integer $start 分页查询,起始位置 - * @param integer $num 分页查询,查询个数 + * 获取图片素材 + * @param int $type 类型 + * @param int $start 起始 + * @param int $num 数量 * @return array * @throws \WeChat\Exceptions\InvalidResponseException * @throws \WeChat\Exceptions\LocalCacheException @@ -468,10 +468,10 @@ class Guide extends BasicWeChat } /** - * 获取文字素材信息 - * @param integer $type 操作类型 - * @param integer $start 分页查询,起始位置 - * @param integer $num 分页查询,查询个数 + * 获取文字素材 + * @param int $type 类型 + * @param int $start 起始 + * @param int $num 数量 * @return array * @throws \WeChat\Exceptions\InvalidResponseException * @throws \WeChat\Exceptions\LocalCacheException @@ -484,8 +484,8 @@ class Guide extends BasicWeChat } /** - * 添加小程序卡片素材 - * @param array $data + * 添加卡片素材 + * @param array $data 素材数据 * @return array * @throws \WeChat\Exceptions\InvalidResponseException * @throws \WeChat\Exceptions\LocalCacheException @@ -499,7 +499,7 @@ class Guide extends BasicWeChat /** * 添加图片素材 - * @param array $data + * @param array $data 素材数据 * @return array * @throws \WeChat\Exceptions\InvalidResponseException * @throws \WeChat\Exceptions\LocalCacheException @@ -512,8 +512,8 @@ class Guide extends BasicWeChat } /** - * 为服务号添加文字素材 - * @param array $data + * 添加文字素材 + * @param array $data 素材数据 * @return array * @throws \WeChat\Exceptions\InvalidResponseException * @throws \WeChat\Exceptions\LocalCacheException diff --git a/WeMini/Image.php b/WeMini/Image.php index fcf3703..6101baf 100644 --- a/WeMini/Image.php +++ b/WeMini/Image.php @@ -3,7 +3,7 @@ // +---------------------------------------------------------------------- // | WeChatDeveloper // +---------------------------------------------------------------------- -// | 版权所有 2014~2025 ThinkAdmin [ thinkadmin.top ] +// | 版权所有 2014~2026 ThinkAdmin [ thinkadmin.top ] // +---------------------------------------------------------------------- // | 官方网站: https://thinkadmin.top // +---------------------------------------------------------------------- @@ -20,16 +20,15 @@ use WeChat\Contracts\BasicWeChat; /** * 小程序图像处理 - * Class Image * @package WeMini */ class Image extends BasicWeChat { /** - * 本接口提供基于小程序的图片智能裁剪能力 - * @param string $img_url 要检测的图片 url,传这个则不用传 img 参数。 - * @param string $img form-data 中媒体文件标识,有filename、filelength、content-type等信息,传这个则不用穿 img_url + * 图片智能裁剪 + * @param string $img_url 图片 URL(与 img 二选一) + * @param string $img form-data 媒体文件(与 img_url 二选一) * @return array * @throws \WeChat\Exceptions\InvalidResponseException * @throws \WeChat\Exceptions\LocalCacheException @@ -41,9 +40,9 @@ class Image extends BasicWeChat } /** - * 本接口提供基于小程序的条码/二维码识别的API - * @param string $img_url 要检测的图片 url,传这个则不用传 img 参数。 - * @param string $img form-data 中媒体文件标识,有filename、filelength、content-type等信息,传这个则不用穿 img_url + * 条码/二维码识别 + * @param string $img_url 图片 URL(与 img 二选一) + * @param string $img form-data 媒体文件(与 img_url 二选一) * @return array * @throws \WeChat\Exceptions\InvalidResponseException * @throws \WeChat\Exceptions\LocalCacheException @@ -55,9 +54,9 @@ class Image extends BasicWeChat } /** - * 本接口提供基于小程序的图片高清化能力 - * @param string $img_url 要检测的图片 url,传这个则不用传 img 参数 - * @param string $img form-data 中媒体文件标识,有filename、filelength、content-type等信息,传这个则不用穿 img_url + * 图片高清化 + * @param string $img_url 图片 URL(与 img 二选一) + * @param string $img form-data 媒体文件(与 img_url 二选一) * @return array * @throws \WeChat\Exceptions\InvalidResponseException * @throws \WeChat\Exceptions\LocalCacheException diff --git a/WeMini/Insurance.php b/WeMini/Insurance.php index 8c4d192..18173f6 100644 --- a/WeMini/Insurance.php +++ b/WeMini/Insurance.php @@ -3,7 +3,7 @@ // +---------------------------------------------------------------------- // | WeChatDeveloper // +---------------------------------------------------------------------- -// | 版权所有 2014~2025 ThinkAdmin [ thinkadmin.top ] +// | 版权所有 2014~2026 ThinkAdmin [ thinkadmin.top ] // +---------------------------------------------------------------------- // | 官方网站: https://thinkadmin.top // +---------------------------------------------------------------------- @@ -20,14 +20,13 @@ use WeChat\Contracts\BasicWeChat; /** * 小程序运费险 - * Class Insurance * @package WeMini */ class Insurance extends BasicWeChat { /** - * 开通无忧退货接口 + * 开通无忧退货 * @return array * @throws \WeChat\Exceptions\InvalidResponseException * @throws \WeChat\Exceptions\LocalCacheException @@ -39,7 +38,7 @@ class Insurance extends BasicWeChat } /** - * 查询开通状态接口 + * 查询开通状态 * @return array * @throws \WeChat\Exceptions\InvalidResponseException * @throws \WeChat\Exceptions\LocalCacheException @@ -51,8 +50,8 @@ class Insurance extends BasicWeChat } /** - * 投保接口(发货时投保) - * @param array $data + * 发货投保 + * @param array $data 投保数据 * @return array * @throws \WeChat\Exceptions\InvalidResponseException * @throws \WeChat\Exceptions\LocalCacheException @@ -64,8 +63,8 @@ class Insurance extends BasicWeChat } /** - * 理赔接口 (收到用户退货后再触发) - * @param array $data + * 退货理赔 + * @param array $data 理赔数据 * @return array * @throws \WeChat\Exceptions\InvalidResponseException * @throws \WeChat\Exceptions\LocalCacheException @@ -77,8 +76,8 @@ class Insurance extends BasicWeChat } /** - * 申请充值订单号接口 (支持自定义金额) - * @param array $data + * 申请充值订单号 + * @param array $data 充值请求 * @return array * @throws \WeChat\Exceptions\InvalidResponseException * @throws \WeChat\Exceptions\LocalCacheException @@ -90,8 +89,8 @@ class Insurance extends BasicWeChat } /** - * 申请支付接口 - * @param array $data + * 申请支付 + * @param array $data 支付数据 * @return array * @throws \WeChat\Exceptions\InvalidResponseException * @throws \WeChat\Exceptions\LocalCacheException @@ -103,8 +102,8 @@ class Insurance extends BasicWeChat } /** - * 拉取充值订单信息接口 - * @param array $data + * 拉取充值订单 + * @param array $data 查询参数 * @return array * @throws \WeChat\Exceptions\InvalidResponseException * @throws \WeChat\Exceptions\LocalCacheException @@ -117,8 +116,8 @@ class Insurance extends BasicWeChat /** - * 退款接口 - * @param array $data + * 保险退款 + * @param array $data 退款参数 * @return array * @throws \WeChat\Exceptions\InvalidResponseException * @throws \WeChat\Exceptions\LocalCacheException @@ -130,8 +129,8 @@ class Insurance extends BasicWeChat } /** - * 拉取摘要接口 (查询当前保费、投保单量、理赔单量、账号余额等信息) - * @param array $data + * 获取保费摘要 + * @param array $data 查询参数 * @return array * @throws \WeChat\Exceptions\InvalidResponseException * @throws \WeChat\Exceptions\LocalCacheException @@ -143,8 +142,8 @@ class Insurance extends BasicWeChat } /** - * 拉取保单信息接口 - * @param array $data + * 拉取保单信息 + * @param array $data 查询参数 * @return array * @throws \WeChat\Exceptions\InvalidResponseException * @throws \WeChat\Exceptions\LocalCacheException @@ -156,8 +155,8 @@ class Insurance extends BasicWeChat } /** - * 设置告警余额接口 - * @param array $data + * 设置告警余额 + * @param array $data 配置参数 * @return array * @throws \WeChat\Exceptions\InvalidResponseException * @throws \WeChat\Exceptions\LocalCacheException @@ -170,7 +169,7 @@ class Insurance extends BasicWeChat /** * 创建退货 ID - * @param array $data + * @param array $data 退货参数 * @return array * @throws \WeChat\Exceptions\InvalidResponseException * @throws \WeChat\Exceptions\LocalCacheException @@ -183,7 +182,7 @@ class Insurance extends BasicWeChat /** * 查询退货 ID 状态 - * @param array $data + * @param array $data 查询参数 * @return array * @throws \WeChat\Exceptions\InvalidResponseException * @throws \WeChat\Exceptions\LocalCacheException @@ -195,8 +194,8 @@ class Insurance extends BasicWeChat } /** - * 查解绑退货 ID - * @param array $data + * 解绑退货 ID + * @param array $data 解绑参数 * @return array * @throws \WeChat\Exceptions\InvalidResponseException * @throws \WeChat\Exceptions\LocalCacheException diff --git a/WeMini/Live.php b/WeMini/Live.php index fb905dd..bf7095c 100644 --- a/WeMini/Live.php +++ b/WeMini/Live.php @@ -3,7 +3,7 @@ // +---------------------------------------------------------------------- // | WeChatDeveloper // +---------------------------------------------------------------------- -// | 版权所有 2014~2025 ThinkAdmin [ thinkadmin.top ] +// | 版权所有 2014~2026 ThinkAdmin [ thinkadmin.top ] // +---------------------------------------------------------------------- // | 官方网站: https://thinkadmin.top // +---------------------------------------------------------------------- @@ -19,15 +19,14 @@ namespace WeMini; use WeChat\Contracts\BasicWeChat; /** - * 小程序直播接口 - * Class Live + * 小程序直播 * @package WeMini */ class Live extends BasicWeChat { /** * 创建直播间 - * @param array $data + * @param array $data 房间信息 * @return array * @throws \WeChat\Exceptions\InvalidResponseException * @throws \WeChat\Exceptions\LocalCacheException @@ -40,8 +39,8 @@ class Live extends BasicWeChat /** * 获取直播房间列表 - * @param integer $start 起始拉取房间 - * @param integer $limit 每次拉取的个数上限 + * @param int $start 起始 + * @param int $limit 数量 * @return array * @throws \WeChat\Exceptions\InvalidResponseException * @throws \WeChat\Exceptions\LocalCacheException @@ -53,8 +52,8 @@ class Live extends BasicWeChat } /** - * 获取回放源视频 - * @param array $data + * 获取直播/回放信息 + * @param array $data 查询参数 * @return array * @throws \WeChat\Exceptions\InvalidResponseException * @throws \WeChat\Exceptions\LocalCacheException @@ -67,7 +66,7 @@ class Live extends BasicWeChat /** * 直播间导入商品 - * @param array $data + * @param array $data 商品列表 * @return array * @throws \WeChat\Exceptions\InvalidResponseException * @throws \WeChat\Exceptions\LocalCacheException @@ -80,7 +79,7 @@ class Live extends BasicWeChat /** * 商品添加并提审 - * @param array $data + * @param array $data 商品信息 * @return array * @throws \WeChat\Exceptions\InvalidResponseException * @throws \WeChat\Exceptions\LocalCacheException @@ -92,8 +91,8 @@ class Live extends BasicWeChat } /** - * 商品撤回审核 - * @param array $data + * 撤回商品审核 + * @param array $data 商品信息 * @return array * @throws \WeChat\Exceptions\InvalidResponseException * @throws \WeChat\Exceptions\LocalCacheException @@ -105,8 +104,8 @@ class Live extends BasicWeChat } /** - * 重新提交审核 - * @param array $data + * 重新提交商品审核 + * @param array $data 商品信息 * @return array * @throws \WeChat\Exceptions\InvalidResponseException * @throws \WeChat\Exceptions\LocalCacheException @@ -119,7 +118,7 @@ class Live extends BasicWeChat /** * 删除商品 - * @param array $data + * @param array $data 商品信息 * @return array * @throws \WeChat\Exceptions\InvalidResponseException * @throws \WeChat\Exceptions\LocalCacheException @@ -132,7 +131,7 @@ class Live extends BasicWeChat /** * 更新商品 - * @param array $data + * @param array $data 商品信息 * @return array * @throws \WeChat\Exceptions\InvalidResponseException * @throws \WeChat\Exceptions\LocalCacheException @@ -145,7 +144,7 @@ class Live extends BasicWeChat /** * 获取商品状态 - * @param array $data + * @param array $data 商品ID列表 * @return array * @throws \WeChat\Exceptions\InvalidResponseException * @throws \WeChat\Exceptions\LocalCacheException @@ -158,9 +157,9 @@ class Live extends BasicWeChat /** * 获取商品列表 - * @param integer $offset 分页条数起点 - * @param integer $status 商品状态,0:未审核。1:审核中,2:审核通过,3:审核驳回 - * @param integer $limit 分页大小,默认30,不超过100 + * @param int $offset 起始 + * @param int $status 0 未审 |1 审核中 |2 通过 |3 驳回 + * @param int $limit 数量(<=100) * @return array * @throws \WeChat\Exceptions\InvalidResponseException * @throws \WeChat\Exceptions\LocalCacheException @@ -173,7 +172,7 @@ class Live extends BasicWeChat /** * 删除直播间 - * @param array $data + * @param array $data 房间信息 * @return array * @throws \WeChat\Exceptions\InvalidResponseException * @throws \WeChat\Exceptions\LocalCacheException @@ -186,7 +185,7 @@ class Live extends BasicWeChat /** * 编辑直播间 - * @param array $data + * @param array $data 房间信息 * @return array * @throws \WeChat\Exceptions\InvalidResponseException * @throws \WeChat\Exceptions\LocalCacheException @@ -198,8 +197,8 @@ class Live extends BasicWeChat } /** - * 获取直播间推流地址 - * @param string $roomId + * 获取推流地址 + * @param string $roomId 房间ID * @return array * @throws \WeChat\Exceptions\InvalidResponseException * @throws \WeChat\Exceptions\LocalCacheException @@ -211,9 +210,9 @@ class Live extends BasicWeChat } /** - * 获取直播间分享二维码 - * @param string $roomId - * @param string $params + * 获取直播间分享码 + * @param string $roomId 房间ID + * @param string $params 自定义参数 * @return array * @throws \WeChat\Exceptions\InvalidResponseException * @throws \WeChat\Exceptions\LocalCacheException @@ -225,8 +224,8 @@ class Live extends BasicWeChat } /** - * 添加管理直播间小助手 - * @param array $data + * 添加小助手 + * @param array $data 助手信息 * @return array * @throws \WeChat\Exceptions\InvalidResponseException * @throws \WeChat\Exceptions\LocalCacheException @@ -238,8 +237,8 @@ class Live extends BasicWeChat } /** - * 修改管理直播间小助手 - * @param array $data + * 修改小助手 + * @param array $data 助手信息 * @return array * @throws \WeChat\Exceptions\InvalidResponseException * @throws \WeChat\Exceptions\LocalCacheException @@ -251,8 +250,8 @@ class Live extends BasicWeChat } /** - * 删除管理直播间小助手 - * @param array $data + * 删除小助手 + * @param array $data 助手信息 * @return array * @throws \WeChat\Exceptions\InvalidResponseException * @throws \WeChat\Exceptions\LocalCacheException @@ -264,8 +263,8 @@ class Live extends BasicWeChat } /** - * 查询管理直播间小助手 - * @param string $roomId + * 查询小助手列表 + * @param string $roomId 房间ID * @return array * @throws \WeChat\Exceptions\InvalidResponseException * @throws \WeChat\Exceptions\LocalCacheException @@ -278,7 +277,7 @@ class Live extends BasicWeChat /** * 添加主播副号 - * @param array $data + * @param array $data 副号信息 * @return array * @throws \WeChat\Exceptions\InvalidResponseException * @throws \WeChat\Exceptions\LocalCacheException @@ -291,7 +290,7 @@ class Live extends BasicWeChat /** * 修改主播副号 - * @param array $data + * @param array $data 副号信息 * @return array * @throws \WeChat\Exceptions\InvalidResponseException * @throws \WeChat\Exceptions\LocalCacheException @@ -303,8 +302,8 @@ class Live extends BasicWeChat } /** - * 修删除主播副号 - * @param array $data + * 删除主播副号 + * @param array $data 副号信息 * @return array * @throws \WeChat\Exceptions\InvalidResponseException * @throws \WeChat\Exceptions\LocalCacheException @@ -316,8 +315,8 @@ class Live extends BasicWeChat } /** - * 查询除主播副号 - * @param string $roomId + * 查询主播副号 + * @param string $roomId 房间ID * @return array * @throws \WeChat\Exceptions\InvalidResponseException * @throws \WeChat\Exceptions\LocalCacheException @@ -329,8 +328,8 @@ class Live extends BasicWeChat } /** - * 开启/关闭直播间官方收录 - * @param array $data + * 开关官方收录 + * @param array $data 房间配置 * @return array * @throws \WeChat\Exceptions\InvalidResponseException * @throws \WeChat\Exceptions\LocalCacheException @@ -342,8 +341,8 @@ class Live extends BasicWeChat } /** - * 开启/关闭回放功能 - * @param array $data + * 开关回放 + * @param array $data 房间配置 * @return array * @throws \WeChat\Exceptions\InvalidResponseException * @throws \WeChat\Exceptions\LocalCacheException @@ -355,8 +354,8 @@ class Live extends BasicWeChat } /** - * 开启/关闭客服功能 - * @param array $data + * 开关客服 + * @param array $data 房间配置 * @return array * @throws \WeChat\Exceptions\InvalidResponseException * @throws \WeChat\Exceptions\LocalCacheException @@ -368,8 +367,8 @@ class Live extends BasicWeChat } /** - * 开启/关闭直播间全局禁言 - * @param array $data + * 开关全局禁言 + * @param array $data 房间配置 * @return array * @throws \WeChat\Exceptions\InvalidResponseException * @throws \WeChat\Exceptions\LocalCacheException @@ -382,7 +381,7 @@ class Live extends BasicWeChat /** * 上下架商品 - * @param array $data + * @param array $data 商品参数 * @return array * @throws \WeChat\Exceptions\InvalidResponseException * @throws \WeChat\Exceptions\LocalCacheException @@ -395,7 +394,7 @@ class Live extends BasicWeChat /** * 删除直播间商品 - * @param array $data + * @param array $data 商品参数 * @return array * @throws \WeChat\Exceptions\InvalidResponseException * @throws \WeChat\Exceptions\LocalCacheException @@ -408,7 +407,7 @@ class Live extends BasicWeChat /** * 推送商品 - * @param array $data + * @param array $data 商品参数 * @return array * @throws \WeChat\Exceptions\InvalidResponseException * @throws \WeChat\Exceptions\LocalCacheException @@ -421,7 +420,7 @@ class Live extends BasicWeChat /** * 商品排序 - * @param array $data + * @param array $data 排序参数 * @return array * @throws \WeChat\Exceptions\InvalidResponseException * @throws \WeChat\Exceptions\LocalCacheException @@ -434,7 +433,7 @@ class Live extends BasicWeChat /** * 下载商品讲解视频 - * @param array $data + * @param array $data 商品信息 * @return array * @throws \WeChat\Exceptions\InvalidResponseException * @throws \WeChat\Exceptions\LocalCacheException @@ -447,7 +446,7 @@ class Live extends BasicWeChat /** * 获取长期订阅用户 - * @param array $data + * @param array $data 查询参数 * @return array * @throws \WeChat\Exceptions\InvalidResponseException * @throws \WeChat\Exceptions\LocalCacheException @@ -459,8 +458,8 @@ class Live extends BasicWeChat } /** - * 长期订阅群发接口 - * @param array $data + * 长订阅群发 + * @param array $data 消息参数 * @return array * @throws \WeChat\Exceptions\InvalidResponseException * @throws \WeChat\Exceptions\LocalCacheException @@ -474,7 +473,7 @@ class Live extends BasicWeChat /** * 设置成员角色 - * @param array $data + * @param array $data 角色参数 * @return array * @throws \WeChat\Exceptions\InvalidResponseException * @throws \WeChat\Exceptions\LocalCacheException @@ -488,7 +487,7 @@ class Live extends BasicWeChat /** * 解除成员角色 - * @param array $data + * @param array $data 角色参数 * @return array * @throws \WeChat\Exceptions\InvalidResponseException * @throws \WeChat\Exceptions\LocalCacheException @@ -502,10 +501,10 @@ class Live extends BasicWeChat /** * 查询成员角色 - * @param int $role - * @param int $offset - * @param int $limit - * @param string $keyword + * @param int $role 角色过滤,-1 全部 + * @param int $offset 起始 + * @param int $limit 数量 + * @param string $keyword 关键词 * @return array * @throws \WeChat\Exceptions\InvalidResponseException * @throws \WeChat\Exceptions\LocalCacheException diff --git a/WeMini/Logistics.php b/WeMini/Logistics.php index 5d2b7f5..596bd33 100644 --- a/WeMini/Logistics.php +++ b/WeMini/Logistics.php @@ -3,7 +3,7 @@ // +---------------------------------------------------------------------- // | WeChatDeveloper // +---------------------------------------------------------------------- -// | 版权所有 2014~2025 ThinkAdmin [ thinkadmin.top ] +// | 版权所有 2014~2026 ThinkAdmin [ thinkadmin.top ] // +---------------------------------------------------------------------- // | 官方网站: https://thinkadmin.top // +---------------------------------------------------------------------- @@ -20,14 +20,13 @@ use WeChat\Contracts\BasicWeChat; /** * 小程序物流助手 - * Class Logistics * @package WeMini */ class Logistics extends BasicWeChat { /** * 生成运单 - * @param array $data + * @param array $data 运单参数 * @return array * @throws \WeChat\Exceptions\InvalidResponseException * @throws \WeChat\Exceptions\LocalCacheException @@ -40,7 +39,7 @@ class Logistics extends BasicWeChat /** * 取消运单 - * @param array $data + * @param array $data 取消参数 * @return array * @throws \WeChat\Exceptions\InvalidResponseException * @throws \WeChat\Exceptions\LocalCacheException @@ -52,7 +51,7 @@ class Logistics extends BasicWeChat } /** - * 获取支持的快递公司列表 + * 获取快递公司列表 * @return array * @throws \WeChat\Exceptions\InvalidResponseException * @throws \WeChat\Exceptions\LocalCacheException @@ -65,7 +64,7 @@ class Logistics extends BasicWeChat /** * 获取运单数据 - * @param array $data + * @param array $data 查询参数 * @return array * @throws \WeChat\Exceptions\InvalidResponseException * @throws \WeChat\Exceptions\LocalCacheException @@ -78,7 +77,7 @@ class Logistics extends BasicWeChat /** * 查询运单轨迹 - * @param array $data + * @param array $data 查询参数 * @return array * @throws \WeChat\Exceptions\InvalidResponseException * @throws \WeChat\Exceptions\LocalCacheException @@ -90,7 +89,7 @@ class Logistics extends BasicWeChat } /** - * 获取打印员。若需要使用微信打单 PC 软件,才需要调用 + * 获取打印员列表(需使用微信打单时调用) * @return array * @throws \WeChat\Exceptions\InvalidResponseException * @throws \WeChat\Exceptions\LocalCacheException @@ -102,8 +101,8 @@ class Logistics extends BasicWeChat } /** - * 获取电子面单余额。仅在使用加盟类快递公司时,才可以调用 - * @param array $data + * 获取电子面单余额(加盟类快递) + * @param array $data 查询参数 * @return array * @throws \WeChat\Exceptions\InvalidResponseException * @throws \WeChat\Exceptions\LocalCacheException @@ -115,8 +114,8 @@ class Logistics extends BasicWeChat } /** - * 模拟快递公司更新订单状态, 该接口只能用户测试 - * @param array $data + * 模拟更新订单状态(测试用) + * @param array $data 模拟参数 * @return array * @throws \WeChat\Exceptions\InvalidResponseException * @throws \WeChat\Exceptions\LocalCacheException @@ -128,8 +127,8 @@ class Logistics extends BasicWeChat } /** - * 配置面单打印员,若需要使用微信打单 PC 软件,才需要调用 - * @param array $data + * 配置面单打印员(微信打单) + * @param array $data 配置参数 * @return array * @throws \WeChat\Exceptions\InvalidResponseException * @throws \WeChat\Exceptions\LocalCacheException @@ -142,7 +141,7 @@ class Logistics extends BasicWeChat /** * 获取面单联系人信息 - * @param array $data + * @param array $data 查询参数 * @return array * @throws \WeChat\Exceptions\InvalidResponseException * @throws \WeChat\Exceptions\LocalCacheException @@ -154,8 +153,8 @@ class Logistics extends BasicWeChat } /** - * 预览面单模板。用于调试面单模板使用 - * @param array $data + * 预览面单模板(调试用) + * @param array $data 模板参数 * @return array * @throws \WeChat\Exceptions\InvalidResponseException * @throws \WeChat\Exceptions\LocalCacheException @@ -168,7 +167,7 @@ class Logistics extends BasicWeChat /** * 更新商户审核结果 - * @param array $data + * @param array $data 审核结果 * @return array * @throws \WeChat\Exceptions\InvalidResponseException * @throws \WeChat\Exceptions\LocalCacheException @@ -181,7 +180,7 @@ class Logistics extends BasicWeChat /** * 更新运单轨迹 - * @param array $data + * @param array $data 轨迹参数 * @return array * @throws \WeChat\Exceptions\InvalidResponseException * @throws \WeChat\Exceptions\LocalCacheException @@ -195,7 +194,7 @@ class Logistics extends BasicWeChat /** * 绑定/解绑物流账号 - * @param array $data + * @param array $data 账号参数 * @return array * @throws \WeChat\Exceptions\InvalidResponseException * @throws \WeChat\Exceptions\LocalCacheException @@ -208,8 +207,8 @@ class Logistics extends BasicWeChat /** - * 获取所有绑定的物流账号 - * @param array $data + * 获取已绑定的物流账号列表 + * @param array $data 查询参数 * @return array * @throws \WeChat\Exceptions\InvalidResponseException * @throws \WeChat\Exceptions\LocalCacheException @@ -222,7 +221,7 @@ class Logistics extends BasicWeChat /** * 批量获取运单数据 - * @param array $data + * @param array $data 查询参数 * @return array * @throws \WeChat\Exceptions\InvalidResponseException * @throws \WeChat\Exceptions\LocalCacheException diff --git a/WeMini/Market.php b/WeMini/Market.php index 46a9505..be41f43 100644 --- a/WeMini/Market.php +++ b/WeMini/Market.php @@ -3,7 +3,7 @@ // +---------------------------------------------------------------------- // | WeChatDeveloper // +---------------------------------------------------------------------- -// | 版权所有 2014~2025 ThinkAdmin [ thinkadmin.top ] +// | 版权所有 2014~2026 ThinkAdmin [ thinkadmin.top ] // +---------------------------------------------------------------------- // | 官方网站: https://thinkadmin.top // +---------------------------------------------------------------------- @@ -19,15 +19,14 @@ namespace WeMini; use WeChat\Contracts\BasicWeChat; /** - * 微信小程序服务市场 - * Class Ocr + * 小程序服务市场 * @package WeMini */ class Market extends BasicWeChat { /** - * 调用服务平台上架的API - * @param array $data + * 调用上架服务 + * @param array $data 服务参数 * @return array * @throws \WeChat\Exceptions\InvalidResponseException * @throws \WeChat\Exceptions\LocalCacheException @@ -39,8 +38,8 @@ class Market extends BasicWeChat } /** - * 获取服务市场返回的数据 - * @param array $data + * 拉取服务结果 + * @param array $data 查询参数 * @return array * @throws \WeChat\Exceptions\InvalidResponseException * @throws \WeChat\Exceptions\LocalCacheException diff --git a/WeMini/Media.php b/WeMini/Media.php index 29782dd..ecde99d 100644 --- a/WeMini/Media.php +++ b/WeMini/Media.php @@ -3,7 +3,7 @@ // +---------------------------------------------------------------------- // | WeChatDeveloper // +---------------------------------------------------------------------- -// | 版权所有 2014~2025 ThinkAdmin [ thinkadmin.top ] +// | 版权所有 2014~2026 ThinkAdmin [ thinkadmin.top ] // +---------------------------------------------------------------------- // | 官方网站: https://thinkadmin.top // +---------------------------------------------------------------------- @@ -21,7 +21,6 @@ use WeChat\Contracts\Tools; /** * 小程序素材操作 - * Class Media * @package WeMini */ class Media extends BasicWeChat @@ -29,7 +28,7 @@ class Media extends BasicWeChat /** * 获取客服消息内的临时素材 - * @param array $data + * @param string $media_id 媒体 ID * @return array * @throws \WeChat\Exceptions\InvalidResponseException * @throws \WeChat\Exceptions\LocalCacheException @@ -42,7 +41,7 @@ class Media extends BasicWeChat /** * 新增图片素材 - * @param array $data + * @param string $filename 本地文件 * @return array * @throws \WeChat\Exceptions\InvalidResponseException * @throws \WeChat\Exceptions\LocalCacheException diff --git a/WeMini/Message.php b/WeMini/Message.php index 9626323..5175cf8 100644 --- a/WeMini/Message.php +++ b/WeMini/Message.php @@ -3,7 +3,7 @@ // +---------------------------------------------------------------------- // | WeChatDeveloper // +---------------------------------------------------------------------- -// | 版权所有 2014~2025 ThinkAdmin [ thinkadmin.top ] +// | 版权所有 2014~2026 ThinkAdmin [ thinkadmin.top ] // +---------------------------------------------------------------------- // | 官方网站: https://thinkadmin.top // +---------------------------------------------------------------------- @@ -20,14 +20,13 @@ use WeChat\Contracts\BasicWeChat; /** * 小程序动态消息 - * Class Message * @package WeMini */ class Message extends BasicWeChat { /** - * 动态消息,创建被分享动态消息的 activity_id - * @param array $data + * 创建动态消息 activity_id + * @param array $data 请求参数 * @return array * @throws \WeChat\Exceptions\InvalidResponseException * @throws \WeChat\Exceptions\LocalCacheException @@ -39,8 +38,8 @@ class Message extends BasicWeChat } /** - * 动态消息,修改被分享的动态消息 - * @param array $data + * 修改动态消息 + * @param array $data 消息数据 * @return array * @throws \WeChat\Exceptions\InvalidResponseException * @throws \WeChat\Exceptions\LocalCacheException @@ -52,8 +51,8 @@ class Message extends BasicWeChat } /** - * 下发小程序和公众号统一的服务消息 - * @param array $data + * 统一服务消息下发 + * @param array $data 消息内容 * @return array * @throws \WeChat\Exceptions\InvalidResponseException * @throws \WeChat\Exceptions\LocalCacheException diff --git a/WeMini/Newtmpl.php b/WeMini/Newtmpl.php index 98ba0bf..fccb00f 100644 --- a/WeMini/Newtmpl.php +++ b/WeMini/Newtmpl.php @@ -3,7 +3,7 @@ // +---------------------------------------------------------------------- // | WeChatDeveloper // +---------------------------------------------------------------------- -// | 版权所有 2014~2025 ThinkAdmin [ thinkadmin.top ] +// | 版权所有 2014~2026 ThinkAdmin [ thinkadmin.top ] // +---------------------------------------------------------------------- // | 官方网站: https://thinkadmin.top // +---------------------------------------------------------------------- @@ -19,15 +19,14 @@ namespace WeMini; use WeChat\Contracts\BasicWeChat; /** - * 公众号小程序订阅消息支持 - * Class Mini - * @package WeChat + * 小程序订阅消息 + * @package WeMini */ class Newtmpl extends BasicWeChat { /** - * 获取小程序账号的类目 - * @param array $data 类目信息列表 + * 添加账号类目 + * @param array $data 类目信息 * @return array * @throws \WeChat\Exceptions\InvalidResponseException * @throws \WeChat\Exceptions\LocalCacheException @@ -39,7 +38,7 @@ class Newtmpl extends BasicWeChat } /** - * 获取小程序账号的类目 + * 获取账号类目 * @return array * @throws \WeChat\Exceptions\InvalidResponseException * @throws \WeChat\Exceptions\LocalCacheException @@ -51,7 +50,7 @@ class Newtmpl extends BasicWeChat } /** - * 获取小程序账号的类目 + * 删除账号类目 * @return array * @throws \WeChat\Exceptions\InvalidResponseException * @throws \WeChat\Exceptions\LocalCacheException @@ -63,8 +62,8 @@ class Newtmpl extends BasicWeChat } /** - * 获取帐号所属类目下的公共模板标题 - * @param string $ids 类目 id,多个用逗号隔开 + * 获取类目下公共模板标题 + * @param string $ids 类目ID,逗号分隔 * @return array * @throws \WeChat\Exceptions\InvalidResponseException * @throws \WeChat\Exceptions\LocalCacheException @@ -77,8 +76,8 @@ class Newtmpl extends BasicWeChat } /** - * 获取模板标题下的关键词列表 - * @param string $tid 模板标题 id,可通过接口获取 + * 获取模板标题关键词 + * @param string $tid 模板标题ID * @return array * @throws \WeChat\Exceptions\InvalidResponseException * @throws \WeChat\Exceptions\LocalCacheException @@ -91,10 +90,10 @@ class Newtmpl extends BasicWeChat } /** - * 组合模板并添加至帐号下的个人模板库 - * @param string $tid 模板标题 id,可通过接口获取,也可登录小程序后台查看获取 - * @param array $kidList 开发者自行组合好的模板关键词列表,关键词顺序可以自由搭配(例如 [3,5,4] 或 [4,5,3]),最多支持5个,最少2个关键词组合 - * @param string $sceneDesc 服务场景描述,15个字以内 + * 组合模板并入库 + * @param string $tid 模板标题ID + * @param array $kidList 关键词ID列表 + * @param string $sceneDesc 场景描述 * @return array * @throws \WeChat\Exceptions\InvalidResponseException * @throws \WeChat\Exceptions\LocalCacheException @@ -106,7 +105,7 @@ class Newtmpl extends BasicWeChat } /** - * 获取当前帐号下的个人模板列表 + * 获取个人模板列表 * @return array * @throws \WeChat\Exceptions\InvalidResponseException * @throws \WeChat\Exceptions\LocalCacheException @@ -118,8 +117,8 @@ class Newtmpl extends BasicWeChat } /** - * 删除帐号下的个人模板 - * @param string $priTmplId 要删除的模板id + * 删除个人模板 + * @param string $priTmplId 模板ID * @return array * @throws \WeChat\Exceptions\InvalidResponseException * @throws \WeChat\Exceptions\LocalCacheException @@ -132,7 +131,7 @@ class Newtmpl extends BasicWeChat /** * 发送订阅消息 - * @param array $data 发送的消息对象数组 + * @param array $data 消息数据 * @return array * @throws \WeChat\Exceptions\InvalidResponseException * @throws \WeChat\Exceptions\LocalCacheException diff --git a/WeMini/Ocr.php b/WeMini/Ocr.php index 2e49a46..7dc4f60 100644 --- a/WeMini/Ocr.php +++ b/WeMini/Ocr.php @@ -3,7 +3,7 @@ // +---------------------------------------------------------------------- // | WeChatDeveloper // +---------------------------------------------------------------------- -// | 版权所有 2014~2025 ThinkAdmin [ thinkadmin.top ] +// | 版权所有 2014~2026 ThinkAdmin [ thinkadmin.top ] // +---------------------------------------------------------------------- // | 官方网站: https://thinkadmin.top // +---------------------------------------------------------------------- @@ -20,14 +20,13 @@ use WeChat\Contracts\BasicWeChat; /** * 小程序ORC服务 - * Class Ocr * @package WeMini */ class Ocr extends BasicWeChat { /** - * 本接口提供基于小程序的银行卡 OCR 识别 - * @param array $data + * 银行卡 OCR + * @param array $data 图片参数(img_url 或 img) * @return array * @throws \WeChat\Exceptions\InvalidResponseException * @throws \WeChat\Exceptions\LocalCacheException @@ -39,8 +38,8 @@ class Ocr extends BasicWeChat } /** - * 本接口提供基于小程序的营业执照 OCR 识别 - * @param array $data + * 营业执照 OCR + * @param array $data 图片参数 * @return array * @throws \WeChat\Exceptions\InvalidResponseException * @throws \WeChat\Exceptions\LocalCacheException @@ -52,8 +51,8 @@ class Ocr extends BasicWeChat } /** - * 本接口提供基于小程序的驾驶证 OCR 识别 - * @param array $data + * 驾驶证 OCR + * @param array $data 图片参数 * @return array * @throws \WeChat\Exceptions\InvalidResponseException * @throws \WeChat\Exceptions\LocalCacheException @@ -65,8 +64,8 @@ class Ocr extends BasicWeChat } /** - * 本接口提供基于小程序的身份证 OCR 识别 - * @param array $data + * 身份证 OCR + * @param array $data 图片参数 * @return array * @throws \WeChat\Exceptions\InvalidResponseException * @throws \WeChat\Exceptions\LocalCacheException @@ -78,8 +77,8 @@ class Ocr extends BasicWeChat } /** - * 本接口提供基于小程序的通用印刷体 OCR 识别 - * @param array $data + * 通用印刷体 OCR + * @param array $data 图片参数 * @return array * @throws \WeChat\Exceptions\InvalidResponseException * @throws \WeChat\Exceptions\LocalCacheException @@ -91,8 +90,8 @@ class Ocr extends BasicWeChat } /** - * 本接口提供基于小程序的行驶证 OCR 识别 - * @param array $data + * 行驶证 OCR + * @param array $data 图片参数 * @return array * @throws \WeChat\Exceptions\InvalidResponseException * @throws \WeChat\Exceptions\LocalCacheException diff --git a/WeMini/Operation.php b/WeMini/Operation.php index 79b1785..09773e0 100644 --- a/WeMini/Operation.php +++ b/WeMini/Operation.php @@ -3,7 +3,7 @@ // +---------------------------------------------------------------------- // | WeChatDeveloper // +---------------------------------------------------------------------- -// | 版权所有 2014~2025 ThinkAdmin [ thinkadmin.top ] +// | 版权所有 2014~2026 ThinkAdmin [ thinkadmin.top ] // +---------------------------------------------------------------------- // | 官方网站: https://thinkadmin.top // +---------------------------------------------------------------------- @@ -20,7 +20,6 @@ use WeChat\Contracts\BasicWeChat; /** * 小程序运维中心 - * Class Operation * @package WeMini */ class Operation extends BasicWeChat @@ -28,7 +27,7 @@ class Operation extends BasicWeChat /** * 实时日志查询 - * @param array $data + * @param array $data 查询参数 * @return array * @throws \WeChat\Exceptions\InvalidResponseException * @throws \WeChat\Exceptions\LocalCacheException @@ -40,8 +39,8 @@ class Operation extends BasicWeChat } /** - * 获取 mediaId 图片 - * @param array $data + * 获取反馈媒体文件 + * @param array $data query 参数 * @return array * @throws \WeChat\Exceptions\InvalidResponseException * @throws \WeChat\Exceptions\LocalCacheException @@ -49,14 +48,14 @@ class Operation extends BasicWeChat public function getFeedbackmedia($data) { $query = http_build_query($data); - $url = 'https://api.weixin.qq.com/cgi-bin/media/getfeedbackmedia?'. $query .'&access_token=ACCESS_TOKEN'; + $url = 'https://api.weixin.qq.com/cgi-bin/media/getfeedbackmedia?' . $query . '&access_token=ACCESS_TOKEN'; return $this->callGetApi($url); } /** - * 实时日志查询 - * @param array $data + * 获取用户反馈列表 + * @param array $data query 参数 * @return array * @throws \WeChat\Exceptions\InvalidResponseException * @throws \WeChat\Exceptions\LocalCacheException @@ -64,7 +63,7 @@ class Operation extends BasicWeChat public function getFeedback($data) { $query = http_build_query($data); - $url = 'https://api.weixin.qq.com/wxaapi/userlog/userlog_search?'.$query.'&access_token=ACCESS_TOKEN'; + $url = 'https://api.weixin.qq.com/wxaapi/userlog/userlog_search?' . $query . '&access_token=ACCESS_TOKEN'; return $this->callGetApi($url); } } \ No newline at end of file diff --git a/WeMini/Plugs.php b/WeMini/Plugs.php index 0a0c4e3..ce244bf 100644 --- a/WeMini/Plugs.php +++ b/WeMini/Plugs.php @@ -3,7 +3,7 @@ // +---------------------------------------------------------------------- // | WeChatDeveloper // +---------------------------------------------------------------------- -// | 版权所有 2014~2025 ThinkAdmin [ thinkadmin.top ] +// | 版权所有 2014~2026 ThinkAdmin [ thinkadmin.top ] // +---------------------------------------------------------------------- // | 官方网站: https://thinkadmin.top // +---------------------------------------------------------------------- @@ -19,15 +19,14 @@ namespace WeMini; use WeChat\Contracts\BasicWeChat; /** - * 微信小程序插件管理 - * Class Plugs + * 小程序插件管理 * @package WeMini */ class Plugs extends BasicWeChat { /** - * 1.申请使用插件 - * @param string $plugin_appid 插件appid + * 申请使用插件 + * @param string $plugin_appid 插件 appid * @return array * @throws \WeChat\Exceptions\InvalidResponseException * @throws \WeChat\Exceptions\LocalCacheException @@ -39,7 +38,7 @@ class Plugs extends BasicWeChat } /** - * 2.查询已添加的插件 + * 查询已添加插件 * @return array * @throws \WeChat\Exceptions\InvalidResponseException * @throws \WeChat\Exceptions\LocalCacheException @@ -51,8 +50,8 @@ class Plugs extends BasicWeChat } /** - * 3.删除已添加的插件 - * @param string $plugin_appid 插件appid + * 删除插件 + * @param string $plugin_appid 插件 appid * @return array * @throws \WeChat\Exceptions\InvalidResponseException * @throws \WeChat\Exceptions\LocalCacheException @@ -64,9 +63,8 @@ class Plugs extends BasicWeChat } /** - * 获取当前所有插件使用方 - * 修改插件使用申请的状态 - * @param array $data + * 获取插件使用方或修改申请状态 + * @param array $data 请求参数 * @return array * @throws \WeChat\Exceptions\InvalidResponseException * @throws \WeChat\Exceptions\LocalCacheException @@ -78,9 +76,9 @@ class Plugs extends BasicWeChat } /** - * 4.获取当前所有插件使用方(供插件开发者调用) - * @param integer $page 拉取第page页的数据 - * @param integer $num 表示每页num条记录 + * 获取插件使用方列表(开发者) + * @param int $page 页码 + * @param int $num 每页数量 * @return array * @throws \WeChat\Exceptions\InvalidResponseException * @throws \WeChat\Exceptions\LocalCacheException @@ -93,8 +91,8 @@ class Plugs extends BasicWeChat } /** - * 5.修改插件使用申请的状态(供插件开发者调用) - * @param string $action dev_agree:同意申请;dev_refuse:拒绝申请;dev_delete:删除已拒绝的申请者 + * 修改插件申请状态(开发者) + * @param string $action dev_agree|dev_refuse|dev_delete * @return array * @throws \WeChat\Exceptions\InvalidResponseException * @throws \WeChat\Exceptions\LocalCacheException diff --git a/WeMini/Poi.php b/WeMini/Poi.php index 776a070..bd31b37 100644 --- a/WeMini/Poi.php +++ b/WeMini/Poi.php @@ -3,7 +3,7 @@ // +---------------------------------------------------------------------- // | WeChatDeveloper // +---------------------------------------------------------------------- -// | 版权所有 2014~2025 ThinkAdmin [ thinkadmin.top ] +// | 版权所有 2014~2026 ThinkAdmin [ thinkadmin.top ] // +---------------------------------------------------------------------- // | 官方网站: https://thinkadmin.top // +---------------------------------------------------------------------- @@ -19,18 +19,17 @@ namespace WeMini; use WeChat\Contracts\BasicWeChat; /** - * 微信小程序地址管理 - * Class Poi + * 小程序地址管理 * @package WeMini */ class Poi extends BasicWeChat { /** - * 添加地点 - * @param string $related_name 经营资质主体 - * @param string $related_credential 经营资质证件号 - * @param string $related_address 经营资质地址 - * @param string $related_proof_material 相关证明材料照片临时素材mediaid + * 添加附近地点 + * @param string $related_name 经营主体 + * @param string $related_credential 证件号 + * @param string $related_address 地址 + * @param string $related_proof_material 证明材料 media_id * @return array * @throws \WeChat\Exceptions\InvalidResponseException * @throws \WeChat\Exceptions\LocalCacheException @@ -47,8 +46,8 @@ class Poi extends BasicWeChat /** * 查看地点列表 - * @param integer $page 起始页id(从1开始计数) - * @param integer $page_rows 每页展示个数(最多1000个) + * @param int $page 页码从1开始 + * @param int $page_rows 每页数量(<=1000) * @return array * @throws \WeChat\Exceptions\InvalidResponseException * @throws \WeChat\Exceptions\LocalCacheException @@ -60,8 +59,8 @@ class Poi extends BasicWeChat } /** - * 删除地点 - * @param string $poi_id 附近地点ID + * 删除附近地点 + * @param string $poi_id 地点ID * @return array * @throws \WeChat\Exceptions\InvalidResponseException * @throws \WeChat\Exceptions\LocalCacheException @@ -73,9 +72,9 @@ class Poi extends BasicWeChat } /** - * 展示/取消展示附近小程序 - * @param string $poi_id 附近地点ID - * @param string $status 0:取消展示;1:展示 + * 设置附近小程序展示 + * @param string $poi_id 地点ID + * @param string $status 0 取消 | 1 展示 * @return array * @throws \WeChat\Exceptions\InvalidResponseException * @throws \WeChat\Exceptions\LocalCacheException diff --git a/WeMini/Qrcode.php b/WeMini/Qrcode.php index 659b435..58ca8f3 100644 --- a/WeMini/Qrcode.php +++ b/WeMini/Qrcode.php @@ -3,7 +3,7 @@ // +---------------------------------------------------------------------- // | WeChatDeveloper // +---------------------------------------------------------------------- -// | 版权所有 2014~2025 ThinkAdmin [ thinkadmin.top ] +// | 版权所有 2014~2026 ThinkAdmin [ thinkadmin.top ] // +---------------------------------------------------------------------- // | 官方网站: https://thinkadmin.top // +---------------------------------------------------------------------- @@ -21,7 +21,6 @@ use WeChat\Contracts\Tools; /** * 微信小程序二维码 - * Class Qrcode * @package WeMini */ class Qrcode extends BasicWeChat @@ -56,6 +55,26 @@ class Qrcode extends BasicWeChat return $this->parseResult(Tools::post($url, Tools::arr2json(array_merge($data, $extra))), $outType); } + /** + * 解释接口数据 + * @param bool|string $result + * @param null|string $outType + * @return array|mixed + * @throws \WeChat\Exceptions\InvalidResponseException + */ + private function parseResult($result, $outType) + { + if (is_array($json = json_decode($result, true))) { + if (!$this->isTry && isset($json['errcode']) && in_array($json['errcode'], ['40014', '40001', '41001', '42001'])) { + [$this->delAccessToken(), $this->isTry = true]; + return call_user_func_array([$this, $this->currentMethod['method']], $this->currentMethod['arguments']); + } + return Tools::json2arr($result); + } else { + return is_null($outType) ? $result : $outType($result); + } + } + /** * 获取小程序码(永久有效) * 接口B:适用于需要的码数量极多的业务场景 @@ -97,24 +116,4 @@ class Qrcode extends BasicWeChat $this->registerApi($url, __FUNCTION__, func_get_args()); return $this->parseResult(Tools::post($url, Tools::arr2json(['path' => $path, 'width' => $width])), $outType); } - - /** - * 解释接口数据 - * @param bool|string $result - * @param null|string $outType - * @return array|mixed - * @throws \WeChat\Exceptions\InvalidResponseException - */ - private function parseResult($result, $outType) - { - if (is_array($json = json_decode($result, true))) { - if (!$this->isTry && isset($json['errcode']) && in_array($json['errcode'], ['40014', '40001', '41001', '42001'])) { - [$this->delAccessToken(), $this->isTry = true]; - return call_user_func_array([$this, $this->currentMethod['method']], $this->currentMethod['arguments']); - } - return Tools::json2arr($result); - } else { - return is_null($outType) ? $result : $outType($result); - } - } } \ No newline at end of file diff --git a/WeMini/Scheme.php b/WeMini/Scheme.php index 4b25f0a..9ab78d8 100644 --- a/WeMini/Scheme.php +++ b/WeMini/Scheme.php @@ -3,7 +3,7 @@ // +---------------------------------------------------------------------- // | WeChatDeveloper // +---------------------------------------------------------------------- -// | 版权所有 2014~2025 ThinkAdmin [ thinkadmin.top ] +// | 版权所有 2014~2026 ThinkAdmin [ thinkadmin.top ] // +---------------------------------------------------------------------- // | 官方网站: https://thinkadmin.top // +---------------------------------------------------------------------- @@ -20,7 +20,6 @@ use WeChat\Contracts\BasicWeChat; /** * 小程序 URL-Scheme - * Class Scheme * @package WeMini */ class Scheme extends BasicWeChat @@ -28,7 +27,7 @@ class Scheme extends BasicWeChat /** * 创建 URL-Scheme - * @param array $data + * @param array $data 场景参数 * @return array * @throws \WeChat\Exceptions\InvalidResponseException * @throws \WeChat\Exceptions\LocalCacheException @@ -41,7 +40,7 @@ class Scheme extends BasicWeChat /** * 查询 URL-Scheme - * @param string $scheme + * @param string $scheme Scheme 字符串 * @return array * @throws \WeChat\Exceptions\InvalidResponseException * @throws \WeChat\Exceptions\LocalCacheException @@ -54,7 +53,7 @@ class Scheme extends BasicWeChat /** * 创建 URL-Link - * @param array $data + * @param array $data 场景参数 * @return array * @throws \WeChat\Exceptions\InvalidResponseException * @throws \WeChat\Exceptions\LocalCacheException @@ -67,7 +66,7 @@ class Scheme extends BasicWeChat /** * 查询 URL-Link - * @param string $urllink + * @param string $urllink URL-Link 字符串 * @return array * @throws \WeChat\Exceptions\InvalidResponseException * @throws \WeChat\Exceptions\LocalCacheException diff --git a/WeMini/Search.php b/WeMini/Search.php index 729db46..d46abea 100644 --- a/WeMini/Search.php +++ b/WeMini/Search.php @@ -3,7 +3,7 @@ // +---------------------------------------------------------------------- // | WeChatDeveloper // +---------------------------------------------------------------------- -// | 版权所有 2014~2025 ThinkAdmin [ thinkadmin.top ] +// | 版权所有 2014~2026 ThinkAdmin [ thinkadmin.top ] // +---------------------------------------------------------------------- // | 官方网站: https://thinkadmin.top // +---------------------------------------------------------------------- @@ -20,14 +20,13 @@ use WeChat\Contracts\BasicWeChat; /** * 小程序搜索 - * Class Search * @package WeMini */ class Search extends BasicWeChat { /** - * 提交小程序页面url及参数信息 - * @param array $pages + * 提交页面 URL 及参数 + * @param array $pages 页面列表 * @return array * @throws \WeChat\Exceptions\InvalidResponseException * @throws \WeChat\Exceptions\LocalCacheException diff --git a/WeMini/Security.php b/WeMini/Security.php index 93dede0..1a01fb0 100644 --- a/WeMini/Security.php +++ b/WeMini/Security.php @@ -3,7 +3,7 @@ // +---------------------------------------------------------------------- // | WeChatDeveloper // +---------------------------------------------------------------------- -// | 版权所有 2014~2025 ThinkAdmin [ thinkadmin.top ] +// | 版权所有 2014~2026 ThinkAdmin [ thinkadmin.top ] // +---------------------------------------------------------------------- // | 官方网站: https://thinkadmin.top // +---------------------------------------------------------------------- @@ -20,15 +20,14 @@ use WeChat\Contracts\BasicWeChat; /** * 小程序内容安全 - * Class Security * @package WeMini */ class Security extends BasicWeChat { /** - * 校验一张图片是否含有违法违规内容 - * @param string $media 要检测的图片文件,格式支持PNG、JPEG、JPG、GIF,图片尺寸不超过 750px x 1334px + * 图片内容安全校验 + * @param string $media 图片文件 * @return array * @throws \WeChat\Exceptions\InvalidResponseException * @throws \WeChat\Exceptions\LocalCacheException @@ -40,9 +39,9 @@ class Security extends BasicWeChat } /** - * 异步校验图片/音频是否含有违法违规内容 - * @param string $media_url - * @param string $media_type + * 异步校验媒体(图片/音频) + * @param string $media_url 媒体 URL + * @param string $media_type 1 音频 | 2 图片 * @return array * @throws \WeChat\Exceptions\InvalidResponseException * @throws \WeChat\Exceptions\LocalCacheException @@ -54,8 +53,8 @@ class Security extends BasicWeChat } /** - * 检查一段文本是否含有违法违规内容 - * @param string $content + * 文本内容安全校验 + * @param string $content 文本内容 * @return array * @throws \WeChat\Exceptions\InvalidResponseException * @throws \WeChat\Exceptions\LocalCacheException diff --git a/WeMini/Shipping.php b/WeMini/Shipping.php index b797d66..11522b1 100644 --- a/WeMini/Shipping.php +++ b/WeMini/Shipping.php @@ -5,16 +5,15 @@ namespace WeMini; use WeChat\Contracts\BasicWeChat; /** - * 小程序发货信息管理服务 - * @class Shipping + * 小程序发货信息管理 * @package WeMini */ class Shipping extends BasicWeChat { /** - * 发货信息录入接口 - * @param array $data + * 录入发货信息 + * @param array $data 发货数据 * @return array * @throws \WeChat\Exceptions\InvalidResponseException * @throws \WeChat\Exceptions\LocalCacheException @@ -26,8 +25,8 @@ class Shipping extends BasicWeChat } /** - * 发货信息合单录入接口 - * @param array $data + * 合单发货录入 + * @param array $data 发货数据 * @return array * @throws \WeChat\Exceptions\InvalidResponseException * @throws \WeChat\Exceptions\LocalCacheException @@ -39,8 +38,8 @@ class Shipping extends BasicWeChat } /** - * 查询订单发货状态 - * @param array $data + * 查询发货状态 + * @param array $data 查询参数 * @return array * @throws \WeChat\Exceptions\InvalidResponseException * @throws \WeChat\Exceptions\LocalCacheException @@ -52,8 +51,8 @@ class Shipping extends BasicWeChat } /** - * 查询订单列表 - * @param array $data + * 查询发货订单列表 + * @param array $data 查询参数 * @return array * @throws \WeChat\Exceptions\InvalidResponseException * @throws \WeChat\Exceptions\LocalCacheException @@ -65,8 +64,8 @@ class Shipping extends BasicWeChat } /** - * 确认收货提醒接口 - * @param array $data + * 提醒确认收货 + * @param array $data 提醒参数 * @return array * @throws \WeChat\Exceptions\InvalidResponseException * @throws \WeChat\Exceptions\LocalCacheException @@ -78,8 +77,8 @@ class Shipping extends BasicWeChat } /** - * 消息跳转路径设置接口 - * @param array $data + * 设置消息跳转路径 + * @param array $data 路径参数 * @return array * @throws \WeChat\Exceptions\InvalidResponseException * @throws \WeChat\Exceptions\LocalCacheException @@ -91,8 +90,8 @@ class Shipping extends BasicWeChat } /** - * 查询小程序是否已开通发货信息管理服务 - * @param array $data + * 查询是否开通发货管理 + * @param array $data 查询参数 * @return array * @throws \WeChat\Exceptions\InvalidResponseException * @throws \WeChat\Exceptions\LocalCacheException @@ -104,8 +103,8 @@ class Shipping extends BasicWeChat } /** - * 查询小程序是否已完成交易结算管理确认 - * @param array $data + * 查询交易结算确认状态 + * @param array $data 查询参数 * @return array * @throws \WeChat\Exceptions\InvalidResponseException * @throws \WeChat\Exceptions\LocalCacheException diff --git a/WeMini/Shopping.php b/WeMini/Shopping.php index 244687e..70db178 100644 --- a/WeMini/Shopping.php +++ b/WeMini/Shopping.php @@ -3,7 +3,7 @@ // +---------------------------------------------------------------------- // | WeChatDeveloper // +---------------------------------------------------------------------- -// | 版权所有 2014~2025 ThinkAdmin [ thinkadmin.top ] +// | 版权所有 2014~2026 ThinkAdmin [ thinkadmin.top ] // +---------------------------------------------------------------------- // | 官方网站: https://thinkadmin.top // +---------------------------------------------------------------------- @@ -20,7 +20,6 @@ use WeChat\Contracts\BasicWeChat; /** * 小程序购物订单 - * Class Shopping * @package WeMini */ class Shopping extends BasicWeChat @@ -28,7 +27,7 @@ class Shopping extends BasicWeChat /** * 上传购物详情 - * @param array $data + * @param array $data 订单数据 * @return array * @throws \WeChat\Exceptions\InvalidResponseException * @throws \WeChat\Exceptions\LocalCacheException @@ -41,7 +40,7 @@ class Shopping extends BasicWeChat /** * 上传物流信息 - * @param array $data + * @param array $data 物流数据 * @return array * @throws \WeChat\Exceptions\InvalidResponseException * @throws \WeChat\Exceptions\LocalCacheException @@ -54,7 +53,7 @@ class Shopping extends BasicWeChat /** * 上传合单购物详情 - * @param array $data + * @param array $data 订单数据 * @return array * @throws \WeChat\Exceptions\InvalidResponseException * @throws \WeChat\Exceptions\LocalCacheException @@ -66,8 +65,8 @@ class Shopping extends BasicWeChat } /** - * 上传合单物流信息 - * @param array $data + * 上传合单物流 + * @param array $data 物流数据 * @return array * @throws \WeChat\Exceptions\InvalidResponseException * @throws \WeChat\Exceptions\LocalCacheException @@ -79,8 +78,8 @@ class Shopping extends BasicWeChat } /** - * 验证购物订单上传结果 - * @param array $data + * 校验购物订单上传结果 + * @param array $data 校验参数 * @return array * @throws \WeChat\Exceptions\InvalidResponseException * @throws \WeChat\Exceptions\LocalCacheException diff --git a/WeMini/Soter.php b/WeMini/Soter.php index 7a5f461..4263436 100644 --- a/WeMini/Soter.php +++ b/WeMini/Soter.php @@ -3,7 +3,7 @@ // +---------------------------------------------------------------------- // | WeChatDeveloper // +---------------------------------------------------------------------- -// | 版权所有 2014~2025 ThinkAdmin [ thinkadmin.top ] +// | 版权所有 2014~2026 ThinkAdmin [ thinkadmin.top ] // +---------------------------------------------------------------------- // | 官方网站: https://thinkadmin.top // +---------------------------------------------------------------------- @@ -20,14 +20,13 @@ use WeChat\Contracts\BasicWeChat; /** * 小程序生物认证 - * Class Soter * @package WeMini */ class Soter extends BasicWeChat { /** - * SOTER 生物认证秘钥签名验证 - * @param array $data + * SOTER 签名验证 + * @param array $data 签名数据 * @return array * @throws \WeChat\Exceptions\InvalidResponseException * @throws \WeChat\Exceptions\LocalCacheException diff --git a/WeMini/Template.php b/WeMini/Template.php index 62aaab1..c41c45e 100644 --- a/WeMini/Template.php +++ b/WeMini/Template.php @@ -3,7 +3,7 @@ // +---------------------------------------------------------------------- // | WeChatDeveloper // +---------------------------------------------------------------------- -// | 版权所有 2014~2025 ThinkAdmin [ thinkadmin.top ] +// | 版权所有 2014~2026 ThinkAdmin [ thinkadmin.top ] // +---------------------------------------------------------------------- // | 官方网站: https://thinkadmin.top // +---------------------------------------------------------------------- @@ -19,15 +19,14 @@ namespace WeMini; use WeChat\Contracts\BasicWeChat; /** - * 公众号小程序模板消息支持 - * Class Mini - * @package WeChat + * 小程序模板消息 + * @package WeMini */ class Template extends BasicWeChat { /** - * 获取小程序模板库标题列表 + * 获取模板库标题列表 * @return array * @throws \WeChat\Exceptions\InvalidResponseException * @throws \WeChat\Exceptions\LocalCacheException @@ -39,8 +38,8 @@ class Template extends BasicWeChat } /** - * 获取模板库某个模板标题下关键词库 - * @param string $template_id 模板标题id,可通过接口获取,也可登录小程序后台查看获取 + * 获取模板关键词库 + * @param string $template_id 模板标题ID * @return array * @throws \WeChat\Exceptions\InvalidResponseException * @throws \WeChat\Exceptions\LocalCacheException @@ -52,9 +51,9 @@ class Template extends BasicWeChat } /** - * 组合模板并添加至帐号下的个人模板库 - * @param string $template_id 模板标题id,可通过接口获取,也可登录小程序后台查看获取 - * @param array $keyword_id_list 开发者自行组合好的模板关键词列表,关键词顺序可以自由搭配(例如[3,5,4]或[4,5,3]),最多支持10个关键词组合 + * 组合关键词并添加模板 + * @param string $template_id 模板标题ID + * @param array $keyword_id_list 关键词 ID 列表 * @return array * @throws \WeChat\Exceptions\InvalidResponseException * @throws \WeChat\Exceptions\LocalCacheException @@ -66,7 +65,7 @@ class Template extends BasicWeChat } /** - * 获取帐号下已存在的模板列表 + * 获取帐号模板列表 * @return array * @throws \WeChat\Exceptions\InvalidResponseException * @throws \WeChat\Exceptions\LocalCacheException @@ -78,8 +77,8 @@ class Template extends BasicWeChat } /** - * 删除模板消息 - * @param string $template_id 要删除的模板id + * 删除模板 + * @param string $template_id 模板 ID * @return array * @throws \WeChat\Exceptions\InvalidResponseException * @throws \WeChat\Exceptions\LocalCacheException @@ -92,7 +91,7 @@ class Template extends BasicWeChat /** * 发送模板消息 - * @param array $data 发送的消息对象数组 + * @param array $data 消息体(touser, template_id, form_id, data 等) * @return array * @throws \WeChat\Exceptions\InvalidResponseException * @throws \WeChat\Exceptions\LocalCacheException diff --git a/WeMini/Total.php b/WeMini/Total.php index eca3416..cc715ac 100644 --- a/WeMini/Total.php +++ b/WeMini/Total.php @@ -3,7 +3,7 @@ // +---------------------------------------------------------------------- // | WeChatDeveloper // +---------------------------------------------------------------------- -// | 版权所有 2014~2025 ThinkAdmin [ thinkadmin.top ] +// | 版权所有 2014~2026 ThinkAdmin [ thinkadmin.top ] // +---------------------------------------------------------------------- // | 官方网站: https://thinkadmin.top // +---------------------------------------------------------------------- @@ -19,16 +19,15 @@ namespace WeMini; use WeChat\Contracts\BasicWeChat; /** - * 微信小程序数据接口 - * Class Total + * 小程序数据统计 * @package WeMini */ class Total extends BasicWeChat { /** - * 数据分析接口 + * 概况趋势(日) * @param string $beginDate 开始日期 - * @param string $endDate 结束日期,限定查询1天数据,end_date允许设置的最大值为昨日 + * @param string $endDate 结束日期,需同一天 * @return array * @throws \WeChat\Exceptions\InvalidResponseException * @throws \WeChat\Exceptions\LocalCacheException @@ -40,9 +39,9 @@ class Total extends BasicWeChat } /** - * 访问分析 + * 访问趋势(日) * @param string $beginDate 开始日期 - * @param string $endDate 结束日期,限定查询1天数据,end_date允许设置的最大值为昨日 + * @param string $endDate 结束日期,需同一天 * @return array * @throws \WeChat\Exceptions\InvalidResponseException * @throws \WeChat\Exceptions\LocalCacheException @@ -54,9 +53,9 @@ class Total extends BasicWeChat } /** - * 周趋势 - * @param string $begin_date 开始日期,为周一日期 - * @param string $end_date 结束日期,为周日日期,限定查询一周数据 + * 访问趋势(周) + * @param string $begin_date 周一 + * @param string $end_date 周日 * @return array * @throws \WeChat\Exceptions\InvalidResponseException * @throws \WeChat\Exceptions\LocalCacheException @@ -68,9 +67,9 @@ class Total extends BasicWeChat } /** - * 月趋势 - * @param string $begin_date 开始日期,为自然月第一天 - * @param string $end_date 结束日期,为自然月最后一天,限定查询一个月数据 + * 访问趋势(月) + * @param string $begin_date 月首日 + * @param string $end_date 月末日 * @return array * @throws \WeChat\Exceptions\InvalidResponseException * @throws \WeChat\Exceptions\LocalCacheException @@ -84,7 +83,7 @@ class Total extends BasicWeChat /** * 访问分布 * @param string $begin_date 开始日期 - * @param string $end_date 结束日期,限定查询1天数据,end_date允许设置的最大值为昨日 + * @param string $end_date 结束日期,需同一天 * @return array * @throws \WeChat\Exceptions\InvalidResponseException * @throws \WeChat\Exceptions\LocalCacheException @@ -96,9 +95,9 @@ class Total extends BasicWeChat } /** - * 日留存 + * 留存(日) * @param string $begin_date 开始日期 - * @param string $end_date 结束日期,限定查询1天数据,end_date允许设置的最大值为昨日 + * @param string $end_date 结束日期,需同一天 * @return array * @throws \WeChat\Exceptions\InvalidResponseException * @throws \WeChat\Exceptions\LocalCacheException @@ -110,9 +109,9 @@ class Total extends BasicWeChat } /** - * 周留存 - * @param string $begin_date 开始日期,为周一日期 - * @param string $end_date 结束日期,为周日日期,限定查询一周数据 + * 留存(周) + * @param string $begin_date 周一 + * @param string $end_date 周日 * @return array * @throws \WeChat\Exceptions\InvalidResponseException * @throws \WeChat\Exceptions\LocalCacheException @@ -124,9 +123,9 @@ class Total extends BasicWeChat } /** - * 月留存 - * @param string $begin_date 开始日期,为自然月第一天 - * @param string $end_date 结束日期,为自然月最后一天,限定查询一个月数据 + * 留存(月) + * @param string $begin_date 月首日 + * @param string $end_date 月末日 * @return array * @throws \WeChat\Exceptions\InvalidResponseException * @throws \WeChat\Exceptions\LocalCacheException @@ -138,9 +137,9 @@ class Total extends BasicWeChat } /** - * 访问页面 + * 访问页面数据 * @param string $begin_date 开始日期 - * @param string $end_date 结束日期,限定查询1天数据,end_date允许设置的最大值为昨日 + * @param string $end_date 结束日期,需同一天 * @return array * @throws \WeChat\Exceptions\InvalidResponseException * @throws \WeChat\Exceptions\LocalCacheException @@ -154,7 +153,7 @@ class Total extends BasicWeChat /** * 用户画像 * @param string $begin_date 开始日期 - * @param string $end_date 结束日期,开始日期与结束日期相差的天数限定为0/6/29,分别表示查询最近1/7/30天数据,end_date允许设置的最大值为昨日 + * @param string $end_date 结束日期,间隔为0/6/29 * @return array * @throws \WeChat\Exceptions\InvalidResponseException * @throws \WeChat\Exceptions\LocalCacheException diff --git a/WeMini/crypt/wxBizDataCrypt.php b/WeMini/crypt/wxBizDataCrypt.php index abc80ab..fde8d27 100644 --- a/WeMini/crypt/wxBizDataCrypt.php +++ b/WeMini/crypt/wxBizDataCrypt.php @@ -2,7 +2,6 @@ /** * 对微信小程序用户加密数据的解密示例代码 - * Class WXBizDataCrypt * @copyright Copyright (c) 1998-2014 Tencent Inc. */ class WXBizDataCrypt diff --git a/WePay/Bill.php b/WePay/Bill.php index 6ea3be5..2e4a6c9 100644 --- a/WePay/Bill.php +++ b/WePay/Bill.php @@ -3,7 +3,7 @@ // +---------------------------------------------------------------------- // | WeChatDeveloper // +---------------------------------------------------------------------- -// | 版权所有 2014~2025 ThinkAdmin [ thinkadmin.top ] +// | 版权所有 2014~2026 ThinkAdmin [ thinkadmin.top ] // +---------------------------------------------------------------------- // | 官方网站: https://thinkadmin.top // +---------------------------------------------------------------------- @@ -22,16 +22,15 @@ use WeChat\Exceptions\InvalidResponseException; /** * 微信商户账单及评论 - * Class Bill * @package WePay */ class Bill extends BasicWePay { /** * 下载对账单 - * @param array $options 静音参数 - * @param null|string $outType 输出类型 - * @return bool|string + * @param array $options 账单参数(bill_date, bill_type 等) + * @param null|string $outType 输出处理回调,为 null 则返回原始内容 + * @return bool|string 原始账单文本或回调结果 * @throws \WeChat\Exceptions\InvalidResponseException * @throws \WeChat\Exceptions\LocalCacheException */ @@ -51,9 +50,9 @@ class Bill extends BasicWePay /** - * 拉取订单评价数据 - * @param array $options - * @return array + * 拉取订单评价数据(需证书) + * @param array $options 查询参数(bill_date, offset, limit 等) + * @return array 评价数据 * @throws \WeChat\Exceptions\InvalidResponseException * @throws \WeChat\Exceptions\LocalCacheException */ diff --git a/WePay/Coupon.php b/WePay/Coupon.php index b7e4343..f31101e 100644 --- a/WePay/Coupon.php +++ b/WePay/Coupon.php @@ -3,7 +3,7 @@ // +---------------------------------------------------------------------- // | WeChatDeveloper // +---------------------------------------------------------------------- -// | 版权所有 2014~2025 ThinkAdmin [ thinkadmin.top ] +// | 版权所有 2014~2026 ThinkAdmin [ thinkadmin.top ] // +---------------------------------------------------------------------- // | 官方网站: https://thinkadmin.top // +---------------------------------------------------------------------- @@ -20,15 +20,14 @@ use WeChat\Contracts\BasicWePay; /** * 微信商户代金券 - * Class Coupon * @package WePay */ class Coupon extends BasicWePay { /** - * 发放代金券 - * @param array $options - * @return array + * 发放代金券(需证书) + * @param array $options 代金券参数(coupon_stock_id, openid, partner_trade_no, op_user_id 等) + * @return array 发券结果 * @throws \WeChat\Exceptions\InvalidResponseException * @throws \WeChat\Exceptions\LocalCacheException */ @@ -40,8 +39,8 @@ class Coupon extends BasicWePay /** * 查询代金券批次 - * @param array $options - * @return array + * @param array $options 查询参数(coupon_stock_id 等) + * @return array 批次详情 * @throws \WeChat\Exceptions\InvalidResponseException * @throws \WeChat\Exceptions\LocalCacheException */ @@ -52,9 +51,9 @@ class Coupon extends BasicWePay } /** - * 查询代金券信息 - * @param array $options - * @return array + * 查询单个代金券信息 + * @param array $options 查询参数(coupon_id, openid, stock_id 等) + * @return array 代金券详情 * @throws \WeChat\Exceptions\InvalidResponseException * @throws \WeChat\Exceptions\LocalCacheException */ diff --git a/WePay/Custom.php b/WePay/Custom.php index ea168a1..8466833 100644 --- a/WePay/Custom.php +++ b/WePay/Custom.php @@ -3,7 +3,7 @@ // +---------------------------------------------------------------------- // | WeChatDeveloper // +---------------------------------------------------------------------- -// | 版权所有 2014~2025 ThinkAdmin [ thinkadmin.top ] +// | 版权所有 2014~2026 ThinkAdmin [ thinkadmin.top ] // +---------------------------------------------------------------------- // | 官方网站: https://thinkadmin.top // +---------------------------------------------------------------------- @@ -20,16 +20,15 @@ use WeChat\Contracts\BasicWePay; /** * 微信扩展上报海关 - * Class Custom * @package WePay */ class Custom extends BasicWePay { /** - * 订单附加信息提交接口 - * @param array $options - * @return array + * 海关申报:订单附加信息提交 + * @param array $options 申报参数(transaction_id 或 out_trade_no,customs,mch_customs_no 等) + * @return array 申报结果 * @throws \WeChat\Exceptions\InvalidResponseException * @throws \WeChat\Exceptions\LocalCacheException */ @@ -40,9 +39,9 @@ class Custom extends BasicWePay } /** - * 订单附加信息查询接口 - * @param array $options - * @return array + * 海关申报:订单附加信息查询 + * @param array $options 查询参数(transaction_id 或 out_trade_no,customs,mch_customs_no 等) + * @return array 申报状态 * @throws \WeChat\Exceptions\InvalidResponseException * @throws \WeChat\Exceptions\LocalCacheException */ @@ -54,9 +53,9 @@ class Custom extends BasicWePay /** - * 订单附加信息重推接口 - * @param array $options - * @return array + * 海关申报:重推申报信息 + * @param array $options 重推参数(transaction_id 或 out_trade_no,customs,mch_customs_no 等) + * @return array 重推结果 * @throws \WeChat\Exceptions\InvalidResponseException * @throws \WeChat\Exceptions\LocalCacheException */ diff --git a/WePay/Order.php b/WePay/Order.php index 46d3f88..9d3a17e 100644 --- a/WePay/Order.php +++ b/WePay/Order.php @@ -3,7 +3,7 @@ // +---------------------------------------------------------------------- // | WeChatDeveloper // +---------------------------------------------------------------------- -// | 版权所有 2014~2025 ThinkAdmin [ thinkadmin.top ] +// | 版权所有 2014~2026 ThinkAdmin [ thinkadmin.top ] // +---------------------------------------------------------------------- // | 官方网站: https://thinkadmin.top // +---------------------------------------------------------------------- @@ -21,16 +21,15 @@ use WeChat\Contracts\Tools; /** * 微信商户订单 - * Class Order * @package WePay */ class Order extends BasicWePay { /** - * 统一下单 - * @param array $options - * @return array + * 统一下单接口 + * @param array $options 订单参数(out_trade_no, body, total_fee, notify_url, trade_type等) + * @return array 返回prepay_id等支付参数 * @throws \WeChat\Exceptions\InvalidResponseException * @throws \WeChat\Exceptions\LocalCacheException */ @@ -41,9 +40,9 @@ class Order extends BasicWePay } /** - * 刷卡支付 - * @param array $options - * @return array + * 刷卡支付接口(被扫支付) + * @param array $options 支付参数(auth_code, out_trade_no, body, total_fee等) + * @return array 支付结果 * @throws \WeChat\Exceptions\InvalidResponseException * @throws \WeChat\Exceptions\LocalCacheException */ @@ -54,9 +53,9 @@ class Order extends BasicWePay } /** - * 查询订单 - * @param array $options - * @return array + * 查询订单接口 + * @param array $options 查询参数(transaction_id或out_trade_no二选一) + * @return array 订单详情 * @throws \WeChat\Exceptions\InvalidResponseException * @throws \WeChat\Exceptions\LocalCacheException */ @@ -67,9 +66,9 @@ class Order extends BasicWePay } /** - * 关闭订单 + * 关闭订单接口 * @param string $outTradeNo 商户订单号 - * @return array + * @return array 关闭结果 * @throws \WeChat\Exceptions\InvalidResponseException * @throws \WeChat\Exceptions\LocalCacheException */ @@ -80,9 +79,9 @@ class Order extends BasicWePay } /** - * 创建JsApi及H5支付参数 - * @param string $prepayId 统一下单预支付码 - * @return array + * 生成JSAPI支付参数(用于前端调起支付) + * @param string $prepayId 统一下单返回的prepay_id + * @return array JSAPI支付所需参数(appId, timeStamp, nonceStr, package, signType, paySign) */ public function jsapiParams($prepayId) { @@ -98,9 +97,9 @@ class Order extends BasicWePay } /** - * 获取支付规则二维码 - * @param string $productId 商户定义的商品id或者订单号 - * @return string + * 生成Native支付二维码URL + * @param string $productId 商品ID或订单号 + * @return string 支付二维码URL(weixin://wxpay/bizpayurl?xxx) */ public function qrcParams($productId) { @@ -116,9 +115,9 @@ class Order extends BasicWePay } /** - * 获取微信App支付秘需参数 - * @param string $prepayId 统一下单预支付码 - * @return array + * 生成APP支付参数(用于移动应用调起支付) + * @param string $prepayId 统一下单返回的prepay_id + * @return array APP支付所需参数(appid, partnerid, prepayid, package, timestamp, noncestr, sign) */ public function appParams($prepayId) { @@ -135,9 +134,9 @@ class Order extends BasicWePay } /** - * 刷卡支付 撤销订单 - * @param array $options - * @return array + * 撤销订单接口(刷卡支付专用,需要证书) + * @param array $options 撤销参数(transaction_id或out_trade_no二选一) + * @return array 撤销结果 * @throws \WeChat\Exceptions\InvalidResponseException * @throws \WeChat\Exceptions\LocalCacheException */ @@ -148,9 +147,9 @@ class Order extends BasicWePay } /** - * 刷卡支付 授权码查询openid - * @param string $authCode 扫码支付授权码,设备读取用户微信中的条码或者二维码信息 - * @return array + * 授权码查询openid接口 + * @param string $authCode 授权码(用户微信中的条码或二维码信息) + * @return array 包含openid等信息 * @throws \WeChat\Exceptions\InvalidResponseException * @throws \WeChat\Exceptions\LocalCacheException */ @@ -161,9 +160,9 @@ class Order extends BasicWePay } /** - * 刷卡支付 交易保障 - * @param array $options - * @return array + * 交易保障接口(用于上报交易数据) + * @param array $options 上报参数(interface_url, execute_time, return_code, result_code等) + * @return array 上报结果 * @throws \WeChat\Exceptions\InvalidResponseException * @throws \WeChat\Exceptions\LocalCacheException */ diff --git a/WePay/ProfitSharing.php b/WePay/ProfitSharing.php index 805346f..8039e01 100644 --- a/WePay/ProfitSharing.php +++ b/WePay/ProfitSharing.php @@ -3,7 +3,7 @@ // +---------------------------------------------------------------------- // | WeChatDeveloper // +---------------------------------------------------------------------- -// | 版权所有 2014~2025 ThinkAdmin [ thinkadmin.top ] +// | 版权所有 2014~2026 ThinkAdmin [ thinkadmin.top ] // +---------------------------------------------------------------------- // | 官方网站: https://thinkadmin.top // +---------------------------------------------------------------------- @@ -20,16 +20,15 @@ use WeChat\Contracts\BasicWePay; /** * 微信分账 - * Class ProfitSharing * @package WePay */ class ProfitSharing extends BasicWePay { /** - * 请求单次分账 - * @param array $options - * @return array + * 请求单次分账(需证书) + * @param array $options 分账参数(transaction_id, out_order_no, receivers 等) + * @return array 分账结果 * @throws \WeChat\Exceptions\InvalidResponseException * @throws \WeChat\Exceptions\LocalCacheException */ @@ -40,9 +39,9 @@ class ProfitSharing extends BasicWePay } /** - * 请求多次分账 - * @param array $options - * @return array + * 请求多次分账(需证书) + * @param array $options 分账参数(transaction_id, out_order_no, receivers 等) + * @return array 分账结果 * @throws \WeChat\Exceptions\InvalidResponseException * @throws \WeChat\Exceptions\LocalCacheException */ @@ -54,8 +53,8 @@ class ProfitSharing extends BasicWePay /** * 查询分账结果 - * @param array $options - * @return array + * @param array $options 查询参数(transaction_id 与 out_order_no) + * @return array 分账状态 * @throws \WeChat\Exceptions\InvalidResponseException * @throws \WeChat\Exceptions\LocalCacheException */ @@ -67,7 +66,7 @@ class ProfitSharing extends BasicWePay /** * 添加分账接收方 - * @param array $options + * @param array $options 接收方信息(type, account, name, relation_type 等) * @return array * @throws \WeChat\Exceptions\InvalidResponseException * @throws \WeChat\Exceptions\LocalCacheException @@ -80,7 +79,7 @@ class ProfitSharing extends BasicWePay /** * 删除分账接收方 - * @param array $options + * @param array $options 接收方信息(type, account) * @return array * @throws \WeChat\Exceptions\InvalidResponseException * @throws \WeChat\Exceptions\LocalCacheException @@ -92,9 +91,9 @@ class ProfitSharing extends BasicWePay } /** - * 完结分账 - * @param array $options - * @return array + * 完结分账(需证书) + * @param array $options 完结参数(transaction_id, out_order_no, description 等) + * @return array 完结结果 * @throws \WeChat\Exceptions\InvalidResponseException * @throws \WeChat\Exceptions\LocalCacheException */ @@ -106,8 +105,8 @@ class ProfitSharing extends BasicWePay /** * 查询订单待分账金额 - * @param array $options - * @return array + * @param array $options 查询参数(transaction_id) + * @return array 待分账金额 * @throws \WeChat\Exceptions\InvalidResponseException * @throws \WeChat\Exceptions\LocalCacheException */ @@ -118,9 +117,9 @@ class ProfitSharing extends BasicWePay } /** - * 分账回退 - * @param array $options - * @return array + * 分账回退(需证书) + * @param array $options 回退参数(out_return_no, out_order_no, return_account_type 等) + * @return array 回退结果 * @throws \WeChat\Exceptions\InvalidResponseException * @throws \WeChat\Exceptions\LocalCacheException */ @@ -132,8 +131,8 @@ class ProfitSharing extends BasicWePay /** * 回退结果查询 - * @param array $options - * @return array + * @param array $options 查询参数(out_return_no 与 out_order_no) + * @return array 回退状态 * @throws \WeChat\Exceptions\InvalidResponseException * @throws \WeChat\Exceptions\LocalCacheException */ diff --git a/WePay/Redpack.php b/WePay/Redpack.php index 4026a6b..c7ccfad 100644 --- a/WePay/Redpack.php +++ b/WePay/Redpack.php @@ -3,7 +3,7 @@ // +---------------------------------------------------------------------- // | WeChatDeveloper // +---------------------------------------------------------------------- -// | 版权所有 2014~2025 ThinkAdmin [ thinkadmin.top ] +// | 版权所有 2014~2026 ThinkAdmin [ thinkadmin.top ] // +---------------------------------------------------------------------- // | 官方网站: https://thinkadmin.top // +---------------------------------------------------------------------- @@ -20,16 +20,15 @@ use WeChat\Contracts\BasicWePay; /** * 微信红包支持 - * Class Redpack * @package WePay */ class Redpack extends BasicWePay { /** - * 发放普通红包 - * @param array $options - * @return array + * 发放普通红包(需证书) + * @param array $options 红包参数(mch_billno, send_name, re_openid, total_amount, total_num, wishing 等) + * @return array 红包发送结果 * @throws \WeChat\Exceptions\InvalidResponseException * @throws \WeChat\Exceptions\LocalCacheException */ @@ -42,9 +41,9 @@ class Redpack extends BasicWePay } /** - * 发放裂变红包 - * @param array $options - * @return array + * 发放裂变红包(需证书) + * @param array $options 红包参数(mch_billno, send_name, re_openid, total_amount, total_num 等,total_num>1) + * @return array 红包发送结果 * @throws \WeChat\Exceptions\InvalidResponseException * @throws \WeChat\Exceptions\LocalCacheException */ @@ -58,8 +57,8 @@ class Redpack extends BasicWePay /** * 查询红包记录 - * @param string $mchBillno 商户发放红包的商户订单号 - * @return array + * @param string $mchBillno 商户红包订单号 + * @return array 红包状态信息 * @throws \WeChat\Exceptions\InvalidResponseException * @throws \WeChat\Exceptions\LocalCacheException */ diff --git a/WePay/Refund.php b/WePay/Refund.php index 72b3e12..b5f5ece 100644 --- a/WePay/Refund.php +++ b/WePay/Refund.php @@ -3,7 +3,7 @@ // +---------------------------------------------------------------------- // | WeChatDeveloper // +---------------------------------------------------------------------- -// | 版权所有 2014~2025 ThinkAdmin [ thinkadmin.top ] +// | 版权所有 2014~2026 ThinkAdmin [ thinkadmin.top ] // +---------------------------------------------------------------------- // | 官方网站: https://thinkadmin.top // +---------------------------------------------------------------------- @@ -23,16 +23,15 @@ use WeChat\Exceptions\InvalidResponseException; /** * 微信商户退款 - * Class Refund * @package WePay */ class Refund extends BasicWePay { /** - * 创建退款订单 - * @param array $options - * @return array + * 申请退款接口(需要证书) + * @param array $options 退款参数(transaction_id或out_trade_no, out_refund_no, total_fee, refund_fee等) + * @return array 退款结果 * @throws \WeChat\Exceptions\InvalidResponseException * @throws \WeChat\Exceptions\LocalCacheException */ @@ -43,9 +42,9 @@ class Refund extends BasicWePay } /** - * 查询退款 - * @param array $options - * @return array + * 查询退款接口 + * @param array $options 查询参数(transaction_id, out_trade_no, out_refund_no, refund_id四选一) + * @return array 退款详情 * @throws \WeChat\Exceptions\InvalidResponseException * @throws \WeChat\Exceptions\LocalCacheException */ @@ -56,9 +55,9 @@ class Refund extends BasicWePay } /** - * 获取退款通知 - * @param string|array $xml - * @return array + * 解析退款通知(自动解密req_info) + * @param string|array $xml 退款通知XML数据,为空则从POST获取 + * @return array 解密后的退款通知数据 * @throws \WeChat\Exceptions\InvalidDecryptException * @throws \WeChat\Exceptions\InvalidResponseException */ diff --git a/WePay/Transfers.php b/WePay/Transfers.php index ca306d7..0d9248e 100644 --- a/WePay/Transfers.php +++ b/WePay/Transfers.php @@ -3,7 +3,7 @@ // +---------------------------------------------------------------------- // | WeChatDeveloper // +---------------------------------------------------------------------- -// | 版权所有 2014~2025 ThinkAdmin [ thinkadmin.top ] +// | 版权所有 2014~2026 ThinkAdmin [ thinkadmin.top ] // +---------------------------------------------------------------------- // | 官方网站: https://thinkadmin.top // +---------------------------------------------------------------------- @@ -20,16 +20,15 @@ use WeChat\Contracts\BasicWePay; /** * 微信商户打款到零钱 - * Class Transfers * @package WePay */ class Transfers extends BasicWePay { /** - * 企业付款到零钱 - * @param array $options - * @return array + * 企业付款到零钱(需证书) + * @param array $options 付款参数(partner_trade_no, openid, amount, desc, check_name 等) + * @return array 付款结果 * @throws \WeChat\Exceptions\InvalidResponseException * @throws \WeChat\Exceptions\LocalCacheException */ @@ -44,9 +43,9 @@ class Transfers extends BasicWePay } /** - * 查询企业付款到零钱 - * @param string $partnerTradeNo 商户调用企业付款API时使用的商户订单号 - * @return array + * 查询企业付款到零钱结果 + * @param string $partnerTradeNo 商户付款单号 + * @return array 付款状态 * @throws \WeChat\Exceptions\InvalidResponseException * @throws \WeChat\Exceptions\LocalCacheException */ diff --git a/WePay/TransfersBank.php b/WePay/TransfersBank.php index 7788346..3d4c296 100644 --- a/WePay/TransfersBank.php +++ b/WePay/TransfersBank.php @@ -3,7 +3,7 @@ // +---------------------------------------------------------------------- // | WeChatDeveloper // +---------------------------------------------------------------------- -// | 版权所有 2014~2025 ThinkAdmin [ thinkadmin.top ] +// | 版权所有 2014~2026 ThinkAdmin [ thinkadmin.top ] // +---------------------------------------------------------------------- // | 官方网站: https://thinkadmin.top // +---------------------------------------------------------------------- @@ -24,16 +24,15 @@ use WeChat\Exceptions\InvalidResponseException; /** * 微信商户打款到银行卡 - * Class TransfersBank * @package WePay */ class TransfersBank extends BasicWePay { /** - * 企业付款到银行卡 - * @param array $options - * @return array + * 企业付款到银行卡(需证书,敏感字段 RSA 加密) + * @param array $options 付款参数(partner_trade_no, enc_bank_no, enc_true_name, bank_code, amount, desc 等) + * @return array 付款结果 * @throws \WeChat\Exceptions\InvalidDecryptException * @throws \WeChat\Exceptions\InvalidResponseException * @throws \WeChat\Exceptions\LocalCacheException @@ -67,24 +66,10 @@ class TransfersBank extends BasicWePay } /** - * 商户企业付款到银行卡操作进行结果查询 - * @param string $partnerTradeNo 商户订单号,需保持唯一 - * @return array - * @throws \WeChat\Exceptions\InvalidResponseException - * @throws \WeChat\Exceptions\LocalCacheException - */ - public function query($partnerTradeNo) - { - $this->params->offsetUnset('appid'); - $url = 'https://api.mch.weixin.qq.com/mmpaysptrans/query_bank'; - return $this->callPostApi($url, ['partner_trade_no' => $partnerTradeNo], true, 'MD5', false); - } - - /** - * RSA加密处理 - * @param string $string + * RSA 加密银行卡号/姓名 + * @param string $string 待加密字符串 * @param string $encrypted - * @return string + * @return string base64 编码密文 * @throws \WeChat\Exceptions\InvalidDecryptException * @throws \WeChat\Exceptions\InvalidResponseException * @throws \WeChat\Exceptions\LocalCacheException @@ -103,8 +88,8 @@ class TransfersBank extends BasicWePay } /** - * 获取签名文件内容 - * @return string + * 获取 RSA 公钥内容 + * @return string 公钥内容 * @throws \WeChat\Exceptions\InvalidResponseException * @throws \WeChat\Exceptions\LocalCacheException */ @@ -123,4 +108,18 @@ class TransfersBank extends BasicWePay Tools::setCache($cacheKey, $data['pub_key'], 600); return $data['pub_key']; } + + /** + * 查询企业付款到银行卡结果 + * @param string $partnerTradeNo 商户订单号 + * @return array 付款状态 + * @throws \WeChat\Exceptions\InvalidResponseException + * @throws \WeChat\Exceptions\LocalCacheException + */ + public function query($partnerTradeNo) + { + $this->params->offsetUnset('appid'); + $url = 'https://api.mch.weixin.qq.com/mmpaysptrans/query_bank'; + return $this->callPostApi($url, ['partner_trade_no' => $partnerTradeNo], true, 'MD5', false); + } } \ No newline at end of file diff --git a/WePayV3/Cert.php b/WePayV3/Cert.php index 94b4386..32256e3 100644 --- a/WePayV3/Cert.php +++ b/WePayV3/Cert.php @@ -3,7 +3,7 @@ // +---------------------------------------------------------------------- // | WeChatDeveloper // +---------------------------------------------------------------------- -// | 版权所有 2014~2025 ThinkAdmin [ thinkadmin.top ] +// | 版权所有 2014~2026 ThinkAdmin [ thinkadmin.top ] // +---------------------------------------------------------------------- // | 官方网站: https://thinkadmin.top // +---------------------------------------------------------------------- @@ -22,7 +22,6 @@ use WePayV3\Contracts\DecryptAes; /** * 平台证书管理 - * Class Cert * @package WePayV3 */ class Cert extends BasicWePay @@ -35,7 +34,7 @@ class Cert extends BasicWePay protected $autoCert = false; /** - * 商户平台下载证书 + * 下载并缓存平台证书 * @return void * @throws \WeChat\Exceptions\InvalidResponseException */ diff --git a/WePayV3/Complaints.php b/WePayV3/Complaints.php index 0ec281c..156ec96 100644 --- a/WePayV3/Complaints.php +++ b/WePayV3/Complaints.php @@ -5,8 +5,7 @@ namespace WePayV3; use WePayV3\Contracts\BasicWePay; /** - * 普通商户消费者投诉2.0 - * @class Complaints + * 消费者投诉 2.0 * @package WePayV3 */ class Complaints extends BasicWePay @@ -14,11 +13,11 @@ class Complaints extends BasicWePay /** * 查询投诉列表 - * @param int $offset 分页开始位置 + * @param int $offset 分页起始 * @param int $limit 分页大小 - * @param String $begin_date 开始日期 - * @param String $end_date 结束日期 - * @return array|string + * @param string $begin_date 开始日期(YYYY-MM-DD) + * @param string $end_date 结束日期(YYYY-MM-DD) + * @return array|string 投诉列表 * @throws \WeChat\Exceptions\InvalidResponseException */ public function complaintList($offset, $limit, $begin_date, $end_date) @@ -30,8 +29,8 @@ class Complaints extends BasicWePay /** * 查询投诉详情 - * @param string $complaint_id 被投诉单号 - * @return array|string + * @param string $complaint_id 投诉单号 + * @return array|string 投诉详情 * @throws \WeChat\Exceptions\InvalidResponseException */ public function complaintDetails($complaint_id) @@ -42,8 +41,8 @@ class Complaints extends BasicWePay /** * 查询投诉协商历史 - * @param string $complaint_id 被投诉单号 - * @return array|string + * @param string $complaint_id 投诉单号 + * @return array|string 协商记录 * @throws \WeChat\Exceptions\InvalidResponseException */ public function negotiationHistory($complaint_id) @@ -54,7 +53,7 @@ class Complaints extends BasicWePay /** * 创建投诉通知回调地址 - * @param string $url 回调通知地址 + * @param string $url 回调地址 * @return array|string * @throws \WeChat\Exceptions\InvalidResponseException */ @@ -77,7 +76,7 @@ class Complaints extends BasicWePay /** * 更新投诉通知回调地址 - * @param string $url 回调通知地址 + * @param string $url 回调地址 * @return array|string * @throws \WeChat\Exceptions\InvalidResponseException */ @@ -98,8 +97,8 @@ class Complaints extends BasicWePay /** * 回复投诉 - * @param string $complaint_id 被投诉单号 - * @param array $content 回复内容 + * @param string $complaint_id 投诉单号 + * @param array $content 回复内容(含跳转链接、文本等) * @return array|string * @throws \WeChat\Exceptions\InvalidResponseException */ @@ -111,8 +110,8 @@ class Complaints extends BasicWePay } /** - * 反馈处理完成 - * @param string $complaint_id 被投诉单号 + * 标记投诉处理完成 + * @param string $complaint_id 投诉单号 * @return array|string * @throws \WeChat\Exceptions\InvalidResponseException */ @@ -124,8 +123,8 @@ class Complaints extends BasicWePay } /** - * 图片请求接口 - * @param string $pathinfo + * 下载投诉图片 + * @param string $pathinfo 文件路径(接口返回的下载地址 path) * @return array|string * @throws \WeChat\Exceptions\InvalidResponseException */ @@ -135,8 +134,8 @@ class Complaints extends BasicWePay } /** - * 图片上传接口 - * @param array $imginfo + * 上传投诉相关图片 + * @param array $imginfo 图片上传参数(文件流对应的 media 字段等) * @return array|string * @throws \WeChat\Exceptions\InvalidResponseException */ diff --git a/WePayV3/Contracts/BasicWePay.php b/WePayV3/Contracts/BasicWePay.php index f0908f0..7ad6d7b 100644 --- a/WePayV3/Contracts/BasicWePay.php +++ b/WePayV3/Contracts/BasicWePay.php @@ -3,7 +3,7 @@ // +---------------------------------------------------------------------- // | WeChatDeveloper // +---------------------------------------------------------------------- -// | 版权所有 2014~2025 ThinkAdmin [ thinkadmin.top ] +// | 版权所有 2014~2026 ThinkAdmin [ thinkadmin.top ] // +---------------------------------------------------------------------- // | 官方网站: https://thinkadmin.top // +---------------------------------------------------------------------- @@ -24,23 +24,20 @@ use WePayV3\Cert; /** * 微信支付基础类 - * Class BasicWePay - * @package WePayV3 + * @package WePayV3\Contracts */ abstract class BasicWePay { - /** - * 接口基础地址 - * @var string - */ - protected $base = 'https://api.mch.weixin.qq.com'; - /** * 实例对象静态缓存 * @var array */ protected static $cache = []; - + /** + * 接口基础地址 + * @var string + */ + protected $base = 'https://api.mch.weixin.qq.com'; /** * 自动配置平台证书 * @var bool @@ -150,6 +147,94 @@ abstract class BasicWePay // } } + /** + * 设置证书内容 + * @param string $key 证书ID或序号 + * @param string $cert 证书文本内容 + * @return string + * @throws \WeChat\Exceptions\InvalidResponseException + */ + private function withCertContent($key, $cert) + { + if (substr(trim($cert), 0, 5) == '-----') { + $this->config['cert_package'][$key] = $cert; + } elseif (file_exists($cert)) { + $this->config['cert_package'][$key] = file_get_contents($cert); + } else { + throw new InvalidResponseException("证书设置失败!"); + } + return $cert; + } + + /** + * 获取支付证书 + * @return mixed|string + */ + private function withCertPayment() + { + foreach ($this->config['cert_package'] as $key => $cert) { + if (strpos($key, 'PUB_KEY_ID_') === 0) { + if (empty($this->config['mp_cert_serial']) || empty($this->config['mp_cert_content'])) { + $this->config['mp_cert_serial'] = $key; + $this->config['mp_cert_content'] = $cert; + } + return $cert; + } + } + return ''; + } + + /** + * 自动配置平台证书 + * @return void + * @throws \WeChat\Exceptions\InvalidResponseException + * @throws \WeChat\Exceptions\LocalCacheException + */ + protected function _autoCert() + { + $certs = $this->tmpFile("{$this->config['mch_id']}_certs"); + if (is_array($certs)) foreach ($certs as $k => $v) { + if ($v['expire'] < time()) unset($certs[$k]); + } + if (empty($certs)) { + Cert::instance($this->config)->download(); + $certs = $this->tmpFile("{$this->config['mch_id']}_certs"); + } + if (empty($certs) || !is_array($certs)) { + throw new InvalidResponseException("读取平台证书失败!"); + } + foreach ($certs as $k => $v) if ($v['expire'] > time() + 10) { + $this->config['cert_package'][$k] = $v['content']; + if (empty($this->config['mp_cert_serial'])) { + $this->config['mp_cert_serial'] = $k; + $this->config['mp_cert_content'] = $v['content']; + } + } + if (empty($this->config['cert_package'])) { + throw new InvalidResponseException("自动配置平台证书失败!"); + } + } + + /** + * 写入或读取临时文件 + * @param string $name + * @param null|array|string $content + * @param integer $expire + * @return array|string + * @throws \WeChat\Exceptions\LocalCacheException + */ + protected function tmpFile($name, $content = null, $expire = 7200) + { + if (is_null($content)) { + $text = Tools::getCache($name); + if (empty($text)) return ''; + $json = json_decode(Tools::getCache($name) ?: '', true); + return isset($json[0]) ? $json[0] : ''; + } else { + return Tools::setCache($name, json_encode([$content], JSON_UNESCAPED_UNICODE), $expire); + } + } + /** * 静态创建对象 * @param array $config @@ -164,61 +249,6 @@ abstract class BasicWePay return self::$cache[$key] = new static($config); } - /** - * 模拟发起请求 - * @param string $method 请求访问 - * @param string $pathinfo 请求路由 - * @param string $jsondata 请求数据 - * @param boolean $verify 是否验证 - * @param boolean $isjson 返回JSON - * @return array|string - * @throws \WeChat\Exceptions\InvalidResponseException - */ - public function doRequest($method, $pathinfo, $jsondata = '', $verify = false, $isjson = true) - { - list($time, $nonce) = [time(), uniqid() . rand(1000, 9999)]; - $signstr = join("\n", [$method, $pathinfo, $time, $nonce, $jsondata, '']); - - // 生成数据签名TOKEN - $token = sprintf('mchid="%s",nonce_str="%s",timestamp="%d",serial_no="%s",signature="%s"', - $this->config['mch_id'], $nonce, $time, $this->config['cert_serial'], $this->signBuild($signstr) - ); - $location = (preg_match('|^https?://|', $pathinfo) ? '' : $this->base) . $pathinfo; - list($header, $content) = $this->_doRequestCurl($method, $location, [ - 'data' => $jsondata, 'header' => [ - 'Accept: application/json', - 'Content-Type: application/json', - 'User-Agent: https://thinkadmin.top', - "Authorization: WECHATPAY2-SHA256-RSA2048 {$token}", - "Wechatpay-Serial: {$this->config['mp_cert_serial']}" - ], - ]); - - if ($verify) { - $headers = []; - foreach (explode("\n", $header) as $line) { - if (stripos($line, 'Wechatpay') !== false) { - list($name, $value) = explode(':', $line); - list(, $keys) = explode('wechatpay-', strtolower($name)); - $headers[$keys] = trim($value); - } - } - try { - if (empty($headers)) { - return $isjson ? json_decode($content, true) : $content; - } - $string = join("\n", [$headers['timestamp'], $headers['nonce'], $content, '']); - if (!$this->signVerify($string, $headers['signature'], $headers['serial'])) { - throw new InvalidResponseException('验证响应签名失败'); - } - } catch (\Exception $exception) { - throw new InvalidResponseException($exception->getMessage(), $exception->getCode()); - } - } - - return $isjson ? json_decode($content, true) : $content; - } - /** * 模拟发起上传请求 * @param string $pathinfo 请求路由 @@ -295,6 +325,17 @@ abstract class BasicWePay return $isjson ? json_decode($content, true) : $content; } + /** + * 生成数据签名 + * @param string $data 签名内容 + * @return string + */ + protected function signBuild($data) + { + $pkeyid = openssl_pkey_get_private($this->config['cert_private']); + openssl_sign($data, $signature, $pkeyid, 'sha256WithRSAEncryption'); + return base64_encode($signature); + } /** * 通过CURL模拟网络请求 @@ -327,18 +368,6 @@ abstract class BasicWePay return [substr($content, 0, $headerSize), substr($content, $headerSize)]; } - /** - * 生成数据签名 - * @param string $data 签名内容 - * @return string - */ - protected function signBuild($data) - { - $pkeyid = openssl_pkey_get_private($this->config['cert_private']); - openssl_sign($data, $signature, $pkeyid, 'sha256WithRSAEncryption'); - return base64_encode($signature); - } - /** * 验证内容签名 * @param string $data 签名内容 @@ -392,54 +421,79 @@ abstract class BasicWePay } /** - * 自动配置平台证书 - * @return void + * 通用接口调用(微信支付 V3) + * @param string $url 完整 URL 或相对路径(如 /v3/pay/transactions/jsapi) + * @param array|string $data 请求体,数组自动 JSON,字符串原样发送 + * @param string $method GET|POST|PUT|DELETE|PATCH|HEAD|OPTIONS,默认 POST + * @param bool $verify 是否验证返回签名 + * @return array 解析后的数组 * @throws \WeChat\Exceptions\InvalidResponseException - * @throws \WeChat\Exceptions\LocalCacheException */ - protected function _autoCert() + public function callApi($url, $data = '', $method = 'POST', $verify = false) { - $certs = $this->tmpFile("{$this->config['mch_id']}_certs"); - if (is_array($certs)) foreach ($certs as $k => $v) { - if ($v['expire'] < time()) unset($certs[$k]); - } - if (empty($certs)) { - Cert::instance($this->config)->download(); - $certs = $this->tmpFile("{$this->config['mch_id']}_certs"); - } - if (empty($certs) || !is_array($certs)) { - throw new InvalidResponseException("读取平台证书失败!"); - } - foreach ($certs as $k => $v) if ($v['expire'] > time() + 10) { - $this->config['cert_package'][$k] = $v['content']; - if (empty($this->config['mp_cert_serial'])) { - $this->config['mp_cert_serial'] = $k; - $this->config['mp_cert_content'] = $v['content']; - } - } - if (empty($this->config['cert_package'])) { - throw new InvalidResponseException("自动配置平台证书失败!"); + $method = strtoupper($method); + + // 处理数据 + if (is_array($data)) { + $data = json_encode($data, JSON_UNESCAPED_UNICODE); } + + return $this->doRequest($method, $url, $data, $verify, true); } /** - * 写入或读取临时文件 - * @param string $name - * @param null|array|string $content - * @param integer $expire + * 模拟发起请求 + * @param string $method 请求访问 + * @param string $pathinfo 请求路由 + * @param string $jsondata 请求数据 + * @param boolean $verify 是否验证 + * @param boolean $isjson 返回JSON * @return array|string - * @throws \WeChat\Exceptions\LocalCacheException + * @throws \WeChat\Exceptions\InvalidResponseException */ - protected function tmpFile($name, $content = null, $expire = 7200) + public function doRequest($method, $pathinfo, $jsondata = '', $verify = false, $isjson = true) { - if (is_null($content)) { - $text = Tools::getCache($name); - if (empty($text)) return ''; - $json = json_decode(Tools::getCache($name) ?: '', true); - return isset($json[0]) ? $json[0] : ''; - } else { - return Tools::setCache($name, json_encode([$content], JSON_UNESCAPED_UNICODE), $expire); + list($time, $nonce) = [time(), uniqid() . rand(1000, 9999)]; + $signstr = join("\n", [$method, $pathinfo, $time, $nonce, $jsondata, '']); + + // 生成数据签名TOKEN + $token = sprintf('mchid="%s",nonce_str="%s",timestamp="%d",serial_no="%s",signature="%s"', + $this->config['mch_id'], $nonce, $time, $this->config['cert_serial'], $this->signBuild($signstr) + ); + $location = (preg_match('|^https?://|', $pathinfo) ? '' : $this->base) . $pathinfo; + list($header, $content) = $this->_doRequestCurl($method, $location, [ + 'data' => $jsondata, 'header' => [ + 'Accept: application/json', + 'Content-Type: application/json', + 'User-Agent: https://thinkadmin.top', + "Authorization: WECHATPAY2-SHA256-RSA2048 {$token}", + "Wechatpay-Serial: {$this->config['mp_cert_serial']}" + ], + ]); + + if ($verify) { + $headers = []; + foreach (explode("\n", $header) as $line) { + if (stripos($line, 'Wechatpay') !== false) { + list($name, $value) = explode(':', $line); + list(, $keys) = explode('wechatpay-', strtolower($name)); + $headers[$keys] = trim($value); + } + } + try { + if (empty($headers)) { + return $isjson ? json_decode($content, true) : $content; + } + $string = join("\n", [$headers['timestamp'], $headers['nonce'], $content, '']); + if (!$this->signVerify($string, $headers['signature'], $headers['serial'])) { + throw new InvalidResponseException('验证响应签名失败'); + } + } catch (\Exception $exception) { + throw new InvalidResponseException($exception->getMessage(), $exception->getCode()); + } } + + return $isjson ? json_decode($content, true) : $content; } /** @@ -457,41 +511,4 @@ abstract class BasicWePay throw new InvalidDecryptException('Rsa Encrypt Error.'); } } - - /** - * 设置证书内容 - * @param string $key 证书ID或序号 - * @param string $cert 证书文本内容 - * @return string - * @throws \WeChat\Exceptions\InvalidResponseException - */ - private function withCertContent($key, $cert) - { - if (substr(trim($cert), 0, 5) == '-----') { - $this->config['cert_package'][$key] = $cert; - } elseif (file_exists($cert)) { - $this->config['cert_package'][$key] = file_get_contents($cert); - } else { - throw new InvalidResponseException("证书设置失败!"); - } - return $cert; - } - - /** - * 获取支付证书 - * @return mixed|string - */ - private function withCertPayment() - { - foreach ($this->config['cert_package'] as $key => $cert) { - if (strpos($key, 'PUB_KEY_ID_') === 0) { - if (empty($this->config['mp_cert_serial']) || empty($this->config['mp_cert_content'])) { - $this->config['mp_cert_serial'] = $key; - $this->config['mp_cert_content'] = $cert; - } - return $cert; - } - } - return ''; - } } \ No newline at end of file diff --git a/WePayV3/Contracts/DecryptAes.php b/WePayV3/Contracts/DecryptAes.php index 49ac8f0..e4dfd75 100644 --- a/WePayV3/Contracts/DecryptAes.php +++ b/WePayV3/Contracts/DecryptAes.php @@ -3,7 +3,7 @@ // +---------------------------------------------------------------------- // | WeChatDeveloper // +---------------------------------------------------------------------- -// | 版权所有 2014~2025 ThinkAdmin [ thinkadmin.top ] +// | 版权所有 2014~2026 ThinkAdmin [ thinkadmin.top ] // +---------------------------------------------------------------------- // | 官方网站: https://thinkadmin.top // +---------------------------------------------------------------------- @@ -21,16 +21,14 @@ use WeChat\Exceptions\InvalidDecryptException; /** * Aes 解密工具类 - * Class DecryptAes * @package WePayV3\Contracts */ class DecryptAes { - private $aesKey; - const KEY_LENGTH_BYTE = 32; const AUTH_TAG_LENGTH_BYTE = 16; + private $aesKey; /** * Constructor diff --git a/WePayV3/Coupon.php b/WePayV3/Coupon.php index ce2a7e0..3f83d45 100644 --- a/WePayV3/Coupon.php +++ b/WePayV3/Coupon.php @@ -3,7 +3,7 @@ // +---------------------------------------------------------------------- // | WeChatDeveloper // +---------------------------------------------------------------------- -// | 版权所有 2014~2025 ThinkAdmin [ thinkadmin.top ] +// | 版权所有 2014~2026 ThinkAdmin [ thinkadmin.top ] // +---------------------------------------------------------------------- // | 官方网站: https://thinkadmin.top // +---------------------------------------------------------------------- @@ -20,8 +20,7 @@ use WeChat\Exceptions\InvalidResponseException; use WePayV3\Contracts\BasicWePay; /** - * 微信支付代金券 - * @class Coupon + * 微信支付代金券 (V3) * @package WePayV3 */ class Coupon extends BasicWePay @@ -30,7 +29,7 @@ class Coupon extends BasicWePay /** * 创建代金券批次 - * @param array $data + * @param array $data 批次参数(stock_name, belong_merchant 等) * @return array|string * @throws InvalidResponseException */ @@ -83,7 +82,7 @@ class Coupon extends BasicWePay * 查询批次详情 * @param string $stock_id 批次号 * @param string $stock_creator_mchid 创建批次的商户号 - * @return array|string + * @return array|string 批次详情 * @throws InvalidResponseException */ public function stocksDetail($stock_id, $stock_creator_mchid) @@ -94,7 +93,7 @@ class Coupon extends BasicWePay /** * 代金券批次可用商品 - * @param array $param + * @param array $param 包含 stock_id 等 * @return array|string * @throws InvalidResponseException */ @@ -106,7 +105,7 @@ class Coupon extends BasicWePay /** * 设置消息通知地址 - * @param array $param + * @param array $param 回调参数(notify_url, switch 等) * @return array|string * @throws InvalidResponseException */ @@ -117,8 +116,8 @@ class Coupon extends BasicWePay } /** - * 发放代金券批次 - * @param array $param 请求参数 + * 发放代金券 + * @param array $param 请求参数(openid, stock_id 等) * @return array|string * @throws InvalidResponseException */ @@ -129,9 +128,9 @@ class Coupon extends BasicWePay } /** - * 根据商户号查用户的券 - * @param array $param 请求参数 - * @return array|string + * 查询用户名下券(按商户号) + * @param array $param 请求参数(openid, appid, stock_id 等) + * @return array|string 券列表 * @throws InvalidResponseException */ public function couponsList(array $param) @@ -141,10 +140,10 @@ class Coupon extends BasicWePay } /** - * 查询代金券详情 - * @param string $openid 用户openid - * @param string $coupon_id 代金券id - * @param string $appid 公众账号ID + * 查询单张代金券详情 + * @param string $openid 用户 openid + * @param string $coupon_id 代金券 id + * @param string $appid 公众账号或小程序 appid * @return array|string * @throws InvalidResponseException */ diff --git a/WePayV3/Ecommerce.php b/WePayV3/Ecommerce.php index e426ba3..e500ce1 100644 --- a/WePayV3/Ecommerce.php +++ b/WePayV3/Ecommerce.php @@ -3,7 +3,7 @@ // +---------------------------------------------------------------------- // | WeChatDeveloper // +---------------------------------------------------------------------- -// | 版权所有 2014~2025 ThinkAdmin [ thinkadmin.top ] +// | 版权所有 2014~2026 ThinkAdmin [ thinkadmin.top ] // +---------------------------------------------------------------------- // | 官方网站: https://thinkadmin.top // +---------------------------------------------------------------------- @@ -20,15 +20,14 @@ use WeChat\Contracts\Tools; use WePayV3\Contracts\BasicWePay; /** - * 平台收付通 - * @class Ecommerce + * 收付通(特约/二级商户、合单、分账等) * @package WePayV3 */ class Ecommerce extends BasicWePay { /** - * 提交申请单(商户进件) - * @param array $data 进件参数 + * 提交进件申请 + * @param array $data 进件参数(含证件、账户、联系人,敏感字段自动 RSA) * @return array * @throws \WeChat\Exceptions\InvalidDecryptException * @throws \WeChat\Exceptions\InvalidResponseException @@ -64,7 +63,7 @@ class Ecommerce extends BasicWePay } /** - * 通过业务申请编号查询申请状态(商户进件) + * 按业务申请编号查询进件状态 * @param string $out_request_no 业务申请编号 * @return array * @throws \WeChat\Exceptions\InvalidResponseException @@ -76,7 +75,7 @@ class Ecommerce extends BasicWePay } /** - * 通过申请单ID查询申请状态(商户进件) + * 按申请单 ID 查询进件状态 * @param string $applyment_id 微信支付申请单号 * @return array * @throws \WeChat\Exceptions\InvalidResponseException @@ -88,9 +87,9 @@ class Ecommerce extends BasicWePay } /** - * 修改结算账户(商户进件) - * @param string $sub_mchid 特约商户/二级商户号 - * @param array $data 包体参数 + * 修改结算账户 + * @param string $sub_mchid 特约/二级商户号 + * @param array $data 账户参数(敏感字段需 RSA) * @return array * @throws \WeChat\Exceptions\InvalidResponseException */ @@ -101,8 +100,8 @@ class Ecommerce extends BasicWePay } /** - * 查询结算账户修改申请状态(商户进件) - * @param string $sub_mchid 特约商户/二级商户号 + * 查询结算账户修改状态 + * @param string $sub_mchid 特约/二级商户号 * @param string $application_no 修改结算账户申请单号 * @return array * @throws \WeChat\Exceptions\InvalidResponseException @@ -115,8 +114,8 @@ class Ecommerce extends BasicWePay /** - * 查询结算账户(商户进件) - * @param string $sub_mchid 特约商户/二级商户号 + * 查询结算账户 + * @param string $sub_mchid 特约/二级商户号 * @return array * @throws \WeChat\Exceptions\InvalidResponseException */ @@ -127,8 +126,8 @@ class Ecommerce extends BasicWePay } /** - * 上传文件(商户进件) - * @param string $filename 文件目录 + * 上传进件所需图片/文件 + * @param string $filename 本地文件路径 * @return array * @throws \WeChat\Exceptions\InvalidResponseException */ @@ -138,8 +137,8 @@ class Ecommerce extends BasicWePay } /** - * APP下单(普通支付) - * @param array $data POST请求参数 + * 合作方 APP 下单 + * @param array $data 下单参数(sp_mchid, sub_mchid, description, out_trade_no, notify_url 等) * @return array * @throws \WeChat\Exceptions\InvalidResponseException */ @@ -150,8 +149,8 @@ class Ecommerce extends BasicWePay } /** - * JSAPI下单(普通支付) - * @param array $data POST请求参数 + * 合作方 JSAPI 下单 + * @param array $data 下单参数(含 payer.openid 等) * @return array * @throws \WeChat\Exceptions\InvalidResponseException */ @@ -162,8 +161,8 @@ class Ecommerce extends BasicWePay } /** - * Native下单(普通支付) - * @param array $data POST请求参数 + * 合作方 Native 下单 + * @param array $data 下单参数 * @return array * @throws \WeChat\Exceptions\InvalidResponseException */ @@ -174,8 +173,8 @@ class Ecommerce extends BasicWePay } /** - * H5下单(普通支付) - * @param array $data POST请求参数 + * 合作方 H5 下单 + * @param array $data 下单参数(含 scene_info 等) * @return array * @throws \WeChat\Exceptions\InvalidResponseException */ @@ -186,9 +185,9 @@ class Ecommerce extends BasicWePay } /** - * 微信支付订单号查询订单(普通支付) - * @param string $transaction_id - * @param string $sub_mchid + * 订单查询(按微信交易号) + * @param string $transaction_id 微信订单号 + * @param string $sub_mchid 二级商户号 * @return array * @throws \WeChat\Exceptions\InvalidResponseException */ @@ -200,9 +199,9 @@ class Ecommerce extends BasicWePay } /** - * 微信支付商户订单号查询订单(普通支付) - * @param string $out_trade_no - * @param string $sub_mchid + * 订单查询(按商户订单号) + * @param string $out_trade_no 商户订单号 + * @param string $sub_mchid 二级商户号 * @return array * @throws \WeChat\Exceptions\InvalidResponseException */ @@ -214,9 +213,9 @@ class Ecommerce extends BasicWePay } /** - * 关闭订单(普通支付) + * 关闭订单 * @param string $out_trade_no 商户订单号 - * @param array $data POST请求参数 + * @param array $data 包含 sub_mchid 等 * @return array * @throws \WeChat\Exceptions\InvalidResponseException */ @@ -228,8 +227,8 @@ class Ecommerce extends BasicWePay } /** - * JSAPI支付(合单下单) - * @param array $data POST请求参数 + * 合单 JSAPI 下单 + * @param array $data 合单参数(combine_out_trade_no, sub_orders 等) * @return array * @throws \WeChat\Exceptions\InvalidResponseException */ @@ -240,8 +239,8 @@ class Ecommerce extends BasicWePay } /** - * APP支付(合单下单) - * @param array $data POST请求参数 + * 合单 APP 下单 + * @param array $data 合单参数 * @return array * @throws \WeChat\Exceptions\InvalidResponseException */ @@ -252,8 +251,8 @@ class Ecommerce extends BasicWePay } /** - * H5支付(合单下单) - * @param array $data POST请求参数 + * 合单 H5 下单 + * @param array $data 合单参数 * @return array * @throws \WeChat\Exceptions\InvalidResponseException */ @@ -264,8 +263,8 @@ class Ecommerce extends BasicWePay } /** - * Native支付(合单下单) - * @param array $data POST请求参数 + * 合单 Native 下单 + * @param array $data 合单参数 * @return array * @throws \WeChat\Exceptions\InvalidResponseException */ @@ -276,8 +275,8 @@ class Ecommerce extends BasicWePay } /** - * 合单查询(合单支付) - * @param string $combine_out_trade_no + * 合单查询 + * @param string $combine_out_trade_no 合单商户订单号 * @return array * @throws \WeChat\Exceptions\InvalidResponseException */ @@ -288,9 +287,9 @@ class Ecommerce extends BasicWePay } /** - * 合单关单(合单下单) - * @param $combine_out_trade_no - * @param array $data POST请求参数 + * 合单关单 + * @param string $combine_out_trade_no 合单商户订单号 + * @param array $data 包含 sub_orders 等 * @return array * @throws \WeChat\Exceptions\InvalidResponseException */ @@ -301,8 +300,8 @@ class Ecommerce extends BasicWePay } /** - * 请求分账(分账) - * @param array $data POST请求参数 + * 电商平台发起分账 + * @param array $data 分账参数 * @return array * @throws \WeChat\Exceptions\InvalidResponseException */ @@ -313,8 +312,8 @@ class Ecommerce extends BasicWePay } /** - * 查询分账结果(分账) - * @param array $param + * 查询分账结果 + * @param array $param 查询参数(sub_mchid, transaction_id, out_order_no 等) * @return array * @throws \WeChat\Exceptions\InvalidResponseException */ @@ -325,8 +324,8 @@ class Ecommerce extends BasicWePay } /** - * 请求分账回退(分账) - * @param array $data POST请求参数 + * 请求分账回退 + * @param array $data 回退参数 * @return array * @throws \WeChat\Exceptions\InvalidResponseException */ @@ -337,8 +336,8 @@ class Ecommerce extends BasicWePay } /** - * 查询分账回退结果(分账) - * @param array $param + * 查询分账回退结果 + * @param array $param 查询参数 * @return array * @throws \WeChat\Exceptions\InvalidResponseException */ @@ -349,8 +348,8 @@ class Ecommerce extends BasicWePay } /** - * 完结分账(分账) - * @param array $data POST请求参数 + * 完结分账 + * @param array $data 完结参数 * @return array * @throws \WeChat\Exceptions\InvalidResponseException */ @@ -361,7 +360,7 @@ class Ecommerce extends BasicWePay } /** - * 查询订单剩余待分金额(分账) + * 查询订单待分金额 * @param string $transaction_id 微信订单号 * @return array * @throws \WeChat\Exceptions\InvalidResponseException @@ -373,8 +372,8 @@ class Ecommerce extends BasicWePay } /** - * 添加分账接收方(分账) - * @param array $data POST请求参数 + * 添加分账接收方 + * @param array $data 接收方参数 * @return array * @throws \WeChat\Exceptions\InvalidResponseException */ @@ -385,8 +384,8 @@ class Ecommerce extends BasicWePay } /** - * 添加分账接收方(分账) - * @param array $data POST请求参数 + * 删除分账接收方 + * @param array $data 接收方参数 * @return array * @throws \WeChat\Exceptions\InvalidResponseException */ @@ -397,8 +396,8 @@ class Ecommerce extends BasicWePay } /** - * 请求补差(补差) - * @param array $data POST请求参数 + * 请求补差 + * @param array $data 补差参数 * @return array * @throws \WeChat\Exceptions\InvalidResponseException */ @@ -409,8 +408,8 @@ class Ecommerce extends BasicWePay } /** - * 请求补差回退(补差) - * @param array $data POST请求参数 + * 补差回退 + * @param array $data 回退参数 * @return array * @throws \WeChat\Exceptions\InvalidResponseException */ @@ -421,8 +420,8 @@ class Ecommerce extends BasicWePay } /** - * 取消补差(补差) - * @param array $data POST请求参数 + * 取消补差 + * @param array $data 取消参数 * @return array * @throws \WeChat\Exceptions\InvalidResponseException */ @@ -433,8 +432,8 @@ class Ecommerce extends BasicWePay } /** - * 申请退款(退款) - * @param array $data POST请求参数 + * 申请退款 + * @param array $data 退款参数 * @return array * @throws \WeChat\Exceptions\InvalidResponseException */ @@ -445,9 +444,9 @@ class Ecommerce extends BasicWePay } /** - * 查询单笔退款(按商户退款单号)(退款) - * @param string $refund_id - * @param string $sub_mchid + * 查询单笔退款(按微信退款号) + * @param string $refund_id 微信退款号 + * @param string $sub_mchid 二级商户号 * @return array * @throws \WeChat\Exceptions\InvalidResponseException */ @@ -458,9 +457,9 @@ class Ecommerce extends BasicWePay } /** - * 查询单笔退款(按商户退款单号)(退款) - * @param string $out_refund_no - * @param string $sub_mchid + * 查询单笔退款(按商户退款号) + * @param string $out_refund_no 商户退款单号 + * @param string $sub_mchid 二级商户号 * @return array * @throws \WeChat\Exceptions\InvalidResponseException */ @@ -471,9 +470,9 @@ class Ecommerce extends BasicWePay } /** - * 查询垫付回补结果(退款) - * @param string $refund_id - * @param string $sub_mchid + * 查询垫付回补结果 + * @param string $refund_id 微信退款号 + * @param string $sub_mchid 二级商户号 * @return array * @throws \WeChat\Exceptions\InvalidResponseException */ @@ -485,8 +484,8 @@ class Ecommerce extends BasicWePay /** * 垫付退款回补 - * @param string $refund_id - * @param array $data + * @param string $refund_id 微信退款号 + * @param array $data 回补参数 * @return array * @throws \WeChat\Exceptions\InvalidResponseException */ diff --git a/WePayV3/Order.php b/WePayV3/Order.php index 09b41a5..c4866dc 100644 --- a/WePayV3/Order.php +++ b/WePayV3/Order.php @@ -3,7 +3,7 @@ // +---------------------------------------------------------------------- // | WeChatDeveloper // +---------------------------------------------------------------------- -// | 版权所有 2014~2025 ThinkAdmin [ thinkadmin.top ] +// | 版权所有 2014~2026 ThinkAdmin [ thinkadmin.top ] // +---------------------------------------------------------------------- // | 官方网站: https://thinkadmin.top // +---------------------------------------------------------------------- @@ -24,7 +24,6 @@ use WePayV3\Contracts\DecryptAes; /** * 直连商户 | 订单支付接口 - * Class Order * @package WePayV3 */ class Order extends BasicWePay @@ -35,10 +34,10 @@ class Order extends BasicWePay const WXPAY_NATIVE = 'native'; /** - * 创建支付订单 - * @param string $type 支付类型 - * @param array $data 支付参数 - * @return array + * 创建支付订单(V3) + * @param string $type 支付类型 h5|app|jsapi|native + * @param array $data 支付参数,按各场景必填(appid, mchid, description, out_trade_no, notify_url 等) + * @return array 预支付结果或前端调起参数 * @throws \WeChat\Exceptions\InvalidResponseException * @document https://pay.weixin.qq.com/wiki/doc/apiv3/apis/chapter3_1_1.shtml */ @@ -78,8 +77,8 @@ class Order extends BasicWePay /** * 支付订单查询 - * @param string $tradeNo 订单单号 - * @return array + * @param string $tradeNo 商户订单号 out_trade_no + * @return array 订单详情 * @throws \WeChat\Exceptions\InvalidResponseException * @document https://pay.weixin.qq.com/wiki/doc/apiv3/apis/chapter3_1_2.shtml */ @@ -91,8 +90,8 @@ class Order extends BasicWePay /** * 关闭支付订单 - * @param string $tradeNo 订单单号 - * @return array + * @param string $tradeNo 商户订单号 out_trade_no + * @return array 关闭结果 * @throws \WeChat\Exceptions\InvalidResponseException */ public function close($tradeNo) @@ -103,31 +102,9 @@ class Order extends BasicWePay } /** - * 支付通知解析 - * @param array|null $data - * @return array - * @throws \WeChat\Exceptions\InvalidDecryptException - */ - public function notify($data = []) - { - if (empty($data)) { - $data = json_decode(Tools::getRawInput(), true); - } - if (isset($data['resource'])) { - $aes = new DecryptAes($this->config['mch_v3_key']); - $data['result'] = $aes->decryptToString( - $data['resource']['associated_data'], - $data['resource']['nonce'], - $data['resource']['ciphertext'] - ); - } - return $data; - } - - /** - * 创建退款订单 - * @param array $data 退款参数 - * @return array + * 创建退款订单(V3) + * @param array $data 退款参数(out_trade_no 或 transaction_id,out_refund_no,amount 等) + * @return array 退款结果 * @throws \WeChat\Exceptions\InvalidResponseException * @document https://pay.weixin.qq.com/wiki/doc/apiv3/apis/chapter3_1_9.shtml */ @@ -139,8 +116,8 @@ class Order extends BasicWePay /** * 退款订单查询 - * @param string $refundNo 退款单号 - * @return array + * @param string $refundNo 商户退款单号 out_refund_no + * @return array 退款详情 * @throws \WeChat\Exceptions\InvalidResponseException * @document https://pay.weixin.qq.com/wiki/doc/apiv3/apis/chapter3_1_10.shtml */ @@ -162,10 +139,32 @@ class Order extends BasicWePay return $this->notify($data); } + /** + * 支付/退款通知解析(自动解密 resource) + * @param array|null $data 通知原文,为空则从输入流读取 + * @return array 解析后的通知数据,包含 result 字段(明文) + * @throws \WeChat\Exceptions\InvalidDecryptException + */ + public function notify($data = []) + { + if (empty($data)) { + $data = json_decode(Tools::getRawInput(), true); + } + if (isset($data['resource'])) { + $aes = new DecryptAes($this->config['mch_v3_key']); + $data['result'] = $aes->decryptToString( + $data['resource']['associated_data'], + $data['resource']['nonce'], + $data['resource']['ciphertext'] + ); + } + return $data; + } + /** * 申请交易账单 - * @param array|string $params - * @return array + * @param array|string $params 账单参数(bill_date, bill_type 等)或已拼好的查询串 + * @return array 含下载地址的申请结果 * @throws \WeChat\Exceptions\InvalidResponseException * @document https://pay.weixin.qq.com/wiki/doc/apiv3/apis/chapter3_3_6.shtml */ @@ -177,8 +176,8 @@ class Order extends BasicWePay /** * 申请资金账单 - * @param array|string $params - * @return array + * @param array|string $params 账单参数(bill_date, account_type 等)或已拼好的查询串 + * @return array 含下载地址的申请结果 * @throws \WeChat\Exceptions\InvalidResponseException * @document https://pay.weixin.qq.com/wiki/doc/apiv3/apis/chapter3_3_7.shtml */ @@ -190,8 +189,8 @@ class Order extends BasicWePay /** * 下载账单文件 - * @param string $fileurl - * @return string 二进制 Excel 内容 + * @param string $fileurl 申请账单返回的 download_url + * @return string 二进制内容(gzip/CSV/Excel) * @throws \WeChat\Exceptions\InvalidResponseException * @document https://pay.weixin.qq.com/wiki/doc/apiv3_partner/apis/chapter7_6_1.shtml */ diff --git a/WePayV3/ProfitSharing.php b/WePayV3/ProfitSharing.php index 8cccb6c..3fc63b9 100644 --- a/WePayV3/ProfitSharing.php +++ b/WePayV3/ProfitSharing.php @@ -3,7 +3,7 @@ // +---------------------------------------------------------------------- // | WeChatDeveloper // +---------------------------------------------------------------------- -// | 版权所有 2014~2025 ThinkAdmin [ thinkadmin.top ] +// | 版权所有 2014~2026 ThinkAdmin [ thinkadmin.top ] // +---------------------------------------------------------------------- // | 官方网站: https://thinkadmin.top // +---------------------------------------------------------------------- @@ -19,15 +19,14 @@ namespace WePayV3; use WePayV3\Contracts\BasicWePay; /** - * 普通商户商家分账 - * Class Profitsharing + * 商家分账 (V3) * @package WePayV3 */ class ProfitSharing extends BasicWePay { /** * 请求分账 - * @param array $options + * @param array $options 分账参数(transaction_id, out_order_no, receivers 等) * @return array * @throws \WeChat\Exceptions\InvalidResponseException */ @@ -41,7 +40,7 @@ class ProfitSharing extends BasicWePay * 查询分账结果 * @param string $outOrderNo 商户分账单号 * @param string $transactionId 微信订单号 - * @return array + * @return array 分账状态 * @throws \WeChat\Exceptions\InvalidResponseException */ public function query($outOrderNo, $transactionId) @@ -52,7 +51,7 @@ class ProfitSharing extends BasicWePay /** * 解冻剩余资金 - * @param array $options + * @param array $options 解冻参数(transaction_id, out_order_no, description) * @return array * @throws \WeChat\Exceptions\InvalidResponseException */ @@ -64,7 +63,7 @@ class ProfitSharing extends BasicWePay /** * 查询剩余待分金额 * @param string $transactionId 微信订单号 - * @return array + * @return array 待分金额 * @throws \WeChat\Exceptions\InvalidResponseException */ public function amounts($transactionId) @@ -75,7 +74,7 @@ class ProfitSharing extends BasicWePay /** * 添加分账接收方 - * @param array $options + * @param array $options 接收方信息(type, account, name 等,name 需 RSA) * @return array * @throws \WeChat\Exceptions\InvalidDecryptException * @throws \WeChat\Exceptions\InvalidResponseException @@ -91,7 +90,7 @@ class ProfitSharing extends BasicWePay /** * 删除分账接收方 - * @param array $options + * @param array $options 接收方信息(type, account) * @return array * @throws \WeChat\Exceptions\InvalidResponseException */ @@ -103,8 +102,8 @@ class ProfitSharing extends BasicWePay /** * 请求分账回退 - * @param array $options - * @return array + * @param array $options 回退参数(out_return_no, out_order_no, return_account 等) + * @return array 回退结果 * @throws \WeChat\Exceptions\InvalidResponseException */ public function backspace(array $options) diff --git a/WePayV3/Refund.php b/WePayV3/Refund.php index 8c1a12a..9795039 100644 --- a/WePayV3/Refund.php +++ b/WePayV3/Refund.php @@ -3,7 +3,7 @@ // +---------------------------------------------------------------------- // | WeChatDeveloper // +---------------------------------------------------------------------- -// | 版权所有 2014~2025 ThinkAdmin [ thinkadmin.top ] +// | 版权所有 2014~2026 ThinkAdmin [ thinkadmin.top ] // +---------------------------------------------------------------------- // | 官方网站: https://thinkadmin.top // +---------------------------------------------------------------------- @@ -28,9 +28,9 @@ use WePayV3\Contracts\BasicWePay; class Refund extends BasicWePay { /** - * 创建退款订单 - * @param array $data 退款参数 - * @return array + * 创建退款订单(兼容入口,转调 Order::createRefund) + * @param array $data 退款参数(out_trade_no 或 transaction_id,out_refund_no,amount 等) + * @return array 退款结果 * @throws \WeChat\Exceptions\InvalidResponseException * @throws \WeChat\Exceptions\LocalCacheException */ @@ -41,9 +41,9 @@ class Refund extends BasicWePay } /** - * 退款订单查询 - * @param string $refundNo 退款单号 - * @return array + * 退款订单查询(兼容入口) + * @param string $refundNo 商户退款单号 out_refund_no + * @return array 退款详情 * @throws \WeChat\Exceptions\InvalidResponseException * @throws \WeChat\Exceptions\LocalCacheException */ @@ -55,9 +55,9 @@ class Refund extends BasicWePay } /** - * 获取退款通知 - * @param mixed $xml - * @return array + * 获取退款通知(兼容入口,转调 Order::notify) + * @param mixed $xml 通知原文 + * @return array 解密后的通知数据 * @throws \WeChat\Exceptions\InvalidDecryptException * @throws \WeChat\Exceptions\InvalidResponseException * @throws \WeChat\Exceptions\LocalCacheException diff --git a/WePayV3/Transfers.php b/WePayV3/Transfers.php index c11a530..43cfe9b 100644 --- a/WePayV3/Transfers.php +++ b/WePayV3/Transfers.php @@ -3,7 +3,7 @@ // +---------------------------------------------------------------------- // | WeChatDeveloper // +---------------------------------------------------------------------- -// | 版权所有 2014~2025 ThinkAdmin [ thinkadmin.top ] +// | 版权所有 2014~2026 ThinkAdmin [ thinkadmin.top ] // +---------------------------------------------------------------------- // | 官方网站: https://thinkadmin.top // +---------------------------------------------------------------------- @@ -19,16 +19,15 @@ namespace WePayV3; use WePayV3\Contracts\BasicWePay; /** - * 普通商户商家转账到零钱 - * @class Transfers + * 商家转账到零钱 (V3) * @package WePayV3 */ class Transfers extends BasicWePay { /** - * 新版商家转换到零钱 - * @param $body + * 商家转账到零钱(单笔) + * @param array $body 转账参数(out_bill_no, transfer_amount, openid/user_name 等,敏感字段需 RSA) * @return array|string * @throws \WeChat\Exceptions\InvalidDecryptException * @throws \WeChat\Exceptions\InvalidResponseException @@ -47,8 +46,8 @@ class Transfers extends BasicWePay /** * 查询转账结果 - * @param $out_bill_no - * @return array|string + * @param string $out_bill_no 商户转账单号 + * @return array|string 转账状态 * @throws \WeChat\Exceptions\InvalidResponseException */ public function billsQuery($out_bill_no) @@ -58,7 +57,7 @@ class Transfers extends BasicWePay /** * 发起商家批量转账 - * @param array $body + * @param array $body 批量参数(out_batch_no, transfer_detail_list 等,姓名需 RSA) * @return array * @throws \WeChat\Exceptions\InvalidDecryptException * @throws \WeChat\Exceptions\InvalidResponseException @@ -84,13 +83,13 @@ class Transfers extends BasicWePay } /** - * 通过微信批次单号查询批次单 - * @param string $batchId 微信批次单号(二选一) - * @param string $outBatchNo 商家批次单号(二选一) - * @param boolean $needQueryDetail 查询指定状态 - * @param integer $offset 请求资源的起始位置 - * @param integer $limit 最大明细条数 - * @param string $detailStatus 查询指定状态 + * 查询批量转账批次 + * @param string $batchId 微信批次单号(二选一) + * @param string $outBatchNo 商户批次单号(二选一) + * @param bool $needQueryDetail 是否拉取明细 + * @param int $offset 明细起始位置 + * @param int $limit 最大明细条数 + * @param string $detailStatus 明细状态 ALL|SUCCESS|FAIL * @return array * @throws \WeChat\Exceptions\InvalidResponseException */ @@ -111,9 +110,9 @@ class Transfers extends BasicWePay } /** - * 通过微信明细单号查询明细单 + * 通过微信明细单号查询明细 * @param string $batchId 微信批次单号 - * @param string $detailId 微信支付系统内部区分转账批次单下不同转账明细单的唯一标识 + * @param string $detailId 微信明细单号 * @return array * @throws \WeChat\Exceptions\InvalidResponseException */ @@ -124,9 +123,9 @@ class Transfers extends BasicWePay } /** - * 通过商家明细单号查询明细单 - * @param string $outBatchNo 商户系统内部的商家批次单号,在商户系统内部唯一 - * @param string $outDetailNo 商户系统内部区分转账批次单下不同转账明细单的唯一标识 + * 通过商家明细单号查询明细 + * @param string $outBatchNo 商户批次单号 + * @param string $outDetailNo 商户明细单号 * @return array * @throws \WeChat\Exceptions\InvalidResponseException */ diff --git a/_test/alipay-app.php b/_test/alipay-app.php index 693af34..155d3b4 100644 --- a/_test/alipay-app.php +++ b/_test/alipay-app.php @@ -3,7 +3,7 @@ // +---------------------------------------------------------------------- // | WeChatDeveloper // +---------------------------------------------------------------------- -// | 版权所有 2014~2025 ThinkAdmin [ thinkadmin.top ] +// | 版权所有 2014~2026 ThinkAdmin [ thinkadmin.top ] // +---------------------------------------------------------------------- // | 官方网站: https://thinkadmin.top // +---------------------------------------------------------------------- @@ -32,7 +32,7 @@ try { 'total_amount' => '1', // 支付金额 'subject' => '支付宝订单标题', // 支付订单描述 ]); - echo $result . PHP_EOL .'

'. PHP_EOL; + echo $result . PHP_EOL . '

' . PHP_EOL; // 请求关闭订单 $result = $pay->close([ diff --git a/_test/alipay-bill.php b/_test/alipay-bill.php index 52a5dec..3a8ffca 100644 --- a/_test/alipay-bill.php +++ b/_test/alipay-bill.php @@ -3,7 +3,7 @@ // +---------------------------------------------------------------------- // | WeChatDeveloper // +---------------------------------------------------------------------- -// | 版权所有 2014~2025 ThinkAdmin [ thinkadmin.top ] +// | 版权所有 2014~2026 ThinkAdmin [ thinkadmin.top ] // +---------------------------------------------------------------------- // | 官方网站: https://thinkadmin.top // +---------------------------------------------------------------------- diff --git a/_test/alipay-callapi-test.php b/_test/alipay-callapi-test.php new file mode 100644 index 0000000..9ba45bd --- /dev/null +++ b/_test/alipay-callapi-test.php @@ -0,0 +1,163 @@ +=== 支付宝通用接口测试 ==="; + + // ============================================ + // 测试1: GET请求 - 查询订单 + // ============================================ + echo "

测试1: GET请求 - 查询订单

"; + try { + $result = $alipay->callApi( + 'alipay.trade.query', // API方法名(必填,第一参数) + [ + 'out_trade_no' => time() - 3600, // 使用一个可能存在的订单号 + ], + 'GET', + false // 不验证响应签名 + ); + echo '
';
+        var_export($result);
+        echo '
'; + } catch (Exception $e) { + echo "错误: " . $e->getMessage() . PHP_EOL; + } + + // ============================================ + // 测试2: GET请求 - 查询订单(验证签名) + // ============================================ + echo "

测试2: GET请求 - 查询订单(验证签名)

"; + try { + $result = $alipay->callApi( + 'alipay.trade.query', // API方法名 + [ + 'out_trade_no' => time() - 3600, + ], + 'GET', + true // 验证响应签名 + ); + echo '
';
+        var_export($result);
+        echo '
'; + } catch (Exception $e) { + echo "错误: " . $e->getMessage() . PHP_EOL; + } + + // ============================================ + // 测试3: POST请求 - 订单退款 + // ============================================ + echo "

测试3: POST请求 - 订单退款

"; + echo "

注意:此测试需要有效的订单号

"; + try { + $result = $alipay->callApi( + 'alipay.trade.refund', // API方法名(第一参数) + [ + 'out_trade_no' => time() - 3600, + 'refund_amount' => '0.01', + ], + 'POST', + false // 不验证响应签名 + ); + echo '
';
+        var_export($result);
+        echo '
'; + } catch (Exception $e) { + echo "错误: " . $e->getMessage() . PHP_EOL; + echo "

这是正常的,因为退款需要有效的订单号

"; + } + + // ============================================ + // 测试4: GET请求 - 退款查询 + // ============================================ + echo "

测试4: GET请求 - 退款查询

"; + try { + $result = $alipay->callApi( + 'alipay.trade.fastpay.refund.query', // API方法名 + [ + 'out_trade_no' => time() - 3600, + 'out_request_no' => time() - 3600, + ], + 'GET', + false // 不验证响应签名 + ); + echo '
';
+        var_export($result);
+        echo '
'; + } catch (Exception $e) { + echo "错误: " . $e->getMessage() . PHP_EOL; + } + + // ============================================ + // 测试5: POST请求 - 关闭订单 + // ============================================ + echo "

测试5: POST请求 - 关闭订单

"; + try { + $result = $alipay->callApi( + 'alipay.trade.close', // API方法名 + [ + 'out_trade_no' => time() - 3600, + ], + 'POST', + false // 不验证响应签名 + ); + echo '
';
+        var_export($result);
+        echo '
'; + } catch (Exception $e) { + echo "错误: " . $e->getMessage() . PHP_EOL; + } + + // ============================================ + // 测试6: PUT请求 - 更新资源(示例) + // ============================================ + echo "

测试6: PUT请求 - 更新资源(示例)

"; + echo "

注意:此示例仅展示PUT请求用法,实际API可能不支持

"; + try { + // PUT请求示例(如果API支持) + // $result = $alipay->callApi( + // 'alipay.some.method', // API方法名 + // ['key' => 'value'], + // 'PUT', + // false + // ); + echo '
PUT请求用法示例(已注释)
'; + } catch (Exception $e) { + echo "错误: " . $e->getMessage() . PHP_EOL; + } + + echo "

=== 所有测试完成 ===

"; +} catch (Exception $e) { + + // 出错啦,处理下吧 + echo "

错误: " . $e->getMessage() . "

"; + echo "
" . $e->getTraceAsString() . "
"; +} diff --git a/_test/alipay-notify.php b/_test/alipay-notify.php index a91e767..26b84f5 100644 --- a/_test/alipay-notify.php +++ b/_test/alipay-notify.php @@ -3,7 +3,7 @@ // +---------------------------------------------------------------------- // | WeChatDeveloper // +---------------------------------------------------------------------- -// | 版权所有 2014~2025 ThinkAdmin [ thinkadmin.top ] +// | 版权所有 2014~2026 ThinkAdmin [ thinkadmin.top ] // +---------------------------------------------------------------------- // | 官方网站: https://thinkadmin.top // +---------------------------------------------------------------------- diff --git a/_test/alipay-pos.php b/_test/alipay-pos.php index 7e748aa..0849795 100644 --- a/_test/alipay-pos.php +++ b/_test/alipay-pos.php @@ -3,7 +3,7 @@ // +---------------------------------------------------------------------- // | WeChatDeveloper // +---------------------------------------------------------------------- -// | 版权所有 2014~2025 ThinkAdmin [ thinkadmin.top ] +// | 版权所有 2014~2026 ThinkAdmin [ thinkadmin.top ] // +---------------------------------------------------------------------- // | 官方网站: https://thinkadmin.top // +---------------------------------------------------------------------- diff --git a/_test/alipay-refund.php b/_test/alipay-refund.php index 0f2ee3e..d880bab 100644 --- a/_test/alipay-refund.php +++ b/_test/alipay-refund.php @@ -3,7 +3,7 @@ // +---------------------------------------------------------------------- // | WeChatDeveloper // +---------------------------------------------------------------------- -// | 版权所有 2014~2025 ThinkAdmin [ thinkadmin.top ] +// | 版权所有 2014~2026 ThinkAdmin [ thinkadmin.top ] // +---------------------------------------------------------------------- // | 官方网站: https://thinkadmin.top // +---------------------------------------------------------------------- diff --git a/_test/alipay-scan.php b/_test/alipay-scan.php index 1855cda..649fa91 100644 --- a/_test/alipay-scan.php +++ b/_test/alipay-scan.php @@ -3,7 +3,7 @@ // +---------------------------------------------------------------------- // | WeChatDeveloper // +---------------------------------------------------------------------- -// | 版权所有 2014~2025 ThinkAdmin [ thinkadmin.top ] +// | 版权所有 2014~2026 ThinkAdmin [ thinkadmin.top ] // +---------------------------------------------------------------------- // | 官方网站: https://thinkadmin.top // +---------------------------------------------------------------------- diff --git a/_test/alipay-transfer-account.php b/_test/alipay-transfer-account.php index 99bc68f..ae5a86f 100644 --- a/_test/alipay-transfer-account.php +++ b/_test/alipay-transfer-account.php @@ -3,7 +3,7 @@ // +---------------------------------------------------------------------- // | WeChatDeveloper // +---------------------------------------------------------------------- -// | 版权所有 2014~2025 ThinkAdmin [ thinkadmin.top ] +// | 版权所有 2014~2026 ThinkAdmin [ thinkadmin.top ] // +---------------------------------------------------------------------- // | 官方网站: https://thinkadmin.top // +---------------------------------------------------------------------- diff --git a/_test/alipay-transfer-create.php b/_test/alipay-transfer-create.php index 3b634b8..9bf4faf 100644 --- a/_test/alipay-transfer-create.php +++ b/_test/alipay-transfer-create.php @@ -3,7 +3,7 @@ // +---------------------------------------------------------------------- // | WeChatDeveloper // +---------------------------------------------------------------------- -// | 版权所有 2014~2025 ThinkAdmin [ thinkadmin.top ] +// | 版权所有 2014~2026 ThinkAdmin [ thinkadmin.top ] // +---------------------------------------------------------------------- // | 官方网站: https://thinkadmin.top // +---------------------------------------------------------------------- diff --git a/_test/alipay-transfer-query.php b/_test/alipay-transfer-query.php index b3dbf1f..434e0cc 100644 --- a/_test/alipay-transfer-query.php +++ b/_test/alipay-transfer-query.php @@ -3,7 +3,7 @@ // +---------------------------------------------------------------------- // | WeChatDeveloper // +---------------------------------------------------------------------- -// | 版权所有 2014~2025 ThinkAdmin [ thinkadmin.top ] +// | 版权所有 2014~2026 ThinkAdmin [ thinkadmin.top ] // +---------------------------------------------------------------------- // | 官方网站: https://thinkadmin.top // +---------------------------------------------------------------------- diff --git a/_test/alipay-transfer.php b/_test/alipay-transfer.php index 1c75f50..48feac7 100644 --- a/_test/alipay-transfer.php +++ b/_test/alipay-transfer.php @@ -3,7 +3,7 @@ // +---------------------------------------------------------------------- // | WeChatDeveloper // +---------------------------------------------------------------------- -// | 版权所有 2014~2025 ThinkAdmin [ thinkadmin.top ] +// | 版权所有 2014~2026 ThinkAdmin [ thinkadmin.top ] // +---------------------------------------------------------------------- // | 官方网站: https://thinkadmin.top // +---------------------------------------------------------------------- diff --git a/_test/alipay-wap.php b/_test/alipay-wap.php index 3fbc9a6..bcb232b 100644 --- a/_test/alipay-wap.php +++ b/_test/alipay-wap.php @@ -3,7 +3,7 @@ // +---------------------------------------------------------------------- // | WeChatDeveloper // +---------------------------------------------------------------------- -// | 版权所有 2014~2025 ThinkAdmin [ thinkadmin.top ] +// | 版权所有 2014~2026 ThinkAdmin [ thinkadmin.top ] // +---------------------------------------------------------------------- // | 官方网站: https://thinkadmin.top // +---------------------------------------------------------------------- diff --git a/_test/alipay-web.php b/_test/alipay-web.php index a14475f..de3cee8 100644 --- a/_test/alipay-web.php +++ b/_test/alipay-web.php @@ -3,7 +3,7 @@ // +---------------------------------------------------------------------- // | WeChatDeveloper // +---------------------------------------------------------------------- -// | 版权所有 2014~2025 ThinkAdmin [ thinkadmin.top ] +// | 版权所有 2014~2026 ThinkAdmin [ thinkadmin.top ] // +---------------------------------------------------------------------- // | 官方网站: https://thinkadmin.top // +---------------------------------------------------------------------- diff --git a/_test/alipay.php b/_test/alipay.php index 3d95faf..28ec6f1 100644 --- a/_test/alipay.php +++ b/_test/alipay.php @@ -3,7 +3,7 @@ // +---------------------------------------------------------------------- // | WeChatDeveloper // +---------------------------------------------------------------------- -// | 版权所有 2014~2025 ThinkAdmin [ thinkadmin.top ] +// | 版权所有 2014~2026 ThinkAdmin [ thinkadmin.top ] // +---------------------------------------------------------------------- // | 官方网站: https://thinkadmin.top // +---------------------------------------------------------------------- diff --git a/_test/alipay2.php b/_test/alipay2.php index f0d3b8a..e0fdd20 100644 --- a/_test/alipay2.php +++ b/_test/alipay2.php @@ -3,7 +3,7 @@ // +---------------------------------------------------------------------- // | WeChatDeveloper // +---------------------------------------------------------------------- -// | 版权所有 2014~2025 ThinkAdmin [ thinkadmin.top ] +// | 版权所有 2014~2026 ThinkAdmin [ thinkadmin.top ] // +---------------------------------------------------------------------- // | 官方网站: https://thinkadmin.top // +---------------------------------------------------------------------- diff --git a/_test/config.php b/_test/config.php index 50640e2..cee0e0a 100644 --- a/_test/config.php +++ b/_test/config.php @@ -3,7 +3,7 @@ // +---------------------------------------------------------------------- // | WeChatDeveloper // +---------------------------------------------------------------------- -// | 版权所有 2014~2025 ThinkAdmin [ thinkadmin.top ] +// | 版权所有 2014~2026 ThinkAdmin [ thinkadmin.top ] // +---------------------------------------------------------------------- // | 官方网站: https://thinkadmin.top // +---------------------------------------------------------------------- diff --git a/_test/mini-login.php b/_test/mini-login.php index a34cfd8..885e28c 100644 --- a/_test/mini-login.php +++ b/_test/mini-login.php @@ -3,7 +3,7 @@ // +---------------------------------------------------------------------- // | WeChatDeveloper // +---------------------------------------------------------------------- -// | 版权所有 2014~2025 ThinkAdmin [ thinkadmin.top ] +// | 版权所有 2014~2026 ThinkAdmin [ thinkadmin.top ] // +---------------------------------------------------------------------- // | 官方网站: https://thinkadmin.top // +---------------------------------------------------------------------- diff --git a/_test/mini-qrc.php b/_test/mini-qrc.php index 2c52b90..9516669 100644 --- a/_test/mini-qrc.php +++ b/_test/mini-qrc.php @@ -3,7 +3,7 @@ // +---------------------------------------------------------------------- // | WeChatDeveloper // +---------------------------------------------------------------------- -// | 版权所有 2014~2025 ThinkAdmin [ thinkadmin.top ] +// | 版权所有 2014~2026 ThinkAdmin [ thinkadmin.top ] // +---------------------------------------------------------------------- // | 官方网站: https://thinkadmin.top // +---------------------------------------------------------------------- diff --git a/_test/pay-callapi-test.php b/_test/pay-callapi-test.php new file mode 100644 index 0000000..f6913ab --- /dev/null +++ b/_test/pay-callapi-test.php @@ -0,0 +1,169 @@ +=== 微信支付V2通用接口测试 ==="; + + // ============================================ + // 测试1: POST请求 - 统一下单(自动签名) + // ============================================ + echo "

测试1: POST请求 - 统一下单(自动签名)

"; + try { + $result = $pay->callApi( + 'https://api.mch.weixin.qq.com/pay/unifiedorder', + [ + 'body' => '测试商品', + 'out_trade_no' => time(), + 'total_fee' => '1', + 'openid' => 'o38gpszoJoC9oJYz3UHHf6bEp0Lo', // 请替换为实际的openid + 'trade_type' => 'JSAPI', + 'notify_url' => 'https://your-domain.com/notify.php', + 'spbill_create_ip' => '127.0.0.1', + ], + 'POST', + false, // 不需要证书 + 'MD5' // 签名类型:MD5 + ); + echo '
';
+        var_export($result);
+        echo '
'; + } catch (Exception $e) { + echo "错误: " . $e->getMessage() . PHP_EOL; + } + + // ============================================ + // 测试2: GET请求 - 查询订单(不自动签名) + // ============================================ + echo "

测试2: GET请求 - 查询订单(不自动签名)

"; + try { + $result = $pay->callApi( + 'https://api.mch.weixin.qq.com/pay/orderquery', + [ + 'out_trade_no' => time() - 3600, // 使用一个可能存在的订单号 + ], + 'GET' + ); + echo '
';
+        var_export($result);
+        echo '
'; + } catch (Exception $e) { + echo "错误: " . $e->getMessage() . PHP_EOL; + } + + // ============================================ + // 测试3: POST请求 - 使用HMAC-SHA256签名 + // ============================================ + echo "

测试3: POST请求 - 使用HMAC-SHA256签名

"; + try { + $result = $pay->callApi( + 'https://api.mch.weixin.qq.com/pay/unifiedorder', + [ + 'body' => '测试商品', + 'out_trade_no' => time() + 1, + 'total_fee' => '1', + 'openid' => 'o38gpszoJoC9oJYz3UHHf6bEp0Lo', + 'trade_type' => 'JSAPI', + 'notify_url' => 'https://your-domain.com/notify.php', + 'spbill_create_ip' => '127.0.0.1', + ], + 'POST', + false, // 不需要证书 + 'HMAC-SHA256' // 使用HMAC-SHA256签名 + ); + echo '
';
+        var_export($result);
+        echo '
'; + } catch (Exception $e) { + echo "错误: " . $e->getMessage() . PHP_EOL; + } + + // ============================================ + // 测试4: POST请求 - 需要证书的接口(如退款) + // ============================================ + echo "

测试4: POST请求 - 需要证书的接口(如退款)

"; + echo "

注意:此测试需要配置证书,如果未配置证书会报错

"; + try { + $result = $pay->callApi( + 'https://api.mch.weixin.qq.com/secapi/pay/refund', + [ + 'out_trade_no' => time() - 3600, + 'out_refund_no' => time(), + 'total_fee' => '1', + 'refund_fee' => '1', + ], + 'POST', + true, // 需要证书 + 'MD5' // 签名类型:MD5 + ); + echo '
';
+        var_export($result);
+        echo '
'; + } catch (Exception $e) { + echo "错误: " . $e->getMessage() . PHP_EOL; + echo "

这是正常的,因为退款接口需要证书且需要有效的订单号

"; + } + + // ============================================ + // 测试5: POST请求 - 不自动签名(手动处理) + // ============================================ + echo "

测试5: POST请求 - 不自动签名(手动处理签名)

"; + try { + // 手动构建参数和签名 + $data = [ + 'body' => '测试商品', + 'out_trade_no' => time() + 2, + 'total_fee' => '1', + 'openid' => 'o38gpszoJoC9oJYz3UHHf6bEp0Lo', + 'trade_type' => 'JSAPI', + 'notify_url' => 'https://your-domain.com/notify.php', + 'spbill_create_ip' => '127.0.0.1', + ]; + + // 手动添加签名 + $data['sign'] = $pay->getPaySign($data, 'MD5'); + + // 注意:手动签名后,callApi仍会自动签名,所以此示例需要调整 + // 实际使用中,如果已经手动签名,应该直接使用 Tools::post 发送 + echo '
注意:手动签名后,callApi仍会自动签名,建议直接使用 Tools::post 发送
'; + echo '
';
+        var_export($result);
+        echo '
'; + } catch (Exception $e) { + echo "错误: " . $e->getMessage() . PHP_EOL; + } + + echo "

=== 所有测试完成 ===

"; +} catch (Exception $e) { + + // 出错啦,处理下吧 + echo "

错误: " . $e->getMessage() . "

"; + echo "
" . $e->getTraceAsString() . "
"; +} diff --git a/_test/pay-config.php b/_test/pay-config.php index a9bf355..f772a05 100644 --- a/_test/pay-config.php +++ b/_test/pay-config.php @@ -3,7 +3,7 @@ // +---------------------------------------------------------------------- // | WeChatDeveloper // +---------------------------------------------------------------------- -// | 版权所有 2014~2025 ThinkAdmin [ thinkadmin.top ] +// | 版权所有 2014~2026 ThinkAdmin [ thinkadmin.top ] // +---------------------------------------------------------------------- // | 官方网站: https://thinkadmin.top // +---------------------------------------------------------------------- diff --git a/_test/pay-download-bill.php b/_test/pay-download-bill.php index 276d4a0..e1d491f 100644 --- a/_test/pay-download-bill.php +++ b/_test/pay-download-bill.php @@ -3,7 +3,7 @@ // +---------------------------------------------------------------------- // | WeChatDeveloper // +---------------------------------------------------------------------- -// | 版权所有 2014~2025 ThinkAdmin [ thinkadmin.top ] +// | 版权所有 2014~2026 ThinkAdmin [ thinkadmin.top ] // +---------------------------------------------------------------------- // | 官方网站: https://thinkadmin.top // +---------------------------------------------------------------------- diff --git a/_test/pay-order-close.php b/_test/pay-order-close.php index d897ce5..229f78c 100644 --- a/_test/pay-order-close.php +++ b/_test/pay-order-close.php @@ -3,7 +3,7 @@ // +---------------------------------------------------------------------- // | WeChatDeveloper // +---------------------------------------------------------------------- -// | 版权所有 2014~2025 ThinkAdmin [ thinkadmin.top ] +// | 版权所有 2014~2026 ThinkAdmin [ thinkadmin.top ] // +---------------------------------------------------------------------- // | 官方网站: https://thinkadmin.top // +---------------------------------------------------------------------- diff --git a/_test/pay-order-create.php b/_test/pay-order-create.php index 1eecfcb..13aa563 100644 --- a/_test/pay-order-create.php +++ b/_test/pay-order-create.php @@ -3,7 +3,7 @@ // +---------------------------------------------------------------------- // | WeChatDeveloper // +---------------------------------------------------------------------- -// | 版权所有 2014~2025 ThinkAdmin [ thinkadmin.top ] +// | 版权所有 2014~2026 ThinkAdmin [ thinkadmin.top ] // +---------------------------------------------------------------------- // | 官方网站: https://thinkadmin.top // +---------------------------------------------------------------------- diff --git a/_test/pay-order-notify.php b/_test/pay-order-notify.php index 79195ef..cd1fc2e 100644 --- a/_test/pay-order-notify.php +++ b/_test/pay-order-notify.php @@ -3,7 +3,7 @@ // +---------------------------------------------------------------------- // | WeChatDeveloper // +---------------------------------------------------------------------- -// | 版权所有 2014~2025 ThinkAdmin [ thinkadmin.top ] +// | 版权所有 2014~2026 ThinkAdmin [ thinkadmin.top ] // +---------------------------------------------------------------------- // | 官方网站: https://thinkadmin.top // +---------------------------------------------------------------------- diff --git a/_test/pay-order-query.php b/_test/pay-order-query.php index 19cfe65..fd75c74 100644 --- a/_test/pay-order-query.php +++ b/_test/pay-order-query.php @@ -3,7 +3,7 @@ // +---------------------------------------------------------------------- // | WeChatDeveloper // +---------------------------------------------------------------------- -// | 版权所有 2014~2025 ThinkAdmin [ thinkadmin.top ] +// | 版权所有 2014~2026 ThinkAdmin [ thinkadmin.top ] // +---------------------------------------------------------------------- // | 官方网站: https://thinkadmin.top // +---------------------------------------------------------------------- diff --git a/_test/pay-redpack-create.php b/_test/pay-redpack-create.php index 3e005a6..0830fb3 100644 --- a/_test/pay-redpack-create.php +++ b/_test/pay-redpack-create.php @@ -3,7 +3,7 @@ // +---------------------------------------------------------------------- // | WeChatDeveloper // +---------------------------------------------------------------------- -// | 版权所有 2014~2025 ThinkAdmin [ thinkadmin.top ] +// | 版权所有 2014~2026 ThinkAdmin [ thinkadmin.top ] // +---------------------------------------------------------------------- // | 官方网站: https://thinkadmin.top // +---------------------------------------------------------------------- diff --git a/_test/pay-refund-create.php b/_test/pay-refund-create.php index 1df3906..b9e6765 100644 --- a/_test/pay-refund-create.php +++ b/_test/pay-refund-create.php @@ -3,7 +3,7 @@ // +---------------------------------------------------------------------- // | WeChatDeveloper // +---------------------------------------------------------------------- -// | 版权所有 2014~2025 ThinkAdmin [ thinkadmin.top ] +// | 版权所有 2014~2026 ThinkAdmin [ thinkadmin.top ] // +---------------------------------------------------------------------- // | 官方网站: https://thinkadmin.top // +---------------------------------------------------------------------- diff --git a/_test/pay-refund-query.php b/_test/pay-refund-query.php index d05f4b2..0b290d6 100644 --- a/_test/pay-refund-query.php +++ b/_test/pay-refund-query.php @@ -3,7 +3,7 @@ // +---------------------------------------------------------------------- // | WeChatDeveloper // +---------------------------------------------------------------------- -// | 版权所有 2014~2025 ThinkAdmin [ thinkadmin.top ] +// | 版权所有 2014~2026 ThinkAdmin [ thinkadmin.top ] // +---------------------------------------------------------------------- // | 官方网站: https://thinkadmin.top // +---------------------------------------------------------------------- diff --git a/_test/pay-transfers-create.php b/_test/pay-transfers-create.php index 1b11143..9f45ccf 100644 --- a/_test/pay-transfers-create.php +++ b/_test/pay-transfers-create.php @@ -3,7 +3,7 @@ // +---------------------------------------------------------------------- // | WeChatDeveloper // +---------------------------------------------------------------------- -// | 版权所有 2014~2025 ThinkAdmin [ thinkadmin.top ] +// | 版权所有 2014~2026 ThinkAdmin [ thinkadmin.top ] // +---------------------------------------------------------------------- // | 官方网站: https://thinkadmin.top // +---------------------------------------------------------------------- diff --git a/_test/pay-transfersbank-create.php b/_test/pay-transfersbank-create.php index b8272b5..664da8d 100644 --- a/_test/pay-transfersbank-create.php +++ b/_test/pay-transfersbank-create.php @@ -3,7 +3,7 @@ // +---------------------------------------------------------------------- // | WeChatDeveloper // +---------------------------------------------------------------------- -// | 版权所有 2014~2025 ThinkAdmin [ thinkadmin.top ] +// | 版权所有 2014~2026 ThinkAdmin [ thinkadmin.top ] // +---------------------------------------------------------------------- // | 官方网站: https://thinkadmin.top // +---------------------------------------------------------------------- diff --git a/_test/pay-v3-callapi-test.php b/_test/pay-v3-callapi-test.php new file mode 100644 index 0000000..7f941a7 --- /dev/null +++ b/_test/pay-v3-callapi-test.php @@ -0,0 +1,205 @@ +=== 微信支付V3通用接口测试 ==="; + + // ============================================ + // 测试1: POST请求 - 使用相对路径创建订单 + // ============================================ + echo "

测试1: POST请求 - 创建JSAPI支付订单(相对路径)

"; + try { + $result = $payment->callApi( + '/v3/pay/transactions/jsapi', + [ + 'appid' => $config['appid'], + 'mchid' => $config['mch_id'], + 'description' => '测试商品', + 'out_trade_no' => (string)time(), + 'notify_url' => 'https://your-domain.com/notify.php', + 'payer' => [ + 'openid' => 'o38gpszoJoC9oJYz3UHHf6bEp0Lo', // 请替换为实际的openid + ], + 'amount' => [ + 'total' => 1, + 'currency' => 'CNY' + ], + ], + 'POST', + false // 不验证响应签名 + ); + echo '
';
+        var_export($result);
+        echo '
'; + } catch (Exception $e) { + echo "错误: " . $e->getMessage() . PHP_EOL; + } + + // ============================================ + // 测试2: GET请求 - 查询订单(完整URL) + // ============================================ + echo "

测试2: GET请求 - 查询订单(完整URL)

"; + try { + $outTradeNo = time() - 3600; // 使用一个可能存在的订单号 + $result = $payment->callApi( + "https://api.mch.weixin.qq.com/v3/pay/transactions/out-trade-no/{$outTradeNo}?mchid={$config['mch_id']}", + '', // GET请求数据为空 + 'GET', + false // 不验证响应签名 + ); + echo '
';
+        var_export($result);
+        echo '
'; + } catch (Exception $e) { + echo "错误: " . $e->getMessage() . PHP_EOL; + } + + // ============================================ + // 测试3: POST请求 - 创建H5支付订单 + // ============================================ + echo "

测试3: POST请求 - 创建H5支付订单

"; + try { + $result = $payment->callApi( + '/v3/pay/transactions/h5', + [ + 'appid' => $config['appid'], + 'mchid' => $config['mch_id'], + 'description' => '测试商品', + 'out_trade_no' => (string)(time() + 1), + 'notify_url' => 'https://your-domain.com/notify.php', + 'amount' => [ + 'total' => 1, + 'currency' => 'CNY' + ], + 'scene_info' => [ + 'h5_info' => [ + 'type' => 'Wap' + ], + 'payer_client_ip' => '127.0.0.1', + ], + ], + 'POST', + false // 不验证响应签名 + ); + echo '
';
+        var_export($result);
+        echo '
'; + } catch (Exception $e) { + echo "错误: " . $e->getMessage() . PHP_EOL; + } + + // ============================================ + // 测试4: POST请求 - 创建退款(需要证书) + // ============================================ + echo "

测试4: POST请求 - 创建退款

"; + echo "

注意:此测试需要有效的订单号

"; + try { + $result = $payment->callApi( + '/v3/refund/domestic/refunds', + [ + 'out_trade_no' => (string)(time() - 3600), + 'out_refund_no' => (string)time(), + 'amount' => [ + 'refund' => 1, + 'total' => 1, + 'currency' => 'CNY' + ], + ], + 'POST', + false // 不验证响应签名 + ); + echo '
';
+        var_export($result);
+        echo '
'; + } catch (Exception $e) { + echo "错误: " . $e->getMessage() . PHP_EOL; + echo "

这是正常的,因为退款需要有效的订单号

"; + } + + // ============================================ + // 测试5: GET请求 - 查询退款 + // ============================================ + echo "

测试5: GET请求 - 查询退款

"; + try { + $outRefundNo = time() - 3600; + $result = $payment->callApi( + "/v3/refund/domestic/refunds/{$outRefundNo}", + '', + 'GET', + false // 不验证响应签名 + ); + echo '
';
+        var_export($result);
+        echo '
'; + } catch (Exception $e) { + echo "错误: " . $e->getMessage() . PHP_EOL; + } + + // ============================================ + // 测试6: POST请求 - 使用数组数据(自动JSON编码) + // ============================================ + echo "

测试6: POST请求 - 使用数组数据(自动JSON编码)

"; + try { + $data = [ + 'appid' => $config['appid'], + 'mchid' => $config['mch_id'], + 'description' => '测试商品', + 'out_trade_no' => (string)(time() + 2), + 'notify_url' => 'https://your-domain.com/notify.php', + 'amount' => [ + 'total' => 1, + 'currency' => 'CNY' + ], + ]; + + // callApi会自动将数组转为JSON + $result = $payment->callApi( + '/v3/pay/transactions/jsapi', + $data, + 'POST' + ); + echo '
';
+        var_export($result);
+        echo '
'; + } catch (Exception $e) { + echo "错误: " . $e->getMessage() . PHP_EOL; + } + + echo "

=== 所有测试完成 ===

"; + +} catch (Exception $e) { + + // 出错啦,处理下吧 + echo "

错误: " . $e->getMessage() . "

"; + echo "
" . $e->getTraceAsString() . "
"; + +} + diff --git a/_test/pay-v3-config-cert.php b/_test/pay-v3-config-cert.php index 3105466..d6393a7 100644 --- a/_test/pay-v3-config-cert.php +++ b/_test/pay-v3-config-cert.php @@ -3,7 +3,7 @@ // +---------------------------------------------------------------------- // | WeChatDeveloper // +---------------------------------------------------------------------- -// | 版权所有 2014~2025 ThinkAdmin [ thinkadmin.top ] +// | 版权所有 2014~2026 ThinkAdmin [ thinkadmin.top ] // +---------------------------------------------------------------------- // | 官方网站: https://thinkadmin.top // +---------------------------------------------------------------------- diff --git a/_test/pay-v3-config.php b/_test/pay-v3-config.php index 6948f6f..26149da 100644 --- a/_test/pay-v3-config.php +++ b/_test/pay-v3-config.php @@ -3,7 +3,7 @@ // +---------------------------------------------------------------------- // | WeChatDeveloper // +---------------------------------------------------------------------- -// | 版权所有 2014~2025 ThinkAdmin [ thinkadmin.top ] +// | 版权所有 2014~2026 ThinkAdmin [ thinkadmin.top ] // +---------------------------------------------------------------------- // | 官方网站: https://thinkadmin.top // +---------------------------------------------------------------------- diff --git a/_test/pay-v3-order-app.php b/_test/pay-v3-order-app.php index 2e25194..9e804a4 100644 --- a/_test/pay-v3-order-app.php +++ b/_test/pay-v3-order-app.php @@ -3,7 +3,7 @@ // +---------------------------------------------------------------------- // | WeChatDeveloper // +---------------------------------------------------------------------- -// | 版权所有 2014~2025 ThinkAdmin [ thinkadmin.top ] +// | 版权所有 2014~2026 ThinkAdmin [ thinkadmin.top ] // +---------------------------------------------------------------------- // | 官方网站: https://thinkadmin.top // +---------------------------------------------------------------------- diff --git a/_test/pay-v3-order-h5.php b/_test/pay-v3-order-h5.php index a69bf10..9284445 100644 --- a/_test/pay-v3-order-h5.php +++ b/_test/pay-v3-order-h5.php @@ -3,7 +3,7 @@ // +---------------------------------------------------------------------- // | WeChatDeveloper // +---------------------------------------------------------------------- -// | 版权所有 2014~2025 ThinkAdmin [ thinkadmin.top ] +// | 版权所有 2014~2026 ThinkAdmin [ thinkadmin.top ] // +---------------------------------------------------------------------- // | 官方网站: https://thinkadmin.top // +---------------------------------------------------------------------- diff --git a/_test/pay-v3-order-jsapi.php b/_test/pay-v3-order-jsapi.php index 833f3df..5f2eacc 100644 --- a/_test/pay-v3-order-jsapi.php +++ b/_test/pay-v3-order-jsapi.php @@ -3,7 +3,7 @@ // +---------------------------------------------------------------------- // | WeChatDeveloper // +---------------------------------------------------------------------- -// | 版权所有 2014~2025 ThinkAdmin [ thinkadmin.top ] +// | 版权所有 2014~2026 ThinkAdmin [ thinkadmin.top ] // +---------------------------------------------------------------------- // | 官方网站: https://thinkadmin.top // +---------------------------------------------------------------------- diff --git a/_test/pay-v3-order-native.php b/_test/pay-v3-order-native.php index 33fbe61..ab720e5 100644 --- a/_test/pay-v3-order-native.php +++ b/_test/pay-v3-order-native.php @@ -3,7 +3,7 @@ // +---------------------------------------------------------------------- // | WeChatDeveloper // +---------------------------------------------------------------------- -// | 版权所有 2014~2025 ThinkAdmin [ thinkadmin.top ] +// | 版权所有 2014~2026 ThinkAdmin [ thinkadmin.top ] // +---------------------------------------------------------------------- // | 官方网站: https://thinkadmin.top // +---------------------------------------------------------------------- diff --git a/_test/pay-v3-transfer.php b/_test/pay-v3-transfer.php index e44472d..6998c79 100644 --- a/_test/pay-v3-transfer.php +++ b/_test/pay-v3-transfer.php @@ -3,7 +3,7 @@ // +---------------------------------------------------------------------- // | WeChatDeveloper // +---------------------------------------------------------------------- -// | 版权所有 2014~2025 ThinkAdmin [ thinkadmin.top ] +// | 版权所有 2014~2026 ThinkAdmin [ thinkadmin.top ] // +---------------------------------------------------------------------- // | 官方网站: https://thinkadmin.top // +---------------------------------------------------------------------- diff --git a/_test/wechat-callapi-test.php b/_test/wechat-callapi-test.php new file mode 100644 index 0000000..1f3cf74 --- /dev/null +++ b/_test/wechat-callapi-test.php @@ -0,0 +1,139 @@ +=== 微信公众号通用接口测试 ==="; + + // ============================================ + // 测试1: GET请求 - 使用完整URL(自动处理ACCESS_TOKEN) + // ============================================ + echo "

测试1: GET请求 - 获取用户列表(完整URL,自动处理ACCESS_TOKEN)

"; + try { + $result = $wechat->callApi( + 'https://api.weixin.qq.com/cgi-bin/user/get?ACCESS_TOKEN', + [], // GET参数(URL中已包含) + 'GET' + ); + echo '
';
+        var_export($result);
+        echo '
'; + } catch (Exception $e) { + echo "错误: " . $e->getMessage() . PHP_EOL; + } + + // ============================================ + // 测试2: GET请求 - 使用完整URL带参数 + // ============================================ + echo "

测试2: GET请求 - 获取用户信息(完整URL带参数)

"; + try { + $result = $wechat->callApi( + 'https://api.weixin.qq.com/cgi-bin/user/info?ACCESS_TOKEN', + [ + 'openid' => 'o38gpszoJoC9oJYz3UHHf6bEp0Lo', // 请替换为实际的openid + 'lang' => 'zh_CN' + ], + 'GET' + ); + echo '
';
+        var_export($result);
+        echo '
'; + } catch (Exception $e) { + echo "错误: " . $e->getMessage() . PHP_EOL; + } + + // ============================================ + // 测试3: POST请求 - 批量获取用户信息 + // ============================================ + echo "

测试3: POST请求 - 批量获取用户信息(自动JSON编码)

"; + try { + $result = $wechat->callApi( + 'https://api.weixin.qq.com/cgi-bin/user/info/batchget?ACCESS_TOKEN', + [ + 'user_list' => [ + ['openid' => 'o38gpszoJoC9oJYz3UHHf6bEp0Lo'], // 请替换为实际的openid + // ['openid' => 'o38gps3vNdCqaggFfrBRCRikwlWY'], + ] + ], + 'POST' + ); + echo '
';
+        var_export($result);
+        echo '
'; + } catch (Exception $e) { + echo "错误: " . $e->getMessage() . PHP_EOL; + } + + // ============================================ + // 测试4: PUT请求 - 更新资源(如果API支持) + // ============================================ + echo "

测试4: PUT请求 - 更新资源(示例)

"; + echo "

注意:此示例仅展示PUT请求用法,实际API可能不支持

"; + try { + // PUT请求示例(如果API支持) + // $result = $wechat->callApi( + // 'https://api.weixin.qq.com/some/api?ACCESS_TOKEN', + // ['key' => 'value'], + // 'PUT' + // ); + echo '
PUT请求用法示例(已注释)
'; + } catch (Exception $e) { + echo "错误: " . $e->getMessage() . PHP_EOL; + } + + // ============================================ + // 测试5: 使用相对路径(需要手动拼接完整URL) + // ============================================ + echo "

测试5: GET请求 - 使用相对路径(需要完整URL)

"; + try { + // 注意:callApi需要完整URL,相对路径需要手动拼接 + $baseUrl = 'https://api.weixin.qq.com'; + $result = $wechat->callApi( + $baseUrl . '/cgi-bin/user/get?ACCESS_TOKEN', + [], + 'GET' + ); + echo '
';
+        var_export($result);
+        echo '
'; + } catch (Exception $e) { + echo "错误: " . $e->getMessage() . PHP_EOL; + } + + echo "

=== 所有测试完成 ===

"; + +} catch (Exception $e) { + + // 出错啦,处理下吧 + echo "

错误: " . $e->getMessage() . "

"; + echo "
" . $e->getTraceAsString() . "
"; + +} + diff --git a/_test/wechat-jssdk-sign.php b/_test/wechat-jssdk-sign.php index af5d4c0..4033146 100644 --- a/_test/wechat-jssdk-sign.php +++ b/_test/wechat-jssdk-sign.php @@ -3,7 +3,7 @@ // +---------------------------------------------------------------------- // | WeChatDeveloper // +---------------------------------------------------------------------- -// | 版权所有 2014~2025 ThinkAdmin [ thinkadmin.top ] +// | 版权所有 2014~2026 ThinkAdmin [ thinkadmin.top ] // +---------------------------------------------------------------------- // | 官方网站: https://thinkadmin.top // +---------------------------------------------------------------------- diff --git a/_test/wechat-menu-get.php b/_test/wechat-menu-get.php index 88abf57..6c1c34f 100644 --- a/_test/wechat-menu-get.php +++ b/_test/wechat-menu-get.php @@ -3,7 +3,7 @@ // +---------------------------------------------------------------------- // | WeChatDeveloper // +---------------------------------------------------------------------- -// | 版权所有 2014~2025 ThinkAdmin [ thinkadmin.top ] +// | 版权所有 2014~2026 ThinkAdmin [ thinkadmin.top ] // +---------------------------------------------------------------------- // | 官方网站: https://thinkadmin.top // +---------------------------------------------------------------------- diff --git a/_test/wechat-qrcode-create.php b/_test/wechat-qrcode-create.php index 19d0619..949e83b 100644 --- a/_test/wechat-qrcode-create.php +++ b/_test/wechat-qrcode-create.php @@ -3,7 +3,7 @@ // +---------------------------------------------------------------------- // | WeChatDeveloper // +---------------------------------------------------------------------- -// | 版权所有 2014~2025 ThinkAdmin [ thinkadmin.top ] +// | 版权所有 2014~2026 ThinkAdmin [ thinkadmin.top ] // +---------------------------------------------------------------------- // | 官方网站: https://thinkadmin.top // +---------------------------------------------------------------------- diff --git a/_test/wechat-user-get.php b/_test/wechat-user-get.php index 411693f..cc43dbc 100644 --- a/_test/wechat-user-get.php +++ b/_test/wechat-user-get.php @@ -3,7 +3,7 @@ // +---------------------------------------------------------------------- // | WeChatDeveloper // +---------------------------------------------------------------------- -// | 版权所有 2014~2025 ThinkAdmin [ thinkadmin.top ] +// | 版权所有 2014~2026 ThinkAdmin [ thinkadmin.top ] // +---------------------------------------------------------------------- // | 官方网站: https://thinkadmin.top // +---------------------------------------------------------------------- diff --git a/_test/work-config.php b/_test/work-config.php index e11336a..fdf4e70 100644 --- a/_test/work-config.php +++ b/_test/work-config.php @@ -3,7 +3,7 @@ // +---------------------------------------------------------------------- // | WeChatDeveloper // +---------------------------------------------------------------------- -// | 版权所有 2014~2025 ThinkAdmin [ thinkadmin.top ] +// | 版权所有 2014~2026 ThinkAdmin [ thinkadmin.top ] // +---------------------------------------------------------------------- // | 官方网站: https://thinkadmin.top // +---------------------------------------------------------------------- diff --git a/_test/work-department.php b/_test/work-department.php index ec61d32..c36878e 100644 --- a/_test/work-department.php +++ b/_test/work-department.php @@ -3,7 +3,7 @@ // +---------------------------------------------------------------------- // | WeChatDeveloper // +---------------------------------------------------------------------- -// | 版权所有 2014~2025 ThinkAdmin [ thinkadmin.top ] +// | 版权所有 2014~2026 ThinkAdmin [ thinkadmin.top ] // +---------------------------------------------------------------------- // | 官方网站: https://thinkadmin.top // +---------------------------------------------------------------------- diff --git a/include.php b/include.php index 00e509f..1e9945d 100644 --- a/include.php +++ b/include.php @@ -3,7 +3,7 @@ // +---------------------------------------------------------------------- // | WeChatDeveloper // +---------------------------------------------------------------------- -// | 版权所有 2014~2025 ThinkAdmin [ thinkadmin.top ] +// | 版权所有 2014~2026 ThinkAdmin [ thinkadmin.top ] // +---------------------------------------------------------------------- // | 官方网站: https://thinkadmin.top // +---------------------------------------------------------------------- diff --git a/readme.md b/readme.md index a4fe930..13b96d3 100644 --- a/readme.md +++ b/readme.md @@ -1,6 +1,7 @@ # WeChatDeveloper for PHP + [![star](https://gitcode.com/ThinkAdmin/WeChatDeveloper/star/badge.svg)](https://gitcode.com/ThinkAdmin/ThinkAdmin) -[![star](https://gitee.com/zoujingli/WeChatDeveloper/badge/star.svg?theme=gvp)](https://gitee.com/zoujingli/ThinkAdmin) +[![star](https://gitee.com/zoujingli/WeChatDeveloper/badge/star.svg?theme=gvp)](https://gitee.com/zoujingli/WeChatDeveloper) [![Latest Stable Version](https://poser.pugx.org/zoujingli/wechat-developer/v/stable)](https://packagist.org/packages/zoujingli/wechat-developer) [![Total Downloads](https://poser.pugx.org/zoujingli/wechat-developer/downloads)](https://packagist.org/packages/zoujingli/wechat-developer) [![Monthly Downloads](https://poser.pugx.org/zoujingli/wechat-developer/d/monthly)](https://packagist.org/packages/zoujingli/wechat-developer) @@ -8,332 +9,961 @@ [![PHP Version Require](http://poser.pugx.org/zoujingli/wechat-developer/require/php)](https://packagist.org/packages/wechat-developer) [![License](https://poser.pugx.org/zoujingli/wechat-developer/license)](https://packagist.org/packages/zoujingli/wechat-developer) -* WeChatDeveloper 是基于 [wechat-php-sdk](https://github.com/zoujingli/wechat-php-sdk) 重构,优化并完善; -* 运行最底要求 PHP 版本 5.4 , 建议在 PHP7 上运行以获取最佳性能; -* 目前 WeChatDeveloper 针对 access_token 失效增加了自动刷新机制; -* 微信的部分接口需要缓存数据在本地,因此配置目录并需要对目录有写权限; -* 我们鼓励大家使用 composer 来管理您的第三方库,方便后期更新操作; -* WeChatDeveloper 已历经数个线上项目考验,欢迎 fork 或 star 此项目。 -* 微信商户已经支持 v2 和 v3 接口,未加入的接口可以使用通用方式调用。 +## 🚀 项目简介 -功能描述 ----- +**WeChatDeveloper** 是一个功能全面、安全可靠的 PHP 微信和支付宝开发 SDK,基于 [wechat-php-sdk](https://github.com/zoujingli/wechat-php-sdk) 重构优化而成。项目经过全面的安全加固和代码质量提升,为开发者提供稳定、安全、易用的微信生态和支付解决方案。 -* 微信小程序,服务端接口支持 -* 微信认证服务号,服务端接口支持 -* 微信支付(账单、卡券、红包、退款、转账、App支付、JSAPI支付、Web支付、扫码支付等) -* 支付宝支付(账单、转账、App支付、刷卡支付、扫码支付、Web支付、Wap支付等) +## ✨ 核心特性 -技术帮助 ----- -PHP开发技术交流(QQ群 513350915) +### 🔒 安全可靠 -[![PHP微信开发群 (SDK)](http://pub.idqqimg.com/wpa/images/group.png)](http://shang.qq.com/wpa/qunwpa?idkey=ae25cf789dafbef62e50a980ffc31242f150bc61a61164458216dd98c411832a) +- **输入验证**:全面防护 XSS 攻击,所有用户输入都经过严格过滤和验证 +- **文件安全**:文件操作前进行存在性和权限检查,防止恶意利用 +- **加密安全**:使用 SHA-256 替代 MD5,提供更强的安全防护 +- **序列化安全**:添加反序列化数据验证,防止代码执行攻击 -WeChatDeveloper 是基于官方接口封装,在做微信开发前,必需先阅读微信官方文档。 +### 🎯 功能全面 -* 微信官方文档:https://mp.weixin.qq.com/wiki -* 商户支付文档:https://pay.weixin.qq.com/wiki/doc/api/index.html +- **微信生态**:支持公众号、小程序、企业微信全生态开发 +- **支付功能**:支持微信支付 V2/V3、支付宝支付全场景 +- **多端支持**:覆盖 App、H5、PC、小程序等所有平台 +- **接口完整**:涵盖用户管理、消息推送、素材管理、支付等所有核心功能 -针对 WeChatDeveloper 也有一准备了帮助资料可供参考。 +### ⚡ 性能优化 -* ThinkAdmin:https://github.com/zoujingli/ThinkAdmin -* WeChatDeveloper:https://www.kancloud.cn/zoujingli/wechat-developer +- **自动刷新**:AccessToken 失效自动刷新机制 +- **缓存支持**:支持自定义缓存驱动,可扩展 Redis 等 +- **错误重试**:智能错误重试机制,提高接口调用成功率 +- **类型安全**:修复所有类型声明问题,提升代码质量 +- **自动缓存清理**:自动清理 CURL 临时缓存文件,适配常驻内存框架 +- **通用接口支持**:提供 `callApi()` 万能接口,支持多种 HTTP 方法,适用于所有场景 -代码仓库 ----- -WeChatDeveloper 为开源项目,允许把它用于任何地方,不受任何约束,欢迎 fork 项目。 +### 🛠 易于使用 -我们的代码仓库已移至 **Github**,而 **Gitee** 和 **Gitcode** 则仅作为国内镜像仓库,方便广大开发者获取和使用。若想提交 **PR** 或 **ISSUE** 请在 [WeChatDeveloper](https://github.com/zoujingli/WeChatDeveloper) 仓库进行操作,如果在其他仓库操作或提交问题将无法处理! +- **统一入口**:通过`\We::`静态方法统一创建各种功能实例 +- **向后兼容**:完全保持原有 API 和参数,无需修改现有代码 +- **通用接口**:提供标准化的 `callApi()` 方法,支持 GET/POST/PUT/DELETE 等多种 HTTP 方法 +- **文档完善**:提供详细的使用文档和示例代码 +- **社区支持**:活跃的社区和持续的技术支持 -* Gitee 仓库地址:https://gitee.com/zoujingli/WeChatDeveloper -* GitHub 仓库地址:https://github.com/zoujingli/WeChatDeveloper -* GitCode 仓库地址:https://gitcode.com/ThinkAdmin/WeChatDeveloper +## 📋 系统要求 -文件说明(后续会根据官方文档增加文件) ----- +- **PHP 版本**:最低要求 PHP 5.4,建议 PHP 7.0+ 以获取最佳性能 +- **扩展要求**:curl、json、xml、openssl、mbstring、bcmath +- **权限要求**:缓存目录需要写权限 +- **推荐环境**:PHP 7.4+ / PHP 8.0+ 生产环境 -| 文件名 | 类名 | 描述 | 类型 | 加载 ① | -|-------------------|---------------------|--------------|-------|---------------------------| -| App.php | AliPay\App | 支付宝App支付 | 支付宝支付 | \We::AliPayApp() | -| Bill.php | AliPay\Bill | 支付宝账单下载 | 支付宝支付 | \We::AliPayBill() | -| Pos.php | AliPay\Pos | 支付宝刷卡支付 | 支付宝支付 | \We::AliPayPos() | -| Scan.php | AliPay\Scan | 支付宝扫码支付 | 支付宝支付 | \We::AliPayScan() | -| Transfer.php | AliPay\Transfer | 支付宝转账 | 支付宝支付 | \We::AliPayTransfer() | -| Wap.php | AliPay\Wap | 支付宝Wap支付 | 支付宝支付 | \We::AliPayWap() | -| Web.php | AliPay\Web | 支付宝Web支付 | 支付宝支付 | \We::AliPayWeb() | -| Card.php | WeChat\Card | 微信卡券接口支持 | 认证服务号 | \We::WeChatCard() | -| Custom.php | WeChat\Custom | 微信客服消息接口支持 | 认证服务号 | \We::WeChatCustom() | -| Media.php | WeChat\Media | 微信媒体素材接口支持 | 认证服务号 | \We::WeChatMedia() | -| Oauth.php | WeChat\Oauth | 微信网页授权消息类接口 | 认证服务号 | \We::WeChatOauth() | -| Pay.php | WeChat\Pay | 微信支付类接口 | 认证服务号 | \We::WeChatPay() | -| Product.php | WeChat\Product | 微信商店类接口 | 认证服务号 | \We::WeChatProduct() | -| Qrcode.php | WeChat\Qrcode | 微信二维码接口支持 | 认证服务号 | \We::WeChatQrcode() | -| Receive.php | WeChat\Receive | 微信推送事件消息处理支持 | 认证服务号 | \We::WeChatReceive() | -| Scan.php | WeChat\Scan | 微信扫一扫接口支持 | 认证服务号 | \We::WeChatScan() | -| Script.php | WeChat\Script | 微信前端JSSDK支持 | 认证服务号 | \We::WeChatScript() | -| Shake.php | WeChat\Shake | 微信蓝牙设备揺一揺接口 | 认证服务号 | \We::WeChatShake() | -| Tags.php | WeChat\Tags | 微信粉丝标签接口支持 | 认证服务号 | \We::WeChatTags() | -| Template.php | WeChat\Template | 微信模板消息接口支持 | 认证服务号 | \We::WeChatTemplate() | -| User.php | WeChat\User | 微信粉丝管理接口支持 | 认证服务号 | \We::WeChatCard() | -| Wifi.php | WeChat\Wifi | 微信门店WIFI管理支持 | 认证服务号 | \We::WeChatWifi() | -| Draft.php | WeChat\Draft | 微信草稿箱 | 认证服务号 | \We::WeChatDraft() | -| Freepublish.php | WeChat\Freepublish | 微信发布能力 | 认证服务号 | \We::WeChatFreepublish() | -| Bill.php | WePay\Bill | 微信商户账单及评论 | 微信支付 | \We::WePayBill() | -| Coupon.php | WePay\Coupon | 微信商户代金券 | 微信支付 | \We::WePayCoupon() | -| Order.php | WePay\Order | 微信商户订单 | 微信支付 | \We::WePayOrder() | -| Redpack.php | WePay\Redpack | 微信红包支持 | 微信支付 | \We::WePayRedpack() | -| Refund.php | WePay\Refund | 微信商户退款 | 微信支付 | \We::WePayRefund() | -| Transfers.php | WePay\Transfers | 微信商户打款到零钱 | 微信支付 | \We::WePayTransfers() | -| TransfersBank.php | WePay\TransfersBank | 微信商户打款到银行卡 | 微信支付 | \We::WePayTransfersBank() | -| Crypt.php | WeMini\Crypt | 微信小程序数据加密处理 | 微信小程序 | \We::WeMiniCrypt() | -| Plugs.php | WeMini\Plugs | 微信小程序插件管理 | 微信小程序 | \We::WeMiniPlugs() | -| Poi.php | WeMini\Poi | 微信小程序地址管理 | 微信小程序 | \We::WeMiniPoi() | -| Qrcode.php | WeMini\Qrcode | 微信小程序二维码管理 | 微信小程序 | \We::WeMiniCrypt() | -| Template.php | WeMini\Template | 微信小程序模板消息支持 | 微信小程序 | \We::WeMiniTemplate() | -| Total.php | WeMini\Total | 微信小程序数据接口 | 微信小程序 | \We::WeMiniTotal() | +## 📦 快速开始 -安装使用 ----- -1.1 通过 Composer 来管理安装 +### 安装方式 -```shell -# 首次安装 线上版本(稳定) +#### 方式一:Composer 安装(推荐) + +```bash +# 安装稳定版本 composer require zoujingli/wechat-developer -# 首次安装 开发版本(开发) +# 安装开发版本 composer require zoujingli/wechat-developer dev-master -# 更新 WeChatDeveloper +# 更新到最新版本 composer update zoujingli/wechat-developer ``` -1.2 如果不使用 Composer, 可以下载 WeChatDeveloper 并解压到项目中 +#### 方式二:直接下载 -```php -# 在项目中加载初始化文件 -include "您的目录/WeChatDeveloper/include.php"; +```bash +# 下载项目到本地 +git clone https://github.com/zoujingli/WeChatDeveloper.git + +# 在项目中引入 +include "WeChatDeveloper/include.php"; ``` -2.1 接口实例所需参数 +### 基础使用 ```php + function ($name, $value, $expired = 360) { -// var_dump(func_get_args()); -// return $value; -// }, -// 'get' => function ($name) { -// var_dump(func_get_args()); -// return $value; -// }, -// 'del' => function ($name) { -// var_dump(func_get_args()); -// return true; -// }, -// 'put' => function ($name) { -// var_dump(func_get_args()); -// return $filePath; -// }, -// ]; - -return [ - // 公众号 APPID(可选) - 'appid' => 'wx3760xxxxxxxxxxxx', - - // 微信商户号(必填) - 'mch_id' => '15293xxxxxx', - - // 微信商户 V3 接口密钥(必填) - 'mch_v3_key' => '98b7fxxxxxxxxxxxxxxxxxxxxxxxxxxxx', - - // 商户证书序列号(可选):用于请求签名 - 'cert_serial' => '49055D67B2XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX', - - // 微信商户证书公钥(必填):可填写证书内容或文件路径,仅用于提取序列号 - 'cert_public' => $certPublic, - - // 微信商户证书私钥(必填):可填写证书内容或文件路径,用于请求数据签名 - 'cert_private' => $certPrivate, - - // 自定义证书包:支持平台证书或支付公钥(可填写文件路径或证书内容) - 'cert_package' => [ - 'PUB_KEY_ID_xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx' => $certPayment - ], - - // 微信平台证书或支付证书序列号(可选) - // 'mp_cert_serial' => 'PUB_KEY_ID_xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx', - - // 微信平台证书或支付证书内容(可选) - // 'mp_cert_content' => $certPayment, - - // 运行时文件缓存路径(可选) - 'cache_path' => '' -]; -``` - -3.1 实例指定接口 - -```php -try { - - // 实例对应的接口对象 - $user = new \WeChat\User($config); - - // 调用接口对象方法 - $list = $user->getUserList(); - - // 处理返回的结果 - echo '
';
-    var_export($list);
-    
-} catch (Exception $e) {
-
-    // 出错啦,处理下吧
-    echo $e->getMessage() . PHP_EOL;
-    
-}
-```
-
-微信支付
----
-
-```php
-  // 创建接口实例
-  $wechat = new \WeChat\Pay($config);
-  
-  // 组装参数,可以参考官方商户文档
-  $options = [
-      'body'             => '测试商品',
-      'out_trade_no'     => time(),
-      'total_fee'        => '1',
-      'openid'           => 'o38gpszoJoC9oJYz3UHHf6bEp0Lo',
-      'trade_type'       => 'JSAPI',
-      'notify_url'       => 'http://a.com/text.html',
-      'spbill_create_ip' => '127.0.0.1',
-  ];
-    
-try {
-
-    // 生成预支付码
-    $result = $wechat->createOrder($options);
-    
-    // 创建JSAPI参数签名
-    $options = $wechat->createParamsForJsApi($result['prepay_id']);
-    
-    // @todo 把 $options 传到前端用js发起支付就可以了
-    
-} catch (Exception $e) {
-
-    // 出错啦,处理下吧
-    echo $e->getMessage() . PHP_EOL;
-    
-}
-```
-
-* 更多功能请阅读测试代码或SDK封装源码
-
-支付宝支付
-----
-
-* 支付参数配置(可用沙箱模式)
-
-```php
+// 2. 配置参数
 $config = [
-    // 沙箱模式
-    'debug'            => true,
-    // 签名类型 ( RSA|RSA2 )
-    'sign_type'        => 'RSA2',
-    // 应用ID
-    'appid'            => '2021000122667306',
-    // 应用私钥内容 ( 需1行填写,特别注意:这里的应用私钥通常由支付宝密钥管理工具生成 )
-    'private_key'      => 'MIIEowIBAAKCAQEAn...',
-    // 公钥模式,支付宝公钥内容 ( 需1行填写,特别注意:这里不是应用公钥而是支付宝公钥,通常是上传应用公钥换取支付宝公钥,在网页可以复制 )
-    'public_key'       => '',
-    // 证书模式,应用公钥证书路径 ( 新版资金类接口转 app_cert_sn,如文件 appCertPublicKey.crt )
-    'app_cert_path'    => __DIR__ . '/alipay/appPublicCert.crt', // 'app_cert' => '证书内容',
-    // 证书模式,支付宝根证书路径 ( 新版资金类接口转 alipay_root_cert_sn,如文件 alipayRootCert.crt )
-    'alipay_root_path' => __DIR__ . '/alipay/alipayRootCert.crt', // 'root_cert' => '证书内容',
-    // 证书模式,支付宝公钥证书路径 ( 未填写 public_key 时启用此参数,如文件 alipayPublicCert.crt )
-    'alipay_cert_path' => __DIR__ . '/alipay/alipayPublicCert.crt', // 'public_key' => '证书内容'
-    // 支付成功通知地址
-    'notify_url'       => '',
-    // 网页支付回跳地址
-    'return_url'       => '',
+    'appid'     => 'your_wechat_appid',
+    'appsecret' => 'your_wechat_appsecret',
+    'mch_id'    => 'your_merchant_id',      // 微信支付需要
+    'mch_key'   => 'your_merchant_key',     // 微信支付需要
+    'cache_path' => '/path/to/cache'        // 可选,缓存目录
+];
+
+// 3. 创建实例并调用
+try {
+    // 微信用户管理
+    $user = \We::WeChatUser($config);
+    $userList = $user->getUserList();
+
+    // 微信支付
+    $pay = \We::WePayOrder($config);
+    $order = $pay->create($orderData);
+
+    // 支付宝支付
+    $alipay = \We::AliPayWeb($config);
+    $html = $alipay->apply($payData);
+
+    // 使用通用接口(万能接口)
+    // 所有接口类都提供 callApi() 方法,支持多种 HTTP 方法
+    $result = $user->callApi('https://api.weixin.qq.com/cgi-bin/user/get?ACCESS_TOKEN', [], 'GET');
+    $result = $pay->callApi('https://api.mch.weixin.qq.com/pay/unifiedorder', $data, 'POST');
+    $result = $alipay->callApi('alipay.trade.query', $params, 'GET');  // 支付宝:apiMethod 作为第一参数
+
+} catch (Exception $e) {
+    echo "错误:" . $e->getMessage();
+}
+```
+
+## 🎯 功能模块
+
+### 📱 微信生态支持
+
+#### 微信公众号
+
+- **用户管理**:用户信息获取、标签管理、分组管理
+- **消息推送**:模板消息、客服消息、群发消息
+- **素材管理**:图片、语音、视频、图文素材上传和管理
+- **菜单管理**:自定义菜单创建、查询、删除
+- **网页授权**:OAuth2.0 网页授权,获取用户信息
+- **二维码**:临时二维码、永久二维码生成
+- **JSSDK**:微信前端 JS-SDK 支持
+- **卡券功能**:微信卡券接口支持
+- **门店管理**:门店 WIFI 管理、摇一摇周边
+
+#### 微信小程序
+
+- **数据加密**:小程序数据加密解密处理
+- **用户管理**:用户信息获取、登录状态管理
+- **消息推送**:订阅消息、模板消息、动态消息
+- **二维码**:小程序码生成、URL Scheme
+- **内容安全**:图片内容检测、文本内容检测
+- **物流助手**:发货信息管理、物流状态查询
+- **直播功能**:小程序直播接口支持
+- **搜索优化**:小程序页面搜索优化
+- **插件管理**:小程序插件申请、管理
+- **OCR 服务**:身份证、银行卡、驾驶证识别
+- **生物认证**:指纹、面部识别支持
+
+#### 企业微信
+
+- **部门管理**:部门信息获取、创建、更新
+- **用户管理**:企业用户信息管理
+- **消息推送**:企业消息推送功能
+
+### 💰 支付功能支持
+
+#### 微信支付
+
+- **V2 接口**:统一下单、查询、关闭、退款
+- **V3 接口**:新一代支付接口,支持更多功能
+- **支付方式**:JSAPI、APP、H5、Native、小程序支付
+- **订单管理**:订单创建、查询、关闭、退款
+- **账单管理**:对账单下载、交易明细查询
+- **企业付款**:打款到零钱、打款到银行卡
+- **分账功能**:微信分账接口支持
+- **代金券**:代金券创建、发放、核销
+- **红包功能**:微信红包发送和管理
+
+#### 支付宝支付
+
+- **支付方式**:App 支付、Web 支付、Wap 支付、扫码支付、刷卡支付
+- **订单管理**:订单创建、查询、关闭、退款
+- **转账功能**:单笔转账、批量转账
+- **账单管理**:对账单下载、交易查询
+- **证书支持**:RSA、RSA2 签名,证书模式支持
+
+## 💡 使用案例
+
+### 📱 微信公众号功能
+
+#### 用户管理
+
+```php
+getUserList();
+
+// 批量获取用户信息
+foreach (array_chunk($result['data']['openid'], 100) as $openids) {
+    $userList = $user->getBatchUserInfo($openids);
+    foreach ($userList['user_info_list'] as $userInfo) {
+        echo "用户:" . $userInfo['nickname'] . "\n";
+    }
+}
+
+// 设置用户备注
+$user->updateMark('openid', 'VIP用户');
+```
+
+#### 二维码生成
+
+```php
+create('场景内容');
+
+// 获取二维码链接
+$url = $qrcode->url($result['ticket']);
+echo "二维码链接:" . $url;
+```
+
+#### 菜单管理
+
+```php
+get();
+
+// 创建自定义菜单
+$menuData = [
+    'button' => [
+        [
+            'type' => 'click',
+            'name' => '今日歌曲',
+            'key' => 'V1001_TODAY_MUSIC'
+        ],
+        [
+            'name' => '菜单',
+            'sub_button' => [
+                [
+                    'type' => 'view',
+                    'name' => '搜索',
+                    'url' => 'http://www.soso.com/'
+                ]
+            ]
+        ]
+    ]
+];
+$menu->create($menuData);
+```
+
+### 💰 微信支付功能
+
+#### 微信支付 V2 接口
+
+```php
+ '测试商品',
+    'out_trade_no'     => time(),
+    'total_fee'        => '1',
+    'openid'           => 'o38gpszoJoC9oJYz3UHHf6bEp0Lo',
+    'trade_type'       => 'JSAPI', // JSAPI/NATIVE/APP/MWEB
+    'notify_url'       => 'https://your-domain.com/notify.php',
+    'spbill_create_ip' => '127.0.0.1',
+];
+
+$result = $pay->create($options);
+
+// 生成JSAPI支付参数
+$jsApiParams = $pay->createParamsForJsApi($result['prepay_id']);
+// 将 $jsApiParams 传给前端发起支付
+```
+
+#### 微信支付 V3 接口
+
+```php
+create('jsapi', [
+    'appid'        => $config['appid'],
+    'mchid'        => $config['mch_id'],
+    'description'  => '商品描述',
+    'out_trade_no' => $order,
+    'notify_url'   => 'https://your-domain.com/notify.php',
+    'payer'        => ['openid' => 'o38gps3vNdCqaggFfrBRCRikwlWY'],
+    'amount'       => ['total' => 2, 'currency' => 'CNY'],
+]);
+
+// H5支付
+$result = $payment->create('h5', [
+    'appid'        => $config['appid'],
+    'mchid'        => $config['mch_id'],
+    'description'  => '商品描述',
+    'out_trade_no' => $order,
+    'notify_url'   => 'https://your-domain.com/notify.php',
+    'amount'       => ['total' => 2, 'currency' => 'CNY'],
+    'scene_info'   => [
+        'h5_info' => ['type' => 'Wap'],
+        'payer_client_ip' => '14.23.150.211',
+    ],
+]);
+
+// 查询订单
+$result = $payment->query($order);
+
+// 创建退款
+$refundResult = $payment->createRefund([
+    'out_trade_no'  => $order,
+    'out_refund_no' => strval(time()),
+    'amount'        => [
+        'refund'   => 2,
+        'total'    => 2,
+        'currency' => 'CNY'
+    ]
+]);
+```
+
+#### 微信红包
+
+```php
+ time(),
+    're_openid'    => 'o38gps3vNdCqaggFfrBRCRikwlWY',
+    'send_name'    => '商户名称',
+    'act_name'     => '活动名称',
+    'total_amount' => '100',
+    'total_num'    => '1',
+    'wishing'      => '感谢您参加活动!',
+    'remark'       => '快来抢红包!',
+    'client_ip'    => '127.0.0.1',
+];
+
+$result = $redpack->create($options);
+
+// 查询红包记录
+$result = $redpack->query($options['mch_billno']);
+```
+
+### 💳 支付宝支付功能
+
+#### 网站支付
+
+```php
+apply([
+    'out_trade_no' => time(),
+    'total_amount' => '1',
+    'subject'      => '支付订单描述',
+]);
+
+// 直接输出HTML表单,用户点击即可跳转支付
+echo $result;
+```
+
+#### App 支付
+
+```php
+apply([
+    'out_trade_no' => strval(time()),
+    'total_amount' => '1',
+    'subject'      => '支付宝订单标题',
+]);
+
+// 返回支付参数字符串,传给App端
+echo $result;
+```
+
+#### 转账功能
+
+```php
+create([
+    'out_biz_no'   => time(),
+    'trans_amount' => '10',
+    'product_code' => 'TRANS_ACCOUNT_NO_PWD',
+    'biz_scene'    => 'DIRECT_TRANSFER',
+    'payee_info'   => [
+        'identity'      => 'zoujingli@qq.com',
+        'identity_type' => 'ALIPAY_LOGON_ID',
+        'name'          => '收款人姓名',
+    ],
+]);
+```
+
+### 📱 微信小程序功能
+
+#### 用户登录和数据解密
+
+```php
+session($code);
+
+// 解密用户数据
+$userInfo = $mini->userInfo($code, $iv, $encryptedData);
+
+// 直接解密数据
+$decoded = $mini->decode($iv, $sessionKey, $encryptedData);
+```
+
+#### 小程序码生成
+
+```php
+create([
+    'scene' => 'id=123',
+    'page'  => 'pages/index/index',
+    'width' => 430
+]);
+```
+
+### 🔧 高级功能
+
+#### 通用接口(万能接口)
+
+所有接口类都提供了 `callApi()` 通用方法,支持多种 HTTP 方法(GET、POST、PUT、DELETE、PATCH、HEAD、OPTIONS),可以直接传入完整 URL 和参数进行请求,适用于官方新增接口或自定义接口调用。
+
+**方法签名:**
+
+```php
+// 微信公众号
+callApi(string $url, array|string $data = [], string $method = 'GET')
+
+// 微信支付V2
+callApi(string $url, array|string $data = [], string $method = 'POST', bool $isCert = false, string $signType = 'HMAC-SHA256')
+
+// 微信支付V3
+callApi(string $url, array|string $data = '', string $method = 'POST', bool $verify = false)
+
+// 支付宝
+callApi(string $apiMethod, array|string $data = [], string $method = 'GET', bool $verify = false)
+```
+
+**支持的 HTTP 方法:**
+
+- `GET` - 获取资源(默认:微信公众号、支付宝)
+- `POST` - 创建/提交数据(默认:微信支付)
+- `PUT` - 更新资源
+- `DELETE` - 删除资源
+- `PATCH` - 部分更新
+- `HEAD` - 获取响应头
+- `OPTIONS` - 获取支持的方法
+
+##### 微信公众号通用接口
+
+```php
+callApi(
+    'https://api.weixin.qq.com/cgi-bin/user/info?openid=OPENID&lang=zh_CN&ACCESS_TOKEN',
+    [], // GET参数(如果URL中已包含参数,这里可以为空)
+    'GET'
+);
+
+// POST请求 - 批量获取用户信息(自动JSON编码)
+$result = $user->callApi(
+    'https://api.weixin.qq.com/cgi-bin/user/info/batchget?ACCESS_TOKEN',
+    ['user_list' => [['openid' => 'xxx'], ['openid' => 'yyy']]],
+    'POST'
+);
+
+// PUT请求 - 更新资源
+$result = $user->callApi($url, $data, 'PUT');
+
+// DELETE请求 - 删除资源
+$result = $user->callApi($url, $data, 'DELETE');
+
+// PATCH请求 - 部分更新
+$result = $user->callApi($url, $data, 'PATCH');
+```
+
+**参数说明:**
+
+- `$url` (string) - 完整URL或相对路径(支持 ACCESS_TOKEN 占位符,自动替换)
+- `$data` (array|string) - 请求参数(GET参数或POST数据,支持数组或字符串)
+- `$method` (string) - 请求方法 GET|POST|PUT|DELETE|PATCH|HEAD|OPTIONS,默认 GET
+
+**默认行为:**
+
+- ✅ 自动处理 ACCESS_TOKEN(URL中包含 ACCESS_TOKEN 时自动替换)
+- ✅ POST 请求自动转为 JSON(数组数据)
+- ✅ 返回解析后的数组
+
+##### 微信支付V2通用接口
+
+```php
+callApi(
+    'https://api.mch.weixin.qq.com/pay/unifiedorder',
+    [
+        'body' => '测试商品',
+        'out_trade_no' => time(),
+        'total_fee' => '1',
+        'openid' => 'o38gpszoJoC9oJYz3UHHf6bEp0Lo',
+        'trade_type' => 'JSAPI',
+        'notify_url' => 'https://your-domain.com/notify.php',
+        'spbill_create_ip' => '127.0.0.1',
+    ],
+    'POST'
+);
+
+// POST请求 - 使用MD5签名
+$result = $pay->callApi(
+    'https://api.mch.weixin.qq.com/pay/unifiedorder',
+    $data,
+    'POST',
+    false,  // 不需要证书
+    'MD5'   // 签名类型:MD5
+);
+
+// POST请求 - 需要证书(如退款)
+$result = $pay->callApi(
+    'https://api.mch.weixin.qq.com/secapi/pay/refund',
+    $data,
+    'POST',
+    true,   // 需要证书
+    'MD5'   // 签名类型
+);
+
+// GET请求 - 查询订单
+$result = $pay->callApi(
+    'https://api.mch.weixin.qq.com/pay/orderquery',
+    ['out_trade_no' => '123456'],
+    'GET'
+);
+
+// PUT/DELETE请求
+$result = $pay->callApi($url, $data, 'PUT', false, 'MD5');
+$result = $pay->callApi($url, $data, 'DELETE', false, 'MD5');
+```
+
+**参数说明:**
+
+- `$url` (string) - 完整URL
+- `$data` (array|string) - 请求参数(支持数组或字符串)
+- `$method` (string) - 请求方法 GET|POST|PUT|DELETE|PATCH,默认 POST
+- `$isCert` (bool) - 是否需要证书,默认 false
+- `$signType` (string) - 签名类型 MD5|HMAC-SHA256,默认 HMAC-SHA256
+
+**默认行为:**
+
+- ✅ 自动签名(POST/PUT/PATCH/DELETE 请求)
+- ✅ 返回解析后的数组(XML格式)
+
+##### 微信支付V3通用接口
+
+```php
+callApi(
+    '/v3/pay/transactions/jsapi',
+    [
+        'appid' => $config['appid'],
+        'mchid' => $config['mch_id'],
+        'description' => '商品描述',
+        'out_trade_no' => (string)time(),
+        'notify_url' => 'https://your-domain.com/notify.php',
+        'payer' => ['openid' => 'o38gpszoJoC9oJYz3UHHf6bEp0Lo'],
+        'amount' => ['total' => 2, 'currency' => 'CNY'],
+    ],
+    'POST'
+);
+
+// GET请求 - 查询订单(完整URL或相对路径)
+$result = $payment->callApi(
+    '/v3/pay/transactions/out-trade-no/123456?mchid=' . $config['mch_id'],
+    '',
+    'GET',
+    true  // 验证响应签名
+);
+
+// PUT请求 - 更新资源
+$result = $payment->callApi('/v3/some/resource/xxx', $data, 'PUT');
+
+// DELETE请求 - 删除资源
+$result = $payment->callApi('/v3/some/resource/xxx', '', 'DELETE');
+```
+
+**参数说明:**
+
+- `$url` (string) - 完整URL或相对路径(如 `/v3/pay/transactions/jsapi`)
+- `$data` (array|string) - 请求数据(数组会自动转为JSON)
+- `$method` (string) - 请求方法 GET|POST|PUT|DELETE|PATCH|HEAD|OPTIONS,默认 POST
+- `$verify` (bool) - 验证响应签名,默认 false
+
+**默认行为:**
+
+- ✅ 数组数据自动转为 JSON
+- ✅ 返回解析后的数组
+
+##### 支付宝通用接口
+
+```php
+callApi(
+    'alipay.trade.query',  // API方法名(必填,第一参数)
+    ['out_trade_no' => '123456'],
+    'GET',
+    false                  // 验证响应签名,默认false
+);
+
+// POST请求 - 订单退款
+$result = $alipay->callApi(
+    'alipay.trade.refund',  // API方法名(第一参数)
+    [
+        'out_trade_no' => '123456',
+        'refund_amount' => '10',
+    ],
+    'POST',
+    false                    // 不验证响应签名
+);
+
+// PUT/DELETE请求
+$result = $alipay->callApi('alipay.some.method', $data, 'PUT', false);
+```
+
+**参数说明:**
+
+- `$apiMethod` (string) - API方法名(如:`alipay.trade.query`),必填,第一参数
+- `$data` (array|string) - 请求参数(支持数组或字符串)
+- `$method` (string) - 请求方法 GET|POST|PUT|DELETE|PATCH,默认 GET
+- `$verify` (bool) - 验证响应签名,默认 false
+
+**默认行为:**
+
+- ✅ 自动使用 gateway 作为请求URL
+- ✅ 自动签名(默认开启)
+- ✅ 返回解析后的数组
+
+#### 自定义缓存
+
+SDK 支持自定义缓存驱动,可以适配 Redis、Memcached 等缓存系统,特别适用于常驻内存框架(Workerman、Swoole 等)。
+
+```php
+ function ($name, $value, $expired = 360) {
+        // 自定义缓存设置逻辑
+        // $name: 缓存名称
+        // $value: 缓存值
+        // $expired: 过期时间(秒)
+        return Redis::setex($name, $expired, serialize($value));
+    },
+    'get' => function ($name) {
+        // 自定义缓存获取逻辑
+        // $name: 缓存名称
+        // 返回: 缓存值或 null
+        $data = Redis::get($name);
+        return $data ? unserialize($data) : null;
+    },
+    'del' => function ($name) {
+        // 自定义缓存删除逻辑
+        // $name: 缓存名称
+        // 返回: boolean
+        return Redis::del($name);
+    },
+    'put' => function ($name, $content) {
+        // 自定义文件缓存逻辑(用于证书等文件)
+        // $name: 文件名称
+        // $content: 文件内容
+        // 返回: 文件路径(必须是可读的文件路径)
+        $file = '/path/to/cache/' . $name;
+        file_put_contents($file, $content);
+        return $file;
+    },
+];
+
+// 注意:
+// 1. 未配置自定义缓存时,默认使用文件缓存
+// 2. 文件缓存路径可通过配置中的 'cache_path' 参数设置
+// 3. SDK 会自动清理 CURL 临时缓存文件,无需手动处理
+// 4. 在常驻内存框架中,建议使用 Redis 等外部缓存替代文件缓存
+```
+
+#### 错误处理
+
+```php
+getUserList();
+} catch (\WeChat\Exceptions\InvalidResponseException $e) {
+    // 接口调用异常
+    echo "接口错误:" . $e->getMessage();
+} catch (\WeChat\Exceptions\LocalCacheException $e) {
+    // 缓存异常
+    echo "缓存错误:" . $e->getMessage();
+} catch (Exception $e) {
+    // 其他异常
+    echo "系统错误:" . $e->getMessage();
+}
+```
+
+### 🧩 小程序快速示例
+
+#### 订阅消息发送
+
+```php
+send([
+    'touser'      => '用户openid',
+    'template_id' => '模板ID',
+    'page'        => 'pages/index?foo=bar',
+    'data'        => [
+        'thing1' => ['value' => '订单已支付'],
+        'time2'  => ['value' => '2024-01-01 12:00'],
+    ],
+]);
+```
+
+#### 内容安全校验
+
+```php
+msgSecCheck('留言内容示例');
+
+// 图片校验(文件流)
+$imgContent = file_get_contents('/path/to/demo.jpg');
+$security->imgSecCheck($imgContent);
+```
+
+## ⚙️ 配置说明
+
+### 基础配置
+
+#### 微信公众号配置
+
+```php
+ 'wx60a43dd8161666d4',
+    'appsecret'      => 'b4e28746f1bd73b5c6684f5e01883c36',
+    'token'          => 'your_wechat_token',
+    'encodingaeskey' => 'your_encodingaeskey',
+    'cache_path'     => '/path/to/cache',
 ];
 ```
 
-* 支付宝发起PC网站支付
+#### 微信支付配置
 
 ```php
-// 参考公共参数  https://docs.open.alipay.com/203/107090/
-$config['notify_url'] = 'http://pay.thinkadmin.top/test/alipay-notify.php';
-$config['return_url'] = 'http://pay.thinkadmin.top/test/alipay-success.php';
+ 'wx60a43dd8161666d4',
+    'mch_id'     => '15293xxxxxx',
+    'mch_key'    => 'your_merchant_key',
+    'cache_path' => '/path/to/cache',
+];
 
-try {
-    
-    // 实例支付对象
-    $pay = We::AliPayWeb($config);
-    // $pay = new \AliPay\Web($config);
-    
-    // 参考链接:https://docs.open.alipay.com/api_1/alipay.trade.page.pay
-    $result = $pay->apply([
-        'out_trade_no' => time(), // 商户订单号
-        'total_amount' => '1',    // 支付金额
-        'subject'      => '支付订单描述', // 支付订单描述
-    ]);
-    
-    echo $result; // 直接输出HTML(提交表单跳转)
-    
-} catch (Exception $e) {
-
-    // 异常处理
-    echo $e->getMessage();
-    
-}
+// 微信支付V3配置(推荐)
+$payV3Config = [
+    'appid'        => 'wx60a43dd8161666d4',
+    'mch_id'       => '15293xxxxxx',
+    'mch_v3_key'   => '98b7fxxxxxxxxxxxxxxxxxxxxxxxxxxxx',
+    'cert_serial'  => '49055D67B2XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX',
+    'cert_public'  => '-----BEGIN CERTIFICATE-----...',
+    'cert_private' => '-----BEGIN PRIVATE KEY-----...',
+    'cache_path'   => '/path/to/cache',
+    'cert_package' => [
+        'PUB_KEY_ID_xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx' => '-----BEGIN CERTIFICATE-----...'
+    ],
+];
 ```
 
-* 支付宝发起手机网站支付
+#### 支付宝配置
 
 ```php
-// 参考公共参数  https://docs.open.alipay.com/203/107090/
-$config['notify_url'] = 'http://pay.thinkadmin.top/test/alipay-notify.php';
-$config['return_url'] = 'http://pay.thinkadmin.top/test/alipay-success.php';
+ '2021000122667306',
+    'private_key' => 'MIIEowIBAAKCAQEAn...',
+    'public_key'  => 'MIIBIjANBgkqhkiG9w0BAQEFAAOCAQ8AMIIBCgKCAQEA...',
+    'sign_type'   => 'RSA2',
+    'notify_url'  => 'https://your-domain.com/alipay/notify',
+    'return_url'  => 'https://your-domain.com/alipay/return',
+    'charset'     => 'utf-8',
+    'debug'       => false, // 生产环境设为false
+];
 
-try {
-
-    // 实例支付对象
-    $pay = We::AliPayWap($config);
-    // $pay = new \AliPay\Wap($config);
-
-    // 参考链接:https://docs.open.alipay.com/api_1/alipay.trade.wap.pay
-    $result = $pay->apply([
-        'out_trade_no' => time(), // 商户订单号
-        'total_amount' => '1',    // 支付金额
-        'subject'      => '支付订单描述', // 支付订单描述
-    ]);
-
-    echo $result; // 直接输出HTML(提交表单跳转)
-
-} catch (Exception $e) {
-
-    // 异常处理
-    echo $e->getMessage();
-
-}
+// 支付宝证书模式配置
+$alipayCertConfig = [
+    'appid'            => '2021000122667306',
+    'private_key'      => 'MIIEowIBAAKCAQEAn...',
+    'app_cert_path'    => '/path/to/appPublicCert.crt',
+    'alipay_root_path' => '/path/to/alipayRootCert.crt',
+    'alipay_cert_path' => '/path/to/alipayPublicCert.crt',
+    'sign_type'        => 'RSA2',
+    'notify_url'       => 'https://your-domain.com/alipay/notify',
+    'return_url'       => 'https://your-domain.com/alipay/return',
+];
 ```
 
-* 更多功能请阅读测试代码或SDK封装源码
+## ❓ 常见问题
 
-## 版权说明
+### Q: 如何获取微信支付证书?
+
+A: 登录微信商户平台,在"账户中心" -> "API 安全" -> "API 证书"中下载证书文件,或使用 API 证书下载工具。
+
+### Q: 支付宝沙箱环境如何配置?
+
+A: 设置 `debug => true` 并使用沙箱环境的 `appid` 和密钥即可。
+
+### Q: AccessToken 过期怎么办?
+
+A: SDK 已内置自动刷新机制,无需手动处理。如需自定义,可设置 `GetAccessTokenCallback` 回调函数。
+
+### Q: 如何自定义缓存存储?
+
+A: 配置 `\WeChat\Contracts\Tools::$cache_callable` 数组,实现自定义的缓存逻辑。
+
+### Q: 支持哪些 PHP 版本?
+
+A: 最低支持 PHP 5.4,建议使用 PHP 7.0+ 以获得最佳性能。
+
+### Q: 如何处理支付回调?
+
+A: 使用 `\WeChat\Receive` 类处理微信支付回调,使用 `\AliPay\Web` 的 `notify()` 方法处理支付宝回调。
+
+### Q: 小程序数据解密失败?
+
+A: 确保 `session_key` 有效且未过期,检查 `iv` 和 `encryptedData` 参数是否正确。
+
+### Q: 如何调试接口调用?
+
+A: 开启错误日志,查看具体的错误信息。SDK 会抛出详细的异常信息帮助定位问题。
+
+### Q: 如何在常驻内存框架中使用?
+
+A: SDK 会自动清理 CURL 缓存文件,无需额外配置。在常驻内存环境中,建议通过自定义缓存驱动(`\WeChat\Contracts\Tools::$cache_callable`)使用 Redis 等外部缓存,避免文件缓存带来的问题。
+
+## 📁 文件说明
+
+| 文件名               | 类名                  | 描述             | 类型    | 加载方法                      |
+|-------------------|---------------------|----------------|-------|---------------------------|
+| **支付宝支付**         |                     |                |       |                           |
+| App.php           | AliPay\App          | 支付宝 App 支付     | 支付宝支付 | \We::AliPayApp()          |
+| Bill.php          | AliPay\Bill         | 支付宝账单下载        | 支付宝支付 | \We::AliPayBill()         |
+| Pos.php           | AliPay\Pos          | 支付宝刷卡支付        | 支付宝支付 | \We::AliPayPos()          |
+| Scan.php          | AliPay\Scan         | 支付宝扫码支付        | 支付宝支付 | \We::AliPayScan()         |
+| Transfer.php      | AliPay\Transfer     | 支付宝转账          | 支付宝支付 | \We::AliPayTransfer()     |
+| Wap.php           | AliPay\Wap          | 支付宝 Wap 支付     | 支付宝支付 | \We::AliPayWap()          |
+| Web.php           | AliPay\Web          | 支付宝 Web 支付     | 支付宝支付 | \We::AliPayWeb()          |
+| **微信公众号**         |                     |                |       |                           |
+| Card.php          | WeChat\Card         | 微信卡券接口支持       | 认证服务号 | \We::WeChatCard()         |
+| Custom.php        | WeChat\Custom       | 微信客服消息接口支持     | 认证服务号 | \We::WeChatCustom()       |
+| Draft.php         | WeChat\Draft        | 微信草稿箱          | 认证服务号 | \We::WeChatDraft()        |
+| Freepublish.php   | WeChat\Freepublish  | 微信发布能力         | 认证服务号 | \We::WeChatFreepublish()  |
+| Media.php         | WeChat\Media        | 微信媒体素材接口支持     | 认证服务号 | \We::WeChatMedia()        |
+| Menu.php          | WeChat\Menu         | 微信菜单管理         | 认证服务号 | \We::WeChatMenu()         |
+| Oauth.php         | WeChat\Oauth        | 微信网页授权消息类接口    | 认证服务号 | \We::WeChatOauth()        |
+| Pay.php           | WeChat\Pay          | 微信支付类接口        | 认证服务号 | \We::WeChatPay()          |
+| Product.php       | WeChat\Product      | 微信商店类接口        | 认证服务号 | \We::WeChatProduct()      |
+| Qrcode.php        | WeChat\Qrcode       | 微信二维码接口支持      | 认证服务号 | \We::WeChatQrcode()       |
+| Receive.php       | WeChat\Receive      | 微信推送事件消息处理支持   | 认证服务号 | \We::WeChatReceive()      |
+| Scan.php          | WeChat\Scan         | 微信扫一扫接口支持      | 认证服务号 | \We::WeChatScan()         |
+| Script.php        | WeChat\Script       | 微信前端 JSSDK 支持  | 认证服务号 | \We::WeChatScript()       |
+| Shake.php         | WeChat\Shake        | 微信蓝牙设备揺一揺接口    | 认证服务号 | \We::WeChatShake()        |
+| Tags.php          | WeChat\Tags         | 微信粉丝标签接口支持     | 认证服务号 | \We::WeChatTags()         |
+| Template.php      | WeChat\Template     | 微信模板消息接口支持     | 认证服务号 | \We::WeChatTemplate()     |
+| User.php          | WeChat\User         | 微信粉丝管理接口支持     | 认证服务号 | \We::WeChatUser()         |
+| Wifi.php          | WeChat\Wifi         | 微信门店 WIFI 管理支持 | 认证服务号 | \We::WeChatWifi()         |
+| **微信支付**          |                     |                |       |                           |
+| Bill.php          | WePay\Bill          | 微信商户账单及评论      | 微信支付  | \We::WePayBill()          |
+| Coupon.php        | WePay\Coupon        | 微信商户代金券        | 微信支付  | \We::WePayCoupon()        |
+| Order.php         | WePay\Order         | 微信商户订单         | 微信支付  | \We::WePayOrder()         |
+| Redpack.php       | WePay\Redpack       | 微信红包支持         | 微信支付  | \We::WePayRedpack()       |
+| Refund.php        | WePay\Refund        | 微信商户退款         | 微信支付  | \We::WePayRefund()        |
+| Transfers.php     | WePay\Transfers     | 微信商户打款到零钱      | 微信支付  | \We::WePayTransfers()     |
+| TransfersBank.php | WePay\TransfersBank | 微信商户打款到银行卡     | 微信支付  | \We::WePayTransfersBank() |
+| **微信小程序**         |                     |                |       |                           |
+| Crypt.php         | WeMini\Crypt        | 微信小程序数据加密处理    | 微信小程序 | \We::WeMiniCrypt()        |
+| Delivery.php      | WeMini\Delivery     | 小程序即时配送        | 微信小程序 | \We::WeMiniDelivery()     |
+| Guide.php         | WeMini\Guide        | 小程序导购助手        | 微信小程序 | \We::WeMiniGuide()        |
+| Image.php         | WeMini\Image        | 小程序图像处理        | 微信小程序 | \We::WeMiniImage()        |
+| Live.php          | WeMini\Live         | 小程序直播接口        | 微信小程序 | \We::WeMiniLive()         |
+| Logistics.php     | WeMini\Logistics    | 小程序物流助手        | 微信小程序 | \We::WeMiniLogistics()    |
+| Message.php       | WeMini\Message      | 小程序动态消息        | 微信小程序 | \We::WeMiniMessage()      |
+| Newtmpl.php       | WeMini\Newtmpl      | 小程序订阅消息        | 微信小程序 | \We::WeMiniNewtmpl()      |
+| Ocr.php           | WeMini\Ocr          | 小程序 ORC 服务     | 微信小程序 | \We::WeMiniOcr()          |
+| Operation.php     | WeMini\Operation    | 小程序运维中心        | 微信小程序 | \We::WeMiniOperation()    |
+| Plugs.php         | WeMini\Plugs        | 微信小程序插件管理      | 微信小程序 | \We::WeMiniPlugs()        |
+| Poi.php           | WeMini\Poi          | 小程序地址管理        | 微信小程序 | \We::WeMiniPoi()          |
+| Qrcode.php        | WeMini\Qrcode       | 微信小程序二维码管理     | 微信小程序 | \We::WeMiniQrcode()       |
+| Scheme.php        | WeMini\Scheme       | 小程序 URL-Scheme | 微信小程序 | \We::WeMiniScheme()       |
+| Search.php        | WeMini\Search       | 小程序搜索          | 微信小程序 | \We::WeMiniSearch()       |
+| Security.php      | WeMini\Security     | 小程序内容安全        | 微信小程序 | \We::WeMiniSecurity()     |
+| Shipping.php      | WeMini\Shipping     | 小程序发货信息        | 微信小程序 | \We::WeMiniShipping()     |
+| Soter.php         | WeMini\Soter        | 小程序生物认证        | 微信小程序 | \We::WeMiniSoter()        |
+| Template.php      | WeMini\Template     | 微信小程序模板消息支持    | 微信小程序 | \We::WeMiniTemplate()     |
+| Total.php         | WeMini\Total        | 微信小程序数据接口      | 微信小程序 | \We::WeMiniTotal()        |
+
+## 📚 文档资源
+
+### 官方文档
+
+- **微信公众平台**:https://mp.weixin.qq.com/wiki
+- **微信支付文档**:https://pay.weixin.qq.com/wiki/doc/api/index.html
+- **支付宝开放平台**:https://opendocs.alipay.com/
+
+### 项目资源
+
+- **ThinkAdmin**:https://github.com/zoujingli/ThinkAdmin
+- **在线文档**:https://www.kancloud.cn/zoujingli/wechat-developer
+- **技术交流群**:QQ 群 513350915
+
+### 代码仓库
+
+- **GitHub**:https://github.com/zoujingli/WeChatDeveloper(主仓库)
+- **Gitee**:https://gitee.com/zoujingli/WeChatDeveloper(国内镜像)
+- **GitCode**:https://gitcode.com/ThinkAdmin/WeChatDeveloper(国内镜像)
+
+## 🛡️ 安全说明
+
+本项目经过全面的安全加固,包括:
+
+- 输入验证和 XSS 防护
+- 文件操作安全检查
+- 加密算法安全升级
+- 序列化数据验证
+- 类型安全修复
+
+建议在生产环境中:
+
+- 定期更新到最新版本
+- 配置 HTTPS 传输
+- 设置适当的文件权限
+- 监控异常访问日志
+
+## 📄 版权说明
 
 **WeChatDeveloper** 遵循 **MIT** 开源协议发布,并免费提供使用。
 
@@ -341,6 +971,8 @@ try {
 
 版权所有 Copyright © 2014-2025 by ThinkAdmin (https://thinkadmin.top) All rights reserved。
 
-## 赞助打赏,请作者喝杯茶 ~
+## 💝 赞助支持
+
+如果这个项目对您有帮助,欢迎赞助支持!
 
 ![赞助](https://thinkadmin.top/static/img/pay.png)