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.TicketManager;
9 import com.foxinmy.weixin4j.token.TokenCreator;
10
11
12
13
14
15
16
17
18
19
20
21 public class WeixinSuiteTokenCreator extends TokenCreator {
22
23 private final TicketManager ticketManager;
24
25
26
27
28
29
30 public WeixinSuiteTokenCreator(TicketManager ticketManager) {
31 this.ticketManager = ticketManager;
32 }
33
34 @Override
35 public String name() {
36 return "qy_suite_token";
37 }
38
39 @Override
40 public String uniqueid() {
41 return ticketManager.getThirdId();
42 }
43
44 @Override
45 public Token create() throws WeixinException {
46 JSONObject obj = new JSONObject();
47 obj.put("suite_id", ticketManager.getThirdId());
48 obj.put("suite_secret", ticketManager.getThirdSecret());
49 obj.put("suite_ticket", ticketManager.getAccessTicket());
50 WeixinResponse response = weixinExecutor.post(
51 URLConsts.SUITE_TOKEN_URL, obj.toJSONString());
52 obj = response.getAsJson();
53 return new Token(obj.getString("suite_access_token"),
54 obj.getLongValue("expires_in") * 1000l);
55 }
56 }