From 386e2238ea793eda822d28d897d808c3bbfe74a2 Mon Sep 17 00:00:00 2001 From: "@zuopngfei" Date: Tue, 11 Nov 2025 18:35:49 +0800 Subject: [PATCH] weew --- pages/contact/index.js | 34 ++++++++++++++++++++++++++++++++-- 1 file changed, 32 insertions(+), 2 deletions(-) diff --git a/pages/contact/index.js b/pages/contact/index.js index 6dad225..027ff45 100644 --- a/pages/contact/index.js +++ b/pages/contact/index.js @@ -30,6 +30,8 @@ Page({ lastMessageId: '', // 最后一条消息的ID,用于检测新消息 // 欢迎消息标记 hasWelcomeMessageSent: false, // 是否已发送欢迎消息 + // 订阅消息 + template_id: '', }, /** @@ -57,10 +59,34 @@ Page({ // 直接进行静默登录,不显示授权弹窗 this.silentLogin(); } + this.getTemplateId(); }, // onShow() { // 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() { const userInfo = wx.getStorageSync('user_info'); @@ -459,9 +485,11 @@ Page({ }, 50); }, - sendText() { + async sendText() { + const text = this.data.inputText && this.data.inputText.trim(); if (!text) return; + const res = await this.dingyue() const now = new Date(); const id = 'u' + Date.now(); // const timeStr = this.formatTime(now); @@ -529,7 +557,9 @@ Page({ // }, 800); }, - chooseImage() { + async chooseImage() { + const resDy = await this.dingyue() + console.log(resDy); const that = this; wx.chooseImage({ count: 1, // 选择图片的数量