JAVA implementation of the third-party website wechat code scanning login Demo

Using JAVA Servlet to realize the Demo of the third-party website wechat code scanning login, it's really hard to do this, it's not easy to achieve, but it's still done. Here, paste the code to avoid the detour of friends who do wechat login development

package com.wxlogin.common;

import java.net.URLEncoder;

public class ConstantManager {
/*Return status failed*/
public static final String ERROR_STATUS = "999";

/** Return status successful**/
public static final String SUCCESS_STATUS = "000";

/** Failed to return information**/
public static final String ERROR_MESSAGE = "FAILED";

/** Return to status waiting**/
public static final String IN_PROGRESS = "666";

/**Insufficient authority**/
public static final String OAUTH_STATUS = "777";

/** Information returned successfully**/
public static final String SUCCESS_MESSAGE = "SUCCESS";

public static final String RETURNMSG = "returnMsg";

public static final String RETURNSTATUS = "returnStatus";

public static final String RETURNDATA = "returnData";

//User details
public static final String OAUTH_USER_INFO="snsapi_userinfo";

public static final String OAUTH_QQ_USER_INFO="get_user_info";


//Silent authorization
public static final String OAUTH_USER_BASE="snsapi_base";

public static final String GRANT_TYPE="authorization_code";

//Page authorization scope
public static final String OAUTH_WEB_LOGIN="snsapi_login";


public static final String PC="pc";

public static final String WAP="wap";







/*************************************************v2******************************************************/



/**
 * PC Authorized callback
 */
public static final String WEBCALLBACKURL = URLEncoder.encode("http://www.sucaiku.xin/callback/wxCallback.do");

}

package com.wxlogin.common;

import javax.annotation.Resource;

import org.apache.commons.lang3.StringUtils;

import com.wxlogin.common.ConstantManager;;

/**
*
*@ description wechat interface call address configuration
*
* @author tjz
*
*@ time February 23, 2017
*/

public class UrlConfig {

/**
 * Wechat global call accessToken
 * 
 * @return
 */
public String getGlobalAccessTokenUrl(String wxMpAppId,String wxMpAppSecrte) {
    return "https://api.weixin.qq.com/cgi-bin/token?grant_type=client_credential&appid=" + wxMpAppId + "&secret="+ wxMpAppSecrte;
}

/**
 * Wechat server IP list
 * 
 * @return
 */
public String getWeiXinIpUrl(String wxMpAppId,String wxMpAppSecrte,String appId) {
    //return "https://api.weixin.qq.com/cgi-bin/getcallbackip?access_token=" + weiXinUtil.getGlobalAccessToken(wxMpAppId, wxMpAppSecrte,appId);
    return null;
}


/**
 * WeChat authorized
 */
public String getOauth(String type,String redirectUrl,String param,String wxMpAppId) {
    return "https://open.weixin.qq.com/connect/oauth2/authorize?appid=" + wxMpAppId + "&redirect_uri="+ redirectUrl + "&response_type=code&scope=" + type + "&state=" + param + "#wechat_redirect";
}



/**
 * Webpage authorization
 */
public String getOauthAccessToken(String code,String wxMpAppId,String wxMpAppSecret) {
    return "https://api.weixin.qq.com/sns/oauth2/access_token?appid=" + wxMpAppId + "&secret=" + wxMpAppSecret+ "&code=" + code + "&grant_type=" + ConstantManager.GRANT_TYPE;
}

/**
 * Refresh web page authorization accessToken
 */
public String refreshAccessToken(String refreshToken,String wxMpAppId) {
    return "https://api.weixin.qq.com/sns/oauth2/refresh_token?appid=" + wxMpAppId+ "&grant_type=refresh_token&refresh_token=" + refreshToken.trim();
}

/**
 * Wechat user details accessToken: webpage authorization accessToken openId: user openid obtained through authorization
 */
public String getUserInfo(String accessToken, String openId) {
    return "https://api.weixin.qq.com/sns/userinfo?access_token=" + accessToken.trim() + "&openid=" + openId.trim()+ "&lang=zh_CN";
}

/**
 * Get user details through global accessToken
 */
public String getUserInfoByGlobalToken(String globalToken, String openId) {
    return "https://api.weixin.qq.com/cgi-bin/user/info?access_token=" + globalToken + "&openid=" + openId+ "&lang=zh_CN ";
}

/**
 * Long short connection conversion
 */
public String getShortUrl(String accessToken) {
    return "https://api.weixin.qq.com/cgi-bin/shorturl?access_token=" + accessToken;
}

/**
 * Get template list
 */
public String getModelList(String accessToken) {
    return "https://api.weixin.qq.com/cgi-bin/template/get_all_private_template?access_token=" + accessToken;
}

/**
 * Send template message
 */
public String sendModelMessage(String accessToken) {
    return "https://api.weixin.qq.com/cgi-bin/message/template/send?access_token=" + accessToken;
}

/**
 * Get industry information of template settings
 */
public String getModelIndustry(String accessToken) {
    return "https://api.weixin.qq.com/cgi-bin/template/get_industry?access_token=" + accessToken;
}

/**
 * Get jsapi signature
 */
public String getJsApiConfig(String accessToken){
    return "https://api.weixin.qq.com/cgi-bin/ticket/getticket?access_token="+accessToken+"&type=jsapi";
}

/**
 * Get a list of users to follow
 */
public String getUserList(String accessToken,String openId){
    if(StringUtils.isBlank(openId)){
        return "https://api.weixin.qq.com/cgi-bin/user/get?access_token="+accessToken;
    }else{
        return "https://api.weixin.qq.com/cgi-bin/user/get?access_token="+accessToken+"&next_openid="+openId;
    }
}

/**
 * Create QR code ticket
 */
public String createQrcodeTicket(String accessToken){
    return " https://api.weixin.qq.com/cgi-bin/qrcode/create?access_token="+accessToken;
}

/**
 * Get QR code through ticket
 */
public String showQrcode(String ticket){
    return "https://mp.weixin.qq.com/cgi-bin/showqrcode?ticket="+ticket;
}

/**
 * Wechat web login url
 */
public String getWxWebLoginUrl(String type,String redirectUrl,String param,String wxOpenAppId){
    return "https://open.weixin.qq.com/connect/qrconnect?appid="+wxOpenAppId+"&redirect_uri="+redirectUrl+"&response_type=code&scope="+type+"&state="+param+"#wechat_redirect";
}

/**
 * Wechat card package ticket
 */
public String getTicketUrl(String accessToken){
    return "https://api.weixin.qq.com/cgi-bin/ticket/getticket?access_token="+accessToken+"&type=wx_card";
}

/**
 * Add customer service account
 * @description 
 *
 * @author tjz
 *
 * @param accessToken
 * @return
 *
 * @time 2018 9:54:20 am, February 2, 2010
 */
public String addKfAccountUrl(String accessToken){
    return "https://api.weixin.qq.com/customservice/kfaccount/add?access_token="+accessToken;
}


/**
 * Get all customer service accounts
 */
public String getKfListUrl(String accessToken){
    return "https://api.weixin.qq.com/cgi-bin/customservice/getkflist?access_token="+accessToken;
}

/**
 * Send customer service message
 */
public String getSendMessageUrl(String accessToken){
    return "https://api.weixin.qq.com/cgi-bin/message/custom/send?access_token="+accessToken;
}

/**
 * Get QQ login Url
 */
public String getQqLoginUrl(String appId,String callbackUrl,String state,String scope){
    return "https://graph.qq.com/oauth2.0/authorize?response_type=code&client_id="+appId+"&redirect_uri="+callbackUrl+"&state="+state+"&scope="+scope;
}




/**
 * Get PC version QQ login accessToken
 */
public String getQqLoginAccessTokenByPcUrl(String qqAppId,String qqAppKey,String code,String redirectUri){
    return "https://graph.qq.com/oauth2.0/token?grant_type=authorization_code&client_id="+qqAppId+"&client_secret="+qqAppKey+"&code="+code+"&redirect_uri="+redirectUri;
}


/**
 * Get WAP QQ login accessToken
 */
public String getQqLoginAccessTokenByWapUrl(String qqAppId,String qqAppKey,String code,String redirectUri){
    return "https://graph.z.qq.com/moc2/token?grant_type=authorization_code&client_id="+qqAppId+"&client_secret="+qqAppKey+"&code="+code+"&redirect_uri="+redirectUri;
}


/**
 * Refresh pc authorized accessToken
 */
public String refreshPcQqAccessTokenUrl(String qqAppId,String qqAppKey,String refreshToken){
    return "https://graph.qq.com/oauth2.0/token?grant_type=refresh_token&client_id="+qqAppId+"&client_secret="+qqAppKey+"&refresh_token="+refreshToken;
}

/**
 * Refresh wap authorization accessToken
 */
public String refreshWapQqAccessTokenUrl(String qqAppId,String qqAppKey,String refreshToken){
    return "https://graph.z.qq.com/moc2/token?grant_type=refresh_token&client_id="+qqAppId+"&client_secret="+qqAppKey+"&refresh_token="+refreshToken;
}

/**
 * Get PC qq user openId
 */
public String getPcQqUserInfoByAccessTokenUrl(String accessToken){
    return "https://graph.qq.com/oauth2.0/me?access_token="+accessToken;
}

/**
 * Get wap qq user openId
 */
public String getWapQqUserInfoByAccessTokenUrl(String accessToken){
    return "https://graph.z.qq.com/moc2/me?access_token="+accessToken;
}


/**
 * Get QQ user details
 */
public String getQqUserInfoByAccessTokenAndOpenId(String appId,String accessToken,String openId){
    return "https://graph.qq.com/user/get_user_info?access_token="+accessToken+"&oauth_consumer_key="+appId+"&openid="+openId;
}

}
package com.wxlogin.config;

public class WeiXinConfig {

public static String wxOpenAppId = "wx92255d9573d";

public static String wxOpenappSecret = "97d500770006b4b3exh4dh554387e6c";

}
package com.wxlogin.entity;

import java.io.Serializable;

/**
*accessToken object
*
* @author Administrator
*
*/
public class AccessToken implements Serializable {

private static final long serialVersionUID = -3443292138870183363L;

private String access_token;

private String expires_in;

private String refresh_token;

private String openid;

private String scope;

public String getAccess_token() {
    return access_token;
}

public void setAccess_token(String access_token) {
    this.access_token = access_token;
}

public String getExpires_in() {
    return expires_in;
}

public void setExpires_in(String expires_in) {
    this.expires_in = expires_in;
}

public String getRefresh_token() {
    return refresh_token;
}

public void setRefresh_token(String refresh_token) {
    this.refresh_token = refresh_token;
}

public String getOpenid() {
    return openid;
}

public void setOpenid(String openid) {
    this.openid = openid;
}

public String getScope() {
    return scope;
}

public void setScope(String scope) {
    this.scope = scope;
}

}
package com.wxlogin.entity;

import java.io.Serializable;
import java.util.List;

/**
*
*@ description wechat user object
*
* @author tjz
*
*@ time March 12, 2017
*/
public class UserEntity implements Serializable {

private static final long serialVersionUID = -920969954069444740L;

private Integer subscribe;// If the subscriber subscribes to the public number label, the value is 0, which means that the user does not pay attention to the public number and can not get the rest of the information.

private String openid;// The identity of the user is unique to the current public number.

private String nickname;// User's nickname

private Integer sex;// User's gender: male when the value is 1, female when the value is 2, unknown when the value is 0

private String city;// User City

private String country;// User's country

private String province;// User's Province

private String language;// User's language, simplified Chinese is zh cn

private String headimgurl;// The last value represents the size of the square head image (0, 46, 64, 96, 132 values are optional, 0 represents 640 * 640 square head image), which is blank when the user does not have a head image. If the user changes the image, the original image URL will be invalid.

private String subscribe_time;// The user pays attention to the time, which is the time stamp. If the user has paid attention to it several times, the last time of attention shall be taken

private String unionid;// This field will appear only if the user is bound to the WeChat open platform account with the public number.

private String remark;// Public operator's notes on fans, public operators can add notes to fans at WeChat public platform user management interface.

private Integer groupid;// Group ID of the user (compatible with the old user group interface)

private List tagid_list;// List of user's labeled ID

public Integer getSubscribe() {
    return subscribe;
}

public void setSubscribe(Integer subscribe) {
    this.subscribe = subscribe;
}

public String getOpenid() {
    return openid;
}

public void setOpenid(String openid) {
    this.openid = openid;
}

public String getNickname() {
    return nickname;
}

public void setNickname(String nickname) {
    this.nickname = nickname;
}

public Integer getSex() {
    return sex;
}

public void setSex(Integer sex) {
    this.sex = sex;
}

public String getCity() {
    return city;
}

public void setCity(String city) {
    this.city = city;
}

public String getCountry() {
    return country;
}

public void setCountry(String country) {
    this.country = country;
}

public String getProvince() {
    return province;
}

public void setProvince(String province) {
    this.province = province;
}

public String getLanguage() {
    return language;
}

public void setLanguage(String language) {
    this.language = language;
}

public String getHeadimgurl() {
    return headimgurl;
}

public void setHeadimgurl(String headimgurl) {
    this.headimgurl = headimgurl;
}

public String getSubscribe_time() {
    return subscribe_time;
}

public void setSubscribe_time(String subscribe_time) {
    this.subscribe_time = subscribe_time;
}

public String getUnionid() {
    return unionid;
}

public void setUnionid(String unionid) {
    this.unionid = unionid;
}

public String getRemark() {
    return remark;
}

public void setRemark(String remark) {
    this.remark = remark;
}

public Integer getGroupid() {
    return groupid;
}

public void setGroupid(Integer groupid) {
    this.groupid = groupid;
}

public List getTagid_list() {
    return tagid_list;
}

public void setTagid_list(List tagid_list) {
    this.tagid_list = tagid_list;
}

}
package com.wxlogin.servlet;

import java.io.IOException;

import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.apache.commons.lang3.StringUtils;

import com.alibaba.fastjson.JSONObject;
import com.wxlogin.common.UrlConfig;
import com.wxlogin.config.WeiXinConfig;
import com.wxlogin.entity.AccessToken;
import com.wxlogin.entity.UserEntity;
import com.wxlogin.util.HttpUtil;

/**
*Wechat PC code scanning login callback
*
* @description
*
* @author tjz
*
*@ time 3:48:08 PM, September 6, 2018
*/
public class CallbackServlet extends HttpServlet {
private static final long serialVersionUID = 1L;

private UrlConfig urlConfig = new UrlConfig();

public CallbackServlet() {
    super();
}

protected void service(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
    String code = request.getParameter("code");
    String state = request.getParameter("state");
    try {
        String result = HttpUtil.doGet(urlConfig.getOauthAccessToken(code, WeiXinConfig.wxOpenAppId, WeiXinConfig.wxOpenappSecret));
        JSONObject jsonObject = JSONObject.parseObject(result);
        Integer errcode = jsonObject.getInteger("errcode");
        if (errcode != null) {
            System.out.println("Wechat callback failed, authorization terminated!");
            return;
        }
        AccessToken accessToken = JSONObject.toJavaObject(jsonObject, AccessToken.class);
        if (accessToken == null) {
            System.out.println("Wechat callback processing failed! Obtain accessToken No result returned!");
            return;
        }

        JSONObject returnJson = getUserInfoByAccessToken(accessToken.getAccess_token(), accessToken.getOpenid());

        System.out.println("Wechat user information acquisition completed*****************************************");
        System.out.println(returnJson.toJSONString());

        //Here you can get the user information and print it out. You can implement it yourself

    } catch (Exception e) {
        e.printStackTrace();
    }
}

/**
 * Get user information through accessToken
 */
public JSONObject getUserInfoByAccessToken(String accessToken, String openId) {
    System.out.println("adopt accessToken Get user information parameters: accessToken: " + accessToken + "*******parameter openId: " + openId);
    JSONObject returnJson = new JSONObject();
    returnJson.put("code", 1);
    try {
        String result = HttpUtil.doGet(urlConfig.getUserInfo(accessToken, openId));
        if (StringUtils.isBlank(result)) {
            System.out.println("By authorization accessToken Failed to get user information!" + accessToken + "openId:" + openId);
            return null;
        }
        JSONObject jsonObject = JSONObject.parseObject(result);
        Integer errcode = jsonObject.getInteger("errcode");
        if (errcode != null) {
            if ("40001".equals(errcode)) {
                System.out.println("Authorization expired, please re authorize!");
            } else {
                System.out.println("Failed to get user information!" + jsonObject.toJSONString());
            }
            return null;
        }
        UserEntity userEntity = JSONObject.toJavaObject(jsonObject, UserEntity.class);
        returnJson.put("data", userEntity);
        returnJson.put("code", 0);
        returnJson.put("msg", "Successfully obtained wechat user information");
    } catch (Exception e) {
        e.printStackTrace();
        System.out.println("adopt accesstoken Exception in getting user details" + e.getMessage());
    }
    return returnJson;
}

}
package com.wxlogin.servlet;

import java.io.IOException;

import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import com.wxlogin.common.ConstantManager;
import com.wxlogin.common.UrlConfig;
import com.wxlogin.config.WeiXinConfig;

public class WxLoginServlet extends HttpServlet {
private static final long serialVersionUID = 1L;

private UrlConfig urlConfig=new UrlConfig();

public WxLoginServlet() {
    super();
    // TODO Auto-generated constructor stub
}

/**
 * Launch wechat login
 */
protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
    String url = urlConfig.getWxWebLoginUrl(ConstantManager.OAUTH_WEB_LOGIN, ConstantManager.WEBCALLBACKURL, null,WeiXinConfig.wxOpenAppId);
    response.sendRedirect(url);

}


protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
    // TODO Auto-generated method stub
    doGet(request, response);
}

}
package com.wxlogin.util;

import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.io.OutputStream;
import java.io.OutputStreamWriter;
import java.net.HttpURLConnection;
import java.net.InetSocketAddress;
import java.net.Proxy;
import java.net.URL;
import java.net.URLConnection;
import java.util.Iterator;
import java.util.Map;

import org.apache.commons.httpclient.HttpClient;
import org.apache.commons.httpclient.methods.GetMethod;
import org.apache.commons.httpclient.methods.PostMethod;
import org.apache.commons.httpclient.methods.RequestEntity;
import org.apache.commons.httpclient.methods.StringRequestEntity;
import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger;

public class HttpUtil {

private static final Logger logger = LogManager.getLogger(HttpUtil.class);

private static String charset = "utf-8";
private Integer connectTimeout = null;
private Integer socketTimeout = null;
private static String proxyHost = null;
private static Integer proxyPort = null;
private static HttpClient httpClient = null;

private static GetMethod getMethod = null;

private static PostMethod postMethod = null;

/**
 * POST Request json
 * @param url
 * @param params
 * @return
 */
public static String doPostJson(String url, String params,boolean header) {
    try {
        HttpClient httpClient = new HttpClient();
        httpClient.getHttpConnectionManager().getParams().setConnectionTimeout(5000);
        httpClient.getParams().setBooleanParameter("http.protocol.expect-continue", false);
        PostMethod postMethod = new PostMethod(url);
        if(header){
            postMethod.setRequestHeader("Content-Type","application/json");
            postMethod.setRequestHeader("Authorization","Basic YWRtaW46YWRtaW4=");
        }
        if(params != null && !params.trim().equals("")) {
            RequestEntity requestEntity = new StringRequestEntity(params,"application/json","UTF-8");
            postMethod.setRequestEntity(requestEntity);
        }
        postMethod.releaseConnection();
        httpClient.executeMethod(postMethod);
        BufferedReader reader = new BufferedReader(new InputStreamReader(postMethod.getResponseBodyAsStream()));  
        StringBuffer stringBuffer = new StringBuffer();  
        String str = "";  
        while((str = reader.readLine())!=null){  
            stringBuffer.append(str);  
        }
        logger.info("Send out POST_JSON request");
        logger.info("URL: "+url);
        logger.info("Parameters:"+params);
        logger.info("Response results:"+stringBuffer.toString());
        return stringBuffer.toString();
    } catch (Exception e) {
        e.printStackTrace();
    }
    return null;
}

/**
 * Send Get request
 * 
 * @param url
 * @return
 * @throws Exception
 */
public static String doGet(String url) throws Exception {
    URL localURL = new URL(url);
    URLConnection connection = openConnection(localURL);
    HttpURLConnection httpURLConnection = (HttpURLConnection) connection;
    httpURLConnection.setRequestProperty("Accept-Charset", charset);
    httpURLConnection.setRequestProperty("Content-Type", "application/x-www-form-urlencoded");
    InputStream inputStream = null;
    InputStreamReader inputStreamReader = null;
    BufferedReader reader = null;
    StringBuffer resultBuffer = new StringBuffer();
    String tempLine = null;
    if (httpURLConnection.getResponseCode() >= 300) {
        throw new Exception("HTTP Request is not success, Response code is " + httpURLConnection.getResponseCode());
    }
    try {
        inputStream = httpURLConnection.getInputStream();
        inputStreamReader = new InputStreamReader(inputStream, "UTF-8");
        reader = new BufferedReader(inputStreamReader);
        while ((tempLine = reader.readLine()) != null) {
            resultBuffer.append(tempLine);
        }
    } finally {
        if (reader != null) {
            reader.close();
        }
        if (inputStreamReader != null) {
            inputStreamReader.close();
        }
        if (inputStream != null) {
            inputStream.close();
        }
    }
    logger.info("Send out GET request");
    logger.info("URL: "+url);
    logger.info("Response results:"+resultBuffer.toString());
    return resultBuffer.toString();
}

/**
 * Send Post request
 * 
 * @param url
 * @param parameterMap
 * @return
 * @throws Exception
 */
public static String doPost(String url, Map parameterMap) throws Exception {
    StringBuffer parameterBuffer = new StringBuffer();
    if (parameterMap != null) {
        Iterator iterator = parameterMap.keySet().iterator();
        String key = null;
        String value = null;
        while (iterator.hasNext()) {
            key = (String) iterator.next();
            if (parameterMap.get(key) != null) {
                value = (String) parameterMap.get(key);
            } else {
                value = "";
            }
            parameterBuffer.append(key).append("=").append(value);
            if (iterator.hasNext()) {
                parameterBuffer.append("&");
            }
        }
    }
    URL localURL = new URL(url);
    URLConnection connection = openConnection(localURL);
    HttpURLConnection httpURLConnection = (HttpURLConnection) connection;
    httpURLConnection.setDoOutput(true);
    httpURLConnection.setRequestMethod("POST");
    httpURLConnection.setRequestProperty("Accept-Charset", charset);
    httpURLConnection.setRequestProperty("Content-Type", "application/x-www-form-urlencoded");
    httpURLConnection.setRequestProperty("Content-Length", String.valueOf(parameterBuffer.length()));
    OutputStream outputStream = null;
    OutputStreamWriter outputStreamWriter = null;
    InputStream inputStream = null;
    InputStreamReader inputStreamReader = null;
    BufferedReader reader = null;
    StringBuffer resultBuffer = new StringBuffer();
    String tempLine = null;
    try {
        outputStream = httpURLConnection.getOutputStream();
        outputStreamWriter = new OutputStreamWriter(outputStream);
        outputStreamWriter.write(parameterBuffer.toString());
        outputStreamWriter.flush();
        if (httpURLConnection.getResponseCode() >= 300) {
            throw new Exception(
                    "HTTP Request is not success, Response code is " + httpURLConnection.getResponseCode());
        }
        inputStream = httpURLConnection.getInputStream();
        inputStreamReader = new InputStreamReader(inputStream);
        reader = new BufferedReader(inputStreamReader);
        while ((tempLine = reader.readLine()) != null) {
            resultBuffer.append(tempLine);
        }
    } finally {
        if (outputStreamWriter != null) {
            outputStreamWriter.close();
        }
        if (outputStream != null) {
            outputStream.close();
        }
        if (reader != null) {
            reader.close();
        }
        if (inputStreamReader != null) {
            inputStreamReader.close();
        }
        if (inputStream != null) {
            inputStream.close();
        }
    }
    logger.info("Send out POST request");
    logger.info("URL: "+url);
    logger.info("Parameters:"+parameterBuffer.toString());
    logger.info("Response results:"+resultBuffer.toString());
    return resultBuffer.toString();
}

private static URLConnection openConnection(URL localURL) throws IOException {
    URLConnection connection;
    if (proxyHost != null && proxyPort != null) {
        Proxy proxy = new Proxy(Proxy.Type.HTTP, new InetSocketAddress(proxyHost, proxyPort));
        connection = localURL.openConnection(proxy);
    } else {
        connection = localURL.openConnection();
    }
    return connection;
}

/**
 * Render request according setting
 * 
 * @param request
 */
private void renderRequest(URLConnection connection) {

    if (connectTimeout != null) {
        connection.setConnectTimeout(connectTimeout);
    }

    if (socketTimeout != null) {
        connection.setReadTimeout(socketTimeout);
    }

}

/*
 * Getter & Setter
 */
public Integer getConnectTimeout() {
    return connectTimeout;
}

public void setConnectTimeout(Integer connectTimeout) {
    this.connectTimeout = connectTimeout;
}

public Integer getSocketTimeout() {
    return socketTimeout;
}

public void setSocketTimeout(Integer socketTimeout) {
    this.socketTimeout = socketTimeout;
}

public String getProxyHost() {
    return proxyHost;
}

public void setProxyHost(String proxyHost) {
    this.proxyHost = proxyHost;
}

public Integer getProxyPort() {
    return proxyPort;
}

public void setProxyPort(Integer proxyPort) {
    this.proxyPort = proxyPort;
}

public String getCharset() {
    return charset;
}

public void setCharset(String charset) {
    this.charset = charset;
}

}

Wechat open platform configuration
com.wxlogin.config.WeiXinConfig
The com.wxlogin.common.ConstantManager variable WEBCALLBACKURL changes the callback address to your own domain name
For example: your domain name / callback/wxCallback.do
Your domain name / doWxLogin.do initiates wechat login
For local testing, you can change the host file to point the domain name to the local machine

Login effect:

If there is any problem in the production process, QQ76949433 can be added to provide technical support!

Keywords: Java Apache JSON log4j

Added by LAEinc. Creations on Tue, 31 Dec 2019 19:30:21 +0200