mirror of
				https://github.com/ZSCNetSupportDept/WechatTicketSystem.git
				synced 2025-10-31 10:26:19 +08:00 
			
		
		
		
	configuration via sql (done)
This commit is contained in:
		
							
								
								
									
										30
									
								
								src/main/java/love/sola/netsupport/config/Settings.java
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										30
									
								
								src/main/java/love/sola/netsupport/config/Settings.java
									
									
									
									
									
										Normal file
									
								
							| @@ -0,0 +1,30 @@ | ||||
| package love.sola.netsupport.config; | ||||
|  | ||||
| import lombok.ToString; | ||||
|  | ||||
| /** | ||||
|  * *********************************************** | ||||
|  * Created by Sola on 2015/11/23. | ||||
|  * Don't modify this source without my agreement | ||||
|  * *********************************************** | ||||
|  */ | ||||
| @ToString | ||||
| public class Settings { | ||||
|  | ||||
| 	public static Settings I; | ||||
|  | ||||
| 	// -------------------------------------------- // | ||||
| 	// CONFIGURATIONS | ||||
| 	// -------------------------------------------- // | ||||
| 	public String Wechat_AppId; | ||||
| 	public String Wechat_Secret; | ||||
| 	public String Wechat_Token; | ||||
| 	public String Wechat_AesKey; | ||||
|  | ||||
|  | ||||
| 	//No arg constructor for Yaml.loadAs | ||||
| 	public Settings() { | ||||
| 		I = this; | ||||
| 	} | ||||
|  | ||||
| } | ||||
| @@ -1,5 +1,7 @@ | ||||
| package love.sola.netsupport.sql; | ||||
|  | ||||
| import com.google.gson.Gson; | ||||
|  | ||||
| import javax.naming.InitialContext; | ||||
| import javax.sql.DataSource; | ||||
|  | ||||
| @@ -12,6 +14,7 @@ import javax.sql.DataSource; | ||||
| public class SQLCore { | ||||
|  | ||||
| 	public static DataSource ds; | ||||
| 	public static Gson gson = new Gson(); | ||||
|  | ||||
| 	static { | ||||
| 		try { | ||||
|   | ||||
| @@ -1,14 +1,39 @@ | ||||
| package love.sola.netsupport.sql; | ||||
|  | ||||
| import love.sola.netsupport.config.Settings; | ||||
|  | ||||
| import java.sql.*; | ||||
|  | ||||
| /** | ||||
|  * *********************************************** | ||||
|  * Created by Sola on 2015/11/10. | ||||
|  * Don't modify this source without my agreement | ||||
|  * *********************************************** | ||||
|  */ | ||||
| public class TableConfig { | ||||
| public class TableConfig extends SQLCore{ | ||||
|  | ||||
| 	public static final String KEY_SYS = "sys"; | ||||
|  | ||||
| 	 | ||||
| 	public static Settings getSettings() { | ||||
| 		try (Connection conn = ds.getConnection()) { | ||||
| 			Statement st = conn.createStatement(); | ||||
| 			ResultSet rs = st.executeQuery("SELECT * FROM settings WHERE type='" + KEY_SYS + "'"); | ||||
| 			if (rs.next()) { | ||||
| 				return gson.fromJson(rs.getString("data"), Settings.class); | ||||
| 			} | ||||
| 		} catch (SQLException e) { } | ||||
| 		return null; | ||||
| 	} | ||||
|  | ||||
| 	public static int saveSettings(Settings obj) { | ||||
| 		try (Connection conn = ds.getConnection()) { | ||||
| 			PreparedStatement ps = conn.prepareStatement("UPDATE settings SET data=? WHERE type=?"); | ||||
| 			ps.setString(1, gson.toJson(obj)); | ||||
| 			ps.setString(2, KEY_SYS); | ||||
| 			return ps.executeUpdate(); | ||||
| 		} catch (SQLException e) { | ||||
| 		} | ||||
| 		return -1; | ||||
| 	} | ||||
|  | ||||
| } | ||||
|   | ||||
| @@ -1,5 +1,6 @@ | ||||
| package love.sola.netsupport.wechat; | ||||
|  | ||||
| import love.sola.netsupport.config.Settings; | ||||
| import me.chanjar.weixin.common.util.StringUtils; | ||||
| import me.chanjar.weixin.mp.api.WxMpInMemoryConfigStorage; | ||||
| import me.chanjar.weixin.mp.api.WxMpMessageRouter; | ||||
| @@ -38,10 +39,10 @@ public class WxMpServlet extends HttpServlet { | ||||
| 		super.init(); | ||||
|  | ||||
| 		config = new WxMpInMemoryConfigStorage(); | ||||
| 		config.setAppId("*****"); | ||||
| 		config.setSecret("*****"); | ||||
| 		config.setToken("*****"); | ||||
| //		config.setAesKey("SolaAES"); | ||||
| 		config.setAppId(Settings.I.Wechat_AppId); | ||||
| 		config.setSecret(Settings.I.Wechat_Secret); | ||||
| 		config.setToken(Settings.I.Wechat_Token); | ||||
| 		config.setAesKey(Settings.I.Wechat_Token); | ||||
|  | ||||
| 		wxMpService = new WxMpServiceImpl(); | ||||
| 		wxMpService.setWxMpConfigStorage(config); | ||||
|   | ||||
		Reference in New Issue
	
	Block a user
	 Sola
					Sola