1 package com.foxinmy.weixin4j.wxa.api;
2
3 import java.util.Properties;
4
5 import com.alibaba.fastjson.TypeReference;
6 import com.foxinmy.weixin4j.exception.WeixinException;
7 import com.foxinmy.weixin4j.http.weixin.WeixinResponse;
8 import com.foxinmy.weixin4j.model.WeixinAccount;
9 import com.foxinmy.weixin4j.wxa.model.Session;
10
11
12
13
14
15
16 public class LoginApi extends WxaApi {
17
18 private final WeixinAccount weixinAccount;
19
20 public LoginApi(WeixinAccount weixinAccount) {
21 this(weixinAccount, null);
22 }
23
24 public LoginApi(WeixinAccount weixinAccount, Properties properties) {
25 super(properties);
26 this.weixinAccount = weixinAccount;
27 }
28
29 public Session jscode2session(String jsCode) throws WeixinException {
30 return jscode2session(jsCode, "authorization_code");
31 }
32
33
34
35
36
37
38
39
40
41
42 public Session jscode2session(String jsCode, String grantType) throws WeixinException {
43 String jscode2sessionUri = getRequestUri("sns_jscode2session",
44 weixinAccount.getId(), weixinAccount.getSecret(), jsCode, grantType);
45 WeixinResponse response = weixinExecutor.get(jscode2sessionUri);
46 return response.getAsObject(new TypeReference<Session>() {
47 });
48 }
49
50 }