Blame view

src/main/java/com/jfinal/weixin/sdk/api/ApiConfig.java 3 KB
e80df919   atao   init
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
  /**
   * Copyright (c) 2011-2014, James Zhan 詹波 (jfinal@126.com).
   *
   * Licensed under the Apache License, Version 2.0 (the "License");
   */
  
  package com.jfinal.weixin.sdk.api;
  
  import java.io.Serializable;
  
  /**
   * 存放 Weixin 服务号需要用到的各个参数
   */
  public class ApiConfig implements Serializable {
  
      private static final long serialVersionUID = 5243926308290263767L;
  
      private String token = null;
      private String appId = null;
      private String appSecret = null;
      private String encodingAesKey = null;
      private boolean messageEncrypt = false;    // 消息加密与否
  
      public ApiConfig() {
  
      }
  
      public ApiConfig(String token) {
          setToken(token);
      }
  
      public ApiConfig(String token, String appId, String appSecret) {
          setToken(token);
          setAppId(appId);
          setAppSecret(appSecret);
      }
  
      public ApiConfig(String token, String appId, String appSecret, boolean messageEncrypt, String encodingAesKey) {
          setToken(token);
          setAppId(appId);
          setAppSecret(appSecret);
          setEncryptMessage(messageEncrypt);
          setEncodingAesKey(encodingAesKey);
      }
  
      public String getToken() {
          if (token == null)
              throw new IllegalStateException("token 未被赋值");
          return token;
      }
  
      public void setToken(String token) {
          if (token == null)
              throw new IllegalArgumentException("token 值不能为 null");
          this.token = token;
      }
  
      public String getAppId() {
          if (appId == null)
              throw new IllegalStateException("appId 未被赋值");
          return appId;
      }
  
      public void setAppId(String appId) {
          if (appId == null)
              throw new IllegalArgumentException("appId 值不能为 null");
          this.appId = appId;
      }
  
      public String getAppSecret() {
          if (appSecret == null)
              throw new IllegalStateException("appSecret 未被赋值");
          return appSecret;
      }
  
      public void setAppSecret(String appSecret) {
          if (appSecret == null)
              throw new IllegalArgumentException("appSecret 值不能为 null");
          this.appSecret = appSecret;
      }
  
      public String getEncodingAesKey() {
          if (encodingAesKey == null)
              throw new IllegalStateException("encodingAesKey 未被赋值");
          return encodingAesKey;
      }
  
      public void setEncodingAesKey(String encodingAesKey) {
          if (encodingAesKey == null)
              throw new IllegalArgumentException("encodingAesKey 值不能为 null");
          this.encodingAesKey = encodingAesKey;
      }
  
      public boolean isEncryptMessage() {
          return messageEncrypt;
      }
  
      /**
       * @param messageEncrypt
       * 是否对消息进行加密,对应于微信平台的消息加解密方式:
       * 1true进行加密且必须配置 encodingAesKey
       * 2false采用明文模式,同时也支持混合模式
       */
      public void setEncryptMessage(boolean messageEncrypt) {
          this.messageEncrypt = messageEncrypt;
      }
  }