D1744-微信小程序禁止PC端打开,防止白嫖和电脑抓接口

介绍

每日靠着微薄的小程序广告度日,继之前检测手机端微信跳过小程序广告插件检测后又发现小程序广告在电脑端经常没广告,导致收入备降!虽然每天只有几块钱的收入,哈哈哈!那么怎么做到禁止小程序使用电脑端微信打开呢?想到获取设备信息判断是否为移动端设备不是就弹窗让用户扫码使用手机微信打开。

通过官方接口文档wx.getSystemInfoSync() 发现platform返参刚好符合我的需求。然后设计一个组件方便后期页面调用。

代码

1.创建一个弹窗组件

a. components/Popup/Popup.wxml:

<view wx:if="{{show}}" class="popup">
  <view class="popup-content">
    <view class="popup-header">
      <text>提示</text>
    </view>
    <image src="{{qrCodeSrc}}" class="qr-code" />
    <view class="popup-footer">
      <text>请用手机端微信扫一扫继续体验</text>
    </view>
  </view>
</view>

b. components/Popup/Popup.wxss:

.popup {
  position: fixed;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  background-color: rgba(128, 128, 128);
  display: flex;
  justify-content: center;
  align-items: center;
  z-index: 999;
}

.popup-content {
  background-color: #fff;
  padding: 20px;
  width: 100%;
  border-radius: 10px;
  text-align: center;
}

.popup-header {
  margin-bottom: 20px;
}

.qr-code {
  width: 200px;
  height: 200px;
  margin-bottom: 20px;
}

.popup-footer {
  margin-top: 20px;
}
图片[1]-D1744-微信小程序禁止PC端打开,防止白嫖和电脑抓接口-榆桦源码网
© 版权声明
THE END
喜欢就支持一下吧
点赞7 分享
评论 抢沙发

请登录后发表评论

    暂无评论内容