From 70222819b96a240d9c99ceb8a5ac923be122cfef Mon Sep 17 00:00:00 2001 From: xl Date: Tue, 14 Nov 2023 14:10:36 +0800 Subject: [PATCH] eee --- wx/Account.php | 37 ++++++++--------- wx/ContentAsyncCheck.php | 10 ++--- wx/Message.php | 80 ++++++++++++++++++------------------- wx/Notify.php | 4 +- wx/PublicTemplate.php | 36 ++++++++--------- wx/SecCheck.php | 8 ++-- wx/V3/WxV3AppPayment.php | 4 +- wx/V3/WxV3NativePayment.php | 18 ++++----- wx/V3/WxV3Payment.php | 4 +- wx/V3/WxV3PaymentNotify.php | 28 ++++++------- wx/V3/WxV3PaymentTait.php | 16 ++++---- wx/V3/WxV3Withdrawal.php | 13 ++++-- wx/WxFactory.php | 4 +- 13 files changed, 133 insertions(+), 129 deletions(-) diff --git a/wx/Account.php b/wx/Account.php index 091e3b9..7ff48d1 100644 --- a/wx/Account.php +++ b/wx/Account.php @@ -15,10 +15,10 @@ class Account extends SmallProgram { /** - * @param $code + * @param string $code * @return Result */ - public function login($code): Result + public function login(string $code): Result { $param['appid'] = $this->payConfig->appId; $param['secret'] = $this->payConfig->appSecret; @@ -29,10 +29,10 @@ class Account extends SmallProgram } /** - * @param $code + * @param string $code * @return Result */ - public function AppLogin($code): Result + public function AppLogin(string $code): Result { $param['appid'] = $this->payConfig->pay->wx->appId; $param['secret'] = $this->payConfig->pay->wx->appSecret; @@ -43,11 +43,10 @@ class Account extends SmallProgram } /** - * @param $openid + * @param string $openid * @return Result - * @throws Exception */ - public function getPublicUserInfo($openid): Result + public function getPublicUserInfo(string $openid): Result { $query = [ 'access_token' => $this->payConfig->getAccessToken(), @@ -58,11 +57,10 @@ class Account extends SmallProgram } /** - * @param $openid + * @param string $openid * @return Result - * @throws Exception */ - public function getAppUserInfo($openid): Result + public function getAppUserInfo(string $openid): Result { $query = [ 'access_token' => $this->payConfig->getAccessToken(), @@ -73,12 +71,11 @@ class Account extends SmallProgram /** - * @param $path - * @param $width + * @param string $path + * @param int $width * @return array|mixed|Result - * @throws Exception */ - public function createwxaqrcode($path, $width): mixed + public function createwxaqrcode(string $path, int $width): mixed { $url = 'cgi-bin/wxaapp/createwxaqrcode?access_token='; $sendBody['path'] = $path; @@ -89,14 +86,14 @@ class Account extends SmallProgram /** - * @param $path - * @param $width + * @param string $path + * @param int $width * @param bool $is_hyaline * @param bool $auto_color * @param string $line_color * @return Result */ - public function getwxacode($path, $width, bool $is_hyaline = false, bool $auto_color = false, string $line_color = ''): Result + public function getwxacode(string $path, int $width, bool $is_hyaline = false, bool $auto_color = false, string $line_color = ''): Result { $sendBody['path'] = $path; $sendBody['width'] = $width; @@ -112,14 +109,14 @@ class Account extends SmallProgram /** - * @param $path - * @param $width + * @param string $path + * @param int $width * @param bool $is_hyaline * @param bool $auto_color * @param string $line_color * @return Result */ - public function getwxacodeunlimit($path, $width, bool $is_hyaline = false, bool $auto_color = false, string $line_color = ''): Result + public function getwxacodeunlimit(string $path, int $width, bool $is_hyaline = false, bool $auto_color = false, string $line_color = ''): Result { $sendBody['path'] = $path; $sendBody['width'] = $width; diff --git a/wx/ContentAsyncCheck.php b/wx/ContentAsyncCheck.php index 0185050..f983c0d 100644 --- a/wx/ContentAsyncCheck.php +++ b/wx/ContentAsyncCheck.php @@ -114,11 +114,11 @@ class ContentAsyncCheck return $class->init($params); } - /** - * @param $params - * @return $this - */ - private function init($params): static + /** + * @param array $params + * @return $this + */ + private function init(array $params): static { foreach ($params as $item => $param) { $this->{'_' . $item} = $param; diff --git a/wx/Message.php b/wx/Message.php index 508521b..40e09eb 100644 --- a/wx/Message.php +++ b/wx/Message.php @@ -19,19 +19,19 @@ class Message extends SmallProgram /** - * @param $openid + * @param string $openid */ - public function setOpenid($openid) + public function setOpenid(string $openid) { $this->msgData['touser'] = $openid; } /** - * @param $content + * @param string $content * @return Result * @throws Exception */ - public function sendTextNews($content): Result + public function sendTextNews(string $content): Result { $this->msgData['msgtype'] = 'text'; $this->msgData['text'] = ['content' => $content]; @@ -40,11 +40,11 @@ class Message extends SmallProgram } /** - * @param $media_id + * @param string $media_id * @return Result * @throws Exception */ - public function sendImageNews($media_id): Result + public function sendImageNews(string $media_id): Result { $this->msgData['msgtype'] = 'image'; $this->msgData['image'] = ['media_id' => $media_id]; @@ -54,11 +54,11 @@ class Message extends SmallProgram /** - * @param $media_id + * @param string $media_id * @return Result * @throws Exception */ - public function sendVoiceNews($media_id): Result + public function sendVoiceNews(string $media_id): Result { $this->msgData['msgtype'] = 'voice'; $this->msgData['voice'] = ['media_id' => $media_id]; @@ -67,11 +67,11 @@ class Message extends SmallProgram } /** - * @param $media_id + * @param string $media_id * @return Result * @throws Exception */ - public function sendMpNewsNews($media_id): Result + public function sendMpNewsNews(string $media_id): Result { $this->msgData['msgtype'] = 'mpnews'; $this->msgData['mpnews'] = ['media_id' => $media_id]; @@ -81,14 +81,14 @@ class Message extends SmallProgram /** - * @param $title - * @param $description - * @param $url - * @param $picurl + * @param string $title + * @param string $description + * @param string $url + * @param string $picurl * @return Result * @throws Exception */ - public function sendNewsNews($title, $description, $url, $picurl): Result + public function sendNewsNews(string $title, string $description, string $url, string $picurl): Result { $this->msgData['msgtype'] = 'news'; $this->msgData['news'] = [ @@ -106,11 +106,11 @@ class Message extends SmallProgram /** - * @param $title + * @param string $title * @return Result * @throws Exception */ - public function sendCardNews($title): Result + public function sendCardNews(string $title): Result { $this->msgData['msgtype'] = 'wxcard'; $this->msgData['wxcard'] = ['card_id' => $title]; @@ -120,14 +120,14 @@ class Message extends SmallProgram /** - * @param $media_id - * @param $thumb_media_id - * @param $title - * @param $description + * @param string $media_id + * @param string $thumb_media_id + * @param string $title + * @param string $description * @return Result * @throws Exception */ - public function sendVideoNews($media_id, $thumb_media_id, $title, $description): Result + public function sendVideoNews(string $media_id, string $thumb_media_id, string $title, string $description): Result { $this->msgData['msgtype'] = 'video'; $this->msgData['video'] = [ @@ -143,15 +143,15 @@ class Message extends SmallProgram /** - * @param $musicurl - * @param $hqmusicurl - * @param $thumb_media_id - * @param $title - * @param $description + * @param string $musicurl + * @param string $hqmusicurl + * @param string $thumb_media_id + * @param string $title + * @param string $description * @return Result * @throws Exception */ - public function sendMusicNews($musicurl, $hqmusicurl, $thumb_media_id, $title, $description): Result + public function sendMusicNews(string $musicurl, string $hqmusicurl, string $thumb_media_id, string $title, string $description): Result { $this->msgData['msgtype'] = 'music'; $this->msgData['music'] = [ @@ -166,13 +166,13 @@ class Message extends SmallProgram /** - * @param $head_content - * @param $tail_content + * @param string $head_content + * @param string $tail_content * @param array $menus * @return Result * @throws Exception */ - public function sendMenuNews($head_content, $tail_content, array $menus = []): Result + public function sendMenuNews(string $head_content, string $tail_content, array $menus = []): Result { $this->msgData['msgtype'] = 'msgmenu'; $this->msgData['msgmenu'] = [ @@ -191,11 +191,11 @@ class Message extends SmallProgram private int $index = 0; /** - * @param $id - * @param $menuName + * @param string $id + * @param string $menuName * @return $this */ - public function addNewsMenu($id, $menuName): static + public function addNewsMenu(string $id, string $menuName): static { $lists['id'] = $id; $lists['content'] = $menuName; @@ -205,14 +205,14 @@ class Message extends SmallProgram } /** - * @param $title - * @param $appid - * @param $pagepath - * @param $thumb_media_id + * @param string $title + * @param string $appid + * @param string $pagepath + * @param string $thumb_media_id * @return Result * @throws Exception */ - public function sendMiniprogrampageNews($title, $appid, $pagepath, $thumb_media_id): Result + public function sendMiniprogrampageNews(string $title, string $appid, string $pagepath, string $thumb_media_id): Result { $this->msgData['msgtype'] = 'msgmenu'; $this->msgData['miniprogrampage'] = [ @@ -270,7 +270,7 @@ class Message extends SmallProgram * @return Result * @throws Exception */ - private function sendKefuMsg() + private function sendKefuMsg(): Result { $url = '/cgi-bin/message/custom/send?access_token=' . $this->payConfig->getAccessToken(); return $this->post('api.weixin.qq.com', $url, $this->msgData); diff --git a/wx/Notify.php b/wx/Notify.php index 7d21d52..3455492 100644 --- a/wx/Notify.php +++ b/wx/Notify.php @@ -76,7 +76,7 @@ class Notify extends SmallProgram * @param $value * @return void */ - public function __set(string $name, $value): void + public function __set(string $name, mixed $value): void { if (property_exists($this, $name)) { $this->$name = $value; @@ -94,7 +94,7 @@ class Notify extends SmallProgram unset($params['sign']); $signType = $this->payConfig->getSignType(); - $privateKey = $this->payConfig->getKey(); + $privateKey = $this->payConfig->pay->wx->secret; $nowSign = Help::sign($params, $privateKey, $signType); if ($sign === $nowSign) { return true; diff --git a/wx/PublicTemplate.php b/wx/PublicTemplate.php index 13fc230..dbfc584 100644 --- a/wx/PublicTemplate.php +++ b/wx/PublicTemplate.php @@ -33,46 +33,46 @@ class PublicTemplate extends SmallProgram } /** - * @param $templateId + * @param string $templateId */ - public function setTemplateId($templateId) + public function setTemplateId(string $templateId) { $this->templateId = $templateId; } /** - * @param $openId + * @param string $openId */ - public function setOpenId($openId) + public function setOpenId(string $openId) { $this->openId = $openId; } /** - * @param $defaultUrl + * @param string $defaultUrl */ - public function setDefaultUrl($defaultUrl) + public function setDefaultUrl(string $defaultUrl) { $this->defaultUrl = $defaultUrl; } /** - * @param $name - * @param $context + * @param string $name + * @param string $context * @param string $color */ - public function replaceKeyword($name, $context, string $color = '') + public function replaceKeyword(string $name, string $context, string $color = '') { $this->keywords[$name] = ['value' => $context, 'color' => $color]; } /** - * @param $name - * @param $context + * @param string $name + * @param string $context * @param null $color */ - public function addKeyword($name, $context, $color = null) + public function addKeyword(string $name, string $context, $color = null) { if (empty($color)) { $color = '#000'; @@ -84,11 +84,11 @@ class PublicTemplate extends SmallProgram } /** - * @param $context + * @param string $context * @param string $color * @return void */ - public function setFirst($context, string $color = '#f00'): void + public function setFirst(string $context, string $color = '#f00'): void { $this->first = [ 'value' => $context, @@ -97,11 +97,11 @@ class PublicTemplate extends SmallProgram } /** - * @param $context + * @param string $context * @param string $color * @return void */ - public function setRemark($context, string $color = '#000'): void + public function setRemark(string $context, string $color = '#000'): void { $this->remark = [ 'value' => $context, @@ -110,11 +110,11 @@ class PublicTemplate extends SmallProgram } /** - * @param $appid + * @param string $appid * @param string $pagepath * @return void */ - public function setMiniprogram($appid, string $pagepath): void + public function setMiniprogram(string $appid, string $pagepath): void { $this->miniprogram = [ 'appid' => $appid, diff --git a/wx/SecCheck.php b/wx/SecCheck.php index 807e385..b3d1549 100644 --- a/wx/SecCheck.php +++ b/wx/SecCheck.php @@ -55,20 +55,20 @@ class SecCheck extends SmallProgram /** - * @param $params + * @param array $params * @return ContentAsyncCheck|null */ - public function readByEvent($params): ?ContentAsyncCheck + public function readByEvent(array $params): ?ContentAsyncCheck { return ContentAsyncCheck::instance($params); } /** - * @param $content + * @param string $content * @return Result */ - public function text($content): Result + public function text(string $content): Result { if (empty($content)) { return $this->sendError('文件不存在', 404); diff --git a/wx/V3/WxV3AppPayment.php b/wx/V3/WxV3AppPayment.php index 6899978..26cb385 100644 --- a/wx/V3/WxV3AppPayment.php +++ b/wx/V3/WxV3AppPayment.php @@ -14,14 +14,14 @@ class WxV3AppPayment extends SmallProgram /** - * @param $orderNo + * @param string $orderNo * @param int $total * @param string|null $openId * @param string $payer_client_ip * @return array * @throws Exception */ - public function payment($orderNo, int $total, string $openId = NULL, string $payer_client_ip = '127.0.0.1'): array + public function payment(string $orderNo, int $total, string $openId = NULL, string $payer_client_ip = '127.0.0.1'): array { $body = $this->getInitCore($orderNo, $total); diff --git a/wx/V3/WxV3NativePayment.php b/wx/V3/WxV3NativePayment.php index 5ac1884..4bc5e49 100644 --- a/wx/V3/WxV3NativePayment.php +++ b/wx/V3/WxV3NativePayment.php @@ -14,16 +14,16 @@ class WxV3NativePayment extends SmallProgram use WxV3PaymentTait; - /** - * @param $orderNo - * @param int $total - * @param string|null $openId - * @param string $payer_client_ip - * @return array - * @throws Exception - */ + /** + * @param string $orderNo + * @param int $total + * @param string|null $openId + * @param string $payer_client_ip + * @return array + * @throws Exception + */ #[ArrayShape(['code_url' => "string"])] - public function payment($orderNo, int $total, string $openId = NULL, string $payer_client_ip = '127.0.0.1'): array + public function payment(string $orderNo, int $total, string $openId = NULL, string $payer_client_ip = '127.0.0.1'): array { $body = $this->getInitCore($orderNo, $total); diff --git a/wx/V3/WxV3Payment.php b/wx/V3/WxV3Payment.php index 6e0f982..66e2cf9 100644 --- a/wx/V3/WxV3Payment.php +++ b/wx/V3/WxV3Payment.php @@ -14,14 +14,14 @@ class WxV3Payment extends SmallProgram /** - * @param $orderNo + * @param string $orderNo * @param int $total * @param string|null $openId * @param string $payer_client_ip * @return array * @throws Exception */ - public function payment($orderNo, int $total, string $openId = NULL, string $payer_client_ip = '127.0.0.1'): array + public function payment(string $orderNo, int $total, string $openId = NULL, string $payer_client_ip = '127.0.0.1'): array { $body = $this->getInitCore($orderNo, $total); $body['payer'] = ['openid' => $openId]; diff --git a/wx/V3/WxV3PaymentNotify.php b/wx/V3/WxV3PaymentNotify.php index 2e9e631..d792ded 100644 --- a/wx/V3/WxV3PaymentNotify.php +++ b/wx/V3/WxV3PaymentNotify.php @@ -30,12 +30,12 @@ class WxV3PaymentNotify extends SmallProgram * @param array $resource */ public function __construct( - public string $id = "EV-2018022511223320873", - public string $create_time = "2015-05-20T13:29:35+08:00", - public string $resource_type = "encrypt-resource", - public string $event_type = "TRANSACTION.SUCCESS", - public string $summary = "支付成功", - public array $resource = [] + public string $id = "EV-2018022511223320873", + public string $create_time = "2015-05-20T13:29:35+08:00", + public string $resource_type = "encrypt-resource", + public string $event_type = "TRANSACTION.SUCCESS", + public string $summary = "支付成功", + public array $resource = [] ) { } @@ -93,10 +93,10 @@ class WxV3PaymentNotify extends SmallProgram /** * @param string $message * @param string $signature - * @param $publicKey + * @param OpenSSLAsymmetricKey $publicKey * @return bool */ - protected function notifyVerify(string $message, string $signature, $publicKey): bool + protected function notifyVerify(string $message, string $signature, OpenSSLAsymmetricKey $publicKey): bool { if (($result = openssl_verify($message, base64_decode($signature), $publicKey, OPENSSL_ALGO_SHA256)) === false) { throw new \UnexpectedValueException('Verified the input $message failed, please checking your $publicKey whether or nor correct.'); @@ -106,11 +106,11 @@ class WxV3PaymentNotify extends SmallProgram /** - * @param $thing + * @param string $thing * @param string $type * @return OpenSSLAsymmetricKey */ - protected function rsaFrom($thing, string $type = KEY_TYPE_PRIVATE): OpenSSLAsymmetricKey + protected function rsaFrom(string $thing, string $type = KEY_TYPE_PRIVATE): OpenSSLAsymmetricKey { $pkey = (($isPublic = $type === KEY_TYPE_PUBLIC) ? openssl_pkey_get_public(file_get_contents($thing)) : openssl_pkey_get_private(file_get_contents($thing))); if (false === $pkey) { @@ -120,12 +120,12 @@ class WxV3PaymentNotify extends SmallProgram } /** - * @param $ciphertext - * @param $nonce - * @param $associated_data + * @param string $ciphertext + * @param string $nonce + * @param string $associated_data * @return bool */ - public function decode($ciphertext, $nonce, $associated_data): bool + public function decode(string $ciphertext, string $nonce, string $associated_data): bool { $data = $this->decrypt($ciphertext, $this->payConfig->pay->wx->secret, $nonce, $associated_data); $this->notifyModel = new NotifyModel(); diff --git a/wx/V3/WxV3PaymentTait.php b/wx/V3/WxV3PaymentTait.php index f0ea982..f38e8f9 100644 --- a/wx/V3/WxV3PaymentTait.php +++ b/wx/V3/WxV3PaymentTait.php @@ -21,11 +21,11 @@ trait WxV3PaymentTait { /** - * @param $orderNo - * @param $total + * @param string $orderNo + * @param int $total * @return array */ - public function getInitCore($orderNo, $total): array + public function getInitCore(string $orderNo, int $total): array { $payConfig = $this->getPayConfig(); if ($payConfig->typeIsApp()) { @@ -87,10 +87,10 @@ trait WxV3PaymentTait /** - * @param $body + * @param string $body * @return string */ - public function openssl_signature($body): string + public function openssl_signature(string $body): string { $payConfig = $this->getPayConfig(); @@ -102,11 +102,11 @@ trait WxV3PaymentTait /** - * @param $json - * @param $body + * @param array $json + * @param array $body * @return array */ - private function createResponse($json, $body): array + private function createResponse(array $json, array $body): array { $responseArray['appId'] = $body['appid']; $responseArray['timeStamp'] = (string)time(); diff --git a/wx/V3/WxV3Withdrawal.php b/wx/V3/WxV3Withdrawal.php index 2438a52..76e3799 100644 --- a/wx/V3/WxV3Withdrawal.php +++ b/wx/V3/WxV3Withdrawal.php @@ -15,14 +15,14 @@ class WxV3Withdrawal extends SmallProgram /** - * @param $orderNo + * @param string $orderNo * @param string $batch_name * @param string $batch_remark * @param TransferDetail[] $details * @return array * @throws Exception */ - public function payment($orderNo, string $batch_name, string $batch_remark, array $details): array + public function payment(string $orderNo, string $batch_name, string $batch_remark, array $details): array { $body = $this->create($orderNo, $batch_name, $batch_remark, $details); @@ -41,8 +41,15 @@ class WxV3Withdrawal extends SmallProgram } + /** + * @param string $orderNo + * @param string $batch_name + * @param string $batch_remark + * @param array $details + * @return array[] + */ #[ArrayShape(['transfer_detail_list' => "array", 'total_amount' => "int", 'total_num' => "int", 'batch_remark' => "string", 'batch_name' => "string", 'out_batch_no' => ""])] - private function create($orderNo, string $batch_name, string $batch_remark, array $details): array + private function create(string $orderNo, string $batch_name, string $batch_remark, array $details): array { $total = 0; $body = ['transfer_detail_list' => []]; diff --git a/wx/WxFactory.php b/wx/WxFactory.php index af6cb3f..0ed253d 100644 --- a/wx/WxFactory.php +++ b/wx/WxFactory.php @@ -11,12 +11,12 @@ class WxFactory /** - * @param $class + * @param string $class * @param AppConfig $config * @return object|null * @throws ReflectionException */ - public static function get($class, AppConfig $config): ?object + public static function get(string $class, AppConfig $config): ?object { $container = Container::instance(); $object = $container->get($class);