一.APP端微信支付

1.首先需要用uni.request()调后端接口获取微信支付必须要的核心参数

2.再将核心参数调用uni.requestPayment()

(其中provider是支付类型,wxpay:微信支付;alipay:支付宝支付;balance:余额支付)

App端微信支付 的orderInfo 为 Object 类型。如果直接使用后端返回的数据作为参数时,需要判断后端返回的类型时字符串还是对象,如果时字符串的话,还需要用JSON.parse(value)进行转换

uni.requestPayment({
						provider: 'wxpay',
						"orderInfo": {
                        "appid": "wx499********7c70e",  // 微信开放平台 - 应用 - AppId,注意和微信小程序、公众号 AppId 可能不一致
                        "noncestr": "c5sEwbaNPiXAF3iv", // 随机字符串
                        "package": "Sign=WXPay",        // 固定值!!!!
                        "partnerid": "148*****52",      // 微信支付商户号
                        "prepayid": "wx202254********************fbe90000", // 统一下单订单号 
                        "timestamp": 1597935292,        // 时间戳(单位:秒)
                        "sign": "A842B45937F6EFF60DEC7A2EAA52D5A0" // 签名,这里用的 MD5/RSA 签名
                        },
							success: e=>{
								console.log("支付成功")
							}, 
							fail: err=>{
								if(err.errMsg.indexOf('取消') > -1 || err.errMsg.indexOf('cancel') >1 || err.errMsg.indexOf('-2') > -1){
									console.log('取消支付');
								}else{
									console.log('支付遇到错误,请稍候重试');
									console.log(err);
								}
							}
						})

二.APP端支付宝支付

1.首先需要用uni.request()调后端接口获取微信支付必须要的核心参数

2.再将核心参数调用uni.requestPayment()

App端,支付宝支付 orderInfo 为 String 类型

uni.requestPayment({
						provider: 'alipay',
						"orderInfo"://后端返回的核心参数字符串,
							success: e=>{
								console.log("支付成功")
							}, 
							fail: err=>{
								if(err.errMsg.indexOf('取消') > -1 || err.errMsg.indexOf('cancel') >1 || err.errMsg.indexOf('-2') > -1){
									console.log('取消支付');
								}else{
									console.log('支付遇到错误,请稍候重试');
									console.log(err);
								}
							}
						})

Logo

为开发者提供学习成长、分享交流、生态实践、资源工具等服务,帮助开发者快速成长。

更多推荐