mirror of
https://gitee.com/huangge1199_admin/vue-pro.git
synced 2024-11-22 15:21:53 +08:00
mp:前端接入发送消息
This commit is contained in:
parent
6325dd288c
commit
541ee81300
@ -37,10 +37,11 @@ public class MpMessageController {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@PostMapping("/send")
|
@PostMapping("/send")
|
||||||
// @ApiOperation("获得粉丝消息表分页")
|
@ApiOperation("给粉丝发送消息")
|
||||||
// @PreAuthorize("@ss.hasPermission('mp:message:query')")
|
@PreAuthorize("@ss.hasPermission('mp:message:send')")
|
||||||
public CommonResult<Long> sendMessage(@Valid @RequestBody MpMessageSendReqVO reqVO) {
|
public CommonResult<MpMessageRespVO> sendMessage(@Valid @RequestBody MpMessageSendReqVO reqVO) {
|
||||||
return success(mpMessageService.sendKefuMessage(reqVO));
|
MpMessageDO message = mpMessageService.sendKefuMessage(reqVO);
|
||||||
|
return success(MpMessageConvert.INSTANCE.convert(message));
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@ -52,8 +52,8 @@ public interface MpMessageService {
|
|||||||
* 注意,该方法会真实发送消息
|
* 注意,该方法会真实发送消息
|
||||||
*
|
*
|
||||||
* @param sendReqVO 消息内容
|
* @param sendReqVO 消息内容
|
||||||
* @return 消息编号
|
* @return 消息
|
||||||
*/
|
*/
|
||||||
Long sendKefuMessage(MpMessageSendReqVO sendReqVO);
|
MpMessageDO sendKefuMessage(MpMessageSendReqVO sendReqVO);
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@ -104,7 +104,7 @@ public class MpMessageServiceImpl implements MpMessageService {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public Long sendKefuMessage(MpMessageSendReqVO sendReqVO) {
|
public MpMessageDO sendKefuMessage(MpMessageSendReqVO sendReqVO) {
|
||||||
// 校验消息格式
|
// 校验消息格式
|
||||||
MpUtils.validateMessage(validator, sendReqVO.getType(), sendReqVO);
|
MpUtils.validateMessage(validator, sendReqVO.getType(), sendReqVO);
|
||||||
|
|
||||||
@ -116,18 +116,17 @@ public class MpMessageServiceImpl implements MpMessageService {
|
|||||||
WxMpKefuMessage wxMessage = MpMessageConvert.INSTANCE.convert(sendReqVO, user);
|
WxMpKefuMessage wxMessage = MpMessageConvert.INSTANCE.convert(sendReqVO, user);
|
||||||
WxMpService mpService = mpServiceFactory.getRequiredMpService(user.getAppId());
|
WxMpService mpService = mpServiceFactory.getRequiredMpService(user.getAppId());
|
||||||
try {
|
try {
|
||||||
boolean result = mpService.getKefuService().sendKefuMessage(wxMessage);
|
mpService.getKefuService().sendKefuMessageWithResponse(wxMessage);
|
||||||
System.out.println(result);
|
|
||||||
} catch (WxErrorException e) {
|
} catch (WxErrorException e) {
|
||||||
throw new RuntimeException(e);
|
throw new RuntimeException(e);
|
||||||
}
|
}
|
||||||
|
|
||||||
// 记录消息
|
// 记录消息
|
||||||
MpMessageDO message = MpMessageConvert.INSTANCE.convert(wxMessage, account, user);
|
MpMessageDO message = MpMessageConvert.INSTANCE.convert(wxMessage, account, user);
|
||||||
message.setSendFrom(MpMessageSendFromEnum.USER_TO_MP.getFrom());
|
message.setSendFrom(MpMessageSendFromEnum.MP_TO_USER.getFrom());
|
||||||
downloadMessageMedia(mpService, message);
|
downloadMessageMedia(mpService, message);
|
||||||
mpMessageMapper.insert(message);
|
mpMessageMapper.insert(message);
|
||||||
return message.getId();
|
return message;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -1,23 +1,6 @@
|
|||||||
import request from '@/utils/request'
|
import request from '@/utils/request'
|
||||||
|
|
||||||
// 创建粉丝消息表
|
// 获得粉丝消息表分页
|
||||||
export function createMessage(data) {
|
|
||||||
return request({
|
|
||||||
url: '/mp/message/create',
|
|
||||||
method: 'post',
|
|
||||||
data: data
|
|
||||||
})
|
|
||||||
}
|
|
||||||
|
|
||||||
// 获得粉丝消息表
|
|
||||||
export function getMessage(id) {
|
|
||||||
return request({
|
|
||||||
url: '/mp/message/get?id=' + id,
|
|
||||||
method: 'get'
|
|
||||||
})
|
|
||||||
}
|
|
||||||
|
|
||||||
// 获得粉丝消息表 分页
|
|
||||||
export function getMessagePage(query) {
|
export function getMessagePage(query) {
|
||||||
return request({
|
return request({
|
||||||
url: '/mp/message/page',
|
url: '/mp/message/page',
|
||||||
@ -25,3 +8,12 @@ export function getMessagePage(query) {
|
|||||||
params: query
|
params: query
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// 给粉丝发送消息
|
||||||
|
export function sendMessage(data) {
|
||||||
|
return request({
|
||||||
|
url: '/mp/message/send',
|
||||||
|
method: 'post',
|
||||||
|
data: data
|
||||||
|
})
|
||||||
|
}
|
||||||
|
@ -88,7 +88,7 @@
|
|||||||
</template>
|
</template>
|
||||||
|
|
||||||
<script>
|
<script>
|
||||||
import { getMessagePage } from '@/api/mp/message'
|
import {getMessagePage, sendMessage} from '@/api/mp/message'
|
||||||
import WxReplySelect from '@/views/mp/components/wx-reply/main.vue'
|
import WxReplySelect from '@/views/mp/components/wx-reply/main.vue'
|
||||||
import WxVideoPlayer from '@/views/mp/components/wx-video-play/main.vue';
|
import WxVideoPlayer from '@/views/mp/components/wx-video-play/main.vue';
|
||||||
import WxVoicePlayer from '@/views/mp/components/wx-voice-play/main.vue';
|
import WxVoicePlayer from '@/views/mp/components/wx-voice-play/main.vue';
|
||||||
@ -107,16 +107,14 @@
|
|||||||
WxMusic
|
WxMusic
|
||||||
},
|
},
|
||||||
props: {
|
props: {
|
||||||
wxUserId: {
|
userId: {
|
||||||
type: String
|
type: String,
|
||||||
|
required: true
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
data() {
|
data() {
|
||||||
return {
|
return {
|
||||||
nowStr: new Date().getTime(), // 当前的时间戳,用于每次消息加载后,回到原位置;具体见 :id="'msg-div' + nowStr" 处
|
nowStr: new Date().getTime(), // 当前的时间戳,用于每次消息加载后,回到原位置;具体见 :id="'msg-div' + nowStr" 处
|
||||||
objData:{
|
|
||||||
repType: 'text'
|
|
||||||
},
|
|
||||||
sendLoading: false, // 发送消息是否加载中
|
sendLoading: false, // 发送消息是否加载中
|
||||||
tableLoading: false, // 消息列表是否正在加载中
|
tableLoading: false, // 消息列表是否正在加载中
|
||||||
loadMore: true, // 是否可以加载更多
|
loadMore: true, // 是否可以加载更多
|
||||||
@ -133,6 +131,9 @@
|
|||||||
nickname: '公众号',
|
nickname: '公众号',
|
||||||
avatar: require("@/assets/images/wechat.png"),
|
avatar: require("@/assets/images/wechat.png"),
|
||||||
},
|
},
|
||||||
|
objData:{ // 微信发送消息
|
||||||
|
repType: 'text'
|
||||||
|
},
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
created() {
|
created() {
|
||||||
@ -140,30 +141,37 @@
|
|||||||
},
|
},
|
||||||
methods:{
|
methods:{
|
||||||
sendMsg(){
|
sendMsg(){
|
||||||
if (this.objData) {
|
if (!this.objData) {
|
||||||
if(this.objData.repType === 'news'){
|
return;
|
||||||
this.objData.content.articles = [this.objData.content.articles[0]]
|
}
|
||||||
this.$message({
|
if (this.objData.repType === 'news') {
|
||||||
showClose: true,
|
this.objData.content.articles = [this.objData.content.articles[0]]
|
||||||
message: '图文消息条数限制在1条以内,已默认发送第一条',
|
this.$message({
|
||||||
type: 'success'
|
showClose: true,
|
||||||
})
|
message: '图文消息条数限制在1条以内,已默认发送第一条',
|
||||||
}
|
type: 'success'
|
||||||
this.sendLoading = true
|
|
||||||
addObj(Object.assign({
|
|
||||||
wxUserId: this.wxUserId
|
|
||||||
},this.objData)).then(data => {
|
|
||||||
this.sendLoading = false
|
|
||||||
data = data.data
|
|
||||||
this.tableData = [...this.tableData , ...[data] ]
|
|
||||||
this.scrollToBottom()
|
|
||||||
this.objData = {
|
|
||||||
repType: 'text'
|
|
||||||
}
|
|
||||||
}).catch(() => {
|
|
||||||
this.sendLoading = false
|
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
this.sendLoading = true
|
||||||
|
sendMessage(Object.assign({
|
||||||
|
userId: this.userId
|
||||||
|
}, {
|
||||||
|
...this.objData,
|
||||||
|
type: this.objData.repType,
|
||||||
|
content: this.objData.repContent,
|
||||||
|
// TODO 芋艿:临时适配,保证可用
|
||||||
|
})).then(response => {
|
||||||
|
this.sendLoading = false
|
||||||
|
// 添加到消息列表,并滚动
|
||||||
|
this.tableData = [...this.tableData , ...[response.data] ]
|
||||||
|
this.scrollToBottom()
|
||||||
|
// 重置 objData 状态
|
||||||
|
this.objData = {
|
||||||
|
repType: 'text'
|
||||||
|
}
|
||||||
|
}).catch(() => {
|
||||||
|
this.sendLoading = false
|
||||||
|
})
|
||||||
},
|
},
|
||||||
loadingMore() {
|
loadingMore() {
|
||||||
this.page.pageNo++
|
this.page.pageNo++
|
||||||
@ -174,7 +182,7 @@
|
|||||||
getMessagePage(Object.assign({
|
getMessagePage(Object.assign({
|
||||||
pageNo: page.pageNo,
|
pageNo: page.pageNo,
|
||||||
pageSize: page.pageSize,
|
pageSize: page.pageSize,
|
||||||
wxUserId: this.wxUserId
|
userId: this.userId
|
||||||
}, params)).then(response => {
|
}, params)).then(response => {
|
||||||
// 计算当前的滚动高度
|
// 计算当前的滚动高度
|
||||||
const msgDiv = document.getElementById('msg-div' + this.nowStr);
|
const msgDiv = document.getElementById('msg-div' + this.nowStr);
|
||||||
|
@ -111,7 +111,7 @@
|
|||||||
@pagination="getList"/>
|
@pagination="getList"/>
|
||||||
|
|
||||||
<el-dialog title="用户消息" :visible.sync="open" width="40%">
|
<el-dialog title="用户消息" :visible.sync="open" width="40%">
|
||||||
<wx-msg wxUserId="1" v-if="true" />
|
<wx-msg user-id="3" v-if="true" />
|
||||||
</el-dialog>
|
</el-dialog>
|
||||||
|
|
||||||
</div>
|
</div>
|
||||||
|
Loading…
Reference in New Issue
Block a user