jiapeng vor 7 Jahren
Ursprung
Commit
c049b42e4f

+ 5 - 8
src/main/java/com/ekexiu/portal/oauth/OAuthService.java

@ -9,7 +9,6 @@ import java.util.Map;
9 9
import java.util.concurrent.TimeUnit;
10 10

11 11
import org.jfw.apt.annotation.Autowrie;
12
import org.jfw.apt.annotation.Nullable;
13 12
import org.jfw.apt.web.annotation.Path;
14 13
import org.jfw.apt.web.annotation.method.SetCookie;
15 14
import org.jfw.apt.web.annotation.operate.Get;
@ -44,8 +43,8 @@ public class OAuthService {
44 43
	@Autowrie
45 44
	private ProfessorDao professorDao;
46 45

47
	private String xcxAppid = "";
48
	private String xcxSecret = "";
46
	private String xcxAppid = "wx92750263b1138a96";
47
	private String xcxSecret = "246e17b10923a30bfd6cc8da1ca88b8a";
49 48

50 49
	private Map<String, OAuthHandler> handlers;
51 50

@ -249,11 +248,9 @@ public class OAuthService {
249 248

250 249
	@Get
251 250
	@Path("/xcx/openid")
252
	public String jscode2session(String code,@Nullable String appid,@Nullable String secret) throws IOException {
253
		if(appid==null) appid = this.xcxAppid;
254
		if(secret ==null) secret = this.xcxSecret;
255
		return (String)HttpUtil.<Map<String,Object>>loadJsonObject("https://api.weixin.qq.com/sns/jscode2session?appid=" + appid + "&secret=" + secret + "&js_code=" + code
256
				+ "&grant_type=authorization_code", MAP_TYPE).get("openid");
251
	public String jscode2session(String code) throws IOException {
252
		return (String) HttpUtil.<Map<String, Object>> loadJsonObject("https://api.weixin.qq.com/sns/jscode2session?appid=" + this.xcxAppid + "&secret="
253
				+ this.xcxSecret + "&js_code=" + code + "&grant_type=authorization_code", MAP_TYPE).get("openid");
257 254
	}
258 255

259 256
	public static class AuthLoginResponse {

+ 17 - 0
src/main/java/com/ekexiu/portal/service/ToolService.java

@ -0,0 +1,17 @@
1
package com.ekexiu.portal.service;
2

3
import java.io.IOException;
4

5
import org.jfw.apt.web.annotation.Path;
6
import org.jfw.util.codec.Base64;
7

8
import com.ekexiu.portal.util.HttpUtil;
9

10
@Path("/tool")
11
public class ToolService {
12
	@Path("/resource/url/base64")
13
	public String urlResource(String uri)throws IOException{
14
		Base64 bs64 = new Base64();
15
		return bs64.encodeToString(HttpUtil.load(uri));		
16
	}
17
}

+ 13 - 0
src/main/java/com/ekexiu/portal/util/HttpUtil.java

@ -37,6 +37,19 @@ public final class HttpUtil {
37 37
            }
38 38
        }
39 39
    }
40
    
41
    public static byte[] load(String url)throws IOException{
42
    	   URL aurl = new URL(url);
43
           HttpURLConnection uc = (HttpURLConnection) aurl.openConnection();
44
           try {
45
               return IoUtil.readStream(uc.getInputStream(), true);
46
           } finally {
47
               try {
48
                   uc.disconnect();
49
               } catch (Throwable th) {
50
               }
51
           }
52
    }
40 53

41 54
    public static <T> T loadJsonObject(String url, String enc, Type typeOfT) throws IOException {
42 55
        URL aurl = new URL(url);