1 package com.foxinmy.weixin4j.qy.suite;
2
3 import com.alibaba.fastjson.JSONObject;
4 import com.foxinmy.weixin4j.exception.WeixinException;
5 import com.foxinmy.weixin4j.http.weixin.WeixinResponse;
6 import com.foxinmy.weixin4j.model.Token;
7 import com.foxinmy.weixin4j.qy.type.URLConsts;
8 import com.foxinmy.weixin4j.token.TokenCreator;
9 import com.foxinmy.weixin4j.token.TokenManager;
10
11
12
13
14
15
16
17
18
19
20
21
22 public class WeixinSuitePreCodeCreator extends TokenCreator {
23
24 private final TokenManager suiteTokenManager;
25 private final String suiteId;
26
27
28
29
30
31
32
33
34 public WeixinSuitePreCodeCreator(TokenManager suiteTokenManager,
35 String suiteId) {
36 this.suiteTokenManager = suiteTokenManager;
37 this.suiteId = suiteId;
38 }
39
40 @Override
41 public String name() {
42 return "qy_suite_precode";
43 }
44
45 @Override
46 public String uniqueid() {
47 return suiteId;
48 }
49
50 @Override
51 public Token create() throws WeixinException {
52 WeixinResponse response = weixinExecutor.post(
53 String.format(URLConsts.SUITE_PRE_CODE_URL,
54 suiteTokenManager.getAccessToken()),
55 String.format("{\"suite_id\":\"%s\"}", suiteId));
56 JSONObject result = response.getAsJson();
57 return new Token(result.getString("pre_auth_code"),
58 result.getLongValue("expires_in") * 1000l);
59 }
60 }