1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27
| package com.white.mvc.controller;
import lombok.extern.slf4j.Slf4j; import org.springframework.stereotype.Controller; import org.springframework.web.bind.annotation.GetMapping; import org.springframework.web.bind.annotation.RequestMapping; import org.springframework.web.bind.annotation.RequestParam; import org.springframework.web.bind.annotation.RestController; import org.springframework.web.client.RestTemplate;
import javax.swing.plaf.basic.BasicInternalFrameTitlePane; @Controller @RestController @RequestMapping("weixin") @Slf4j public class WeixinController { @GetMapping("/auth") public String auth(@RequestParam("code") String code){ System.out.println("进入auth方法"); System.out.println("code="+code); String url ="https://api.weixin.qq.com/sns/oauth2/access_token?appid=wx44beca8ea3d45813&secret=91bef154d8d8bb1aafae026173a44c9b&code=" + code +"&grant_type=authorization_code"; RestTemplate restTemplate = new RestTemplate(); String response = restTemplate.getForObject(url,String.class); System.out.println(response); return "index"; } }
|