扫普通链接二维码打开小程序与小程序分享功能

做一个点击分享注册小程序,  扫描二维码注册的功能

 1.先来看看分享好友 

(1)button 的    data-name="shareBtn" open-type="share"  属性直接调用右上角的三个点的分享好友方法

        <u-button data-name="shareBtn" open-type="share" iconColor="#FFFFFF" class="uButton" shape="circle"
               icon="attach" text="分享好友">
       </u-button>

(2) onShareAppMessage方法

onShareAppMessage: function(options) {
var that = this;
var urlData = this.qrcodeUrl.split("?")[1];
// 设置菜单中的转发按钮触发转发事件时的转发内容
var shareObj = {
title: "银客通", // 默认是小程序的名称(可以写slogan等)
path: '/subpages/login/shareLogin?urldata=' + urlData, // 默认是当前页面,必须是以‘/'开头的完整路径
imageUrl: 'https://boss.yoliinfo.com/ykt/static/imgs/me/Share.png', //自定义图片路径,可以是本地文件路径、代码包文件路径或者网络图片路径,支持PNG及JPG,不传入 imageUrl 则使用默认截图。显示图片长宽比是 5:4
success: function(res) {
// 转发成功之后的回调
if (res.errMsg == 'shareAppMessage:ok') {

}
},
fail: function() {
// 转发失败之后的回调
if (res.errMsg == 'shareAppMessage:fail cancel') {
// 用户取消转发
} else if (res.errMsg == 'shareAppMessage:fail') {
// 转发失败,其中 detail message 为详细失败信息
}
},
// complete: fucntion() {
// // 转发结束之后的回调(转发成不成功都会执行)
// }
};
// 来自页面内的按钮的转发
if (options.from == 'button') {
var urlData = this.qrcodeUrl.split("?")[1];
// console.log(urlData,"参数",this.qrcodeUrl.split("?")[1]); // shareBtn
// 此处可以修改 shareObj 中的内容 查看分享页 eData.name 携带参数
//这个是跳转到的页面地址
shareObj.path = '/subpages/login/shareLogin?urldata=' + urlData;
}
console.log(shareObj)
// 返回shareObj
return shareObj;
},

 (3)跳转到的页面 /subpages/login/shareLogin 接受参数

              if (option.q) {

//这里是扫描二维码带来的参数 需要转码
const sceneStr = decodeURIComponent(option.q).split("urldata=")[1]; //这里的值就是二维码里带的参
this.formData.recommendNo = sceneStr;
this.obtainInforeferee(sceneStr);
} else {

//这里页面传输的是字符串所以不用转码  点击分享好友带来的参数
this.formData.recommendNo = option.urldata;
this.obtainInforeferee(option.urldata);
}

2.扫描二维码注册 主要是扫描二维码 进入指定页面并且把随之 的参数带过来

   (1).先需要去小程序配置页面里面配置 扫描进入指定页面

      

 

 

 

 

 选择草料二维码测试一下二维码带过来的参数是什么样的格式

(3)跳转到的页面 /subpages/login/shareLogin 接受参数

              if (option.q) {

//这里是扫描二维码带来的参数 需要转码
const sceneStr = decodeURIComponent(option.q).split("urldata=")[1]; //这里的值就是二维码里带的参
this.formData.recommendNo = sceneStr;
this.obtainInforeferee(sceneStr);
} else {

//这里页面传输的是字符串所以不用转码  点击分享好友带来的参数
this.formData.recommendNo = option.urldata;
this.obtainInforeferee(option.urldata);
}

(4)扫描跳转的时候注意页面的接口不需要token传参

posted @ 2023-05-12 10:09  小猴子会上树  阅读(235)  评论(0编辑  收藏  举报