package com.cftech.pay.api.testeropenid;

import com.alibaba.fastjson.JSONObject;
import com.cftech.pay.weixin.kit.HttpUtilKit;
import lombok.extern.slf4j.Slf4j;
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.ResponseBody;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;

/**
 * Created by user on 2017/5/12.
 */
@Controller
@Slf4j
@RequestMapping("/mobile/api")
public class GetOpenIdController {


    @RequestMapping(value = "/getOpenId")
    @ResponseBody
    public void showOpenId(String code, String qq,HttpServletRequest request, HttpServletResponse response)
    {
        String URL="https://api.weixin.qq.com/sns/oauth2/access_token?appid=wx82576a6142b4e6ee&secret=ea00ff2d00839c3702309000e4f47b7e&code="+code+"&grant_type=authorization_code";
        try {
            String xmlStr = HttpUtilKit.doGet(URL);
            System.out.println(xmlStr);
            JSONObject json = JSONObject.parseObject(xmlStr);
            response.getWriter().print(json.toString());
            response.getWriter().close();
        } catch (IOException e) {
            e.printStackTrace();
        }

    }


}
