提交 988b5318 authored 作者: zyx's avatar zyx

添加 小程序支付

上级 f95fefa0
import './index.scss' import './index.scss'
import PayH5 from './src/PayH5.vue' import PayH5 from './src/PayH5.vue'
import PayWeChart from './src/PayWeChart.vue'
const components = [ const components = [
PayH5 PayH5,
PayWeChart
] ]
const install = function (Vue, opts = {}) { const install = function (Vue, opts = {}) {
...@@ -26,5 +28,6 @@ if (typeof window !== 'undefined' && window.Vue) { ...@@ -26,5 +28,6 @@ if (typeof window !== 'undefined' && window.Vue) {
export default { export default {
install, install,
PayH5 PayH5,
PayWeChart
} }
...@@ -3,45 +3,10 @@ ...@@ -3,45 +3,10 @@
<div class="pay-box"></div> <div class="pay-box"></div>
</template> </template>
<script> <script>
import { Toast } from 'vant'
import Pay from '../action' import Pay from '../action'
export default { export default {
name: 'PayH5', name: 'PayH5',
components: { data () {},
[Toast.name]: Toast
},
data () {
const _this = this
return {
isCard: false,
opaKey: ['A', 'B', 'C', 'D', 'E', 'F', 'G'],
remainingTime: '01:00:00',
currentNum: 1,
isAnalysis: false,
swiperOptions: {
observer: true,
on: {
slideChangeTransitionStart: function() {
document.getElementById('bottom-view').scrollTop = 0
_this.isAnalysis = false
_this.currentNum = this.activeIndex + 1
}
}
},
questionsData: {
questions: []
},
requestData: {},
requestData2: {},
clockCount: null,
isExamEnd: true,
// examIsShow: false,
isExamSubPop: false,
timePopIsShow: false,
initTime: null,
cache: null
}
},
props: { props: {
requestParam: { requestParam: {
type: Object, type: Object,
...@@ -125,7 +90,6 @@ export default { ...@@ -125,7 +90,6 @@ export default {
}) })
}, },
wxWakeUpToPay (obj) { wxWakeUpToPay (obj) {
Toast(obj)
if (typeof WeixinJSBridge === 'undefined') { if (typeof WeixinJSBridge === 'undefined') {
obj.code = 4001 obj.code = 4001
obj.msg = '缺少微信api' obj.msg = '缺少微信api'
......
<template>
<!-- 暂时无用 -->
<div class="pay-box"></div>
</template>
<script>
import Pay from '../action'
export default {
name: 'PayWeChart',
data () {},
props: {
requestParam: {
type: Object,
required: false,
default () {
return {
product_id: '', // 提前设定
open_id: '', // 通过微信授权获取
prepay_id: '', // 通过调用接口获取
app_id: '', // 提前设定
app_secret: '', // 提前设定
// 新增字段 接口返回
timeStamp: '',
nonceStr: '',
signType: '',
paySign: ''
}
}
}
},
beforeDestroy() {
},
mounted () {
this.onReady()
},
methods: {
onBridgeReady () {
this.VueEvent.$off('pay-wx-chart').$on('pay-wx-chart', (obj) => {
this.goToPay()
})
},
goToPay () {
const obj = { code: 0, msg: '', data: {} }
if (!this.requestParam.product_id) {
obj.code = 3001
obj.msg = '没有商品ID'
this.VueEvent.$emit('pay-wx-chart-callback', obj)
return false
}
if (!this.requestParam.open_id) {
obj.code = 3002
obj.msg = '没有小程序用户openid'
this.VueEvent.$emit('pay-wx-chart-callback', obj)
return false
}
Pay.getOrderId(this.requestParam).then(res => {
if (res.code) {
// this.requestParam.product_id
// this.requestParam.open_id
this.requestParam.prepay_id = res.data.prepay_id
this.requestParam.app_id = res.data.options.appId
// this.requestParam.app_secret
this.requestParam.timeStamp = res.data.options.timeStamp
this.requestParam.nonceStr = res.data.options.nonceStr
this.requestParam.signType = res.data.options.signType
this.requestParam.paySign = res.data.options.paySign
this.wxWakeUpToPay(obj)
} else {
obj.code = 3003
obj.msg = '获取订单ID失败'
this.VueEvent.$emit('pay-wx-chart-callback', obj)
}
}).catch(e => {
obj.code = 5001
obj.msg = e.message
this.VueEvent.$emit('pay-wx-chart-callback', obj)
return obj
})
},
wxWakeUpToPay (obj) {
obj.code = 200
obj.data = this.requestParam
this.VueEvent.$emit('pay-wx-chart-callback', obj)
}
}
}
</script>
<style lang="scss">
</style>
Markdown 格式
0%
您添加了 0 到此讨论。请谨慎行事。
请先完成此评论的编辑!
注册 或者 后发表评论