zoukankan      html  css  js  c++  java
  • Spring-Security-OAuth2调用微信API

    class WeixinClientCredentialsAccessTokenProvider extends ClientCredentialsAccessTokenProvider {

    public WeixinClientCredentialsAccessTokenProvider() {

    List<HttpMessageConverter<?>> converters = new ArrayList<HttpMessageConverter<?>>();

    converters.add(new MappingJackson2HttpMessageConverter());

    this.setMessageConverters(converters);

    this.setTokenRequestEnhancer(new RequestEnhancer() {

    @Override

    public void enhance(AccessTokenRequest request, OAuth2ProtectedResourceDetails resource,

     

    MultiValueMap<String, String> form, HttpHeaders headers) {

    form.set("appid", resource.getClientId());

    form.set("secret", resource.getClientSecret());

    form.set("grant_type", "client_credential");

    }

    });

    }

     

    }

    OAuth2ClientContext context = new DefaultOAuth2ClientContext();

    ClientCredentialsResourceDetails resource = new ClientCredentialsResourceDetails();

    resource.setClientId("xxxxxxxxx");

    resource.setClientSecret("xxxxxxxxxxxxxxx");

    resource.setAccessTokenUri("https://api.weixin.qq.com/cgi-bin/token");

    resource.setAuthenticationScheme(AuthenticationScheme.form);

    OAuth2RestTemplate restTemplate = new OAuth2RestTemplate(resource, context);

    restTemplate.setAccessTokenProvider(new WeixinClientCredentialsAccessTokenProvider());

    restTemplate.setRetryBadAccessTokens(true);

    ResponseEntity<Object> response = restTemplate.getForEntity("https://api.weixin.qq.com/cgi-bin/user/get", Object.class);

    if (response.getStatusCode() == HttpStatus.OK) {

    System.out.println(response.getBody());

    }

  • 相关阅读:
    changing a pointer rather than erasing memory cells
    验证码识别 edge enhancement 轮廓增强 region finding 区域查找
    Manipulating Data Structures
    passing parameters by value is inefficient when the parameters represent large blocks of data
    Aliasing 走样
    Artificial Intelligence Research Methodologies 人工智能研究方法
    Thread safety
    include pointers as a primitive data type
    flat file
    functional cohesion
  • 原文地址:https://www.cnblogs.com/kingsy/p/6375880.html
Copyright © 2011-2022 走看看