<?php

namespace App\Services\QQMiniApp;

use Ixudra\Curl\Facades\Curl;

class Login
{


    public const APP_ID = '1109284509';

    public const APP_SECRET = 'ybA99k3beETy1YVu';

    public function code2Session($js_code)
    {
        $url = "https://api.q.qq.com/sns/jscode2session?" . http_build_query([
                "appid" => self::APP_ID,
                "secret" => self::APP_SECRET,
                "js_code" => $js_code,
                "grant_type" => "authorization_code",
            ]);
        $response = Curl::to($url)->asJsonResponse()->get();
        if ($response->errcode == 0) {
            return $response;
        } else {
            throw new QQException($response->errmsg, $response->errcode);
        }
    }
}
