//封装好了一套微信分享与收货地址js方法,直接将wechatload(window.location.href)方法放到需要使用微信分享功能的页面
function wechatload(page){
	//引入微信js
	$.getScript('http://res.wx.qq.com/open/js/jweixin-1.1.0.js',function(){
		//引入完成后的回调
		getconfig(page);
	})
}
function getconfig(page){
	//从后台获取config
	var url="/api/weixin/getWXSignature";
	var data={url:page}
	$.get(url,data,function(res){
		wx.config({
		    debug: false, // 开启调试模式,调用的所有api的返回值会在客户端alert出来,若要查看传入的参数,可以在pc端打开,参数信息会通过log打出,仅在pc端时才会打印。
		    appId: '', // 必填,公众号的唯一标识
		    timestamp: res.timeStamp, // 必填,生成签名的时间戳
		    nonceStr: res.nonceStr, // 必填,生成签名的随机串
		    signature: res.signature,// 必填,签名,见附录1
		    jsApiList: ['onMenuShareTimeline','onMenuShareAppMessage','openAddress',] // 必填,需要使用的JS接口列表,所有JS接口列表见附录2
		});
		wx.ready(function(){
			//判断进入的页面,并调用不同的方法
			if(page.indexOf('index.html')>-1){
				 onshare(page);
			}
			else if(page.indexOf('classify.html')>-1){
				onshare(page);
			}
			else if(page.indexOf('goodDetails.html')>-1){
				onshare(page);
			}else if(page.indexOf('pay.html')>-1){
				maddress()
			}
		});

	});
}
function onshare(page){
	var desc='';
	var title='';
	var param = '';
	var imgurl=seturl("/static/wechat/jiu/images/ke_01.png");
	var link=seturl("/static/wechat/jiu/index.html");
	if(page.indexOf('index')>-1){
			desc="进口葡萄酒、进口红酒立体销售平台,平均每分钟销售一瓶葡萄酒。一个主张葡萄酒消费应该简单、随意、休闲的新锐品牌。";
			title='红酒世界';
			link=seturl("/static/wechat/jiu/index.html");
	}else if(page.indexOf('classify')>-1){
			desc="酒商平台:上万品牌红酒1元起购,不止5折,全场醉高满199减50,快来抢购吧!";
			title='红酒世界';
			link=seturl("/static/wechat/jiu/classify.html");
	}
	else if(page.indexOf('goodDetails')>-1){
			desc="在线供应白酒,红酒,葡萄酒,洋酒,黄酒,啤酒,保健酒等多品类酒水.品牌授权,渠道正规,手续完备,支持货到付款.用心卖好酒。:";
			title='红酒世界';
			link=seturl("/static/wechat/jiu/goodDetails.html");
	}
	wx.onMenuShareAppMessage({
	    title: title, // 分享标题
	    desc: desc, // 分享描述
	    link: link, // 分享链接
	    imgUrl: imgurl, // 分享图标
	    type: '', // 分享类型,music、video或link,不填默认为link
	    dataUrl: '', // 如果type是music或video,则要提供数据链接,默认为空
	    success: function () { 
	        // 用户确认分享后执行的回调函数
	     
	    },
	    cancel: function () { 
	        // 用户取消分享后执行的回调函数
	    }
	});
	wx.onMenuShareTimeline({
	    title: title, // 分享标题
	    link: link,// 分享链接
	    imgUrl: imgurl, // 分享图标
	    success: function () { 
	        // 用户确认分享后执行的回调函数
	    },
	    cancel: function () { 
	        // 用户取消分享后执行的回调函数
	    }
	});
}
//微信收货地址
function maddress(){
	wx.openAddress({
	     success: function (res) {
	     		//姓名:res.userName 电话:res.telNumber 邮编:res.postalCode 
	     		//省:res.provinceName 市:res.cityName 区:res.countryName 详细地址:res.detailInfo
	     		$(".payone").empty();
	     		$(".payone").append('<div style="width: 100%;height: 30px;line-height: 30px;">'
	     							+'<span id="userName">'+res.userName+'</span>'
	     							+'  <span id="telNumber">电话:'+res.telNumber+'</span>'
	     							+'  <span id="postalCode">邮编:'+res.postalCode+'</span>'
	     							+'</div>'
									+'<div style="width: 100%;height: auto;line-height: 30px;">'
									+'<span id="provinceName">'+res.provinceName+'</span>'
									+'<span id="cityName">'+res.cityName+'</span>'
									+'<span id="countryName">'+res.countryName+'</span>'
									+'<span id="detailInfo">'+res.detailInfo+'</span>'
									+'</div>');
	          // 用户成功拉出地址 
	          },
	     cancel: function (res) { 
	          // 用户取消拉出地址
				}
	     });
}

Logo

讨论HarmonyOS开发技术,专注于API与组件、DevEco Studio、测试、元服务和应用上架分发等。

更多推荐