package com.house365.common.constant;

import org.springframework.boot.context.properties.ConfigurationProperties;
import org.springframework.stereotype.Component;

import java.net.URLEncoder;

/**
 * <p>Title: </p>
 * <p>Description: </p>
 * <p>Date: 2016/12/30</p>
 *
 * @author XN
 * @version 1.0
 */
@Component
@ConfigurationProperties(prefix = "urlConst")
public class UrlConst {

    public static final String SESSIONUSER = "user";

    public static final String HOUSE365_CORPID = "wx32f3a81d82530a8f";
    public static final String HOUSE365_SECRET = "a1wzzur0EQNiiXFvSxYlfnTw497jtlj00KDw7D-IRQZqgox7q2gZBfUWURW05YT6";
    public static final String loginURL = "https://qy.weixin.qq.com/cgi-bin/loginpage?";
    public static final String getUserInfoURL = "https://qyapi.weixin.qq.com/cgi-bin/user/get?";
    public static String redirectURL;

    //企业获取code, 用于获取用户信息
    public static String getCodeURL(String state) {
        return "https://open.weixin.qq.com/connect/oauth2/authorize?appid=wx32f3a81d82530a8f&redirect_uri=" + URLEncoder.encode(
                redirectURL) + "&response_type=code&scope=snsapi_base&state=" + state + "#wechat_redirect";
    }

    //第三方登录授权接口URL
    public static String getLoginURL(String state, String corpId, String redirectURL) {
        return loginURL + "corp_id=" + HOUSE365_CORPID + "&redirect_uri=" + URLEncoder.encode(
                redirectURL) + "&state=" + state + "&usertype=all";
    }

    public static String getRedirectURL() {
        return redirectURL;
    }

    public static void setRedirectURL(String redirectURL) {
        UrlConst.redirectURL = redirectURL;
    }
}
