44 lines
956 B
PHP
44 lines
956 B
PHP
<?php
|
|
/**
|
|
* Created by PhpStorm.
|
|
* User: whwyy
|
|
* Date: 2018/4/19 0019
|
|
* Time: 16:12
|
|
*/
|
|
|
|
namespace wchat\qq;
|
|
|
|
use Kiri\Client;
|
|
use wchat\common\Result;
|
|
|
|
class Account extends SmallProgram
|
|
{
|
|
|
|
/**
|
|
* @param string $code
|
|
* @return Result
|
|
*/
|
|
public function login(string $code): Result
|
|
{
|
|
$param['appid'] = $this->config->getAppid();
|
|
$param['secret'] = $this->config->getAppsecret();
|
|
$param['js_code'] = $code;
|
|
$param['grant_type'] = 'authorization_code';
|
|
|
|
$client = new Client('api.q.qq.com', 443, true);
|
|
$client->withHeader(['Content-Type' => 'application/json']);
|
|
|
|
$proxyHost = $this->getConfig()->getProxyHost();
|
|
$proxyPort = $this->getConfig()->getProxyPort();
|
|
if (!empty($proxyHost) && $proxyPort > 0) {
|
|
$client->withProxyHost($proxyHost)->withProxyPort($proxyPort);
|
|
}
|
|
|
|
$client->get('sns/jscode2session', $param);
|
|
$client->close();
|
|
|
|
return Result::init($client);
|
|
}
|
|
|
|
}
|