對獲取的二維碼進行處理獲取 access_token
$url = "https://api.weixin.qq.com/cgi-bin/token?grant_type=client_credential&appid=$appid&secret=$secret";
$result = httpGet($url);
$data = json_decode($result, true);
$access_token = $data['access_token'];
根據介面獲取二維碼
$params = ['path' => "/pages/index/index?PID=" . '2', 'width' => '280'];
$data = json_encode($params);
$url = "https://api.weixin.qq.com/cgi-bin/wxaapp/createwxaqrcode?access_token=" . $access_token;
$response = httpPost($url, $data);
對檔案進行 處理
if (!is_dir('./public/qrcode')) {
mkdir('./public/qrcode', 0777, true);
}
$filePath = "/public/qrcode/" . 'uid-tg-' . $this->user_id . '.png';
$domain = http() . $_SERVER['HTTP_HOST'];
if (file_exists('./public/qrcode/' . 'uid-tg-' . $this->user_id . '.png')) {
$this->ajaxReturn(['code' => 200, 'message' => '推廣二維碼', 'data' => ['path' => $domain . $filePath]]);
}
file_put_contents('./public/qrcode/' . 'uid-tg-' . $this->user_id . '.png', $response);