uni-app Alipay and WeChat Pay (APP)

Basic layout

<view class="payButton" @click="payButton">确定支付</view>

Use uni-app encapsulated api uni.requestPayment to initiate payment, if it is WeChat payment alipay, change to wxpay

async payButton(){
    
    
	var orderInfo = await this.getOrderInfo(); //微信、支付宝订单数据
	// 支付宝支付
	uni.requestPayment({
    
    
    provider: 'alipay', // 服务提供商,通过 uni.getProvider 在onLoad中获取。
    orderInfo: orderInfo.data, //微信、支付宝订单数据
    success: function (res) {
    
     // 接口调用成功的回调
        console.log('success:' + JSON.stringify(res));
    },
    fail: function (err) {
    
     // 接口调用失败的回调函数
        console.log('fail:' + JSON.stringify(err));
    }
});
},

Get the service provider alipay, Alipay payment, wxpay WeChat payment, appleiap Apple in-app payment...

onLoad(option) {
    
    
	uni.getProvider({
    
    
	    service: 'payment',
	    success: function (res) {
    
    
	        console.log(res.provider)
	    }
	});
}

You can use the interface provided by uni-app to obtain data to test the payment process interface address parameter total is the account of the uni-app payment account used by the price

getOrderInfo(type){
    
    
	return new Promise((reslove)=>{
    
    
		uni.request({
    
    
			url:"https://demo.dcloud.net.cn/payment/?payid=alipay&total=1", // 支付宝支付
			//url:"https://demo.dcloud.net.cn/payment/?payid=wxpay&total=1", // 微信支付
			success(res) {
    
    
				reslove(res)
			}
		})
	})
	
}

Own account launched Alipay first apply APP Alipay payment into the console to create web & mobile applications → → payment application access, and signature generation applications, the need to use the application signature tool download , at the bottom of the page to download the apk file, you can simulate the installation tool, and also install the App packaged into the simulator, click the signature tool already installed, install the package name when the input, the application can generate a signature, packaging methods can click to see when finished click OK to add the ability to create, fill in Encrypted information, can only be used after approval

WeChat payment setup process [appid, merchant number, key]

Guess you like

Origin blog.csdn.net/weixin_44640323/article/details/112920101