<?php
namespace Addons\QyWechat\Services;

use Services\Service;
use Models\BaseModel as Model;
class Oauth2JsSdk extends Service
{
    //生成OAuth2的URL
    public function oauth2_authorize($AppId,$redirect_url, $scope, $state = NULL){
        $url = "https://open.weixin.qq.com/connect/oauth2/authorize?appid=".$AppId
            ."&redirect_uri=".$redirect_url
            ."&response_type=code&scope=".$scope."&state=".$state."#wechat_redirect";
        return $url;
    }

    //生成OAuth2的Access Token
    public function oauth2_access_token($AppId,$AppSecret,$code){
        $url = "https://api.weixin.qq.com/sns/oauth2/access_token?appid="
            .$AppId."&secret="
            .$AppSecret."&code="
            .$code."&grant_type=authorization_code";
        $res = curlGet($url);
        return json_decode($res, true);
    }
	
    public function oauth2_user_info($access_token,$openid){
        $url = 'https://api.weixin.qq.com/sns/userinfo?access_token='.$access_token.'&openid='.$openid.'&lang=zh_CN';
        $res = curlGet($url);
        return json_decode($res, true);
    }
}
