@@ -48,6 +48,51 @@ public class CommonConfig { | |||
*/ | |||
public static String airportURL; | |||
/** | |||
* 小程序 appId | |||
*/ | |||
public static String appId; | |||
/** | |||
* 小程序 appSecret | |||
*/ | |||
public static String appSecret; | |||
/** | |||
* 主题id | |||
*/ | |||
public static String templateId; | |||
/** | |||
* 小程序 appId赋值 | |||
* | |||
* @param id 小程序 appId | |||
*/ | |||
@Value("${wx.appId}") | |||
public void setAppId(String id) { | |||
appId = id; | |||
} | |||
/** | |||
* 小程序 appSecret赋值 | |||
* | |||
* @param secret 小程序 appSecret | |||
*/ | |||
@Value("${wx.appSecret}") | |||
public void setAppSecret(String secret) { | |||
appSecret = secret; | |||
} | |||
/** | |||
* 小程序 templateId赋值 | |||
* @param tempId | |||
*/ | |||
@Value("${wx.templateId}") | |||
public void setTemplateId(String tempId) { | |||
templateId = tempId; | |||
} | |||
/** | |||
* 图片域名赋值 | |||
* |
@@ -32,6 +32,9 @@ spring: | |||
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 | |||
# username: root | |||
# password: TH22#2022 | |||
filter: | |||
slf4j: | |||
enabled: true |
@@ -0,0 +1,34 @@ | |||
package com.tuoheng.miniprogram.controller; | |||
import com.tuoheng.common.core.utils.JsonResult; | |||
import com.tuoheng.miniprogram.service.IWxService; | |||
import lombok.extern.slf4j.Slf4j; | |||
import org.springframework.beans.factory.annotation.Autowired; | |||
import org.springframework.web.bind.annotation.GetMapping; | |||
import org.springframework.web.bind.annotation.PathVariable; | |||
import org.springframework.web.bind.annotation.RequestMapping; | |||
import org.springframework.web.bind.annotation.RestController; | |||
/** | |||
* @Author ChengWang | |||
* @Date 2023/6/23 | |||
*/ | |||
@RestController | |||
@Slf4j | |||
@RequestMapping("/weiXin") | |||
public class WxController { | |||
@Autowired | |||
private IWxService iWxService; | |||
//根据code获取openId | |||
@GetMapping("/getOpenId/{code}") | |||
public JsonResult getOpenId(@PathVariable("code") String code){ | |||
log.info("进入获取openId接口"); | |||
return iWxService.openid(code); | |||
} | |||
//获取access_code值 | |||
} |
@@ -0,0 +1,13 @@ | |||
package com.tuoheng.miniprogram.dao; | |||
import com.baomidou.mybatisplus.core.mapper.BaseMapper; | |||
import com.tuoheng.miniprogram.entity.LiveChannel; | |||
/** | |||
* @Author ChengWang | |||
* @Date 2022/12/1 | |||
*/ | |||
public interface LiveChannelMapper extends BaseMapper<LiveChannel> { | |||
} |
@@ -0,0 +1,74 @@ | |||
package com.tuoheng.miniprogram.entity; | |||
import com.baomidou.mybatisplus.annotation.TableName; | |||
import com.tuoheng.common.core.common.BaseEntity; | |||
import lombok.Data; | |||
import lombok.EqualsAndHashCode; | |||
import lombok.experimental.Accessors; | |||
/** | |||
* @Author ChengWang | |||
* @Date 2022/12/1 | |||
*/ | |||
@Data | |||
@EqualsAndHashCode(callSuper = true) | |||
@Accessors(chain = true) | |||
@TableName("th_live_channel") | |||
public class LiveChannel extends BaseEntity { | |||
private static final long serialVersionUID = 1L; | |||
/** | |||
* 租户ID | |||
*/ | |||
private String tenantId; | |||
/** | |||
* 部门id | |||
*/ | |||
private String deptId; | |||
/** | |||
* 巡检任务ID | |||
*/ | |||
private String inspectionId; | |||
/** | |||
*通道编号 | |||
*/ | |||
private String channelCode; | |||
/** | |||
* 直播通道名称 | |||
*/ | |||
private String name; | |||
/** | |||
*无人机推流地址 | |||
*/ | |||
private String pushUrl; | |||
/** | |||
* 无人机拉流地址 | |||
*/ | |||
private String pullUrl; | |||
/** | |||
* AI推流地址 | |||
*/ | |||
private String aipushUrl; | |||
/** | |||
* AI拉流地址 | |||
*/ | |||
private String aipullUrl; | |||
/** | |||
* 备注 | |||
*/ | |||
private String note; | |||
/** | |||
*状态:1正常 2停用 | |||
*/ | |||
private Integer status; | |||
} |
@@ -0,0 +1,19 @@ | |||
package com.tuoheng.miniprogram.entity.dto; | |||
import lombok.AllArgsConstructor; | |||
import lombok.Data; | |||
import lombok.NoArgsConstructor; | |||
/** | |||
* @Author ChengWang | |||
* @Date 2023/6/23 | |||
*/ | |||
@Data | |||
@AllArgsConstructor | |||
@NoArgsConstructor | |||
public class TemplateMinDto { | |||
/** | |||
* 填充信息 | |||
*/ | |||
private String value; | |||
} |
@@ -0,0 +1,34 @@ | |||
package com.tuoheng.miniprogram.param; | |||
import com.tuoheng.miniprogram.entity.dto.TemplateMinDto; | |||
import lombok.Data; | |||
import java.util.Map; | |||
/** | |||
* @Author ChengWang | |||
* @Date 2023/6/23 | |||
*/ | |||
@Data | |||
public class WxSendMessageParam { | |||
/** | |||
* 接收者openId | |||
*/ | |||
private String openId; | |||
/** | |||
* 订阅模板id | |||
*/ | |||
private String template_id; | |||
/** | |||
* 点击模板卡片跳转页面 | |||
*/ | |||
private String page; | |||
/** | |||
* 填充信息 | |||
*/ | |||
private Map<String, TemplateMinDto> data; | |||
} |
@@ -0,0 +1,13 @@ | |||
package com.tuoheng.miniprogram.service; | |||
import com.tuoheng.common.core.utils.JsonResult; | |||
/** | |||
* @Author ChengWang | |||
* @Date 2023/6/23 | |||
*/ | |||
public interface IWxService { | |||
//根据code获取openId | |||
JsonResult openid(String code); | |||
} |
@@ -49,6 +49,9 @@ public class InspectionServiceImpl implements IInspectionService { | |||
@Autowired | |||
private TenantMapper tenantMapper; | |||
@Autowired | |||
private LiveChannelMapper liveChannelMapper; | |||
/** | |||
* 任务列表(分页) | |||
* @param query | |||
@@ -75,8 +78,6 @@ public class InspectionServiceImpl implements IInspectionService { | |||
query.setTenantId(tenantId); | |||
query.setType(1); | |||
//查询部门及下级部门列表 | |||
List<Dept> list = deptMapper.selectList(Wrappers.<Dept>lambdaQuery() | |||
.eq(Dept::getMark, MarkEnum.VALID.getCode())); | |||
//初始部门id | |||
String deptIdInt = query.getDeptId(); | |||
//获取当前部门对应的巡检任务 | |||
@@ -193,11 +194,27 @@ public class InspectionServiceImpl implements IInspectionService { | |||
.eq(Inspection::getTenantId, tenantId) | |||
.eq(Inspection::getMark, MarkEnum.VALID.getCode()) | |||
.eq(Inspection::getId, id)); | |||
if(ObjectUtil.isNull(inspection)){ | |||
return JsonResult.error("任务不存在"); | |||
} | |||
PlayBackInfoVo vo = new PlayBackInfoVo(); | |||
BeanUtils.copyProperties(inspection,vo); | |||
//对视频地址进行处理 | |||
if(StringUtils.isNotEmpty(inspection.getAiVideoUrl())){ | |||
vo.setAiVideoUrl(CommonConfig.videoURL+inspection.getAiVideoUrl()); | |||
if(15 == inspection.getStatus()){ | |||
if(StringUtils.isNotEmpty(inspection.getAiVideoUrl())){ | |||
vo.setAiVideoUrl(CommonConfig.videoURL+inspection.getAiVideoUrl()); | |||
} | |||
} | |||
if(10 == inspection.getStatus()){ | |||
LiveChannel liveChannel = liveChannelMapper.selectOne(Wrappers.<LiveChannel>lambdaQuery() | |||
.eq(LiveChannel::getInspectionId, inspection.getId()) | |||
.eq(LiveChannel::getMark, MarkEnum.VALID.getCode())); | |||
if(ObjectUtil.isNull(liveChannel)){ | |||
return JsonResult.error("直播通道数据为空"); | |||
} | |||
if(StringUtils.isNotEmpty(liveChannel.getAipullUrl())){ | |||
vo.setAiVideoUrl(liveChannel.getAipullUrl()); | |||
} | |||
} | |||
return JsonResult.success(vo); |
@@ -0,0 +1,33 @@ | |||
package com.tuoheng.miniprogram.service.impl; | |||
import com.alibaba.fastjson.JSONObject; | |||
import com.tuoheng.common.core.config.common.CommonConfig; | |||
import com.tuoheng.common.core.utils.JsonResult; | |||
import com.tuoheng.common.core.utils.StringUtils; | |||
import com.tuoheng.miniprogram.service.IWxService; | |||
import com.tuoheng.miniprogram.utils.GetOpenIdUtil; | |||
import lombok.extern.slf4j.Slf4j; | |||
import org.springframework.stereotype.Service; | |||
/** | |||
* @Author ChengWang | |||
* @Date 2023/6/23 | |||
*/ | |||
@Service | |||
@Slf4j | |||
public class WxServiceImpl implements IWxService { | |||
@Override | |||
public JsonResult openid(String code) { | |||
String openidResult = GetOpenIdUtil.getopenid(code, CommonConfig.appId, CommonConfig.appSecret); | |||
String openid = JSONObject.parseObject(openidResult).getString("openid"); | |||
if(StringUtils.isNotEmpty(openid)){ | |||
return JsonResult.success(openid); | |||
}else { | |||
log.error("获取openid失败:",openidResult); | |||
return JsonResult.error("获取openid失败"); | |||
} | |||
} | |||
} |
@@ -0,0 +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); | |||
} | |||
} | |||
} |
@@ -0,0 +1,60 @@ | |||
package com.tuoheng.miniprogram.utils; | |||
import com.alibaba.fastjson.JSONObject; | |||
import java.io.BufferedReader; | |||
import java.io.InputStreamReader; | |||
import java.net.URL; | |||
import java.net.URLConnection; | |||
/** | |||
* 微信登陆工具类 | |||
*/ | |||
public class GetOpenIdUtil { | |||
public static void main(String[] args) { | |||
System.out.println("start"); | |||
String openidJson = getopenid("061pTj0w3j6DaZ23141w3X12aP0pTj04", "wxd0f247d7272ca1b7", "541002e33cd4b011d4c13954ed34efdb"); | |||
System.out.println("openid:" + openidJson); | |||
JSONObject jsonObject = JSONObject.parseObject(openidJson); | |||
String openid = jsonObject.getString("openid"); | |||
System.out.println("end"); | |||
} | |||
public static String getopenid(String code,String appid,String secret) { | |||
BufferedReader in = null; | |||
//appid和secret是开发者分别是小程序ID和小程序密钥,开发者通过微信公众平台-》设置-》开发设置就可以直接获取, | |||
String url="https://api.weixin.qq.com/sns/jscode2session?appid=" | |||
+appid+"&secret="+secret+"&js_code="+code+"&grant_type=authorization_code"; | |||
try{ | |||
URL weChatUrl = new URL(url); | |||
// 打开和URL之间的连接 | |||
URLConnection connection = weChatUrl.openConnection(); | |||
// 设置通用的请求属性 | |||
connection.setConnectTimeout(5000); | |||
connection.setReadTimeout(5000); | |||
// 建立实际的连接 | |||
connection.connect(); | |||
// 定义 BufferedReader输入流来读取URL的响应 | |||
in = new BufferedReader(new InputStreamReader(connection.getInputStream())); | |||
StringBuffer sb = new StringBuffer(); | |||
String line; | |||
while ((line = in.readLine()) != null) { | |||
sb.append(line); | |||
} | |||
return sb.toString(); | |||
}catch (Exception e) { | |||
throw new RuntimeException(e); | |||
} | |||
// 使用finally块来关闭输入流 | |||
finally { | |||
try { | |||
if (in != null) { | |||
in.close(); | |||
} | |||
} catch (Exception e2) { | |||
e2.printStackTrace(); | |||
} | |||
} | |||
} | |||
} |
@@ -44,4 +44,10 @@ public class PlayBackInfoVo { | |||
* 原视频地址 | |||
*/ | |||
private String aiVideoUrl; | |||
/** | |||
* 视频直播地址 | |||
*/ | |||
private String aipullUrl; | |||
} |
@@ -89,6 +89,12 @@ tuoheng: | |||
staticAccessPath: /** | |||
#静态资源实际存储路径 | |||
uploadFolder: /data/java/tuoheng_telecomumale/uploads/ | |||
#城管小程序 | |||
wx: | |||
appId: wxd0f247d7272ca1b7 | |||
appSecret: 541002e33cd4b011d4c13954ed34efdb | |||
templateId: _7WZK-DEsBk4goXP2jThDk0u606Nz0YQBXWkej6BJfg | |||
## 配置feign熔断 | |||
#feign: | |||
# circuitbreaker: |
@@ -26,9 +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 | |||
# 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 | |||
username: root | |||
password: idontcare | |||
password: TH22#2022 | |||
# Redis数据源 | |||
redis: | |||
# 缓存库默认索引0 | |||
@@ -89,6 +92,10 @@ tuoheng: | |||
staticAccessPath: /** | |||
#静态资源实际存储路径 | |||
uploadFolder: /data/java/tuoheng_telecomumale/uploads/ | |||
#城管小程序 | |||
wx: | |||
appId: wxd0f247d7272ca1b7 | |||
appSecret: 541002e33cd4b011d4c13954ed34efdb | |||
## 配置feign熔断 | |||
#feign: | |||
# circuitbreaker: |
@@ -89,6 +89,10 @@ tuoheng: | |||
staticAccessPath: /** | |||
#静态资源实际存储路径 | |||
uploadFolder: /data/java/tuoheng_telecomumale/uploads/ | |||
#城管小程序 | |||
wx: | |||
appId: wxd0f247d7272ca1b7 | |||
appSecret: 541002e33cd4b011d4c13954ed34efdb | |||
## 配置feign熔断 | |||
#feign: | |||
# circuitbreaker: |
@@ -89,6 +89,10 @@ tuoheng: | |||
staticAccessPath: /** | |||
#静态资源实际存储路径 | |||
uploadFolder: /data/java/tuoheng_telecomumale/uploads/ | |||
#城管小程序 | |||
wx: | |||
appId: wxd0f247d7272ca1b7 | |||
appSecret: 541002e33cd4b011d4c13954ed34efdb | |||
## 配置feign熔断 | |||
#feign: | |||
# circuitbreaker: |
@@ -81,7 +81,7 @@ | |||
and ti.dept_id = #{request.deptId} | |||
</if> | |||
<if test="request.status !=null"> | |||
and ti.status = #{request.status} | |||
and ti.status in (10,15) | |||
</if> | |||
<if test="request.inspectionType !=null"> | |||
and ti.inspection_type = #{request.inspectionType} |
@@ -0,0 +1,7 @@ | |||
<?xml version="1.0" encoding="UTF-8" ?> | |||
<!DOCTYPE mapper | |||
PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" | |||
"http://mybatis.org/dtd/mybatis-3-mapper.dtd"> | |||
<mapper namespace="com.tuoheng.miniprogram.dao.LiveChannelMapper"> | |||
</mapper> |