将支付功能剥离到独立的小程序
This commit is contained in:
parent
f5f7fa316c
commit
7477de4694
@ -12,5 +12,37 @@
|
||||
"appid": "wx815bf59d472c0a63",
|
||||
"projectname": "game",
|
||||
"miniprogramRoot": "dist/",
|
||||
"condition": {}
|
||||
"condition": {
|
||||
"search": {
|
||||
"current": -1,
|
||||
"list": []
|
||||
},
|
||||
"conversation": {
|
||||
"current": -1,
|
||||
"list": []
|
||||
},
|
||||
"plugin": {
|
||||
"current": -1,
|
||||
"list": []
|
||||
},
|
||||
"game": {
|
||||
"list": []
|
||||
},
|
||||
"miniprogram": {
|
||||
"current": 0,
|
||||
"list": [
|
||||
{
|
||||
"id": 0,
|
||||
"name": "支付返回",
|
||||
"pathName": "pages/gameInfo",
|
||||
"query": "id=1100309",
|
||||
"scene": 1038,
|
||||
"referrerInfo": {
|
||||
"appId": "wxbf333d56b4de3905",
|
||||
"extraData": "{ \"type\": \"item\", \"event_type\": \"pay_result\", \"success\": true, \"gid\": 1100309 }"
|
||||
}
|
||||
}
|
||||
]
|
||||
}
|
||||
}
|
||||
}
|
15
src/app.wpy
15
src/app.wpy
@ -32,9 +32,7 @@ export default class extends wepy.app {
|
||||
'pages/gameInfo',
|
||||
'pages/login',
|
||||
'pages/search',
|
||||
'pages/product',
|
||||
'pages/jumppage',
|
||||
'pages/buyvip'
|
||||
'pages/jumppage'
|
||||
],
|
||||
window: {
|
||||
backgroundTextStyle: 'light',
|
||||
@ -121,7 +119,16 @@ export default class extends wepy.app {
|
||||
console.log('app.onShow');
|
||||
console.log(options);
|
||||
if (options.scene === 1038) { //从小程序返回
|
||||
jcEvent.emit(jcEvent.events.NEED_UPDATE_SCORE, {})
|
||||
jcEvent.emit(jcEvent.events.NEED_UPDATE_SCORE, {});
|
||||
let referrerInfo = options.referrerInfo;
|
||||
let data = referrerInfo.extraData;
|
||||
if (data && data.event_type === 'pay_result') {
|
||||
if (data.type === 'item' ) {
|
||||
jcEvent.emit(jcEvent.events.BUY_ITEM_RESULT, data);
|
||||
} else {
|
||||
jcEvent.emit(jcEvent.events.BUY_VIP_RESULT, data);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
getUserInfo() {
|
||||
|
@ -30,6 +30,8 @@ export default {
|
||||
UPDATE_RECENT_GAMES: 'update-recent-games',
|
||||
UPDATE_GAME_STATUS: 'update-game-status',
|
||||
NEED_UPDATE_SCORE: 'need-update-score',
|
||||
NEED_UPDATE_CFG: 'need-update-cfg'
|
||||
NEED_UPDATE_CFG: 'need-update-cfg',
|
||||
BUY_ITEM_RESULT: 'buy-item-result',
|
||||
BUY_VIP_RESULT: 'buy-vip-result'
|
||||
}
|
||||
}
|
||||
|
@ -57,7 +57,7 @@
|
||||
target="miniProgram"
|
||||
open-type="navigate"
|
||||
app-id="wxbf333d56b4de3905"
|
||||
path="/pages/product?{{params}}}"
|
||||
path="/pages/product?{{config.params}}}"
|
||||
extra-data=""
|
||||
version="develop"
|
||||
>促销开通</navigator>
|
||||
|
@ -1,156 +0,0 @@
|
||||
<style lang="less">
|
||||
.msg-box{
|
||||
width: 750rpx;
|
||||
height: 300rpx;
|
||||
border-radius:5px;
|
||||
background-color: #fff;
|
||||
display: flex;
|
||||
flex-flow: column;
|
||||
}
|
||||
.msg-title {
|
||||
height: 200rpx;
|
||||
widht: 600rpx;
|
||||
align-items: center;
|
||||
padding: 10px;
|
||||
font-size:18px;
|
||||
color:#777;
|
||||
|
||||
}
|
||||
.msg-action-bar {
|
||||
height: 80rpx;
|
||||
overflow: hidden;
|
||||
display: flex;
|
||||
border-top: 1rpx solid #e5e5e5;
|
||||
}
|
||||
.msg-action-bar .msg-action-btn {
|
||||
width: 50%;
|
||||
height: 80rpx;
|
||||
justify-content: center;
|
||||
align-items: center;
|
||||
display: flex;
|
||||
font-size: 20px;
|
||||
}
|
||||
.msg-action-bar .msg-action-btn:first-child {
|
||||
border-right: 1rpx solid #e5e5e5 ;
|
||||
}
|
||||
.msg-action-bar .msg-action-btn:last-child {
|
||||
color: #3283fa;
|
||||
}
|
||||
.row{
|
||||
width: 750rpx;
|
||||
text-align: center;
|
||||
}
|
||||
</style>
|
||||
<template>
|
||||
<view class="container">
|
||||
<view class="msg-box">
|
||||
<view class="msg-title">
|
||||
<view class="row">5元购买一个月</view>
|
||||
<view class="row">30元购买终身卡</view>
|
||||
</view>
|
||||
<view class="msg-action-bar">
|
||||
<view class="msg-action-btn" @tap="buyMonth"><text>购买一个月</text></view>
|
||||
<view class="msg-action-btn" @tap="buyAll">购买终身VIP</view>
|
||||
</view>
|
||||
</view>
|
||||
</view>
|
||||
</template>
|
||||
<script>
|
||||
import wepy from 'wepy';
|
||||
import http from '../utils/http';
|
||||
import jcEvent from '../common/jc-event';
|
||||
|
||||
export default class BuyVipPage extends wepy.page {
|
||||
config = {
|
||||
navigationBarTitleText: '购买VIP'
|
||||
};
|
||||
data = {
|
||||
gid: '',
|
||||
bottomActionCfg: {
|
||||
hide: false,
|
||||
mainBtnIconClass: 'icon-cart',
|
||||
mainBtnTitle: '购买',
|
||||
secondBtnIconClass: 'icon-forbid',
|
||||
secondBtnTitle: '取消'
|
||||
},
|
||||
tid: ''
|
||||
};
|
||||
methods = {
|
||||
buyMonth(){
|
||||
this.buy('vip_month');
|
||||
},
|
||||
buyAll() {
|
||||
this.buy('vip');
|
||||
}
|
||||
};
|
||||
|
||||
onLoad(params) {
|
||||
this.gid = decodeURIComponent(params.gid);
|
||||
}
|
||||
buy(type) {
|
||||
let self = this;
|
||||
wepy.showLoading({
|
||||
title: '支付中'
|
||||
})
|
||||
http.post('/api/emulated/pre_pay', { gid: this.gid, type: type })
|
||||
.then(res => {
|
||||
console.log(res.data);
|
||||
if (res.errcode === 0) {
|
||||
let payResult = res.data;
|
||||
self.tid = res.tid;
|
||||
wx.requestPayment({
|
||||
'timeStamp': payResult.timeStamp,
|
||||
'nonceStr': payResult.nonceStr,
|
||||
'package': payResult.package,
|
||||
'signType': 'MD5',
|
||||
'paySign': payResult.paySign,
|
||||
complete: (res) => {
|
||||
wepy.hideLoading();
|
||||
if (res.errMsg === 'requestPayment:ok') {
|
||||
console.log('支付成功')
|
||||
self.queryOrder();
|
||||
} else if (res.errMsg === 'requestPayment:fail cancel' || res.errMsg === 'requestPayment:cancel') {
|
||||
wepy.showToast({
|
||||
title: '用户取消支付',
|
||||
icon: 'none',
|
||||
duration: 2000
|
||||
})
|
||||
} else {
|
||||
console.log('支付失败');
|
||||
let msg = res.errMsg.replace('requestPayment:fail', '')
|
||||
wepy.showToast({
|
||||
title: msg,
|
||||
icon: 'none',
|
||||
duration: 2000
|
||||
})
|
||||
}
|
||||
}
|
||||
})
|
||||
}
|
||||
})
|
||||
.catch(err => {
|
||||
console.log('err update game history');
|
||||
});
|
||||
}
|
||||
async queryOrder() {
|
||||
try {
|
||||
let res = await http.post('/api/emulated/query_order', {tid: this.tid});
|
||||
if (res.errcode === 0 && res.result === 1) {
|
||||
wepy.showToast({
|
||||
title: '支付成功',
|
||||
icon: 'none',
|
||||
duration: 2000
|
||||
})
|
||||
jcEvent.emit(jcEvent.events.NEED_UPDATE_SCORE, {});
|
||||
}
|
||||
} catch (err) {
|
||||
console.log(err);
|
||||
wepy.showToast({
|
||||
title: '支付失败',
|
||||
icon: 'none',
|
||||
duration: 2000
|
||||
})
|
||||
}
|
||||
}
|
||||
}
|
||||
</script>
|
@ -140,14 +140,6 @@
|
||||
this.showAll = this.$parent.showAll();
|
||||
console.log(this.id);
|
||||
let self = this;
|
||||
jcEvent.on(jcEvent.events.BUY_GAME_SUCCESS, this, data => {
|
||||
self.record.owned = true;
|
||||
self.bottomActionCfg.mainBtnIconClass = 'icon-merge';
|
||||
self.bottomActionCfg.mainBtnTitle = '开始游戏';
|
||||
self.bottomActionCfg.primary = true;
|
||||
jcEvent.emit(jcEvent.events.UPDATE_GAME_STATUS, {gid: self.id});
|
||||
self.$apply();
|
||||
});
|
||||
jcEvent.on(jcEvent.events.NEED_UPDATE_SCORE, this, data => {
|
||||
this.getUserInfo();
|
||||
});
|
||||
@ -157,6 +149,28 @@
|
||||
this.showAll = !cfg ? false : !cfg.hide_main;
|
||||
this.$apply();
|
||||
})
|
||||
jcEvent.on(jcEvent.events.BUY_ITEM_RESULT, this, data => {
|
||||
this.zActionSheetCfg.hide = true;
|
||||
if (data.success) {
|
||||
wepy.showToast({
|
||||
title: '开通成功',
|
||||
icon: 'none',
|
||||
duration: 2000
|
||||
});
|
||||
self.record.owned = true;
|
||||
self.bottomActionCfg.mainBtnIconClass = 'icon-merge';
|
||||
self.bottomActionCfg.mainBtnTitle = '开始游戏';
|
||||
self.bottomActionCfg.primary = true;
|
||||
jcEvent.emit(jcEvent.events.UPDATE_GAME_STATUS, {gid: self.id});
|
||||
} else {
|
||||
wepy.showToast({
|
||||
title: '开通失败',
|
||||
icon: 'none',
|
||||
duration: 2000
|
||||
})
|
||||
}
|
||||
self.$apply();
|
||||
});
|
||||
this.getRecord();
|
||||
}
|
||||
onShow() {
|
||||
@ -254,9 +268,9 @@
|
||||
}
|
||||
}
|
||||
onUnload() {
|
||||
jcEvent.remove(jcEvent.events.BUY_GAME_SUCCESS, this);
|
||||
jcEvent.remove(jcEvent.events.NEED_UPDATE_SCORE, this);
|
||||
jcEvent.remove(jcEvent.events.NEED_UPDATE_CFG, this);
|
||||
jcEvent.remove(jcEvent.events.BUY_ITEM_RESULT, this);
|
||||
}
|
||||
async requestAd(text) {
|
||||
try {
|
||||
|
@ -97,11 +97,6 @@
|
||||
wepy.navigateTo({
|
||||
url: '/pages/search'
|
||||
})
|
||||
},
|
||||
buy_vip() {
|
||||
wepy.navigateTo({
|
||||
url: '/pages/buyvip'
|
||||
})
|
||||
}
|
||||
};
|
||||
|
||||
@ -165,6 +160,22 @@
|
||||
this.showAll = !cfg ? false : !cfg.hide_main;
|
||||
this.$apply();
|
||||
})
|
||||
jcEvent.on(jcEvent.events.BUY_VIP_RESULT, this, data => {
|
||||
if (data.success) {
|
||||
wepy.showToast({
|
||||
title: '购买成功',
|
||||
icon: 'none',
|
||||
duration: 2000
|
||||
})
|
||||
this.getUserInfo();
|
||||
} else {
|
||||
wepy.showToast({
|
||||
title: '购买失败',
|
||||
icon: 'none',
|
||||
duration: 2000
|
||||
})
|
||||
}
|
||||
})
|
||||
}
|
||||
getAllData() {
|
||||
this.getRecords();
|
||||
@ -178,7 +189,7 @@
|
||||
jcEvent.remove(jcEvent.events.UPDATE_GAME_STATUS, this);
|
||||
jcEvent.remove(jcEvent.events.NEED_UPDATE_SCORE, this);
|
||||
jcEvent.remove(jcEvent.events.NEED_UPDATE_CFG, this);
|
||||
jcEvent.remove(jcEvent.events.UPDATE_MY_GAMES, this);
|
||||
jcEvent.remove(jcEvent.events.BUY_VIP_RESULT, this);
|
||||
}
|
||||
onShow() {
|
||||
let cfg = wepy.getStorageSync('cfg');
|
||||
|
@ -1,111 +0,0 @@
|
||||
<style lang="less">
|
||||
</style>
|
||||
<template>
|
||||
<view class="container">
|
||||
|
||||
</view>
|
||||
<gameBottomBar :config.sync="bottomActionCfg" @bottomMainTap.user="bottomMainTap"
|
||||
@bottomSecondTap.user="bottomSecondTap"/>
|
||||
</template>
|
||||
<script>
|
||||
import wepy from 'wepy';
|
||||
import gameBottomBar from '../components/game-bottom-bar';
|
||||
import http from '../utils/http';
|
||||
import jcEvent from '../common/jc-event';
|
||||
|
||||
export default class ProductPage extends wepy.page {
|
||||
components = {
|
||||
gameBottomBar: gameBottomBar
|
||||
};
|
||||
config = {
|
||||
navigationBarTitleText: '购买产品'
|
||||
};
|
||||
data = {
|
||||
gid: '',
|
||||
bottomActionCfg: {
|
||||
hide: false,
|
||||
mainBtnIconClass: 'icon-cart',
|
||||
mainBtnTitle: '购买',
|
||||
secondBtnIconClass: 'icon-forbid',
|
||||
secondBtnTitle: '取消'
|
||||
},
|
||||
tid: ''
|
||||
};
|
||||
methods = {
|
||||
bottomMainTap(e) {
|
||||
console.log('bottomMainTap');
|
||||
let self = this;
|
||||
wepy.showLoading({
|
||||
title: '支付中'
|
||||
})
|
||||
http.post('/api/emulated/pre_pay', { gid: this.gid })
|
||||
.then(res => {
|
||||
console.log(res.data);
|
||||
if (res.errcode === 0) {
|
||||
let payResult = res.data;
|
||||
self.tid = res.tid;
|
||||
wx.requestPayment({
|
||||
'timeStamp': payResult.timeStamp,
|
||||
'nonceStr': payResult.nonceStr,
|
||||
'package': payResult.package,
|
||||
'signType': 'MD5',
|
||||
'paySign': payResult.paySign,
|
||||
complete: (res) => {
|
||||
wepy.hideLoading();
|
||||
if (res.errMsg === 'requestPayment:ok') {
|
||||
console.log('支付成功')
|
||||
self.queryOrder();
|
||||
} else if (res.errMsg === 'requestPayment:fail cancel' || res.errMsg === 'requestPayment:cancel') {
|
||||
wepy.showToast({
|
||||
title: '用户取消支付',
|
||||
icon: 'none',
|
||||
duration: 2000
|
||||
})
|
||||
} else {
|
||||
console.log('支付失败');
|
||||
let msg = res.errMsg.replace('requestPayment:fail', '')
|
||||
wepy.showToast({
|
||||
title: msg,
|
||||
icon: 'none',
|
||||
duration: 2000
|
||||
})
|
||||
}
|
||||
}
|
||||
})
|
||||
}
|
||||
})
|
||||
.catch(err => {
|
||||
console.log('err update game history');
|
||||
});
|
||||
},
|
||||
bottomSecondTap(e) {
|
||||
console.log('bottomSecondTap');
|
||||
wepy.navigateBack()
|
||||
}
|
||||
};
|
||||
|
||||
onLoad(params) {
|
||||
this.gid = decodeURIComponent(params.gid);
|
||||
}
|
||||
async queryOrder() {
|
||||
try {
|
||||
let res = await http.post('/api/emulated/query_order', {tid: this.tid});
|
||||
if (res.errcode === 0 && res.result === 1) {
|
||||
wepy.showToast({
|
||||
title: '支付成功',
|
||||
icon: 'none',
|
||||
duration: 2000
|
||||
})
|
||||
jcEvent.emit(jcEvent.events.BUY_GAME_SUCCESS, {});
|
||||
}
|
||||
} catch (err) {
|
||||
console.log(err);
|
||||
wepy.showToast({
|
||||
title: '支付失败',
|
||||
icon: 'none',
|
||||
duration: 2000
|
||||
})
|
||||
}
|
||||
}
|
||||
}
|
||||
</script>
|
Loading…
x
Reference in New Issue
Block a user