当前位置: 首页 > news >正文

内网网站模板广西住房和城乡建设厅培训中心网站首页

内网网站模板,广西住房和城乡建设厅培训中心网站首页,宁波建设工程有限公司,网站域名被抢注做商标参考链接 需求#xff1a;从外部浏览器#xff0c;点击H5链接跳转打开微信小程序#xff1b;以及在微信内直接点击H5链接打开微信小程序#xff1b; 步骤1#xff1a; 小程序开发需要使用云开发创建项目#xff0c;使用云开发生成的项目会自带云函数文件夹#xff1b;…参考链接 需求从外部浏览器点击H5链接跳转打开微信小程序以及在微信内直接点击H5链接打开微信小程序 步骤1 小程序开发需要使用云开发创建项目使用云开发生成的项目会自带云函数文件夹 步骤2 项目开启云开发 步骤3 下载官方的H5静态html和public文件进行配置下载地址点击下载HTML 即可下载全部文件下载后文件夹有两个位置需要修改 下载的文件夹 步骤3.1更改静态的html替换6项云开发字段直接搜索replace 将对象位置的信息改成你的云开发配置 步骤3.2更改public文件跳转打开路径 上面静态html和public的index修改文件我放在了末尾可以详细看下 步骤4更改好上述两个文件后回到微信开发者工具将刚才修改好的public文件添加到cloudfunctions文件夹下只需要public下的文件静态文件html不用放进来 步骤5public文件夹右键上传并部署如报云端安装依赖和没有上传并部署问题看下面截图 问题5.1如云函数右键没有上传可能是没有连接上云函数环境。可以修改project.config.json文件修改对应的目录cloudfunctionRoot为云开发的目录 miniprogramRoot: miniprogram/, cloudfunctionRoot: cloudfunctions/,**问题5.2**上传并部署-报问题缺少依赖安装依赖即可 npm install --production步骤6开启两个权限 开启6.1开启 未登录用户访问云资源权限设置 开启6.2云函数的权限设置开启 允许所有用户访问 步骤7上传之前修改好的云环境参数的静态H5文件jump-mp.html 上传成功后点击详情复制链接在微信和浏览器地址栏都可以打开小程序了 8.此时操作完按理来说就可以通过链接打开微信小程序了但实际操作中发现在微信端可以打开但是外部浏览器输入链接后没有跳转微信打开没反应了直接如下图 **问题8.1**查看jump-mp.html代码将原方法注释使用try catch方法 alertres看看到底什么原因导致再具体修改即可。 代码 async function openWeapp(onBeforeJump) {var c window.cconst res await c.callFunction({name: public,data: {action: getUrlScheme,},})console.warn(res)if (onBeforeJump) {onBeforeJump()}location.href res.result.openlink}/* async function openWeapp(onBeforeJump) {alert(静态)var c window.ctry {const res await c.callFunction({name: public,data: {action: getUrlScheme,},})alert(res)alert(res.result.openlink)console.warn(res)//跳转地址alert(res.result.openlink)if (onBeforeJump) {onBeforeJump()}alert(res.result.openlink)location.href res.result.openlink} catch (error) {alert(error)}} */我当时问题报的Error: errCode: -404011 cloud function execution error | errMsg: cloud.callFunction:fail requestID , cloud function service error code -501023, error message Unauthenticated access is denied (callid 1626072949050-0.6283798683396115); at cloud.callFunction api; 步骤9打开链接成功跳转到小程序 微信端打开链接 外部浏览器打开链接 步骤10.部分代码 10.1生成静态H5连接的文件jump-mp.html htmlheadtitle打开小程序/titlemeta http-equivContent-Type contenttext/html; charsetutf-8meta nameviewport contentwidthdevice-width, user-scalableno, initial-scale1, maximum-scale1scriptwindow.onerror e {console.error(e)alert(发生错误 e)}/script!-- weui 样式 --link relstylesheet hrefhttps://res.wx.qq.com/open/libs/weui/2.4.1/weui.min.css/link!-- 调试用的移动端 console --!-- script srchttps://cdn.jsdelivr.net/npm/eruda/script --!-- scripteruda.init();/script --!-- 公众号 JSSDK --script srchttps://res.wx.qq.com/open/js/jweixin-1.6.0.js/script!-- 云开发 Web SDK --script srchttps://res.wx.qq.com/open/js/cloudbase/1.1.0/cloud.js/scriptscriptfunction docReady(fn) {if (document.readyState complete || document.readyState interactive) {fn()} else {document.addEventListener(DOMContentLoaded, fn);}}docReady(async function () {var ua navigator.userAgent.toLowerCase()var isWXWork ua.match(/wxwork/i) wxworkvar isWeixin !isWXWork ua.match(/micromessenger/i) micromessengervar isMobile falsevar isDesktop falseif (navigator.userAgent.match(/(phone|pad|pod|iPhone|iPod|ios|iPad|Android|Mobile|IEMobile)/i)) {isMobile true} else {isDesktop true}if (isWeixin) {var containerEl document.getElementById(wechat-web-container)containerEl.classList.remove(hidden)containerEl.classList.add(full, wechat-web-container)var launchBtn document.getElementById(launch-btn)launchBtn.addEventListener(ready, function (e) {console.log(开放标签 ready)})launchBtn.addEventListener(launch, function (e) {console.log(开放标签 success)})launchBtn.addEventListener(error, function (e) {console.log(开放标签 fail, e.detail)})wx.config({// debug: true, // 调试时可开启appId: wxf6be280b0bb, // !-- replace --timestamp: 0, // 必填填任意数字即可nonceStr: nonceStr, // 必填填任意非空字符串即可signature: signature, // 必填填任意非空字符串即可jsApiList: [chooseImage], // 必填随意一个接口即可 openTagList: [wx-open-launch-weapp], // 填入打开小程序的开放标签名})} else if (isDesktop) {// 在 pc 上则给提示引导到手机端打开var containerEl document.getElementById(desktop-web-container)containerEl.classList.remove(hidden)containerEl.classList.add(full, desktop-web-container)} else {var containerEl document.getElementById(public-web-container)containerEl.classList.remove(hidden)containerEl.classList.add(full, public-web-container)var c new cloud.Cloud({// 必填表示是未登录模式identityless: true,// 资源方 AppIDresourceAppid: wxf6be280b0bb, // !-- replace --// 资源方环境 IDresourceEnv: zuihuibaomarket-1gerisnfx, // !-- replace --})await c.init()window.c cvar buttonEl document.getElementById(public-web-jump-button)var buttonLoadingEl document.getElementById(public-web-jump-button-loading)try {await openWeapp(() {buttonEl.classList.remove(weui-btn_loading)buttonLoadingEl.classList.add(hidden)})} catch (e) {buttonEl.classList.remove(weui-btn_loading)buttonLoadingEl.classList.add(hidden)throw e}}})// 如果在外部浏览器链接中打开不跳转微信小程序可能是返回的res有问题可以把这个方法注释掉 把下方的注释方法打开根据具体的报错进行修改async function openWeapp(onBeforeJump) {var c window.cconst res await c.callFunction({name: public,data: {action: getUrlScheme,},})console.warn(res)if (onBeforeJump) {onBeforeJump()}location.href res.result.openlink}/* async function openWeapp(onBeforeJump) {alert(静态)var c window.ctry {const res await c.callFunction({name: public,data: {action: getUrlScheme,},})alert(res)alert(res.result.openlink)console.warn(res)//跳转地址alert(res.result.openlink)if (onBeforeJump) {onBeforeJump()}alert(res.result.openlink)location.href res.result.openlink} catch (error) {alert(error)}} *//scriptstyle.hidden {display: none;}.full {position: absolute;top: 0;bottom: 0;left: 0;right: 0;}.public-web-container {display: flex;flex-direction: column;align-items: center;}.public-web-container p {position: absolute;top: 40%;}.public-web-container a {position: absolute;bottom: 40%;}.wechat-web-container {display: flex;flex-direction: column;align-items: center;}.wechat-web-container p {position: absolute;top: 40%;}.wechat-web-container wx-open-launch-weapp {position: absolute;bottom: 40%;left: 0;right: 0;display: flex;flex-direction: column;align-items: center;}.desktop-web-container {display: flex;flex-direction: column;align-items: center;}.desktop-web-container p {position: absolute;top: 40%;}/style /headbodydiv classpage fulldiv idpublic-web-container classhiddenp class正在打开 “惠多保”.../p !-- replace --a idpublic-web-jump-button hrefjavascript: classweui-btn weui-btn_primary weui-btn_loadingonclickopenWeapp()span idpublic-web-jump-button-loading classweui-primary-loading weui-primary-loading_transparenticlassweui-primary-loading__dot/i/span打开小程序/a/divdiv idwechat-web-container classhiddenp class点击以下按钮打开 “惠多保”/p !-- replace --!-- 跳转小程序的开放标签。文档 https://developers.weixin.qq.com/doc/offiaccount/OA_Web_Apps/Wechat_Open_Tag.html --wx-open-launch-weapp idlaunch-btn usernamegh_bafb9bdb0517 pathpages/index/index!-- replace --templatebuttonstylewidth: 200px; height: 45px; text-align: center; font-size: 17px; display: block; margin: 0 auto; padding: 8px 24px; border: none; border-radius: 4px; background-color: #07c160; color:#fff;打开小程序/button/template/wx-open-launch-weapp/divdiv iddesktop-web-container classhiddenp class请在手机打开网页链接/p/div/div /body/html10.2:public文件夹下的index.js云函数 // 云函数入口文件 const cloud require(wx-server-sdk)cloud.init()// 云函数入口函数 exports.main async (event, context) {const wxContext cloud.getWXContext()switch (event.action) {case getUrlScheme: {return getUrlScheme()}}return action not found }async function getUrlScheme() {return cloud.openapi.urlscheme.generate({jumpWxa: {// path: /page/component/index, // !-- replace --// 外部浏览器打开的小程序页面地址path: /pages/index/index, // !-- replace --query: ,},// 如果想不过期则置为 false并可以存到数据库isExpire: false,// 一分钟有效期expireTime: parseInt(Date.now() / 1000 60),}) } 10.3public下的另外两个文件config.json和package.json无需修改
http://www.yutouwan.com/news/81237/

相关文章:

  • 工程信息价查询网站广告设计海报
  • 洛阳便宜网站建设报价石家庄网站推广软件
  • 招聘58同城找工作网站做优化必须要ftp吗
  • 怎么在网上注册自己的网站有没有做网站兼职
  • 请别人做网站注意事项营销网站的设计思路
  • 公司网站设计需要多少钱招生平台网站开发
  • 东莞网站建设主要学什么酒店网站html模板
  • 网站建设沙漠风苏州网站建设及推广
  • 优秀网站设计网站seo诊断专家
  • 在阿里巴巴网站上怎么做贸易上海人才网官网下载
  • 网站开发层次想学设计没有基础怎么办
  • 收废品做网站怎么做建筑人才网最新招聘信息息
  • 做网站的无锡大学生网页设计作业代码
  • 重庆万州网站建设哪家好北京传媒公司
  • 南宁优质手机网站建设公司建设银行官网首页登录入口
  • 网站建设方案可行性秦皇岛市建设银行网点
  • 自学it做网站大连网站怎么推广
  • 满屏网站设计做多大上海专业网站建设渠道
  • 免费做相册video的网站做网站要买什么服务器
  • php网站游客试用怎么做网站备案核验单
  • 网站建设与运营固定资产jsp 数据库做网站
  • 网站到底是域名需要备案还是空间做网站的主要作用
  • 程序员和网站建设网页设计考试
  • seo整站优化方案番禺24小时核酸检测
  • 自己做都网站怎么发朋友圈保定高端网站建设
  • 网站建设代码实例网站开发和合同范本
  • 合肥建设网官方网站在线制作网站的工具
  • 广州网站建设专注乐云seo建设银行网络平台
  • 大型企业网站源码wordpress 管理员权限设置密码
  • 网站站内链接百度联系方式