diff --git a/app/api/controller/Wxserver.php b/app/api/controller/Wxserver.php index f73968c7..54cb4d0b 100644 --- a/app/api/controller/Wxserver.php +++ b/app/api/controller/Wxserver.php @@ -10,8 +10,12 @@ class Wxserver extends BaseController public function index() { $obj = new \app\common\library\wxserver\Server(); - $data = $obj->getQrcode('wxe3ed157849bd07b5'); - return $this->renderSuccess($data); + $img = $obj->getQrcode('wxe3ed157849bd07b5'); + $img_url = ''; + if ($img) { + $img_url = $this->request->domain(true) . $img; + } + return $this->renderSuccess(compact($img_url)); } public function verifyTicket() diff --git a/app/common/library/wxserver/Server.php b/app/common/library/wxserver/Server.php index 9fdc6175..c1ae621e 100644 --- a/app/common/library/wxserver/Server.php +++ b/app/common/library/wxserver/Server.php @@ -142,6 +142,9 @@ class Server $info = $info->toArray(); $access_token = $this->authorizerAccessToken($appid, $info['refresh_token']); if ($access_token) { + $savePath = root_path() . "public/wxserve/experience"; + !is_dir($savePath) && mkdir($savePath, 0755, true); + $savePath .= '/' . $appid . 'jpg'; $url = 'https://api.weixin.qq.com/wxa/get_qrcode?access_token=' . $access_token; $ch = curl_init(); curl_setopt($ch, CURLOPT_URL, $url); @@ -150,12 +153,12 @@ class Server curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, false); // 同上 $qrcode_response = curl_exec($ch); curl_close($ch); - $qrcode_response = json_decode($qrcode_response, true); - var_dump($url); - exit(); + if (file_put_contents($savePath, $qrcode_response)) { + return '/wxserve/experience/' . $appid . '.jpg'; + } } } - return []; + return ''; } /**