|
|
@ -2,11 +2,12 @@ package org.jeecg.modules.api.service.impl; |
|
|
|
|
|
|
|
|
|
|
|
import com.alibaba.fastjson.JSON; |
|
|
|
import com.alibaba.fastjson.JSONObject; |
|
|
|
import com.alibaba.fastjson.TypeReference; |
|
|
|
import com.aliyun.oss.OSS; |
|
|
|
import com.aliyun.oss.OSSClientBuilder; |
|
|
|
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper; |
|
|
|
import com.baomidou.mybatisplus.extension.plugins.pagination.Page; |
|
|
|
import com.google.gson.Gson; |
|
|
|
import org.apache.commons.fileupload.FileItem; |
|
|
|
import org.apache.commons.fileupload.disk.DiskFileItemFactory; |
|
|
|
import org.apache.commons.lang.StringUtils; |
|
|
@ -51,8 +52,6 @@ import org.jeecg.modules.cityTrends.entity.CityTrends; |
|
|
|
import org.jeecg.modules.cityTrends.service.ICityTrendsService; |
|
|
|
import org.jeecg.modules.hanHaiMember.entity.HanHaiMember; |
|
|
|
import org.jeecg.modules.hanHaiMember.service.IHanHaiMemberService; |
|
|
|
import org.jeecg.modules.hanHaiMember.service.impl.HanHaiMemberServiceImpl; |
|
|
|
import org.jeecg.modules.webCase.entity.WebCase; |
|
|
|
import org.springframework.beans.factory.annotation.Value; |
|
|
|
import org.springframework.http.HttpMethod; |
|
|
|
import org.springframework.http.ResponseEntity; |
|
|
@ -65,10 +64,10 @@ import org.springframework.web.multipart.commons.CommonsMultipartFile; |
|
|
|
|
|
|
|
import javax.annotation.Resource; |
|
|
|
import java.io.*; |
|
|
|
import java.util.Date; |
|
|
|
import java.util.HashMap; |
|
|
|
import java.util.List; |
|
|
|
import java.util.Map; |
|
|
|
import java.net.HttpURLConnection; |
|
|
|
import java.net.URL; |
|
|
|
import java.nio.charset.StandardCharsets; |
|
|
|
import java.util.*; |
|
|
|
|
|
|
|
@Service |
|
|
|
public class YaoDuApiServiceImpl implements YaoDuApiService { |
|
|
@ -248,6 +247,7 @@ public class YaoDuApiServiceImpl implements YaoDuApiService { |
|
|
|
Page<CityTrends> page1 = cityTrendsService |
|
|
|
.lambdaQuery() |
|
|
|
.orderByDesc(CityTrends::getCreateTime) |
|
|
|
.eq(CityTrends::getIsState,1) |
|
|
|
.page(page); |
|
|
|
|
|
|
|
if(StringUtils.isNotBlank(classId)){ |
|
|
@ -255,9 +255,40 @@ public class YaoDuApiServiceImpl implements YaoDuApiService { |
|
|
|
.lambdaQuery() |
|
|
|
.eq(CityTrends::getClassId,classId) |
|
|
|
.orderByDesc(CityTrends::getCreateTime) |
|
|
|
.eq(CityTrends::getIsState,1) |
|
|
|
.page(page); |
|
|
|
|
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
//获取评论数量 |
|
|
|
List<CityTrends> records = page1.getRecords(); |
|
|
|
//创建一个新的集合 |
|
|
|
List<CityTrends> newRecords = new ArrayList<>(); |
|
|
|
for (CityTrends cityTrends : records) { |
|
|
|
cityTrends.setIsComment(Math.toIntExact(cityCommentService.lambdaQuery().eq(CityComment::getOrderId, cityTrends.getId()).count())); |
|
|
|
HanHaiMember one = hanHaiMemberService.lambdaQuery().eq(HanHaiMember::getId, cityTrends.getUserId()).one(); |
|
|
|
if(StringUtils.isBlank(one.getName())){ |
|
|
|
cityTrends.setUserName(one.getNickName()); |
|
|
|
}else{ |
|
|
|
cityTrends.setUserName(one.getName()); |
|
|
|
} |
|
|
|
cityTrends.setUserImage(one.getHeadImage()); |
|
|
|
cityTrends.setYearDate(one.getYearDate()); |
|
|
|
cityTrends.setAddress(one.getAddress()); |
|
|
|
if (one.getIdCardOpen() == null){ |
|
|
|
cityTrends.setIsContent(""); |
|
|
|
}else if (one.getIdCardOpen()== 1){ |
|
|
|
cityTrends.setIsContent("个人实名"); |
|
|
|
} else if (one.getIdCardOpen()== 2){ |
|
|
|
cityTrends.setIsContent("店铺实名"); |
|
|
|
}else{ |
|
|
|
cityTrends.setIsContent(""); |
|
|
|
} |
|
|
|
newRecords.add(cityTrends); |
|
|
|
} |
|
|
|
page1.setRecords(newRecords); |
|
|
|
|
|
|
|
return Result.OK(page1); |
|
|
|
} |
|
|
|
|
|
|
@ -265,6 +296,9 @@ public class YaoDuApiServiceImpl implements YaoDuApiService { |
|
|
|
@Override |
|
|
|
public Result<?> getPostDetail(String id){ |
|
|
|
CityTrends cityTrends = cityTrendsService.getById(id); |
|
|
|
//修改帖子浏览量 |
|
|
|
cityTrends.setIsBrowse(cityTrends.getIsBrowse() + 1); |
|
|
|
cityTrendsService.updateById(cityTrends); |
|
|
|
//根据用户表示查询用信息 |
|
|
|
HanHaiMember byId = hanHaiMemberService.getById(cityTrends.getUserId()); |
|
|
|
cityTrends.setUserId(byId.getNickName()); |
|
|
@ -384,6 +418,7 @@ public class YaoDuApiServiceImpl implements YaoDuApiService { |
|
|
|
public Result<?> getPublishButtonList(){ |
|
|
|
List<CityAdd> list = cityAddService |
|
|
|
.lambdaQuery() |
|
|
|
.eq(CityAdd::getIsOpen,"Y") |
|
|
|
.list(); |
|
|
|
return Result.OK(list); |
|
|
|
} |
|
|
@ -436,6 +471,11 @@ public class YaoDuApiServiceImpl implements YaoDuApiService { |
|
|
|
@Override |
|
|
|
public Result<?> publishPost(String token, CityTrends cityTrends){ |
|
|
|
HanHaiMember hanHaiMember = shiroRealm.checkUserTokenIsEffectHanHaiOpenId(token); |
|
|
|
|
|
|
|
|
|
|
|
//验证 |
|
|
|
this.sendMsgSecCheck(hanHaiMember.getAppletOpenid(), cityTrends.getTitle()); |
|
|
|
|
|
|
|
//设置配置 |
|
|
|
cityTrends.setUserId(hanHaiMember.getId()); |
|
|
|
cityTrends.setUserName(hanHaiMember.getNickName()); |
|
|
@ -443,6 +483,7 @@ public class YaoDuApiServiceImpl implements YaoDuApiService { |
|
|
|
cityTrends.setCreateTime(new Date()); |
|
|
|
cityTrends.setSex(hanHaiMember.getSex()); |
|
|
|
cityTrends.setYearDate(hanHaiMember.getYearDate()); |
|
|
|
cityTrends.setIsState(0); |
|
|
|
cityTrendsService.saveOrUpdate(cityTrends); |
|
|
|
return Result.OK("编辑成功"); |
|
|
|
} |
|
|
@ -507,6 +548,7 @@ public class YaoDuApiServiceImpl implements YaoDuApiService { |
|
|
|
.lambdaQuery() |
|
|
|
.eq(CityTrends::getUserId,hanHaiMember.getId()) |
|
|
|
.orderByDesc(CityTrends::getCreateTime) |
|
|
|
.eq(CityTrends::getIsState,1) |
|
|
|
.page(page); |
|
|
|
return Result.OK(page1); |
|
|
|
} |
|
|
@ -753,6 +795,12 @@ public class YaoDuApiServiceImpl implements YaoDuApiService { |
|
|
|
//发布评论 |
|
|
|
public Result<?> comment(String token,CityComment cityComment) { |
|
|
|
HanHaiMember hanHaiMember = shiroRealm.checkUserTokenIsEffectHanHaiOpenId(token); |
|
|
|
|
|
|
|
//验证 |
|
|
|
this.sendMsgSecCheck(hanHaiMember.getAppletOpenid(), cityComment.getUserValue()); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
cityComment.setUserId(hanHaiMember.getId()); |
|
|
|
cityComment.setUserName(hanHaiMember.getNickName()); |
|
|
|
cityComment.setUserHead(hanHaiMember.getHeadImage()); |
|
|
@ -773,4 +821,117 @@ public class YaoDuApiServiceImpl implements YaoDuApiService { |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@Override |
|
|
|
public Result<?> sendMsgSecCheck(String openid,String content){ |
|
|
|
int scene = 1; // 场景枚举值(1 资料;2 评论;3 论坛;4 社交日志) |
|
|
|
int version = 2; // 接口版本号 |
|
|
|
try { |
|
|
|
JSONObject response =this.sendMsgSecCheckRequest(openid, scene, version, content); |
|
|
|
//命中标签枚举值, |
|
|
|
// 100 正常; |
|
|
|
// 10001 广告; |
|
|
|
// 20001 时政; |
|
|
|
// 20002 色情; |
|
|
|
// 20003 辱骂; |
|
|
|
// 20006 违法犯罪; |
|
|
|
// 20008 欺诈; |
|
|
|
// 20012 低俗; |
|
|
|
// 20013 版权; |
|
|
|
// 21000 其他 |
|
|
|
Object result = response.get("result"); |
|
|
|
System.out.println(response.get("result")); |
|
|
|
Gson gson = new Gson(); |
|
|
|
JSONObject result1 = gson.fromJson(response.get("result").toString(), JSONObject.class); |
|
|
|
|
|
|
|
String labelStr = result1.get("label").toString(); |
|
|
|
double labelDouble = Double.parseDouble(labelStr); |
|
|
|
int label = (int) labelDouble; |
|
|
|
|
|
|
|
System.out.println(label); |
|
|
|
if(label == 10001){ |
|
|
|
return Result.error("内容含有敏感信息"); |
|
|
|
} |
|
|
|
if(label == 20001){ |
|
|
|
return Result.error("内容含有敏感信息"); |
|
|
|
} |
|
|
|
if(label == 20002){ |
|
|
|
return Result.error("内容含有敏感信息"); |
|
|
|
} |
|
|
|
if(label == 20003){ |
|
|
|
return Result.error("内容含有敏感信息"); |
|
|
|
} |
|
|
|
if(label == 20006){ |
|
|
|
return Result.error("内容含有敏感信息"); |
|
|
|
} |
|
|
|
if(label == 20008){ |
|
|
|
return Result.error("内容含有敏感信息"); |
|
|
|
} |
|
|
|
if(label == 20012){ |
|
|
|
return Result.error("内容含有敏感信息"); |
|
|
|
} |
|
|
|
if(label == 20013){ |
|
|
|
return Result.error("内容含有敏感信息"); |
|
|
|
} |
|
|
|
|
|
|
|
return Result.OK(label ); |
|
|
|
} catch (Exception e) { |
|
|
|
e.printStackTrace(); |
|
|
|
} |
|
|
|
return Result.OK(); |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
private JSONObject sendMsgSecCheckRequest(String openid, int scene, int version, String content) throws IOException { |
|
|
|
String accessToken = this.getAccessToken(); |
|
|
|
String API_URL = "https://api.weixin.qq.com/wxa/msg_sec_check?access_token=" + accessToken; |
|
|
|
URL url = new URL(API_URL); |
|
|
|
HttpURLConnection conn = (HttpURLConnection) url.openConnection(); |
|
|
|
conn.setRequestMethod("POST"); |
|
|
|
conn.setRequestProperty("Content-Type", "application/json; utf-8"); |
|
|
|
conn.setRequestProperty("Accept", "application/json"); |
|
|
|
conn.setDoOutput(true); |
|
|
|
|
|
|
|
// 构建请求体 |
|
|
|
JSONObject jsonInput = new JSONObject(); |
|
|
|
jsonInput.put("openid", openid); |
|
|
|
jsonInput.put("scene", scene); |
|
|
|
jsonInput.put("version", version); |
|
|
|
jsonInput.put("content", content); |
|
|
|
|
|
|
|
try (DataOutputStream os = new DataOutputStream(conn.getOutputStream())) { |
|
|
|
byte[] input = jsonInput.toString().getBytes(StandardCharsets.UTF_8); |
|
|
|
os.write(input, 0, input.length); |
|
|
|
} |
|
|
|
|
|
|
|
int responseCode = conn.getResponseCode(); |
|
|
|
if (responseCode != 200) { |
|
|
|
throw new IOException("Failed : HTTP error code : " + responseCode); |
|
|
|
} |
|
|
|
|
|
|
|
// 读取响应 |
|
|
|
try (BufferedReader br = new BufferedReader( |
|
|
|
new InputStreamReader(conn.getInputStream(), StandardCharsets.UTF_8))) { |
|
|
|
StringBuilder response = new StringBuilder(); |
|
|
|
String responseLine; |
|
|
|
while ((responseLine = br.readLine()) != null) { |
|
|
|
response.append(responseLine.trim()); |
|
|
|
} |
|
|
|
Gson gson = new Gson(); |
|
|
|
return gson.fromJson(response.toString(), JSONObject.class); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
} |