<?php

namespace App\Http\Controllers\Wechat\User;

use App\Http\Requests;
use Illuminate\Http\Request;
use Illuminate\Http\Response;
use EasyWeChat\Foundation\Application;

/**
 * 用户信息
 * @author zhoulingjie
 *
 */
class UserInfosController
{

    public function __construct($_param)
    {
    	$this->param = $_param;
		$this->app = $_param['app'];
		$this->official_account = $this->param['official_account'];
    }
   
    public function get_oauth_user_info($openid,$force_subscribe_sceneId){
    	try{
    		$user_data = $this->app->user->get($openid);
    		v('get_oauth_user_info_user_data:');v($user_data);
    		$data = array();
    		$data['appid'] = isset($this->official_account['appid'])?$this->official_account['appid']:'';
    		$data['official_account_id'] = isset($this->official_account['id'])?$this->official_account['id']:'';
    		$data['distribution_channel_id'] = isset($this->official_account['distribution_channel_id'])?$this->official_account['distribution_channel_id']:'';
    		$data['nick_name'] = isset($user_data['nickname'])?$user_data['nickname']:'';
    		$data['openid'] = isset($user_data['openid'])?$user_data['openid']:'';
    		$data['sex'] = isset($user_data['sex'])?$user_data['sex']:'';
    		$data['city'] = isset($user_data['city'])?$user_data['city']:'';
    		$data['country'] = isset($user_data['country'])?$user_data['country']:'';
    		$data['uid'] = $force_subscribe_sceneId;
    		$data['unionid'] = isset($user_data['unionid'])?$user_data['unionid']:'';
    		$data['province'] = isset($user_data['province'])?$user_data['province']:'';
    		$data['head_img'] = isset($user_data['headimgurl'])?$user_data['headimgurl']:'';
    		$data['is_subscribed'] = isset($user_data['subscribe'])?$user_data['subscribe']:0;
    		$data['subscribe_time'] = isset($user_data['subscribe_time'])?$user_data['subscribe_time']:'';

    	}catch(\Exception $e){
    		v('get_oauth_user_info_ept:'.$e->getMessage());
    	}
    	v('get_oauth_user_info:');v($data);
    	return $data;
    	
    }
    
}