add clear

This commit is contained in:
2022-09-09 16:42:55 +08:00
parent ad76b45b45
commit 7273fe1ce5
63 changed files with 2625 additions and 5287 deletions
+17 -36
View File
@@ -8,58 +8,39 @@
namespace wchat\qq;
use Kiri\Client;
use wchat\common\Decode;
use wchat\common\HttpClient;
use wchat\common\Result;
class Account extends SmallProgram
{
/**
* @param $code
* @param string $code
* @return Result
*/
public function login($code)
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';
if (empty($code)) {
return new Result(['code' => 404, 'message' => '临时登录凭证不能为空.']);
$client = new Client('api.q.qq.com', 443, true);
$client->withHeader(['Content-Type' => 'application/json']);
$client->get('sns/jscode2session', $param);
$client->close();
if (!in_array($client->getStatusCode(), [101, 200, 201])) {
return new Result(code: 505, message: 'network error.');
}
$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);
}
$this->request->setHost('api.q.qq.com');
$this->request->addHeader('Host', 'api.q.qq.com');
$this->request->setMethod(HttpClient::GET);
$this->request->setIsSSL(true);
$this->request->setUseSwoole($this->config->isUsrSwoole());
return $this->request->get('sns/jscode2session', $param);
}
/**
* @param $encryptedData
* @param $iv
* @param $sessionKey
* @param $asArray
* @return object|array
* @throws
*
* * <li>-41001: encodingAesKey 非法</li>
* <li>-41003: aes 解密失败</li>
* <li>-41004: 解密后得到的buffer非法</li>
* <li>-41005: base64加密失败</li>
* <li>-41016: base64解密失败</li>
*/
public function decode($encryptedData, $iv, $sessionKey, $asArray = false)
{
$decode = new Decode();
$decode->setAppId($this->config->getAppid());
$decode->setIv($iv);
$decode->setEncryptedData($encryptedData);
$decode->setSessionKey($sessionKey);
return $decode->decode($asArray);
}
}