From 2c711e5480f51c2c231d21ac65e42ae7ca950370 Mon Sep 17 00:00:00 2001 From: "as2252258@163.com" Date: Wed, 17 Jul 2019 17:27:31 +0800 Subject: [PATCH] add clear --- test.php | 22 +++++++++++++++++++++- wx/Config.php | 19 ++++++++++++++++++- wx/Message.php | 28 ++++------------------------ wx/Miniprogarampage.php | 8 +++++++- wx/Template.php | 9 ++++----- wx/WxClient.php | 6 +++--- 6 files changed, 57 insertions(+), 35 deletions(-) diff --git a/test.php b/test.php index 541402a..28af3f6 100644 --- a/test.php +++ b/test.php @@ -18,7 +18,8 @@ $config->setAppsecret(''); $config->setMchId(''); $config->setKey(''); $config->setRemoteAddr(''); -$config-> +$config->setDeviceInfo(''); +$config->setAccessToken(''); $instance = \wchat\Wx::getMiniProGaRamPage(); @@ -26,4 +27,23 @@ $instance->setConfig($config); $recharge = $instance->getRecharge(); $recharge->cashWithdrawal(1, 'xxx', 'ooo'); +$recharge->recharge(1, '', ''); +$account = $instance->getAccount(); +$account->setSavePath(''); +$account->login(''); +$account->createwxaqrcode('pages/index/index',200); +$account->getwxacode('pages/index/index',150,true); +$account->getwxacodeunlimit('pages/index/index',150,true); + + +$message = $instance->getMessage(); +$message->setOpenid(''); +$message->sendCardNews(''); + +$template = $instance->getTemplate(); +$template->setOpenId(''); +$template->setFormId(''); +$template->setTemplateId(''); +$template->setPage(''); +$template->sendTemplate(); diff --git a/wx/Config.php b/wx/Config.php index 5d143d7..644b9d4 100644 --- a/wx/Config.php +++ b/wx/Config.php @@ -69,7 +69,7 @@ class Config * * 异步回调地址 */ - private $notify_url = "https://game-slave-trade-api.zhuangb123.com/recharge/notify"; + private $notify_url = ""; /** * @var string @@ -106,6 +106,23 @@ class Config * @var string */ private $key = ''; + private $access_token = ''; + + /** + * @return string + */ + public function getAccessToken(): string + { + return $this->access_token; + } + + /** + * @param string $access_token + */ + public function setAccessToken(string $access_token) + { + $this->access_token = $access_token; + } /** * @param string $remote_addr diff --git a/wx/Message.php b/wx/Message.php index 05e73f5..29bbee4 100644 --- a/wx/Message.php +++ b/wx/Message.php @@ -6,7 +6,6 @@ namespace wchat; class Message extends Miniprogarampage { - const TEXT = 0; const IMAGE = 1; const VOICE = 2; @@ -16,20 +15,9 @@ class Message extends Miniprogarampage const MINIPROGRAMPAGE = 6; const WXCARD = 7; - - private $type = self::TEXT; - private $openid = ''; private $msgData = []; - private $token = ''; - /** - * @param int $type - */ - public function setType(int $type) - { - $this->type = $type; - } /** * @param string $openid @@ -40,15 +28,6 @@ class Message extends Miniprogarampage $this->msgData['touser'] = $openid; } - /** - * @param string $token - */ - public function setToken(string $token) - { - $this->token = $token; - } - - /** * @param string $content * @return Result @@ -216,10 +195,11 @@ class Message extends Miniprogarampage throw new \Exception('暂不支持的文件类型'); } + $token = $this->getAccessToken(); if ($isPermanent) { - $url = "https://api.weixin.qq.com/cgi-bin/material/add_material?access_token={$this->token}&type={$type}"; + $url = "https://api.weixin.qq.com/cgi-bin/material/add_material?access_token={$token}&type={$type}"; } else { - $url = "https://api.weixin.qq.com/cgi-bin/media/upload?access_token={$this->token}&type={$type}"; + $url = "https://api.weixin.qq.com/cgi-bin/media/upload?access_token={$token}&type={$type}"; } $mime = mime_content_type($filePath); @@ -275,7 +255,7 @@ class Message extends Miniprogarampage { $data = json_encode($this->msgData, JSON_UNESCAPED_UNICODE); - $url = '/cgi-bin/message/custom/send?access_token=' . $this->token; + $url = '/cgi-bin/message/custom/send?access_token=' . $this->getAccessToken(); $this->request->setMethod(WxClient::POST); /** @var Result $body */ diff --git a/wx/Miniprogarampage.php b/wx/Miniprogarampage.php index 9ac5ec1..4261d9b 100644 --- a/wx/Miniprogarampage.php +++ b/wx/Miniprogarampage.php @@ -51,6 +51,10 @@ abstract class Miniprogarampage */ protected function getAccessToken() { + $access = $this->config->getAccessToken(); + if (!empty($access)) { + return $access; + } $this->request->setMethod(WxClient::GET); $data = $this->request->get('/cgi-bin/token', [ 'grant_type' => 'client_credential', @@ -60,7 +64,9 @@ abstract class Miniprogarampage if (!$data->isResultsOK()) { throw new \Exception($data->getMessage()); } - return $data->getData('access_token'); + $access = $data->getData('access_token'); + $this->config->setAccessToken($access); + return $access; } /** diff --git a/wx/Template.php b/wx/Template.php index 5872687..30b9cb8 100644 --- a/wx/Template.php +++ b/wx/Template.php @@ -111,23 +111,22 @@ class Template extends Miniprogarampage } /** - * @param string $access * @return Result * @throws \Exception * * 奴隶交易通知 */ - public function sendTemplate(string $access) + public function sendTemplate() { - $url = $this->sendUrl . '?access_token=' . $access; + $url = $this->sendUrl . '?access_token=' . $this->getAccessToken(); - $params = [ + $params = json_encode([ "touser" => $this->openId, "template_id" => $this->templateId, "page" => $this->page, "form_id" => $this->formId, "data" => $this->keywords, - ]; + ], JSON_UNESCAPED_UNICODE); if (!empty($this->emphasis_keyword)) { $params['emphasis_keyword'] = $this->emphasis_keyword; diff --git a/wx/WxClient.php b/wx/WxClient.php index 52a53e2..be7a9aa 100644 --- a/wx/WxClient.php +++ b/wx/WxClient.php @@ -171,11 +171,11 @@ class WxClient } switch (strtolower($this->method)) { - case self::POST: - $client->post($url, $data); + case self::GET: + $client->get($url); break; default: - $client->get($url); + $client->post($url, $data); } return $client; }