diff --git a/base/Subject.php b/base/Subject.php index 41335b5..01dce8b 100644 --- a/base/Subject.php +++ b/base/Subject.php @@ -16,185 +16,185 @@ abstract class Subject extends Multiprogramming { - private array $keywords = []; - private string $templateId = ''; - private string $openId = ''; - private string $page = 'pages/index/index'; - private string $emphasis_keyword = ''; - private string $oac_appid = ''; - private string $use_robot = ''; + private array $keywords = []; + private string $templateId = ''; + private string $openId = ''; + private string $page = 'pages/index/index'; + private string $emphasis_keyword = ''; + private string $oac_appid = ''; + private string $use_robot = ''; - /** - * @param array $keywords - */ - public function setKeywords(array $keywords) - { - $this->keywords = $keywords; - } + /** + * @param array $keywords + */ + public function setKeywords(array $keywords) + { + $this->keywords = $keywords; + } - /** - * @param $templateId - */ - public function setTemplateId($templateId) - { - $this->templateId = $templateId; - } + /** + * @param $templateId + */ + public function setTemplateId($templateId) + { + $this->templateId = $templateId; + } - /** - * @param $openId - */ - public function setOpenId($openId) - { - $this->openId = $openId; - } + /** + * @param $openId + */ + public function setOpenId($openId) + { + $this->openId = $openId; + } - /** - * @param $page - */ - public function setPage($page) - { - $this->page = $page; - } + /** + * @param $page + */ + public function setPage($page) + { + $this->page = $page; + } - /** - * @param $emphasis_keyword - */ - public function setEmphasisKeyword($emphasis_keyword) - { - $this->emphasis_keyword = $emphasis_keyword; - } + /** + * @param $emphasis_keyword + */ + public function setEmphasisKeyword($emphasis_keyword) + { + $this->emphasis_keyword = $emphasis_keyword; + } - /** - * @param $index - * @param $context - * @param string $color - */ - public function replaceKeyword($index, $context, string $color = '') - { - if (empty($color)) { - $color = '#000'; - } - $this->keywords['keyword' . $index] = [ - 'value' => $context, - 'color' => $color - ]; - } + /** + * @param $index + * @param $context + * @param string $color + */ + public function replaceKeyword($index, $context, string $color = '') + { + if (empty($color)) { + $color = '#000'; + } + $this->keywords['keyword' . $index] = [ + 'value' => $context, + 'color' => $color + ]; + } - /** - * @param $color - * @param $context - */ - public function addKeyword($context, $color = null) - { - if (empty($color)) { - $color = '#000'; - } - $this->keywords['keyword' . (count($this->keywords) + 1)] = [ - 'value' => $context, - 'color' => $color - ]; - } + /** + * @param $color + * @param $context + */ + public function addKeyword($context, $color = null) + { + if (empty($color)) { + $color = '#000'; + } + $this->keywords['keyword' . (count($this->keywords) + 1)] = [ + 'value' => $context, + 'color' => $color + ]; + } - abstract public function getUrl(); + abstract public function getUrl(); - abstract public function getHost(); + abstract public function getHost(); - /** - * @return string - */ - public function getOacAppid(): string - { - return $this->oac_appid; - } + /** + * @return string + */ + public function getOacAppid(): string + { + return $this->oac_appid; + } - /** - * @param string $oac_appid - */ - public function setOacAppid(string $oac_appid): void - { - $this->oac_appid = $oac_appid; - } + /** + * @param string $oac_appid + */ + public function setOacAppid(string $oac_appid): void + { + $this->oac_appid = $oac_appid; + } - /** - * @return string - */ - public function getUseRobot(): string - { - return $this->use_robot; - } + /** + * @return string + */ + public function getUseRobot(): string + { + return $this->use_robot; + } - /** - * @param string $use_robot - */ - public function setUseRobot(string $use_robot): void - { - $this->use_robot = $use_robot; - } + /** + * @param string $use_robot + */ + public function setUseRobot(string $use_robot): void + { + $this->use_robot = $use_robot; + } - /** - * @return Result - * @throws \Exception - */ - public function sendTemplate(): Result - { - $access_token = $this->config->getAccessToken(); - if (empty($access_token)) { - throw new \Exception('request access_token con\'t null.'); - } - $params = [ - "touser" => $this->openId, - "template_id" => $this->templateId, - "page" => $this->page, - "data" => $this->keywords, - ]; - if (!empty($this->emphasis_keyword)) { - $params['emphasis_keyword'] = $this->emphasis_keyword; - } - if (!empty($this->oac_appid)) { - $params['oac_appid'] = $this->oac_appid; - } - if (!empty($this->use_robot)) { - $params['use_robot'] = $this->use_robot; - } - $this->reset($result); + /** + * @return Result + * @throws \Exception + */ + public function sendTemplate(): Result + { + $access_token = $this->payConfig->getAccessToken(); + if (empty($access_token)) { + throw new \Exception('request access_token con\'t null.'); + } + $params = [ + "touser" => $this->openId, + "template_id" => $this->templateId, + "page" => $this->page, + "data" => $this->keywords, + ]; + if (!empty($this->emphasis_keyword)) { + $params['emphasis_keyword'] = $this->emphasis_keyword; + } + if (!empty($this->oac_appid)) { + $params['oac_appid'] = $this->oac_appid; + } + if (!empty($this->use_robot)) { + $params['use_robot'] = $this->use_robot; + } + $this->reset($result); - $client = new Client($this->getHost(), 443, true); - $client->withHeader(['Content-Type' => 'application/json; charset=utf-8']); + $client = new Client($this->getHost(), 443, true); + $client->withHeader(['Content-Type' => 'application/json; charset=utf-8']); - $proxyHost = $this->getConfig()->getProxyHost(); - $proxyPort = $this->getConfig()->getProxyPort(); + $proxyHost = $this->payConfig->getProxyHost(); + $proxyPort = $this->payConfig->getProxyPort(); if (!empty($proxyHost) && $proxyPort > 0) { $client->withProxyHost($proxyHost)->withProxyPort($proxyPort); } $client->post($this->getUrl() . '?access_token=' . $access_token, $params); - $client->close(); + $client->close(); - if (!in_array($client->getStatusCode(), [101, 200, 201])) { - return new Result(code: 505, message: $client->getBody()); - } - $body = json_decode($client->getBody(), true); - if (isset($body['errcode']) && $body['errcode'] != 0) { - return new Result(code: $body['errcode'], message: $body['errmsg']); - } else { - return new Result(code: 0, data: $body); - } - } + if (!in_array($client->getStatusCode(), [101, 200, 201])) { + return new Result(code: 505, message: $client->getBody()); + } + $body = json_decode($client->getBody(), true); + if (isset($body['errcode']) && $body['errcode'] != 0) { + return new Result(code: $body['errcode'], message: $body['errmsg']); + } else { + return new Result(code: 0, data: $body); + } + } - /** - * @param $result - * @return mixed - */ - public function reset($result) - { - $this->openId = ''; - $this->keywords = []; - $this->templateId = ''; - $this->page = ''; + /** + * @param $result + * @return mixed + */ + public function reset($result) + { + $this->openId = ''; + $this->keywords = []; + $this->templateId = ''; + $this->page = ''; - return $result; - } + return $result; + } } diff --git a/base/Template.php b/base/Template.php index 2483a2f..3cf4782 100644 --- a/base/Template.php +++ b/base/Template.php @@ -68,11 +68,11 @@ abstract class Template extends Multiprogramming $this->emphasis_keyword = $emphasis_keyword; } - /** - * @param $index - * @param $context - * @param $color - */ + /** + * @param $index + * @param $context + * @param string $color + */ public function replaceKeyword($index, $context, string $color = '') { if (empty($color)) { @@ -112,7 +112,7 @@ abstract class Template extends Multiprogramming */ public function sendTemplate(): Result { - $access_token = $this->config->getAccessToken(); + $access_token = $this->payConfig->getAccessToken(); if (empty($access_token)) { throw new \Exception('request access_token con\'t null.'); } @@ -134,8 +134,8 @@ abstract class Template extends Multiprogramming $client = new Client($this->getHost(), 443, true); $client->withHeader(['Content-Type' => 'application/json; charset=utf-8']); - $proxyHost = $this->getConfig()->getProxyHost(); - $proxyPort = $this->getConfig()->getProxyPort(); + $proxyHost = $this->payConfig->getProxyHost(); + $proxyPort = $this->payConfig->getProxyPort(); if (!empty($proxyHost) && $proxyPort > 0) { $client->withProxyHost($proxyHost)->withProxyPort($proxyPort); } diff --git a/common/Multiprogramming.php b/common/Multiprogramming.php index 21a75ac..056c0aa 100644 --- a/common/Multiprogramming.php +++ b/common/Multiprogramming.php @@ -18,9 +18,6 @@ abstract class Multiprogramming implements Progaram protected string $errorMsg = ''; - protected string $host = 'api.weixin.qq.com'; - - /** * @var AppConfig */ @@ -87,49 +84,54 @@ abstract class Multiprogramming implements Progaram /** + * @param string $host * @param string $requestUrl * @param mixed $body * @param string $contentType * @return Result */ - protected function post(string $requestUrl, mixed $body, string $contentType = 'application/application'): Result + protected function post(string $host, string $requestUrl, mixed $body, string $contentType = 'application/application'): Result { - return $this->request('post', $requestUrl, $body, $contentType); + return $this->request($host, 'post', $requestUrl, $body, $contentType); } /** + * @param string $host + * @param string $requestUrl + * @param mixed $body + * @param string $contentType + * @return Result + */ + protected function get(string $host, string $requestUrl, mixed $body, string $contentType = 'application/application'): Result + { + return $this->request($host, 'get', $requestUrl, $body, $contentType); + } + + + /** + * @param string $host * @param string $requestUrl * @param mixed $body * @return Result */ - protected function get(string $requestUrl, mixed $body, string $contentType = 'application/application'): Result + protected function upload(string $host, string $requestUrl, mixed $body): Result { - return $this->request('get', $requestUrl, $body, $contentType); - } - - - /** - * @param string $requestUrl - * @param mixed $body - * @return Result - */ - protected function upload(string $requestUrl, mixed $body): Result - { - return $this->request('upload', $requestUrl, $body); + return $this->request($host, 'upload', $requestUrl, $body); } /** + * @param string $host * @param string $method * @param string $requestUrl * @param $body * @param string $contentType * @return Result */ - private function request(string $method, string $requestUrl, $body, string $contentType = 'application/application'): Result + private function request(string $host, string $method, string $requestUrl, $body, string $contentType = 'application/application'): Result { - $client = new Client($this->host, 443, true); + $client = new Client($host, 80, true); $proxyHost = $this->payConfig->getProxyHost(); $proxyPort = $this->payConfig->getProxyPort(); if (!empty($proxyHost) && $proxyPort > 0) { diff --git a/qq/Account.php b/qq/Account.php index a1e900e..7dfff53 100644 --- a/qq/Account.php +++ b/qq/Account.php @@ -25,7 +25,24 @@ class Account extends SmallProgram $param['js_code'] = $code; $param['grant_type'] = 'authorization_code'; - return $this->get('/sns/jscode2session', $param); + return $this->get('api.q.qq.com', '/sns/jscode2session', $param); + } + + + /** + * @param string $code + * @return Result + */ + public function appLogin(string $code): Result + { + $param['appid'] = $this->payConfig->appId; + $param['secret'] = $this->payConfig->appSecret; + $param['js_code'] = $code; + $param['grant_type'] = 'authorization_code'; + + $this->host = 'graph.qq.com'; + + return $this->get('api.q.qq.com', '/user/get_user_info', $param); } } diff --git a/qq/Recharge.php b/qq/Recharge.php index dea1bda..6a48c92 100644 --- a/qq/Recharge.php +++ b/qq/Recharge.php @@ -51,7 +51,7 @@ class Recharge extends SmallProgram $this->orderNo = $orderNo; $this->data['openid'] = $openId; - return $this->post($this->uniformer, $this->builder(), 'application/xml'); + return $this->post('api.q.qq.com', $this->uniformer, $this->builder(), 'application/xml'); } diff --git a/qq/Redhat.php b/qq/Redhat.php index eae16cb..fe4b748 100644 --- a/qq/Redhat.php +++ b/qq/Redhat.php @@ -299,11 +299,10 @@ class Redhat extends SmallProgram { $client = new Client('api.qpay.qq.com', 443, true); $client->withHeader(['Content-Type' => 'application/x-www-form-urlencoded']); - $client->withSslKeyFile($this->payConfig->getSslKey()); - $client->withSslCertFile($this->payConfig->getSslCert()); - $client->withCa($this->payConfig->getSslCa()); - $proxyHost = $this->getConfig()->getProxyHost(); - $proxyPort = $this->getConfig()->getProxyPort(); + $client->withSslKeyFile($this->payConfig->pay->wx->mchKey); + $client->withSslCertFile($this->payConfig->pay->wx->mchCert); + $proxyHost = $this->payConfig->getProxyHost(); + $proxyPort = $this->payConfig->getProxyPort(); if (!empty($proxyHost) && $proxyPort > 0) { $client->withProxyHost($proxyHost)->withProxyPort($proxyPort); } @@ -332,15 +331,15 @@ class Redhat extends SmallProgram public function searchByOrderNo($listid, $orderNo = null): Result { $requestParam['nonce_str'] = Help::random(31); - $requestParam['mch_id'] = $this->payConfig->getMchId(); + $requestParam['mch_id'] = $this->payConfig->pay->wx->mchId; $requestParam['listid'] = $listid; if (!empty($orderNo)) { $requestParam['mch_billno'] = $orderNo; } $requestParam['sign'] = $this->builderSign($requestParam); $client = new Client('qpay.qq.com', 443, true); - $proxyHost = $this->getConfig()->getProxyHost(); - $proxyPort = $this->getConfig()->getProxyPort(); + $proxyHost = $this->payConfig->getProxyHost(); + $proxyPort = $this->payConfig->getProxyPort(); if (!empty($proxyHost) && $proxyPort > 0) { $client->withProxyHost($proxyHost)->withProxyPort($proxyPort); } diff --git a/qq/SecCheck.php b/qq/SecCheck.php index e4646a0..55d9822 100644 --- a/qq/SecCheck.php +++ b/qq/SecCheck.php @@ -35,7 +35,7 @@ class SecCheck extends SmallProgram 'form-data[filename]' => $path, 'form-data[content-type]' => $real_path->getMimeType() ]; - return $this->upload($path, $data); + return $this->upload('api.q.qq.com', $this->_url, $data); } @@ -48,9 +48,9 @@ class SecCheck extends SmallProgram if (empty($content)) { return $this->sendError('文件不存在', 404); } - $url = '/' . ltrim($this->_url, '/') . $this->payConfig->getAccessToken(); + $url = '/' . ltrim($this->_msgUrl, '/') . $this->payConfig->getAccessToken(); - return $this->post($url, ['appid' => $this->payConfig->appId, 'content' => $content]); + return $this->post('api.q.qq.com', $url, ['appid' => $this->payConfig->appId, 'content' => $content]); } } diff --git a/qq/Token.php b/qq/Token.php index 71f7107..97aed79 100644 --- a/qq/Token.php +++ b/qq/Token.php @@ -20,7 +20,7 @@ class Token extends SmallProgram 'appid' => $this->payConfig->appId, 'secret' => $this->payConfig->appSecret ]; - return $this->get('/api/getToken', $query); + return $this->get('api.q.qq.com', '/api/getToken', $query); } } diff --git a/wx/Account.php b/wx/Account.php index 09ac317..091e3b9 100644 --- a/wx/Account.php +++ b/wx/Account.php @@ -9,7 +9,6 @@ namespace wchat\wx; use Exception; -use wchat\common\Decode; use wchat\common\Result; class Account extends SmallProgram @@ -26,7 +25,7 @@ class Account extends SmallProgram $param['js_code'] = $code; $param['grant_type'] = 'authorization_code'; - return $this->get('/sns/jscode2session', $param); + return $this->get('api.weixin.qq.com', '/sns/jscode2session', $param); } /** @@ -40,7 +39,7 @@ class Account extends SmallProgram $param['js_code'] = $code; $param['grant_type'] = 'authorization_code'; - return $this->get('/sns/oauth2/access_token', $param); + return $this->get('api.weixin.qq.com', '/sns/oauth2/access_token', $param); } /** @@ -55,7 +54,7 @@ class Account extends SmallProgram 'openid' => $openid, 'lang' => 'zh_CN' ]; - return $this->get('/cgi-bin/user/info', $query); + return $this->get('api.weixin.qq.com', '/cgi-bin/user/info', $query); } /** @@ -69,33 +68,7 @@ class Account extends SmallProgram 'access_token' => $this->payConfig->getAccessToken(), 'openid' => $openid, ]; - return $this->get('/sns/userinfo', $query); - } - - - /** - * @param $encryptedData - * @param $iv - * @param $sessionKey - * @param bool $asArray - * @return object|array - * @throws - * - * *