同步操作将从 黎晓/JavaScript 强制同步,此操作会覆盖自 Fork 仓库以来所做的任何修改,且无法恢复!!!
确定后同步将在后台操作,完成时将刷新页面,请耐心等待。
<!DOCTYPE html><html><head><title>微信Js API Demo</title><meta http-equiv="Content-Type" content="text/html; charset=UTF-8"><link rel="dns-prefetch" href="http://mmbiz.qpic.cn"><link rel="dns-prefetch" href="http://res.wx.qq.com"><meta name="viewport" content="width=device-width,height=device-height,inital-scale=1.0;"><meta name="apple-mobile-web-app-capable" content="yes"><meta name="apple-mobile-web-app-status-bar-style" content="black"><meta name="format-detection" content="telephone=no"><style type="text/css">p {padding: 5px 10px;}</style><script type="text/javascript" src="WeixinApi.js"></script></head><body><p>这是一个测试页面!请直接分享到微信好友、朋友圈、腾讯微博看效果吧!</p><p>如果你是扫一扫过来的,可以复制连接,然后发给任何一个微信好友,再点击连接进入测试</p><p><button id="optionMenu">WeixinApi.hideOptionMenu</button></p><p><button id="networkType">WeixinApi.getNetworkType</button></p><p><button id="imagePreview">WeixinApi.imagePreview</button></p><p><button id="closeWindow">WeixinApi.closeWindow</button></p><p><button id="scanQRCode">WeixinApi.scanQRCode</button></p><p><button id="getInstallState">WeixinApi.getInstallState</button></p><p><button id="sendEmail">WeixinApi.sendEmail</button></p><p><a href="?" id="refresh">点击这里刷新!!!!</a></p><script type="text/javascript">// 开启Api的debug模式WeixinApi.enableDebugMode();// 给按钮增加click事件:请不要太纠结这个写法,demo而已var addEvent = function(elId,listener){document.getElementById(elId).addEventListener('click',function(e){if(!window.WeixinApi || !window.WeixinJSBridge) {alert('请确认您是在微信内置浏览器中打开的,并且WeixinApi.js已正确引用');e.preventDefault();return false;}listener(this,e);},false);};// 两个Flagvar optionMenuOn = true;var toolbarOn = true;// optionMenu的控制addEvent('optionMenu',function(el,e){if(optionMenuOn) {el.innerHTML = "WeixinApi.showOptionMenu";WeixinApi.hideOptionMenu();}else{el.innerHTML = "WeixinApi.hideOptionMenu";WeixinApi.showOptionMenu();}optionMenuOn = !optionMenuOn;});// 获取网络类型addEvent('networkType',function(el,e){WeixinApi.getNetworkType(function(network) {alert("当前网络类型:" + network);});});// 调起客户端的图片播放组件addEvent('imagePreview',function(el,e){location.href = "http://www.baidufe.com/wximage?tag=%E7%BE%8E%E5%A5%B3";});// 关闭窗口addEvent('closeWindow',function(el,e){WeixinApi.closeWindow({success : function(resp){alert('关闭窗口成功!');},fail : function(resp){alert('关闭窗口失败');}});});// 打开扫码addEvent('scanQRCode',function(el,e){WeixinApi.scanQRCode({success : function(resp){alert('扫描器已打开!');},fail : function(resp){alert('扫描器无法打开');}});});// 判断是否安装对应的应用(需要官方打开权限)addEvent("getInstallState", function(el, e) {WeixinApi.getInstallState({packageName: "cn.dxy.android.aspirin",packageUrl: "dxy-aspirin"}, {success: function(resp) {alert("App is installed, version " + resp.version);},fail: function(resp) {alert("Oops, something goes wrong or app is not installed.");}})});// 发送邮件addEvent("sendEmail", function(el, e) {WeixinApi.sendEmail({subject : 'Hello world!',body : '这是一封测试邮件,Demo而已,慢慢玩儿吧!'});});// 刷新addEvent('refresh',function(el,e){e.preventDefault();location.replace('?' + Math.random(),true);});// 需要分享的内容,请放到ready里WeixinApi.ready(function(Api) {// 微信分享的数据var wxData = {"appId": "", // 服务号可以填写appId"imgUrl" : 'http://www.baidufe.com/fe/blog/static/img/weixin-qrcode-2.jpg',"link" : 'http://www.baidufe.com',"desc" : '大家好,我是Alien,Web前端&Android客户端码农,喜欢技术上的瞎倒腾!欢迎多交流',"title" : "大家好,我是赵先烈"};// 分享的回调var wxCallbacks = {// 收藏操作是否触发回调,默认是开启的favorite : false,// 分享操作开始之前ready : function() {// 你可以在这里对分享的数据进行重组alert("准备分享");},// 分享被用户自动取消cancel : function(resp) {// 你可以在你的页面上给用户一个小Tip,为什么要取消呢?alert("分享被取消,msg=" + resp.err_msg);},// 分享失败了fail : function(resp) {// 分享失败了,是不是可以告诉用户:不要紧,可能是网络问题,一会儿再试试?alert("分享失败,msg=" + resp.err_msg);},// 分享成功confirm : function(resp) {// 分享成功了,我们是不是可以做一些分享统计呢?alert("分享成功,msg=" + resp.err_msg);},// 整个分享过程结束all : function(resp,shareTo) {// 如果你做的是一个鼓励用户进行分享的产品,在这里是不是可以给用户一些反馈了?alert("分享" + (shareTo ? "到" + shareTo : "") + "结束,msg=" + resp.err_msg);}};// 用户点开右上角popup菜单后,点击分享给好友,会执行下面这个代码Api.shareToFriend(wxData, wxCallbacks);// 点击分享到朋友圈,会执行下面这个代码Api.shareToTimeline(wxData, wxCallbacks);// 点击分享到腾讯微博,会执行下面这个代码Api.shareToWeibo(wxData, wxCallbacks);// iOS上,可以直接调用这个API进行分享,一句话搞定Api.generalShare(wxData,wxCallbacks);// 有可能用户是直接用微信"扫一扫"打开的,这个情况下,optionMenu是off状态// 为了方便用户测试,我先来trigger show一下var elOptionMenu = document.getElementById('optionMenu');elOptionMenu.click(); // 先隐藏elOptionMenu.click(); // 再显示});</script></body></html>
此处可能存在不合适展示的内容,页面不予展示。您可通过相关编辑功能自查并修改。
如您确认内容无涉及 不当用语 / 纯广告导流 / 暴力 / 低俗色情 / 侵权 / 盗版 / 虚假 / 无价值内容或违法国家有关法律法规的内容,可点击提交进行申诉,我们将尽快为您处理。