当前位置:网站首页>Wechat official account subscription message Wx open subscribe implementation and pit closure guide
Wechat official account subscription message Wx open subscribe implementation and pit closure guide
2022-07-01 15:02:00 【a_ Jing】
Let's start with a successful rendering :
Mainly look at the bottom of the picture success Log status by accept It means that the user clicked authorization , by reject Indicates that the user has rejected the authorization .


Let's see the implementation , This article uses uniapp frame , Run in wechat browser H5 End
A pit guide :
1. wx-open-subscribe label , Display on Android ,IOS No display ?
Solution : stay manifest.json The file routing mode is changed to hash . And when you visit the first page of your application , it wx.config To configure .
2. wx-open-subscribe Label style setting is troublesome ? Or set not to take effect ?
Solution : Wrap a... In the outer layer div, Complex styles are written on the outer layer , Try to write simple styles for open labels , If it doesn't work, you can learn from the code posted later .
3. wx-open-subscribe Components , How to monitor user clicks “ Cancel ”、“ allow ”? Why the official success The event returns no such as :{ errMsg: "subscribe:ok", subscribeDetails: "{"TenvU22BA1jCp4YHfYEpRuESXYReQyDuhs4vbdWA99I":"{\"status\":\"accept\"}"}, It's going back to 
Solution :success The parameters received inside should be written as success({detail}) Format is OK , It's written in success(e) There will be no e.detail.
<wx-open-subscribe id="subscribe-btn" ref="subscribeBtn"
style="position: fixed;z-idnex:9999; top: 0px, left: 0px;bottom:0px;right:0px;width: 100%;height: 100%;"
template="Qw2bWImUYSgS5y9UoAGa-fd3RUC2aXZ5m25MApxIpA4" id="subscribe-btn">
<!-- Qw2bWImUYSgS5y9UoAGa-fd3RUC2aXZ5m25MApxIpA4 test -->
<!-- NtmNRrJl5FMKND8FuyZhZxL_jbRLNg0-h-iNCr0z0ak formal -->
<script type="text/wxtag-template">
<div style="position: fixed;z-idnex:9999; top: 0px, left: 0px;bottom:0px;right:0px;width: 100%;height: 100%;" />
</script>
</wx-open-subscribe>
// wx-open-subscribe Native binding click event
this.$nextTick(() => {
var btn = this.$refs.subscribeBtn;
btn.addEventListener('success', ({detail}) => {
console.log('success1', detail);
});
btn.addEventListener('error', ({detail}) => {
console.log('fail1', detail);
});
})4. wx-open-subscribe The outer layer of the component div, Click event doesn't work ?
Solution :wx-open-subscribe Component events do not bubble , Can be in success Do event processing after returning .
Implementation code :
<view class="subscribeBlock" v-if="showSubscribe">
<wx-open-subscribe id="subscribe-btn" ref="subscribeBtn"
style="position: fixed;z-idnex:9999; top: 0px, left: 0px;bottom:0px;right:0px;width: 100%;height: 100%;"
template="Qw2bWImUYSgS5y9UoAGa-fd3RUC2aXZ5m25MApxIpA4" id="subscribe-btn">
<!-- Qw2bWImUYSgS5y9UoAGa-fd3RUC2aXZ5m25MApxIpA4 test -->
<!-- NtmNRrJl5FMKND8FuyZhZxL_jbRLNg0-h-iNCr0z0ak formal -->
<script type="text/wxtag-template">
<div style="position: fixed;z-idnex:9999; top: 0px, left: 0px;bottom:0px;right:0px;width: 100%;height: 100%;" />
</script>
</wx-open-subscribe>
</view>js
<script>
var that;
export default {
components: {
search
},
data() {
return {
showSubscribe: false,
};
},
onReady() {
// wx-open-subscribe Native binding click event
this.$nextTick(() => {
var btn = this.$refs.subscribeBtn;
btn.addEventListener('success', ({detail}) => {
console.log('success1', detail);
this.clickSubscribe()
});
btn.addEventListener('error', ({detail}) => {
console.log('fail1', detail);
this.clickSubscribe()
});
})
},
onLoad(option) {
},
methods: {
clickSubscribe() {
console.log(' Click subscribe ');
this.showSubscribe = false;
},
goTest() {
// let url = '/pages/test/test'
// this.goOtherPages(url)
},
}
};
</script>css
.subscribeBlock {
z-index: 99999;
position: fixed;
width: 100vw;
height: 100vh;
left: 0px;
right: 0px;
top: 0px;
bottom: 0px;
}
jssdk Package file : need node install jweixin-module , Baidu can check the specific installation
import config from "./config.js";
import api from "./api.js";
import myRequest from "./request.js";
let jweixin = require('jweixin-module')
Vue.prototype.$wx = jweixin
var wxjssdk = (_wx) => {
return new Promise(rr => {
let url = location.href;
if (url.indexOf('http://localhost') !== -1) url = config.http_url
console.log('url', url)
let data = {
url: encodeURIComponent(url)
}
myRequest.request(api.sdk.wechatJsSdkTicket, data).then(res => {
console.log('wechatJsSdkTicket',res);
let configData = res.data;
console.log('configData',configData);
_wx.config({
// debug: true, // Turn on debugging mode , Call all api The return value of will be on the client side alert come out , To see the parameters passed in , Can be in pc End open , The parameter information will go through log play , Only in pc Only when the end is printed .
debug: false, // Turn on debugging mode , Call all api The return value of will be on the client side alert come out , To see the parameters passed in , Can be in pc End open , The parameter information will go through log play , Only in pc Only when the end is printed .
appId: configData.appId, // Required , The only sign of official account number
timestamp: configData.timestamp, // Required , Generate signature timestamp
nonceStr: configData.nonceStr, // Required , Generate a random string of signatures
signature: configData.signature, // Required , Signature
jsApiList: ['updateAppMessageShareData', 'getNetworkType',
'updateTimelineShareData', 'getLocation'
],
openTagList: ['wx-open-launch-weapp','wx-open-subscribe']
});
_wx.ready(function(res) {
console.log('wx-jssdk-ready', res)
rr(true)
// config It will be executed after information verification ready Method , All interface calls must be in the config After the interface gets the result ,config Is an asynchronous operation of a client , So if you need to call the relevant interface when the page is loaded , The relevant interface shall be ready The function is used to ensure proper execution. . Interface called only when triggered by the user , You can call , No need to put ready Function .
});
_wx.error(function(err) {
console.log('wx-jssdk-error', err)
rr(false)
// config It will be executed after information verification ready Method , All interface calls must be in the config After the interface gets the result ,config Is an asynchronous operation of a client , So if you need to call the relevant interface when the page is loaded , The relevant interface shall be ready The function is used to ensure proper execution. . Interface called only when triggered by the user , You can call , No need to put ready Function .
});
})
})
}
export default wxjssdk;
边栏推荐
- 竣达技术丨室内空气环境监测终端 pm2.5、温湿度TVOC等多参数监测
- tensorflow2-savedmodel convert to pb(frozen_graph)
- Demand prioritization method based on value quantification
- 使用net core 6 c# 的 NPOI 包,讀取excel..xlsx單元格內的圖片,並存儲到指定服務器
- OpenSSL client programming: SSL session failure caused by an insignificant function
- Flink 系例 之 TableAPI & SQL 与 Kafka 消息获取
- Summary of empty string judgment in the project
- 保证生产安全!广州要求危化品企业“不安全不生产、不变通”
- Reorganize the trivial knowledge points at the end of the term
- QT capture interface is displayed as picture or label
猜你喜欢

炎炎夏日,这份安全用气指南请街坊们收好!
![[14. Interval sum (discretization)]](/img/e5/8b29aca7068a6385e8ce90c2742c37.png)
[14. Interval sum (discretization)]

It's settled! 2022 Hainan secondary cost engineer examination time is determined! The registration channel has been opened!

The difference between arrow function and ordinary function in JS

Basic use process of cmake

定了!2022海南二级造价工程师考试时间确定!报名通道已开启!
![opencv学习笔记六--图像特征[harris+SIFT]+特征匹配](/img/50/5c8adacea78e470c255070c8621ddd.png)
opencv学习笔记六--图像特征[harris+SIFT]+特征匹配

openssl客户端编程:一个不起眼的函数导致的SSL会话失败问题

opencv学习笔记六--图像拼接

JVM performance tuning and practical basic theory part II
随机推荐
MySQL service is starting. MySQL service cannot be started. Solution
solidty-基础篇-基础语法和定义函数
竣达技术丨多台精密空调微信云监控方案
Solidty智能合约开发-简易入门
Tensorflow 2. X realizes iris classification
这3款在线PS工具,得试试
Pat 1121 damn single (25 points) set
Configuration of ZABBIX API and PHP
Opencv learning note 4 -- bank card number recognition
基于价值量化的需求优先级排序方法
IDEA全局搜索快捷键(ctrl+shift+F)失效修复
Build your own website (14)
Quelle valeur le pdnp peut - il apporter aux gestionnaires de produits? Vous savez tout?
Flink 系例 之 TableAPI & SQL 与 MYSQL 插入数据
DirectX修复工具V4.1公测![通俗易懂]
Mongodb second talk - - mongodb High available Cluster Implementation
JVM performance tuning and practical basic theory part II
[leetcode] 16. The sum of the nearest three numbers
Solid basic basic grammar and definition function
skywalking 6.4 分布式链路跟踪 使用笔记