All Downloads are FREE. Search and download functionalities are using the official Maven repository.

com.quhaodian.user.oauth.impl.WeiAppOauthHandler Maven / Gradle / Ivy

There is a newer version: 1.8.7
Show newest version
package com.quhaodian.user.oauth.impl;

import com.quhaodian.user.oauth.api.OauthHandler;
import com.quhaodian.user.oauth.domain.TokenResponse;
import com.quhaodian.user.oauth.domain.WeiApp;
import com.quhaodian.utils.http.Connection;
import com.quhaodian.utils.http.HttpConnection;
import com.google.gson.Gson;

/**
 * Created by ada on 2017/6/29.
 */
public class WeiAppOauthHandler implements OauthHandler {

    private String   oauth_consumer_key;
    private String   secret;

    @Override
    public void setKey(String oauth_consumer_key) {
        this.oauth_consumer_key = oauth_consumer_key;
    }

    @Override
    public void setSecret(String secret) {
        this.secret=secret;
    }

    @Override
    public WeiApp login(String access_token, String openid) {
        WeiApp weixin=null;
        try {
            Connection con = HttpConnection.connect("https://api.weixin.qq.com/sns/jscode2session");
            con.data("js_code", access_token);
            con.data("appid", oauth_consumer_key);
            con.data("secret", secret);
            String body;
            body = con.execute().body();
            Gson gson = new Gson();
            weixin=gson.fromJson(body,WeiApp.class);
        } catch (Exception e) {
            e.printStackTrace();
        }
        return weixin;

    }

    @Override
    public TokenResponse getToken(String code) {
        return null;
    }
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy