1、首先要勾选支持支付宝支付。

2、根据后台返回参数作处理。

 //获取URL字段
		 getparams(url, field){
		 	let url2 = url.split('#');
		 	let txt = "";
		 	url2.forEach((res,i)=>{
		 		if(res.includes('=')){
		 			let val = res.split('=');
		 			if(val[0]==field){
		 				txt = val[1]
		 			}
		 		}
		 	})
		 	return txt;
		 },
		 
		 //APP支付宝支付
		 appAliPay(data){			 
				let url = data.url;
				let params = {
					alipay_sdk:'alipay-sdk-java-4.35.37.ALL',
					app_id: this.getparams(url,'app_id'),
					biz_content: this.getparams(url,'biz_content'),
					charset:'UTF-8',
					format:'json',
					method:'alipay.trade.app.pay',
					notify_url: this.getparams(url,'notify_url'),
					return_url: this.getparams(url,'return_url'),
					sign_type:'RSA2',
					timestamp: this.getparams(url,'timestamp'),
					version: this.getparams(url,'version'),
					sign: this.getparams(url,'sign')
				}
				console.log(params,11)
				let payurl = "";
				for(let o in params){	payurl += `${o}=${params[o]}&`; }
				let orderInfo = payurl.substring(0, payurl.length-1)
				console.log(orderInfo,22)
				uni.requestPayment({
					 "provider": "alipay", //固定值为"alipay"
					 "orderInfo": orderInfo, //此处为服务器返回的订单信息字符串
					 success: function (res) {
						 that.payComplete();
					 },
					 fail: function (err) {
						 uni.redirectTo({url:'/pages/my/order/index'})
					 }
				});
		 },

Logo

华为开发者空间,是为全球开发者打造的专属开发空间,汇聚了华为优质开发资源及工具,致力于让每一位开发者拥有一台云主机,基于华为根生态开发、创新。

更多推荐