package com.icloud.server.wxserver;

import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.client.RestTemplate;

@RestController
@RequestMapping("/weixin")
@Slf4j
public class WeixinController {

    @GetMapping("/auth/{goodsid}")
    public void auth(@RequestParam("code") String code,@PathVariable("goodsid") Integer goodsid){
        String appid="wx3c42b420d22aacbf";
        String appsecret="2f755b9edde90d8405285410475c82f1";
        System.out.println("goodsid:"+goodsid);
        log.info("进入了auth方法...");
        log.info("code = {}",code);
        String url = "https://api.weixin.qq.com/sns/oauth2/access_token?appid="+appid+"&secret="+appsecret+"&code=" + code + "&grant_type=authorization_code";
        RestTemplate restTemplate = new RestTemplate();
        String response = restTemplate.getForObject(url, String.class);
        System.out.println(response);
    }

}
