This commit is contained in:
@zuopngfei 2025-11-11 18:35:49 +08:00
parent bb20e4ea87
commit 386e2238ea

View File

@ -30,6 +30,8 @@ Page({
lastMessageId: '', // 最后一条消息的ID用于检测新消息 lastMessageId: '', // 最后一条消息的ID用于检测新消息
// 欢迎消息标记 // 欢迎消息标记
hasWelcomeMessageSent: false, // 是否已发送欢迎消息 hasWelcomeMessageSent: false, // 是否已发送欢迎消息
// 订阅消息
template_id: '',
}, },
/** /**
@ -57,10 +59,34 @@ Page({
// 直接进行静默登录,不显示授权弹窗 // 直接进行静默登录,不显示授权弹窗
this.silentLogin(); this.silentLogin();
} }
this.getTemplateId();
}, },
// onShow() { // onShow() {
// this.getMessages() // this.getMessages()
// }, // },
getTemplateId() {
const accountInfo = wx.getAccountInfoSync();
request('wechat/template', 'post', {
app_id: accountInfo.miniProgram.appId
}).then((res) => {
this.setData({
template_id: res.template_id
});
});
},
dingyue() {
return new Promise((resolve, reject) => {
wx.requestSubscribeMessage({
tmplIds: [this.data.template_id],
success: (res) => {
resolve(res);
},
fail: (err) => {
reject(err);
}
});
});
},
getMessages() { getMessages() {
const userInfo = wx.getStorageSync('user_info'); const userInfo = wx.getStorageSync('user_info');
@ -459,9 +485,11 @@ Page({
}, 50); }, 50);
}, },
sendText() { async sendText() {
const text = this.data.inputText && this.data.inputText.trim(); const text = this.data.inputText && this.data.inputText.trim();
if (!text) return; if (!text) return;
const res = await this.dingyue()
const now = new Date(); const now = new Date();
const id = 'u' + Date.now(); const id = 'u' + Date.now();
// const timeStr = this.formatTime(now); // const timeStr = this.formatTime(now);
@ -529,7 +557,9 @@ Page({
// }, 800); // }, 800);
}, },
chooseImage() { async chooseImage() {
const resDy = await this.dingyue()
console.log(resDy);
const that = this; const that = this;
wx.chooseImage({ wx.chooseImage({
count: 1, // 选择图片的数量 count: 1, // 选择图片的数量