package com.wechat.controller;

import java.io.IOException;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RequestParam;

import com.alibaba.fastjson.JSON;
import com.wechat.common.Constants;
import com.wechat.common.utils.MvcUtil;
import com.wechat.global.base.BaseController;
import com.wechat.global.message.InfoMsg;
import com.wechat.model.dto.AuzAccesTokenDto;
import com.wechat.model.responseDto.JsonResp;
import com.wechat.service.AuthorizedService;


@Controller
@RequestMapping("account")
public class AuthorizedController extends BaseController {
	
    // 微信静默授权
    @Autowired
    private AuthorizedService auzService;

    /**
     * 授权获取用户信息
     * 
     * @param code
     * @return
     */
 /*   @RequestMapping(value = "getOpenid", method = RequestMethod.GET)
    public void getOpenid(@RequestParam String code, HttpServletRequest request, HttpServletResponse response) throws Exception {
        JsonResp<String> resp = new JsonResp<String>();

        AuzAccesTokenDto auzAccesTokenDto = auzService.getAccessTokenDto(code);
        if(auzAccesTokenDto == null)
        {
            resp.setResult(Constants.RESULT_WARNING);
            resp.setMsg(InfoMsg.ERROR_AUZ_FAILED);
        }
        else
        {
            resp.setInfo(auzAccesTokenDto.getOpenid());
        }

        String json = JSON.toJSONString(resp, true);
        try {
            MvcUtil.writeJson(request, response, json);
        } catch (IOException e) {
            // TODO Auto-generated catch block
           log.error(e);
        }

    }*/
    
}
