微信公众号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);
			}
			
		},
		
	})
}

 

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值