微信公众号h5支付功能

首先要配置参数:jsApiList:["chooseWXPay"]

// 获取微信配置
function getconfig(){
	
	var urls = location.href;
	
	$.ajax({
		url: "http://saas.juwoxing.com/order/api.php?s=/api/share/getSignPackage",
		type: "get",
		dataType: "json",
		data:{
			url:urls,
		},
		success: function(res) {
			console.log(res);
	    var data = res;
			
			// 配置
			wx.config({
			  debug: false, // 开启调试模式,调用的所有api的返回值会在客户端alert出来,若要查看传入的参数,可以在pc端打开,参数信息会通过log打出,仅在pc端时才会打印。
			  appId: data.appId, // 必填,公众号的唯一标识
			  timestamp: data.timestamp, // 必填,生成签名的时间戳
			  nonceStr: data.nonceStr, // 必填,生成签名的随机串
			  signature: data.signature,// 必填,签名
			  jsApiList: ["chooseWXPay"] // 必填,需要使用的JS接口列表
			});
			
			
		}
	})
	
}

然后再使用

function tapjoin(){
	$.ajax({
		url: "http://120.77.80.30:8337/app/share/jointemplate",
		type: "post",
		dataType: "json",
		data:{
			openid:openid,
			token:token,
			id:id,
			url_record_id:url_record_id,
			mobile:mobile,
			license_number:license_number
		},
		success: function(res) {
			console.log(res);
			if(res.code==0){
				var data = res.data;
				
				//支付
				wx.chooseWXPay({
					appId:data.appId, 
				   	timestamp: data.timestamps, // 支付签名时间戳,注意微信jssdk中的所有使用timestamp字段均为小写。但最新版的支付后台生成签名使用的timeStamp字段名需大写其中的S字符
					nonceStr:data.nonceStr, //随机串
					package:data.package,     
					signType:data.signType,         //微信签名方式:     
					paySign:data.paySign, //微信签名 
				   	success: function (res) {
						console.log(res);
				    // 支付成功后的回调函数
				  }
				});
				
			}else{
				alert(res.msg);
			}
			
		},
		
	})
}

猜你喜欢

转载自blog.csdn.net/weixin_44285250/article/details/107959581