天天看点

hbuilder H5+调起小程序

//调起本地小程序 和调用第三方小程序进行支付

1.微信开放平台在对应的app项目下对小程序进行关联

2.代码

<script>
var  shares=null
mui.plusReady(function() {
 setTimeout(updateSerivces, 500);//延时获取服务列表,避免影响窗口动画
})
/**
 * 更新分享服务
 */
function updateSerivces(){
	plus.share.getServices(function(s){
		shares={};
		for(var i in s){
			var t=s[i];
			shares[t.id]=t;
		}
	}, function(e){
		outSet('获取分享服务列表失败:'+e.message);
	});
}
//点击时调起小程序
$('btn').click(function(){
    launchMiniProgram(shares,params)
})
function launchMiniProgram (shares,params){
		if(!shares['weixin']){
			plus.nativeUI.toast('未配置微信分享模块!');
			return;
		}
		var herf='pages/app/jsminipg_pay/jsminipg_pay.html'+params.substr(params.indexOf('?'))
		shares['weixin'].launchMiniProgram({
			id: 'gh_01f3f7658564',//小程序原始
			path:herf,//跳转到小程序的页面并传参
			type: 0	
		});
		setTimeout(function(){
			payMask.close();
		},2000)
	};
</script>