一、注册微信开发平台
1、app分享需要先到微信开放平台注册应用,并获得开放平台的 appId和秘钥
2、配置开发者信息如下图
3、安卓版的应用签名生成
3.1 打包好uniApp的安卓版本,并安装到手机上(打包配置)
3.2 选择文件下载,并安装到安卓手机上
下载地址:https://developers.weixin.qq.com/doc/oplatform/Downloads/Android_Resource.html
3.3 安装好下载的软件后,打开输入第二步配置的包名生成秘钥,再把秘钥配置到第二步里
二、uni-app 安卓版本打包
1、模块配置
打开HBuilder X 开发工具,如下图操作步骤操作,其中appid 是第一步在开放平台注册之后生成的
2、云打包配置
2.1 生成自有证书
https://ask.dcloud.net.cn/article/35777
2.2 共有证书
开发测试的时候可以使用,正式环境不能使用
2.3 云打包配置
3、查看证书命令
在cmd 命令窗口中输入 keytool -list -v -keystore community.keystore
三、分享代码
文档:https://uniapp.dcloud.io/api/plugins/share?id=onshareappmessage
1、小程序分享
JavaScript // 小程序分享 shareMini() { uni.share({ provider: 'weixin', scene: "WXSceneSession", type: 5, imageUrl: 'https://bjetxgzv.cdn.bspapp.com/VKCEYUGU-uni-app-doc/962fc340-4f2c-11eb-bdc1-8bd33eb6adaa.png', title: '打开APP测试', miniProgram: { id: 'gh_60e75c691915', path: 'pages/work/work', type: 0, webUrl: 'http://uniapp.dcloud.io' }, success: ret => { console.log(JSON.stringify(ret)); } }); }, |
2、图文分享
JavaScript // 图文分享 shareImgTex() { uni.share({ provider: "weixin", scene: "WXSceneSession", type: 0, href: "http://uniapp.dcloud.io/", title: "加入社群邀请", summary: "民警-张丽邀请你加入社群", imageUrl: "/static/images/code.png", success: function(res) { console.log("success:" + JSON.stringify(res)); }, fail: function(err) { console.log("fail:" + JSON.stringify(err)); } }); }, |
3、图片分享
JavaScript // 图片分享 shareImg() { uni.share({ provider: "weixin", scene: "WXSceneSession", type: 2, imageUrl: "/static/images/code.png", success: function(res) { console.log("success:" + JSON.stringify(res)); }, fail: function(err) { console.log("fail:" + JSON.stringify(err)); } }); }, |
四、微信打开APP
1、H5 页面打开APP
文档:https://developers.weixin.qq.com/doc/oplatform/Mobile_App/WeChat_H5_Launch_APP.html
2、小程序打开APP
文档:https://developers.weixin.qq.com/miniprogram/dev/framework/open-ability/launchApp.html
注意:打开需要特定的场景值,也就是说只有app 分享(小程序类型的分享) 到微信聊天的卡片点击进入小程序才能跳转到APP内
小程序打开APP的代码:
Scala <button class="margin-top" open-type="launchApp" size="default" type="primary" app-parameter="wechat" :binderror="launchAppError()">打开APP</button> |
3、uniapp 打开小程序
JavaScript //打开微信小程序 ,appId:小程序原始ID,path跳转的小程序页面 openWxMiniApp(appId, path) { plus.share.getServices(function(res) { var sweixin = null; for (var i = 0; i < res.length; i++) { var t = res[i]; if (t.id == 'weixin') { sweixin = t; } } if (sweixin) { // 发送分享 if(sweixin.authenticated){ sweixin.launchMiniProgram({ id: appId, type: 0, path: path || '' }); }else { sweixin.authorize(function(){ doShare(sweixin, msg); }, function(e){ // code 错误码 http://ask.dcloud.net.cn/article/282 uni.showToast({ title: e?.code === -8 ? '微信客户端未安装' : e?.message, icon: 'none' }) }); } } else { uni.showToast({ title: '打开小程序失败', icon: 'none' }) } }, function(res) { console.log(JSON.stringify(res)); uni.showToast({ title: '打开小程序失败', icon: 'none' }) }); }, |