add clear

This commit is contained in:
as2252258@163.com
2019-11-11 18:14:47 +08:00
parent 62a2326e23
commit 7f138ef255
47 changed files with 2440 additions and 1100 deletions
+75
View File
@@ -0,0 +1,75 @@
<?php
namespace officialaccount;
use common\HttpClient;
use common\Result;
class QrCode extends AfficialAccount
{
private $tick_url = 'https://api.weixin.qq.com/cgi-bin/qrcode/create?access_token=';
private $temporary_url = 'https://mp.weixin.qq.com/cgi-bin/showqrcode';
private $permanent_qr_code_url = 'https://api.weixin.qq.com/cgi-bin/qrcode/create?access_token=';
/**
* @param $scene_id
* @return mixed
* @throws \Exception
*/
public function temporaryQrCode($scene_id)
{
$requestParam['expire_seconds'] = 24 * 3600 * 30;
$requestParam['action_name'] = 'QR_SCENE';
$requestParam['action_info[scene][scene_id]'] = $scene_id;
$tick = $this->get_tick($requestParam);
$client = HttpClient::NewRequest();
return $client->get($this->temporary_url, ['ticket' => $tick]);
}
/**
* @param $scene_id
* @return array|mixed|\common\Result
* @throws \Exception
*/
public function permanent_qr_code($scene_id)
{
$requestParam['action_name'] = 'QR_LIMIT_SCENE';
$requestParam['action_info[scene][scene_id]'] = $scene_id;
$tick = $this->get_tick($requestParam);
$client = HttpClient::NewRequest();
return $client->get($this->permanent_qr_code_url, ['ticket' => $tick]);
}
/**
* @param $requestParam
* @return mixed
* @throws \Exception
* tick
*/
private function get_tick($requestParam)
{
$request = HttpClient::NewRequest();
$request->setCallback(function ($body) {
if (is_array($body)) {
$param = ['code' => $body['errcode'], 'message' => $body['errmsg'], 'data' => $body];
} else {
$param = ['code' => 0, 'data' => json_decode($body, true)];
}
return new Result($param);
});
$data = $request->post($this->tick_url . $this->config->getAccessToken(), json_encode($requestParam));
if (!$data->isResultsOK()) {
throw new \Exception($data->getMessage());
}
return $data->getData('ticket');
}
}