Files
kiri-wchat/wchat/qq/Account.php
T

44 lines
956 B
PHP
Raw Normal View History

2019-10-25 15:20:09 +08:00
<?php
/**
* Created by PhpStorm.
* User: whwyy
* Date: 2018/4/19 0019
* Time: 16:12
*/
2020-03-05 12:41:49 +08:00
namespace wchat\qq;
2019-10-25 15:20:09 +08:00
2022-09-09 16:42:55 +08:00
use Kiri\Client;
2020-03-05 12:41:49 +08:00
use wchat\common\Result;
2019-10-25 15:20:09 +08:00
2019-11-11 18:14:47 +08:00
class Account extends SmallProgram
2019-10-25 15:20:09 +08:00
{
2022-09-09 16:42:55 +08:00
2019-10-25 15:20:09 +08:00
/**
2022-09-09 16:42:55 +08:00
* @param string $code
2019-10-25 15:20:09 +08:00
* @return Result
*/
2022-09-09 16:42:55 +08:00
public function login(string $code): Result
2019-10-25 15:20:09 +08:00
{
$param['appid'] = $this->config->getAppid();
$param['secret'] = $this->config->getAppsecret();
$param['js_code'] = $code;
$param['grant_type'] = 'authorization_code';
2022-09-09 16:42:55 +08:00
$client = new Client('api.q.qq.com', 443, true);
$client->withHeader(['Content-Type' => 'application/json']);
2023-11-07 15:13:11 +08:00
$proxyHost = $this->getConfig()->getProxyHost();
$proxyPort = $this->getConfig()->getProxyPort();
if (!empty($proxyHost) && $proxyPort > 0) {
$client->withProxyHost($proxyHost)->withProxyPort($proxyPort);
}
$client->get('sns/jscode2session', $param);
2022-09-09 16:42:55 +08:00
$client->close();
2019-10-25 15:20:09 +08:00
2023-07-11 21:04:33 +08:00
return Result::init($client);
2019-10-25 15:20:09 +08:00
}
}