Sfoglia il codice sorgente

Merge branch 'develop' of gitadmin/tuoheng_telecomumale into release

tags/v1.0.0^2
chengwang 1 anno fa
parent
commit
13b21a2373
5 ha cambiato i file con 93 aggiunte e 90 eliminazioni
  1. +77
    -77
      tuoheng-service/tuoheng-miniprogram/src/main/java/com/tuoheng/miniprogram/utils/AccessTokenManager.java
  2. +2
    -2
      tuoheng-service/tuoheng-miniprogram/src/main/resources/application-dev.yml
  3. +8
    -7
      tuoheng-service/tuoheng-miniprogram/src/main/resources/application-local.yml
  4. +3
    -2
      tuoheng-service/tuoheng-miniprogram/src/main/resources/application-prod.yml
  5. +3
    -2
      tuoheng-service/tuoheng-miniprogram/src/main/resources/application-test.yml

+ 77
- 77
tuoheng-service/tuoheng-miniprogram/src/main/java/com/tuoheng/miniprogram/utils/AccessTokenManager.java Vedi File

@@ -1,77 +1,77 @@
package com.tuoheng.miniprogram.utils;
import com.alibaba.fastjson.JSONObject;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.scheduling.annotation.Scheduled;
import org.springframework.stereotype.Service;
import org.springframework.web.client.RestTemplate;
import java.util.Objects;
import java.util.concurrent.locks.ReentrantReadWriteLock;
@Service
@Slf4j
@RequiredArgsConstructor
public class AccessTokenManager {
private String accessToken = null;
@Value("${wx.appId}")
private String appId;
@Value("${wx.secret}")
private String secret;
private final RestTemplate restTemplate;
private final ReentrantReadWriteLock reentrantReadWriteLock = new ReentrantReadWriteLock();
public String getAccessToken(){
String ret;
ReentrantReadWriteLock.ReadLock readLock = reentrantReadWriteLock.readLock();
try{
readLock.lock();
ret = accessToken;
}
finally {
readLock.unlock();
}
return ret;
}
public void updateAccessToken(String accessToken){
ReentrantReadWriteLock.WriteLock writeLock = reentrantReadWriteLock.writeLock();
try{
writeLock.lock();
this.accessToken = accessToken;
}
finally {
writeLock.unlock();
}
}
/**
* 获取微信accessToken
*/
@Scheduled(cron = "0 0 * * * ?")
public void refreshToken() {
String accessToken;
try {
String url =
String.format(
"https://api.weixin.qq.com/cgi-bin/token?grant_type=client_credential&appid=%s&secret=%s",
appId,
secret);
JSONObject body = restTemplate.getForEntity(url, JSONObject.class).getBody();
if (!Objects.isNull(body)){
log.info("获取accessToken返回内容:"+body.toJSONString());
accessToken = (String) body.get("access_token");
updateAccessToken(accessToken);
}
} catch (Exception e) {
log.error("调用获取微信accessToken接口出错:", e);
}
}
}
//package com.tuoheng.miniprogram.utils;
//
//import com.alibaba.fastjson.JSONObject;
//import lombok.RequiredArgsConstructor;
//import lombok.extern.slf4j.Slf4j;
//import org.springframework.beans.factory.annotation.Value;
//import org.springframework.scheduling.annotation.Scheduled;
//import org.springframework.stereotype.Service;
//import org.springframework.web.client.RestTemplate;
//
//import java.util.Objects;
//import java.util.concurrent.locks.ReentrantReadWriteLock;
//
//@Service
//@Slf4j
//@RequiredArgsConstructor
//public class AccessTokenManager {
//
// private String accessToken = null;
//
// @Value("${wx.appId}")
// private String appId;
// @Value("${wx.secret}")
// private String secret;
//
// private final RestTemplate restTemplate;
//
// private final ReentrantReadWriteLock reentrantReadWriteLock = new ReentrantReadWriteLock();
//
//
// public String getAccessToken(){
// String ret;
// ReentrantReadWriteLock.ReadLock readLock = reentrantReadWriteLock.readLock();
// try{
// readLock.lock();
// ret = accessToken;
// }
// finally {
// readLock.unlock();
// }
// return ret;
// }
//
// public void updateAccessToken(String accessToken){
// ReentrantReadWriteLock.WriteLock writeLock = reentrantReadWriteLock.writeLock();
// try{
// writeLock.lock();
// this.accessToken = accessToken;
// }
// finally {
// writeLock.unlock();
// }
// }
//
// /**
// * 获取微信accessToken
// */
// @Scheduled(cron = "0 0 * * * ?")
// public void refreshToken() {
// String accessToken;
// try {
// String url =
// String.format(
// "https://api.weixin.qq.com/cgi-bin/token?grant_type=client_credential&appid=%s&secret=%s",
// appId,
// secret);
// JSONObject body = restTemplate.getForEntity(url, JSONObject.class).getBody();
// if (!Objects.isNull(body)){
// log.info("获取accessToken返回内容:"+body.toJSONString());
// accessToken = (String) body.get("access_token");
// updateAccessToken(accessToken);
// }
// } catch (Exception e) {
// log.error("调用获取微信accessToken接口出错:", e);
// }
// }
//}

+ 2
- 2
tuoheng-service/tuoheng-miniprogram/src/main/resources/application-dev.yml Vedi File

@@ -91,8 +91,8 @@ tuoheng:
uploadFolder: /data/java/tuoheng_telecomumale/uploads/
#城管小程序
wx:
appId: wxd0f247d7272ca1b7
appSecret: 541002e33cd4b011d4c13954ed34efdb
appId: wx8e25cc4a7eec55c6
appSecret: ff104538eb568d0d99405638e35af8ad
templateId: _7WZK-DEsBk4goXP2jThDk0u606Nz0YQBXWkej6BJfg

## 配置feign熔断

+ 8
- 7
tuoheng-service/tuoheng-miniprogram/src/main/resources/application-local.yml Vedi File

@@ -26,12 +26,12 @@ spring:
type: com.alibaba.druid.pool.DruidDataSource
driver-class-name: com.mysql.cj.jdbc.Driver
# 填写你数据库的url、登录名、密码和数据库名
# url: jdbc:mysql://192.168.11.13:3306/tuoheng_telecomumale?useUnicode=true&characterEncoding=UTF-8&serverTimezone=GMT%2b8&useSSL=true&tinyInt1isBit=false
# username: root
# password: idontcare
url: jdbc:mysql://rm-uf6z740323e8053pj4o.mysql.rds.aliyuncs.com:3306/tuoheng_airmonitor?useUnicode=true&characterEncoding=UTF-8&serverTimezone=GMT%2b8&useSSL=true&tinyInt1isBit=false
url: jdbc:mysql://192.168.11.13:3306/tuoheng_telecomumale?useUnicode=true&characterEncoding=UTF-8&serverTimezone=GMT%2b8&useSSL=true&tinyInt1isBit=false
username: root
password: TH22#2022
password: idontcare
# url: jdbc:mysql://rm-uf6z740323e8053pj4o.mysql.rds.aliyuncs.com:3306/tuoheng_telecomumale?useUnicode=true&characterEncoding=UTF-8&serverTimezone=GMT%2b8&useSSL=true&tinyInt1isBit=false
# username: root
# password: TH22#2022
# Redis数据源
redis:
# 缓存库默认索引0
@@ -94,8 +94,9 @@ tuoheng:
uploadFolder: /data/java/tuoheng_telecomumale/uploads/
#城管小程序
wx:
appId: wxd0f247d7272ca1b7
appSecret: 541002e33cd4b011d4c13954ed34efdb
appId: wx8e25cc4a7eec55c6
appSecret: ff104538eb568d0d99405638e35af8ad
templateId: _7WZK-DEsBk4goXP2jThDk0u606Nz0YQBXWkej6BJfg
## 配置feign熔断
#feign:
# circuitbreaker:

+ 3
- 2
tuoheng-service/tuoheng-miniprogram/src/main/resources/application-prod.yml Vedi File

@@ -91,8 +91,9 @@ tuoheng:
uploadFolder: /data/java/tuoheng_telecomumale/uploads/
#城管小程序
wx:
appId: wxd0f247d7272ca1b7
appSecret: 541002e33cd4b011d4c13954ed34efdb
appId: wx8e25cc4a7eec55c6
appSecret: ff104538eb568d0d99405638e35af8ad
templateId: _7WZK-DEsBk4goXP2jThDk0u606Nz0YQBXWkej6BJfg
## 配置feign熔断
#feign:
# circuitbreaker:

+ 3
- 2
tuoheng-service/tuoheng-miniprogram/src/main/resources/application-test.yml Vedi File

@@ -91,8 +91,9 @@ tuoheng:
uploadFolder: /data/java/tuoheng_telecomumale/uploads/
#城管小程序
wx:
appId: wxd0f247d7272ca1b7
appSecret: 541002e33cd4b011d4c13954ed34efdb
appId: wx8e25cc4a7eec55c6
appSecret: ff104538eb568d0d99405638e35af8ad
templateId: _7WZK-DEsBk4goXP2jThDk0u606Nz0YQBXWkej6BJfg
## 配置feign熔断
#feign:
# circuitbreaker:

Loading…
Annulla
Salva