<?php
namespace Base\Domain\lib\WeChatOpen\WeChatLogin\Api;

use PhalApi\Exception\BadRequestException;

/**
 * Class SnsapiUserinfo 获取个人信息
 * @package Base\Domain\Authorization
 */
class Userinfo extends ApiBase {

    //接口
   protected $api = "sns/userinfo?access_token=%s&openid=%s";

    /**
     * 请求api接口
     * @return string
     */
    public function requestApi($access_token, $openid){
        $resultApi = sprintf($this->domainApi.$this->api, $access_token, $openid);
        $result = $this->curl->get($resultApi);
        if (!empty($result)){
            $result = json_decode($result, true);
            //错误码不为空
            if (!empty($result['errcode'])){
                throw new BadRequestException($result['errmsg']);
            }
        }
        return $result;
    }

}
