100字范文,内容丰富有趣,生活中的好帮手!
100字范文 > 微信小程序支付(建行支付)

微信小程序支付(建行支付)

时间:2023-04-05 03:16:08

相关推荐

微信小程序支付(建行支付)

微信小程序支付流程:

调用微信登录api获取code;

根据code换取openid(需要开发者开发者服务器调用微信接口);

根据openid及支付金额/订单号等信息请求支付信息(开发者服务器);

根据服务端返回的支付信息,调起微信支付;

接收支付回调;

const app = getApp() // 获取应用实例import { getOpenid, postPayInfo } from '../../utils/http/api'// 导入http api// 支付流程:微信登录获取code,根据code获取openid,根据openid/金额等信息获取微信支付信息,调起微信支付,接收支付回调。export function openWxPay(order,money) {wx.showLoading({ title: '获取支付信息', mask: true })// 微信登录获取codewx.login({async success(res) {// console.log('小程序登录成功。。。res.code = ',res.code)if (res.code) {// 根据登录code 换取openidlet { code, msg, data } = await getOpenid({ code: res.code })// console.log(`getOpenid...code=${code},msg=${msg},data=`, data)if (code == '1' && data.openid) {// 根据openid获取支付信息reqPayInfo(data.openid, order,money)} else {wx.showToast({ title: msg, icon: 'error' })}} else {wx.hideLoading()wx.showToast({ title: '微信code错误', icon: 'error' })console.log('微信code错误...', res.errMsg)}},fail(res) {wx.hideLoading()wx.showToast({ title: '微信code获取失败', icon: 'error' })console.log('微信code获取失败...', res)},})}

export async function reqPayInfo(SUB_OPENID, order,money) {wx.showLoading({ title: '获取支付信息', mask: true, })let { code, msg, data } = await postPayInfo({SUB_OPENID, order, money})// console.log(`reqPayInfo...code=${code},msg=${msg},data=`, data)if (code == '1' && data.ERRCODE == '000000') {wx.showLoading({ title: '等待支付结果..', mask: true, })// 调起微信支付wx.requestPayment({timeStamp: data.timeStamp,nonceStr: data.nonceStr,package: data.package,signType: data.signType,paySign: data.paySign,// 用户支付成功success(res) {wx.hideLoading()wx.showModal({title: '提示', content: '支付成功', showCancel: false,success(res) {if (res.confirm) {// 点击确定wx.navigateBack();// 关闭当前页面}}});},fail(res) {wx.hideLoading()wx.showToast({ title: '支付失败', icon: 'none', })}})} else {wx.hideLoading()wx.showToast({ title: msg, icon: 'error' })}}

本内容不代表本网观点和政治立场,如有侵犯你的权益请联系我们处理。
网友评论
网友评论仅供其表达个人看法,并不表明网站立场。