支付
准备工作
- 支付厂商:获取id
- 微信:微信支付平台
https://pay.weixin.qq.com/
- 微信:微信支付平台
- 打包时候
- 在manifest.json文件里配置
- app模块配置
- payment支付
- 在manifest.json文件里配置
app的支付步骤
- 01 获取支付厂商:uni.getProvider()
uni.getProvider({service: "payment"})
- 02 用户发起支付:
requestPayment(item,index){}
- 03 获取订单信息:
getOrderInfo(item.id)
- 04 发起支付api
uni.requestPayment({ provider:item.id, //提供商 orderInfo: orderInfo, //订单信息 })
App支付完整代码
- template
<template> <view> <view class="title">支付</view> <view> 支付金额:<input :value="price" maxlength="4" @input="priceChange" placeholder="请求输入支付金额" /> <view> <!-- app支付 --> <!-- #ifdef APP-PLUS --> <button size="mini" type="primary" v-for="(item,index) in providerList" :key="item.id" :loading="item.loading" @click="requestPayment(item,index)">{ {item.name}}支付</button> <!-- #endif --> </view> </view> </view> </template>
- script
<script> export default { data() { return { price:1, providerList: [], //支付厂商,微信,或者支付 openid:'' ,//用户id loading:false,//小程序微信支付 } }, onLoad(){ var that = this; // 获取支付厂商 uni.getProvider({ service: "payment", success: (e) => { console.log(JSON.stringify(e)) var pr