当前位置:网站首页>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;
边栏推荐
- 关于软件测试的一些思考
- 项目中字符串判空总结
- Day-02 database
- Flink 系例 之 TableAPI & SQL 与 MYSQL 插入数据
- opencv学习笔记六--图像特征[harris+SIFT]+特征匹配
- Redis安装及Ubuntu 14.04下搭建ssdb主从环境
- skywalking 6.4 分布式链路跟踪 使用笔记
- 定了!2022海南二级造价工程师考试时间确定!报名通道已开启!
- Basic use process of cmake
- What are the books that have greatly improved the thinking and ability of programming?
猜你喜欢
C learning notes (5) class and inheritance
写在Doris毕业后的第一天
Word2vec yyds dry goods inventory
官宣:Apache Doris 顺利毕业,成为 ASF 顶级项目!
JVM第二话 -- JVM内存模型以及垃圾回收
【ROS进阶篇】第五讲 ROS中的TF坐标变换
Chapter 4 of getting started with MySQL: creation, modification and deletion of data tables
What are the books that have greatly improved the thinking and ability of programming?
[零基础学IoT Pwn] 复现Netgear WNAP320 RCE
Internet hospital system source code hospital applet source code smart hospital source code online consultation system source code
随机推荐
Opencv learning note 4 -- bank card number recognition
Beilianzhuguan joined the dragon lizard community to jointly promote carbon neutralization
TypeScript: let
【LeetCode】16、最接近的三数之和
opencv学习笔记五--文件扫描+OCR文字识别
The first technology podcast month will be broadcast soon
NPDP能给产品经理带来什么价值?你都知道了吗?
These three online PS tools should be tried
Fix the failure of idea global search shortcut (ctrl+shift+f)
[advanced ROS] lesson 5 TF coordinate transformation in ROS
DirectX repair tool v4.1 public beta! [easy to understand]
[leetcode] 16. The sum of the nearest three numbers
购物商城6.27待完成
Hidden rules of the workplace that must be understood before 30
En utilisant le paquet npoi de net Core 6 c #, lisez Excel.. Image dans la cellule xlsx et stockée sur le serveur spécifié
solidty-基础篇-基础语法和定义函数
[zero basic IOT pwn] reproduce Netgear wnap320 rce
Tensorflow 2. X realizes iris classification
[leetcode 324] swing sorting II thinking + sorting
Opencv Learning Notes 6 -- image feature [harris+sift]+ feature matching