提交 c8c67f87 authored 作者: 王鹏飞's avatar 王鹏飞

对接微信支付

上级 f7ede5c9
...@@ -7,9 +7,6 @@ import * as api from '../api.js' ...@@ -7,9 +7,6 @@ import * as api from '../api.js'
export default { export default {
name: 'wxPay', name: 'wxPay',
props: {
productId: { type: String, required: true }
},
data() { data() {
return { return {
openId: '', openId: '',
...@@ -29,7 +26,7 @@ export default { ...@@ -29,7 +26,7 @@ export default {
methods: { methods: {
// 获取openid // 获取openid
getOpenId() { getOpenId() {
api.getOpenId({ id: this.user.id, identity: 'transport' }).then(response => { api.getOpenId({ id: this.user.id, identity: 'transport-mini' }).then(response => {
this.openId = response.data.openid this.openId = response.data.openid
// 生成订单 // 生成订单
this.genOrder() this.genOrder()
...@@ -38,14 +35,22 @@ export default { ...@@ -38,14 +35,22 @@ export default {
// 生成订单 // 生成订单
genOrder() { genOrder() {
const params = { const params = {
product_id: this.productId,
open_id: this.openId, open_id: this.openId,
type: 'certs-h5' buy_count: '1',
payment_method: '3',
shop_id: webConf.others.PAY_SHOP_ID,
spu_id: webConf.others.PAY_SPU_ID,
sku_id: webConf.others.PAY_SKU_ID
} }
api.genOrder(params).then(response => { api.createOrder(params).then(response => {
this.order = response.data if (response.code === 0) {
// 调起微信支付 const options = JSON.parse(response.payment_more_info)
this.wxPay() this.order = Object.assign(response, { options })
// 调起微信支付
this.wxPay()
} else {
this.$toast(response.msg)
}
}) })
}, },
// 微信支付 // 微信支付
...@@ -53,15 +58,16 @@ export default { ...@@ -53,15 +58,16 @@ export default {
const options = this.order.options const options = this.order.options
WeixinJSBridge.invoke( WeixinJSBridge.invoke(
'getBrandWCPayRequest', 'getBrandWCPayRequest',
{ options,
appId: options.appId, // 公众号名称,由商户传入 // {
timeStamp: options.timeStamp, // 支付签名时间戳,注意微信jssdk中的所有使用timestamp字段均为小写。但最新版的支付后台生成签名使用的timeStamp字段名需大写其中的S字符 // appId: options.appId, // 公众号名称,由商户传入
nonceStr: options.nonceStr, // 支付签名随机串,不长于 32 位 // timeStamp: options.timeStamp, // 支付签名时间戳,注意微信jssdk中的所有使用timestamp字段均为小写。但最新版的支付后台生成签名使用的timeStamp字段名需大写其中的S字符
package: `prepay_id=${this.order.prepay_id}`, // 统一支付接口返回的prepay_id参数值,提交格式如:prepay_id=\*\*\*) // nonceStr: options.nonceStr, // 支付签名随机串,不长于 32 位
signType: options.signType, // 签名方式,默认为'SHA1',使用新版支付需传入'MD5' // package: `prepay_id=${this.order.prepay_id}`, // 统一支付接口返回的prepay_id参数值,提交格式如:prepay_id=\*\*\*)
paySign: options.paySign // 支付签名 // signType: options.signType, // 签名方式,默认为'SHA1',使用新版支付需传入'MD5'
}, // paySign: options.paySign // 支付签名
function (res) { // },
function(res) {
if (res.err_msg === 'get_brand_wcpay_request:ok') { if (res.err_msg === 'get_brand_wcpay_request:ok') {
// 使用以上方式判断前端返回,微信团队郑重提示: // 使用以上方式判断前端返回,微信团队郑重提示:
// res.err_msg将在用户支付成功后返回ok,但并不保证它绝对可靠。 // res.err_msg将在用户支付成功后返回ok,但并不保证它绝对可靠。
......
...@@ -18,7 +18,7 @@ ...@@ -18,7 +18,7 @@
<div class="c">199.00</div> <div class="c">199.00</div>
<div class="r">原价999.00</div> <div class="r">原价999.00</div>
</div> </div>
<div class="new-b" v-if="orderStatus === 0">课程有效期剩余{{expireDay}}</div> <div class="new-b" v-if="orderStatus === 0">课程有效期剩余{{ expireDay }}</div>
</div> </div>
<div class="btn" @click="goPay" v-if="orderStatus === 100">立即购买</div> <div class="btn" @click="goPay" v-if="orderStatus === 100">立即购买</div>
<div class="btn" v-if="orderStatus === 1" @click="goHome">已购买</div> <div class="btn" v-if="orderStatus === 1" @click="goHome">已购买</div>
...@@ -37,7 +37,7 @@ ...@@ -37,7 +37,7 @@
/> />
</div> </div>
</div> </div>
<h5-pay :productId="productId" ref="h5pay"></h5-pay> <h5-pay ref="h5pay"></h5-pay>
</div> </div>
</template> </template>
<script> <script>
...@@ -49,9 +49,7 @@ import h5Pay from './components/h5Pay.vue' ...@@ -49,9 +49,7 @@ import h5Pay from './components/h5Pay.vue'
export default { export default {
components: { h5Pay }, components: { h5Pay },
data() { data() {
const productId = webConf.isDev === 'production' ? '6684359515615264768' : '6682927830365372416'
return { return {
productId,
popVisible: false, popVisible: false,
expireDay: 0, expireDay: 0,
orderStatusTimer: null, orderStatusTimer: null,
......
Markdown 格式
0%
您添加了 0 到此讨论。请谨慎行事。
请先完成此评论的编辑!
注册 或者 后发表评论