// pages/certification/certification.ts import { getPayInfo } from '../../apis/pay' import { realNameAuthentication } from '../../apis/login' const app = getApp() Page({ /** * 页面的初始数据 */ data: { step: 1, name: '', idCard: '', phoneNumber: app.globalData.userInfo?.username, info: {}, payShow: false, isRefresh: false }, /** * 生命周期函数--监听页面加载 */ onLoad(options) { this.setData({ phoneNumber: app.globalData.userInfo?.username, idCard: options.idCard === '' ? '' : app.globalData.userInfo?.idCard, name: options.idCard === '' ? '' : app.globalData.userInfo?.name, isRefresh: options.idCard !== '' }) this.getInfo() }, getInfo() { getPayInfo({}).then((res: any) => { this.setData({ info: res.d }) }) }, pay() { const { name, idCard, phoneNumber,isRefresh } = this.data realNameAuthentication({ name, idCard, phoneNumber, wxPayApiType: 'JSAPI', authType:isRefresh?'PHONE_REFRESH':'FIRST' }).then((res: any) => { console.log(res) wx.requestPayment({ ...res.d, success: (res: any) => { console.log(res) wx.navigateTo({ url: '/pages/certificationResult/certificationResult' }) }, fail: (err: any) => { console.log(err) wx.showToast({ icon: 'none', title: '支付失败, 请稍后再试!' }) } }) }) }, showShadow() { this.setData({ payShow: true }) }, hideShadow() { this.setData({ payShow: false }) }, next() { const { name, idCard } = this.data if (!name) { wx.showToast({ icon: 'none', title: '请输入您的真实姓名' }) return } if (!idCard) { wx.showToast({ icon: 'none', title: '请输入您的身份证号' }) return } this.setData({ step: 2 }) }, edit() { this.setData({ step: 1 }) }, /** * 生命周期函数--监听页面初次渲染完成 */ onReady() { }, /** * 生命周期函数--监听页面显示 */ onShow() { }, /** * 生命周期函数--监听页面隐藏 */ onHide() { }, /** * 生命周期函数--监听页面卸载 */ onUnload() { }, /** * 页面相关事件处理函数--监听用户下拉动作 */ onPullDownRefresh() { }, /** * 页面上拉触底事件的处理函数 */ onReachBottom() { }, /** * 用户点击右上角分享 */ onShareAppMessage() { } })