package com.sino.weixin.oauth.util;

import java.net.URLDecoder;
import java.net.URLEncoder;

public class WeixinUrlUtil {
	public static String  GetCodeRequest = "https://open.weixin.qq.com/connect/oauth2/authorize?appid=APPID&redirect_uri=REDIRECT_URI&response_type=code&scope=SCOPE&state=STATE#wechat_redirect";
    public static String getCodeRequest(){
        String result = null;
        GetCodeRequest  = GetCodeRequest.replace("APPID", urlEnodeUTF8(Constants.AppId));
        GetCodeRequest  = GetCodeRequest.replace("REDIRECT_URI",urlEnodeUTF8("http://www.sino-assistance.com.cn/weixin4s/customService.do"));
        GetCodeRequest = GetCodeRequest.replace("SCOPE", Constants.scope);
        result = GetCodeRequest;
        return result;
    }
    

    
    
    public static String urlEnodeUTF8(String str){
        String result = str;
        try {
            result = URLEncoder.encode(str,"UTF-8");
        } catch (Exception e) {
            e.printStackTrace();
        }
        return result;
    }
    public static String urlDecodeUTF8(String str){
        String result = str;
        try {
        	result = URLDecoder.decode(str,"UTF-8");
        } catch (Exception e) {
            e.printStackTrace();
        }
        return result;
    }
    public static void main(String[] args) {
    	String dd = WeixinUrlUtil.getCodeRequest();
    	System.out.println(dd);
        //System.out.println(urlDecodeUTF8("https://open.weixin.qq.com/connect/oauth2/authorize?appid=wxefb4777c6e6b1a17&redirect_uri=http%3A%2F%2Fmt.smartcarwashing.com%2Forder%2Fpre_order&response_type=code&scope=snsapi_base&state=1#wechat_redirect"));
    }

}
