zhangjinli 3 years ago
parent 9e258a0a92
commit 7cdb21ee0b

@ -7,15 +7,13 @@ import com.baomidou.mybatisplus.core.conditions.update.UpdateWrapper;
import com.zh.project0512.annotation.AdminCheckAuthorityAnnotation; import com.zh.project0512.annotation.AdminCheckAuthorityAnnotation;
import com.zh.project0512.annotation.AdminTokenValid; import com.zh.project0512.annotation.AdminTokenValid;
import com.zh.project0512.mapper.UserEffectRecordsMapper; import com.zh.project0512.mapper.UserEffectRecordsMapper;
import com.zh.project0512.model.AppMessage; import com.zh.project0512.model.*;
import com.zh.project0512.model.UserEffectRecords;
import com.zh.project0512.model.Video;
import com.zh.project0512.model.VideoEffectSetting;
import com.zh.project0512.service.IUserEffectRecordsService; import com.zh.project0512.service.IUserEffectRecordsService;
import com.zh.project0512.service.IUserService; import com.zh.project0512.service.IUserService;
import com.zh.project0512.service.IVideoEffectSettingService; import com.zh.project0512.service.IVideoEffectSettingService;
import com.zh.project0512.service.IVideoService; import com.zh.project0512.service.IVideoService;
import com.zh.project0512.utils.AppMessageUtil; import com.zh.project0512.utils.AppMessageUtil;
import com.zh.project0512.utils.HttpUtil;
import com.zh.project0512.utils.MybatisPlusUtil; import com.zh.project0512.utils.MybatisPlusUtil;
import com.zh.project0512.utils.result.HttpStatusEnum; import com.zh.project0512.utils.result.HttpStatusEnum;
import com.zh.project0512.utils.result.Result; import com.zh.project0512.utils.result.Result;
@ -54,6 +52,8 @@ public class VideoController {
private IVideoEffectSettingService videoEffectSettingService; private IVideoEffectSettingService videoEffectSettingService;
@Autowired @Autowired
private UserEffectRecordsMapper userEffectRecordsMapper; private UserEffectRecordsMapper userEffectRecordsMapper;
@Autowired
private HttpUtil httpUtil;
@Data @Data
static class VParam { static class VParam {
@ -165,7 +165,7 @@ public class VideoController {
up.set("effectResult", effectResult); up.set("effectResult", effectResult);
up.set("updateAt", LocalDateTime.now()); up.set("updateAt", LocalDateTime.now());
videoService.update(up); videoService.update(up);
userEffectRecordsMapper.saveEffectResult(new UserEffectRecords().setUserId(video.getUserId()).setEffectResultTran(effectResult-originEffectResult).setCreateAt(LocalDateTime.now())); userEffectRecordsMapper.saveEffectResult(new UserEffectRecords().setUserId(video.getUserId()).setEffectResultTran(effectResult - originEffectResult).setCreateAt(LocalDateTime.now()));
String platForm = "未知平台"; String platForm = "未知平台";
switch (video.getType()) { switch (video.getType()) {
case 1: case 1:
@ -182,8 +182,20 @@ public class VideoController {
break; break;
default: default:
} }
AppMessageUtil.sendMessage(new AppMessage().setTitle("传播效果审核结果").setDescription("恭喜您," + platForm + "传播效果审核通过,平台评定传播值为" + effectResult + "。") AppMessage appMessage = new AppMessage().setTitle("传播效果审核结果")
.setUrl("pages/quest/subpage/detail/detail?id=" + video.getTaskId()).setReceiverId(video.getUserId())); .setDescription("恭喜您," + platForm + "传播效果审核通过,平台评定传播值为" + effectResult + "。")
.setUrl("pages/quest/subpage/detail/detail?id=" + video.getTaskId())
.setReceiverId(video.getUserId());
// 企业微信消息通知
String touser = userService.getById(video.getUserId()).getUserid();
if (touser != null) {
appMessage.setTouser(touser);
// List<JSONObject>
JSONObject content_item = new JSONObject();
// content_item.fluentPut("")
httpUtil.qywxMessage(httpUtil.qywxGetToken(),touser,"传播效果审核",null,appMessage.getUrl(),null);
}
AppMessageUtil.sendMessage(appMessage);
return Result.success("", "审核完成"); return Result.success("", "审核完成");
} }

@ -4,7 +4,9 @@ import com.baomidou.mybatisplus.annotation.TableName;
import com.baomidou.mybatisplus.annotation.IdType; import com.baomidou.mybatisplus.annotation.IdType;
import com.baomidou.mybatisplus.extension.activerecord.Model; import com.baomidou.mybatisplus.extension.activerecord.Model;
import com.baomidou.mybatisplus.annotation.TableId; import com.baomidou.mybatisplus.annotation.TableId;
import java.time.LocalDateTime; import java.time.LocalDateTime;
import com.baomidou.mybatisplus.annotation.TableField; import com.baomidou.mybatisplus.annotation.TableField;
import lombok.Data; import lombok.Data;
import lombok.EqualsAndHashCode; import lombok.EqualsAndHashCode;
@ -58,6 +60,12 @@ public class AppMessage extends Model {
@TableField("receiverId") @TableField("receiverId")
private Integer receiverId; private Integer receiverId;
/**
* userid
*/
@TableField("touser")
private String touser;
/** /**
* *
*/ */

@ -2,6 +2,7 @@ package com.zh.project0512.utils;
import com.zh.project0512.mapper.AppMessageMapper; import com.zh.project0512.mapper.AppMessageMapper;
import com.zh.project0512.model.AppMessage; import com.zh.project0512.model.AppMessage;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component; import org.springframework.stereotype.Component;
import javax.annotation.PostConstruct; import javax.annotation.PostConstruct;
@ -15,7 +16,6 @@ import java.time.LocalDateTime;
public class AppMessageUtil { public class AppMessageUtil {
@Resource @Resource
AppMessageMapper appMessageMapper; AppMessageMapper appMessageMapper;
//解决工具类无法调用Dao层数据数据为null //解决工具类无法调用Dao层数据数据为null
//静态初始化当前类 //静态初始化当前类
private static AppMessageUtil appMessageUtil; private static AppMessageUtil appMessageUtil;

@ -1,6 +1,7 @@
package com.zh.project0512.utils; package com.zh.project0512.utils;
import com.alibaba.fastjson.JSONObject; import com.alibaba.fastjson.JSONObject;
import com.zh.project0512.model.AppMessage;
import lombok.extern.slf4j.Slf4j; import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Value; import org.springframework.beans.factory.annotation.Value;
import org.springframework.stereotype.Component; import org.springframework.stereotype.Component;
@ -21,42 +22,75 @@ public class HttpUtil {
private String corpid; private String corpid;
@Value("${qywx.corpsecret}") @Value("${qywx.corpsecret}")
private String corpsecret; private String corpsecret;
@Value("${qywx.agentid}")
private String agentid;
@Value("${wx.appid}")
private String appid;
public String qywxGetToken(){ public String qywxGetToken() {
String url = "https://qyapi.weixin.qq.com/cgi-bin/gettoken"; String url = "https://qyapi.weixin.qq.com/cgi-bin/gettoken";
String requestUrl = url + "?corpid=" + corpid + "&corpsecret=" + corpsecret; String requestUrl = url + "?corpid=" + corpid + "&corpsecret=" + corpsecret;
String str = httpRequest(requestUrl, "GET", null); String str = httpRequest(requestUrl, "GET", null);
return JSONObject.parseObject(str).getString("access_token"); return JSONObject.parseObject(str).getString("access_token");
} }
public JSONObject qywxDepartmentList(String access_token){
public JSONObject qywxDepartmentList(String access_token) {
String url = "https://qyapi.weixin.qq.com/cgi-bin/department/list"; String url = "https://qyapi.weixin.qq.com/cgi-bin/department/list";
String requestUrl = url + "?access_token=" + access_token; String requestUrl = url + "?access_token=" + access_token;
String str = httpRequest(requestUrl, "GET", null); String str = httpRequest(requestUrl, "GET", null);
return JSONObject.parseObject(str); return JSONObject.parseObject(str);
} }
public JSONObject qywxUserSession(String access_token,String code){
public JSONObject qywxUserSession(String access_token, String code) {
String url = "https://qyapi.weixin.qq.com/cgi-bin/miniprogram/jscode2session"; String url = "https://qyapi.weixin.qq.com/cgi-bin/miniprogram/jscode2session";
String requestUrl = url + "?access_token=" + access_token +"&js_code="+ code +"&grant_type=authorization_code"; String requestUrl = url + "?access_token=" + access_token + "&js_code=" + code + "&grant_type=authorization_code";
String str = httpRequest(requestUrl, "GET", null); String str = httpRequest(requestUrl, "GET", null);
return JSONObject.parseObject(str); return JSONObject.parseObject(str);
} }
public JSONObject qywxUser(String access_token,String userid){
public JSONObject qywxUser(String access_token, String userid) {
String url = "https://qyapi.weixin.qq.com/cgi-bin/user/get"; String url = "https://qyapi.weixin.qq.com/cgi-bin/user/get";
String requestUrl = url + "?access_token=" + access_token +"&userid="+ userid ; String requestUrl = url + "?access_token=" + access_token + "&userid=" + userid;
String str = httpRequest(requestUrl, "GET", null); String str = httpRequest(requestUrl, "GET", null);
return JSONObject.parseObject(str); return JSONObject.parseObject(str);
} }
public Integer qywxDepartmentParentid(String access_token,int id,int loop){ public Integer qywxDepartmentParentid(String access_token, int id, int loop) {
String url = " https://qyapi.weixin.qq.com/cgi-bin/department/get"; String url = " https://qyapi.weixin.qq.com/cgi-bin/department/get";
String requestUrl = url + "?access_token=" + access_token +"&id="+ id ; String requestUrl = url + "?access_token=" + access_token + "&id=" + id;
String str = httpRequest(requestUrl, "GET", null); String str = httpRequest(requestUrl, "GET", null);
Integer parentid = JSONObject.parseObject(str).getJSONObject("department").getInteger("parentid"); Integer parentid = JSONObject.parseObject(str).getJSONObject("department").getInteger("parentid");
if( parentid != 1 && loop< 8 ){ if (parentid != 1 && loop < 8) {
qywxDepartmentParentid(access_token,parentid,++loop); qywxDepartmentParentid(access_token, parentid, ++loop);
} }
return parentid; return parentid;
} }
/**
*
* @param access_token
* @param touser:ID|1000eg:"zhangsan|lisi"
* @param title:4-12
* @param description:4-12
* @param wxAppUrl:1024
* @param content_item:10item
*/
public void qywxMessage(String access_token,String touser, String title,String description,String wxAppUrl,JSONObject content_item) {
JSONObject obj = new JSONObject();
obj.fluentPut("msgtype", "miniprogram_notice").fluentPut("agentid", agentid).fluentPut("touser", touser)
.fluentPut("miniprogram_notice",
new JSONObject().fluentPut("appid",appid)
.fluentPut("description",description)
.fluentPut("page",wxAppUrl)
.fluentPut("title",title)
.fluentPut("content_item",content_item));
String url = " https://qyapi.weixin.qq.com/cgi-bin/message/send";
String requestUrl = url + "?access_token=" + access_token;
String str = httpPost(requestUrl, obj);
System.out.println(obj);
System.out.println(str);
}
public static String httpRequest(String requestUrl, String requestMethod, String output) { public static String httpRequest(String requestUrl, String requestMethod, String output) {
try { try {
URL url = new URL(requestUrl); URL url = new URL(requestUrl);
@ -125,7 +159,7 @@ public class HttpUtil {
new InputStreamReader(conn.getInputStream())); new InputStreamReader(conn.getInputStream()));
String line; String line;
while ((line = in.readLine()) != null) { while ((line = in.readLine()) != null) {
result=result.concat(line); result = result.concat(line);
} }
} catch (Exception e) { } catch (Exception e) {
System.out.println("发送 POST 请求出现异常!" + e); System.out.println("发送 POST 请求出现异常!" + e);

@ -102,6 +102,7 @@ wx:
qywx: qywx:
corpid: wwf8467e6545ca4032 corpid: wwf8467e6545ca4032
corpsecret: u0bzd2vXOib7a6sVy60fwzR9v0Xgea929CApV4eChD0 corpsecret: u0bzd2vXOib7a6sVy60fwzR9v0Xgea929CApV4eChD0
agentid: 1000003
# 抖音开放平台配置信息 # 抖音开放平台配置信息
dy: dy:
clientKey: awty3wnxx90jper9 #抖音开放平台key clientKey: awty3wnxx90jper9 #抖音开放平台key

Loading…
Cancel
Save