// 判断是否是企业微信PC端
async isEnterpriseWeChatPC() {
const {
platform,
environment
} = await wx.getSystemInfo();
console.log('平台、环境',platform,environment)
if (platform === 'windows' && environment === 'wxwork') {
return true
} else {
return false
}
},
// 请求订阅消息
async requestSubscribeMessage() {
return new Promise((resolve, reject) => {
uni.requestSubscribeMessage({
tmplIds: [this.templateId],
success: () => {
uni.showToast({
title: "订阅成功",
icon: "none"
}).then(() => this.updateSubscription());
resolve(); // 授权成功
},
fail: (err) => {
console.error('订阅消息请求失败:', err);
reject(err); // 授权失败
}
});
});
},
// 更新订阅信息
async updateSubscription() {
try {
const userInfo = uni.getStorageSync('uni-id-pages-userInfo');
const userId = userInfo._id;
const nickname = userInfo.nickname;
await subscription1.updateSubscriptionCount(userId, nickname, this.templateId);
console.log('订阅信息更新成功');
} catch (error) {
console.error('更新订阅信息失败:', error);
}
},
async navigateTofwzx(){
const result = await this.isEnterpriseWeChatPC();
if (result) {
// 企业微信PC端直接跳转
uni.navigateTo({
url: `/pages/fwzx/fwzx`
});
} else {
// 手机端触发订阅消息请求后再跳转
try {
await this.requestSubscribeMessage(); // 请求订阅消息
uni.navigateTo({
url: `/pages/fwzx/fwzx`
}); // 跳转到目标页面
} catch (err) {
console.error('订阅消息授权失败,无法跳转至目标页面:', err);
}
}
},小程序在微信手机端、pc端都可以正常运行,现在在企业微信手机端、pc端都出现错误errMsg: "requestSubscribeMessage:fail can only be invoked by user TAP gesture."
你好,请移步企微官方讨论区:https://developer.work.weixin.qq.com/community/question