<!VDNDOC "PageBase":"nvo_wxsdk_corp","IniEvent":"PageIni">
<!DOCTYPE html>
<html>

	<head>
		<meta charset="utf-8">
		<title>微信JS-SDK</title>
		<meta name="viewport" content="width=device-width, initial-scale=1,maximum-scale=1,user-scalable=no">
		<meta name="apple-mobile-web-app-capable" content="yes">
		<meta name="apple-mobile-web-app-status-bar-style" content="black">

		<!--标准mui.css-->
		<link rel="stylesheet" href="css/mui.min.css">
		<!--App自定义的css-->
		<link rel="stylesheet" type="text/css" href="css/app.css" />
		<style>
			h5 {
				margin: 5px 7px;
			}
		</style>
		<!--图片预览-->
		<style type="text/css">
			.mui-preview-image.mui-fullscreen {
				position: fixed;
				img z-index: 20;
				background-color: #000;
			}
			
			.mui-preview-header,
			.mui-preview-footer {
				position: absolute;
				width: 100%;
				left: 0;
				z-index: 10;
			}
			
			.mui-preview-header {
				height: 44px;
				top: 0;
			}
			
			.mui-preview-footer {
				height: 50px;
				bottom: 0px;
			}
			
			.mui-preview-header .mui-preview-indicator {
				display: block;
				line-height: 25px;
				color: #fff;
				text-align: center;
				margin: 15px auto 4;
				width: 70px;
				background-color: rgba(0, 0, 0, 0.4);
				border-radius: 12px;
				font-size: 16px;
			}
			
			.mui-preview-image {
				display: none;
				-webkit-animation-duration: 0.5s;
				animation-duration: 0.5s;
				-webkit-animation-fill-mode: both;
				animation-fill-mode: both;
			}
			
			.mui-preview-image.mui-preview-in {
				-webkit-animation-name: fadeIn;
				animation-name: fadeIn;
			}
			
			.mui-preview-image.mui-preview-out {
				background: none;
				-webkit-animation-name: fadeOut;
				animation-name: fadeOut;
			}
			
			.mui-preview-image.mui-preview-out .mui-preview-header,
			.mui-preview-image.mui-preview-out .mui-preview-footer {
				display: none;
			}
			
			.mui-zoom-scroller {
				position: absolute;
				display: -webkit-box;
				display: -webkit-flex;
				display: flex;
				-webkit-box-align: center;
				-webkit-align-items: center;
				align-items: center;
				-webkit-box-pack: center;
				-webkit-justify-content: center;
				justify-content: center;
				left: 0;
				right: 0;
				bottom: 0;
				top: 0;
				width: 100%;
				height: 100%;
				margin: 0;
				-webkit-backface-visibility: hidden;
			}
			
			.mui-zoom {
				-webkit-transform-style: preserve-3d;
				transform-style: preserve-3d;
			}
			
			.mui-slider .mui-slider-group .mui-slider-item img {
				width: auto;
				height: auto;
				max-width: 100%;
				max-height: 100%;
			}
			
			.mui-android-4-1 .mui-slider .mui-slider-group .mui-slider-item img {
				width: 100%;
			}
			
			.mui-android-4-1 .mui-slider.mui-preview-image .mui-slider-group .mui-slider-item {
				display: inline-table;
			}
			
			.mui-android-4-1 .mui-slider.mui-preview-image .mui-zoom-scroller img {
				display: table-cell;
				vertical-align: middle;
			}
			
			.mui-preview-loading {
				position: absolute;
				width: 100%;
				height: 100%;
				top: 0;
				left: 0;
				display: none;
			}
			
			.mui-preview-loading.mui-active {
				display: block;
			}
			
			.mui-preview-loading .mui-spinner-white {
				position: absolute;
				top: 50%;
				left: 50%;
				margin-left: -25px;
				margin-top: -25px;
				height: 50px;
				width: 50px;
			}
			
			.mui-preview-image img.mui-transitioning {
				-webkit-transition: -webkit-transform 0.5s ease, opacity 0.5s ease;
				transition: transform 0.5s ease, opacity 0.5s ease;
			}
			
			@-webkit-keyframes fadeIn {
				0% {
					opacity: 0;
				}
				100% {
					opacity: 1;
				}
			}
			
			@keyframes fadeIn {
				0% {
					opacity: 0;
				}
				100% {
					opacity: 1;
				}
			}
			
			@-webkit-keyframes fadeOut {
				0% {
					opacity: 1;
				}
				100% {
					opacity: 0;
				}
			}
			
			@keyframes fadeOut {
				0% {
					opacity: 1;
				}
				100% {
					opacity: 0;
				}
			}
			
			.img-content {
				position: relative;
				padding: 0px;
				align-content: center;
				display: inline-table;
				padding-left: 3px;
			}
			
			.img-content img {
				max-width: 150px;
				height: 150px;
			}
			
			.badge-close {
				position: absolute;
				top: 0px;
				right: 0px;
				z-index: 1;
				padding: 0 !important;
				background-color: red;
				color: white;
				width: 20px;
				height: 20px;
				font-size: 15pt;
				border-radius: 50%;
				-moz-border-radius: 50%;
				-webkit-border-radius: 50%;
			}
		</style>
	</head>

	<body>
		<div class="mui-content">
			<div class="mui-content-padded" style="margin: 5px;">
				<p style="text-indent: 22px;">使用微信JS SDK接口需要的Access_Token(令牌)、api_ticket(票据)、signature(权限签名)及wx.config(...)这些工作VDN都进行了封装只要简单调用就可以完成。Access_Token和api_ticket每2小时过期需要定期获取及全局存储，通过VDN的任务计划来完成这一操作。</p>
			</div>
			<div class="mui-content-padded" style="margin: 5px;">
				<p style="text-indent: 22px;">接口说明参见：
					<a href="https://mp.weixin.qq.com/wiki?t=resource/res_main&id=mp1421141115">微信JS-SDK说明文档</a>
				</p>
			</div>
			<h5>部分接口示例：</h5>
			<div class="mui-input-row">
				<textarea name="t_content" id="t_content" placeholder="内容..." type="text" /></textarea>
			</div>
			<div class="mui-content-padded mui-left">
				<div class="">
					<h6>微信扫一扫：</h6>
					<button id="b_scanQRCode_Rtn" class="mui-btn mui-btn-primary">扫一扫(返回值)</button>
					<button id="b_scanQRCode" class="mui-btn mui-btn-primary">扫一扫(微信处理)</button>
				</div>
				<div>
					<h6>发送一个模板消息给自己：</h6>
					<button id="b_msg" class="mui-btn mui-btn-yellow">模板消息</button>
				</div>
				<div>
					<h6>上传图片：</h6>
					<button id="b_img" class="mui-btn mui-btn-green">上传图片</button>
					<button id="b_preveiw" class="mui-btn mui-btn-blue">预览图片</button>
				</div>
				<div>
					<h6>隐藏指定系统菜单(右上角)：</h6>
					<button id="b_hide_spec" class="mui-btn mui-btn-green">隐藏复制链接</button>
					<button id="b_show_spec" class="mui-btn mui-btn-blue">显示复制链接</button>
				</div>
				<div>
					<h6>隐藏全部菜单(非基础按钮)：</h6>
					<button id="b_hide_all" class="mui-btn mui-btn-yellow">隐藏所有</button>
					<button id="b_show_all" class="mui-btn mui-btn-blue">显示所有</button></div>
				<div>
					<h6>关闭窗口：</h6>
					<button id="b_close" class="mui-btn mui-btn-red" onclick="wx.closeWindow();">关闭</button>
				</div>
			</div>
			<div class="mui-content">
				<div class="mui-content-padded">
					<p>这是图片放大预览示例，点击如下图片体验全屏预览功能</p>
					<p id="list">

					</p>
				</div>
			</div>
		</div>
		<script src="js/jweixin-1.2.0.js"></script>
		<script src="js/mui.min.js"></script>
		<script src="js/imgeview/mui.zoom.js"></script>
		<script src="js/imgeview/mui.previewimage.js"></script>
		<script type="text/javascript" src="js/jquery-2.2.3.min.js"></script>
		<script type="text/javascript" src="js/vdn.js"></script>
		<script>
			mui.init();
			//===========================微信SDK初始化==================================
			var config_ok = true;
			<!--INCLUDE:wx_config;JS-->
			wx.error(function(err) {
				config_ok = false;
				mui.toast(err.errMsg);
			});
			wx.ready(function() {

			})
			//============================微信扫一扫====================================
			//返回扫描信息
			$("#b_scanQRCode_Rtn").click(function() {
				wx.scanQRCode({
					needResult: 1, // 默认为0，扫描结果由微信处理，1则直接返回扫描结果，
					scanType: ["qrCode", "barCode"], // 可以指定扫二维码还是一维码，默认二者都有
					success: function(res) {
						var result = res.resultStr; // 当needResult 为 1 时，扫码返回的结果
						$("#t_content").val(result);
					},
					fail: function(err) {
						mui.toast(err.errMsg);
					}
				});
			});
			//扫一扫 微信直接处理信息
			$("#b_scanQRCode").click(function() {
				wx.scanQRCode({
					needResult: 0, // 默认为0，扫描结果由微信处理，1则直接返回扫描结果，
					scanType: ["qrCode", "barCode"], // 可以指定扫二维码还是一维码，默认二者都有
					success: function(res) {

					},
					fail: function(err) {
						mui.toast(err.errMsg);
					}
				});
			});
			//=====================================发送消息================================
			$("#b_msg").click(function() {
				vdn.post({
						"method": "nvo_wxsdk_corp.send_msg",
						"params": []
					}, function(data) {
						alert("消息发送成功");
					},
					function(err) {
						mui.toast(err.Message + "(" + err.Code.toString() + ")");
					}
				);
			});

			//===================================上传图片=======================================
			var localIds;
			var imgList = new Array();
			$("#b_img").click(function() {
				if (imgList.length >=9){
					alert("最多上传9张图片");
					return;
				}
				//选择图片
				wx.chooseImage({
					count: 9, // 默认9
					sizeType: ['original', 'compressed'], // 可以指定是原图还是压缩图，默认二者都有
					sourceType: ['album', 'camera'], // 可以指定来源是相册还是相机，默认二者都有
					success: function(res) {
						//imgList = []; //clear
						localIds = res.localIds;
						mui("#b_img").button('loading');
						uploadImage();
					},
					fail: function(err) {
						mui.toast(err.errMsg);
					}
				});
				//预览初始化
				mui.previewImage();
			});
			//上传图片
			function uploadImage() {
				var localId = localIds.shift();
				//先上传到微信服务器端
				wx.uploadImage({
					localId: localId, // 需要上传的图片的本地ID，由chooseImage接口获得
					isShowProgressTips: 1, // 默认为1，显示进度提示
					success: function(res) {
						//再通知后台从VDN服务器端下载\n
						vdn.async = false;
						vdn.post({
								"method": "nvo_wxsdk.upimage_json",
								"params": [res.serverId]
							}, function(data) {
								imgList.push(data.Result.url);
								var fmt = '<div class="img-content">';
								fmt += '<span class="badge-close mui-icon mui-icon-closeempty" ref="' + data.Result.id + '"></span>';
								fmt += '<img src="' + localId + '" data-preview-src="" data-preview-group="1" /></div>';
								$(fmt).appendTo("#list");
								//如果多图继续上传下一幅
								if(localIds.length > 0) {
									uploadImage();
								} else {
									mui("#b_img").button('reset');
								}
							},
							function(err) {
								mui.toast(err.Message + "(" + err.Code.toString() + ")");
							});
					}
				});
			}
			//删除图片
			$(document).on("tap", ".badge-close", function() {
				if(!confirm("确定删除该图片?")) return;
				var obj = $(this);
				vdn.post({
						"method": "nvo_wxsdk.delimage",
						"params": [$(this).attr("ref")]
					}, function(data) {
						obj.parent().remove();
					},
					function(err) {
						mui.toast(err.Message + "(" + err.Code.toString() + ")");
					});
			});
			//预览图片
			$("#b_preveiw").click(function() {
				if(imgList.length > 0) {
					wx.previewImage({
						current: imgList[0], // 当前显示图片的http链接
						urls: imgList // 需要预览的图片http链接列表
					});
				} else {
					alert("请先上传图片");
				}
			});
			//============================隐藏菜单===================================
			$(document).on('tap', '#b_hide_spec', function(e) {
				wx.hideMenuItems({
					menuList: ["menuItem:copyUrl"],
					success: function(res) {
						mui.toast("菜单已隐藏");
					},
					fail: function(err) {
						mui.toast(err.errMsg);
					} // 要隐藏的菜单项，只能隐藏“传播类”和“保护类”按钮，所有menu项见附录3
				});
			});
			$(document).on('tap', '#b_show_spec', function(e) {
				wx.showMenuItems({
					menuList: ["menuItem:copyUrl"], //要显示的菜单项，所有menu项见附录3
					success: function(res) {
						mui.toast("菜单已显示");
					},
					fail: function(err) {
						mui.toast(err.errMsg);
					}
				});
			});
			$(document).on('tap', '#b_hide_all', function(e) {
				//隐藏所有非基础按钮接口
				wx.hideAllNonBaseMenuItem({
					success: function(res) {
						mui.toast("菜单已隐藏");
					},
					fail: function(err) {
						mui.toast(err.errMsg);
					}
				});
			});
			$(document).on('tap', '#b_show_all', function(e) {
				//显示所有功能按钮接口
				wx.showAllNonBaseMenuItem({
					success: function(res) {
						mui.toast("所有菜单已显示");
					},
					fail: function(err) {
						mui.toast(err.errMsg);
					}
				});
			});
		</script>
	</body>

</html>