ICode9

精准搜索请尝试: 精确搜索
首页 > 其他分享> 文章详细

uni-app 支付宝支付

2022-05-07 09:00:34  阅读:161  来源: 互联网

标签:info 支付宝 console res app reject 支付 uni


//封装全局APP支付方法
import {weixinPay} from "@/utils/api/api.js"; //微信支付
import {aliPay} from "@/utils/api/api.js"; //支付宝支付
//封装APP支付方法
/**
 * 参数1 必传 log_id
 * 参数2  money  价格
 * 参数3  e 1微信支付 2支付宝支付
 * 参数4 order_id  订单id
 * 参数5  type  订单类型
 * **/
const apppay =  (log_id,money,e,order_id,type,isshowmode=true)=>{
    return new Promise((resolve,reject)=>{
		if(e==1){ //微信支付
			weixinPay({
				log_id:log_id,//=》支付日志id
				amount:money,//=》支付金额
				//区分是什么设备  wechat  app
				// #ifdef APP-PLUS
				user_type:"app",
				// #endif
				// #ifndef APP-PLUS
				user_type:"wechat",
				// #endif
				
			}).then(res=>{
				console.info("111",res);
				uni.hideLoading();
				if(res.code ==1){
					
					// #ifdef APP-PLUS
					let orderInfo = res.data.result;
					console.info("orderInfo",orderInfo);
					uni.requestPayment({
					    provider:"wxpay" ,
					    orderInfo:orderInfo,
					    success: (e) => {
							if(isshowmode){
								uni.showToast({
									title:'支付成功',
									icon:'none'
								});
							}
							
							resolve(res);
					    },
					    fail: (e) => {
							console.info("支付错误",e);
							uni.showToast({
								title:'取消支付',
								icon:'none'
							})
							reject(false);
					    },
					    complete: (e) => {
							console.info("e",e);
							reject(false);
					    }
					})
					
					// #endif
					
					
					//小程序支付
					// #ifndef APP-PLUS
					let objinfo = {
						timeStamp: res.data.result.timeStamp,
						nonceStr: res.data.result.nonceStr,
						package: res.data.result.package,
						signType: res.data.result.signType,
						paySign: res.data.result.paySign,
					};
					wx.requestPayment({
						provider: "wxpay",
						// orderInfo: objinfo,
						...objinfo,
						success: (e) => {
							resolve(true);
						},
						fail: (e) => {
							console.info(e,"错误");
							uni.showToast({
								title: '取消支付',
								icon: 'none'
							})
							reject(false);
						},
						complete: (e) => {
							reject(false);
						}
					})
					// #endif
					//----------------小程序微信支付-------------------
					
					
					
				}else{
					uni.showToast({
						title:res.msg,
						icon:'none'
					})
				}
				
			}).catch(err=>{
				console.info("err",err);
				uni.hideLoading();
				reject(false);
			})
			
		}else{ //支付宝支付
			aliPay({
				log_id:log_id,
				amount:money,
			}).then(res=>{
				console.info(res,"res");
				uni.hideLoading();
				
				// https://segmentfault.com/q/1010000022492163?bd_source_light=4746641
				//--------------H5 PLUS --------------------------------
				
				// try{
				// 	let channel;
				// 	plus.payment.getChannels((channels) =>{
				// 			channel = channels[1];
				// 			let payserve = res.data.response;
				// 			// 手机调用请求
				// 			plus.payment.request(channel,payserve,(result)=>{
				// 					// plus.nativeUI.alert("支付成功!", function() {
				// 					// 	back();
				// 					// });
				// 					reject(true);
				// 				},(error)=>{
				// 					let err = JSON.stringify(
				// 						"支付失败:" + error.code + error.message
				// 					);
				// 					uni.showToast({
				// 						title:'取消支付',
				// 						icon:'none'
				// 					})
				// 					console.info(err);
				// 					reject(false);
				// 				}
				// 			);
							
				// 		},function(e) {
				// 			console.info("获取支付通道失败:" + e.message);
				// 			uni.showToast({
				// 				title:'取消支付',
				// 				icon:'none'
				// 			})
				// 			reject(false);
				// 		}
				// 	);
				// }catch(e){
				// 	console.info("catch e:" + e);
				// 	uni.showToast({
				// 		title:'取消支付',
				// 		icon:'none'
				// 	})
				// 	reject(false);
				// }
				
				//----------------------------------------------
				
				
				//-------------------------uni-APP ALIAPY-------------------------------------
				try{
					console.info("----------5555555555-----");
					uni.requestPayment({
					    provider:"alipay" ,
					    orderInfo:res.data.response,//params,//res.data,
					    success: (e) => {
							if(isshowmode){
								uni.showToast({
									title:'支付成功',
									icon:'none'
								});
							}
							resolve(res);
					    },
					    fail: (err) => {
							console.info("支付错误",err);
							uni.showToast({
								title:'取消支付',
								icon:'none'
							})
							reject(false);
					    },
					    complete: (e) => {
							console.info("err",e);
							reject(false);
					    }
					})
				}catch(e){
					console.info('e',e);
				}
				
				//--------------------------------------------------------------
				
			}).catch(err=>{
				console.info("err",err);
				uni.hideLoading();
				reject(false);
			})
		}
		
    });

}

export {apppay}

  

标签:info,支付宝,console,res,app,reject,支付,uni
来源: https://www.cnblogs.com/shaozhu520/p/16241028.html

本站声明: 1. iCode9 技术分享网(下文简称本站)提供的所有内容,仅供技术学习、探讨和分享;
2. 关于本站的所有留言、评论、转载及引用,纯属内容发起人的个人观点,与本站观点和立场无关;
3. 关于本站的所有言论和文字,纯属内容发起人的个人观点,与本站观点和立场无关;
4. 本站文章均是网友提供,不完全保证技术分享内容的完整性、准确性、时效性、风险性和版权归属;如您发现该文章侵犯了您的权益,可联系我们第一时间进行删除;
5. 本站为非盈利性的个人网站,所有内容不会用来进行牟利,也不会利用任何形式的广告来间接获益,纯粹是为了广大技术爱好者提供技术内容和技术思想的分享性交流网站。

专注分享技术,共同学习,共同进步。侵权联系[81616952@qq.com]

Copyright (C)ICode9.com, All Rights Reserved.

ICode9版权所有