|
@@ -0,0 +1,128 @@
|
|
|
+// import APIClient from '../../../utils/APIClient.js'
|
|
|
+import httpRequestApi from '../../utils/APIClient';
|
|
|
+
|
|
|
+Page({
|
|
|
+ /**
|
|
|
+ * 页面的初始数据
|
|
|
+ */
|
|
|
+ data: {
|
|
|
+ name: '小学语文朗读配音',
|
|
|
+ price: 9
|
|
|
+ },
|
|
|
+ /**
|
|
|
+ * 生命周期函数--监听页面加载
|
|
|
+ */
|
|
|
+ onLoad: function (options) {
|
|
|
+ console.log('产品页', options)
|
|
|
+ if (options.price) {
|
|
|
+ this.setData({
|
|
|
+ price: options.price
|
|
|
+ })
|
|
|
+ }
|
|
|
+ },
|
|
|
+ /**
|
|
|
+ * 生命周期函数--监听页面初次渲染完成
|
|
|
+ */
|
|
|
+ onReady: function () {
|
|
|
+
|
|
|
+ },
|
|
|
+
|
|
|
+ buy() {
|
|
|
+ this.messageAuth();
|
|
|
+ },
|
|
|
+ // 授权
|
|
|
+ messageAuth() {
|
|
|
+ if (!wx.getStorageSync('message')) {
|
|
|
+ wx.requestSubscribeMessage({
|
|
|
+ tmplIds: ['KJ0YtcAacJNSXDBsE27JXqoaFrcJ1-N6Jcu85yTtQuY',
|
|
|
+ '-2ZZpWFoyKvAtX1HwEIQLQ92LnN8cryamB94LqLGo98'
|
|
|
+ ],
|
|
|
+ success: (res) => {
|
|
|
+ console.log(res)
|
|
|
+ if (res['KJ0YtcAacJNSXDBsE27JXqoaFrcJ1-N6Jcu85yTtQuY'] === 'reject') {
|
|
|
+ console.log('用户不同意订阅')
|
|
|
+ wx.setStorageSync('message', false)
|
|
|
+ } else if (res['KJ0YtcAacJNSXDBsE27JXqoaFrcJ1-N6Jcu85yTtQuY'] === 'accept') {
|
|
|
+ console.log('订阅成功')
|
|
|
+ wx.setStorageSync('message', true)
|
|
|
+ }
|
|
|
+ this.order();
|
|
|
+ },
|
|
|
+ fail: () => {
|
|
|
+ this.order();
|
|
|
+ }
|
|
|
+ })
|
|
|
+ } else {
|
|
|
+ this.order();
|
|
|
+ }
|
|
|
+ },
|
|
|
+ // 支付
|
|
|
+ order() {
|
|
|
+ // 渠道id
|
|
|
+ const productId = wx.getStorageSync('productId');
|
|
|
+ httpRequestApi.createOrder(productId).success(res => {
|
|
|
+ console.log(res.data.data.package);
|
|
|
+ const timeStamp = res.data.data.timeStamp;
|
|
|
+ const nonceStr = res.data.data.nonceStr;
|
|
|
+ const packages = res.data.data.package;
|
|
|
+ const paySign = res.data.data.sign;
|
|
|
+ wx.requestPayment({
|
|
|
+ timeStamp,
|
|
|
+ nonceStr,
|
|
|
+ package: packages,
|
|
|
+ signType: 'MD5',
|
|
|
+ paySign,
|
|
|
+ success: (res) => {
|
|
|
+ if (this.data.iphoneType === 'iphone') {
|
|
|
+ this.setData({
|
|
|
+ tipsType: 'tips',
|
|
|
+ tipsImg: 'http://reader-wx.ai160.com/images/reader/pay/success.png'
|
|
|
+ })
|
|
|
+ }
|
|
|
+ httpRequestApi.getAuthActivity().success(res => {
|
|
|
+ if (!res.data.data) {
|
|
|
+ wx.setStorageSync('vip', false)
|
|
|
+ wx.setStorageSync('date', '')
|
|
|
+ } else {
|
|
|
+ wx.setStorageSync('vip', true)
|
|
|
+ wx.setStorageSync('date', res.data.data)
|
|
|
+ // this.setData({
|
|
|
+ // ['myData.isVIP']: true,
|
|
|
+ // ['myData.date']: res.data.data
|
|
|
+ // })
|
|
|
+ const pages = getCurrentPages();
|
|
|
+ const prevPage = pages[pages.length - 2];
|
|
|
+ prevPage.setData({
|
|
|
+ ['myData.isVIP']: true,
|
|
|
+ ['myData.date']: res.data.data
|
|
|
+ }, () => {
|
|
|
+ wx.navigateBack({
|
|
|
+ delta: 1
|
|
|
+ })
|
|
|
+ })
|
|
|
+ // this.showGift();
|
|
|
+ }
|
|
|
+ }).fail(error => {
|
|
|
+ console.log(error)
|
|
|
+ })
|
|
|
+ },
|
|
|
+ fail(res) {}
|
|
|
+ })
|
|
|
+ })
|
|
|
+ },
|
|
|
+
|
|
|
+ // // 购买成功告诉首页显示邀请有礼
|
|
|
+ // showGift() {
|
|
|
+ // console.log('通知')
|
|
|
+ // this.setData({
|
|
|
+ // isVip: true
|
|
|
+ // })
|
|
|
+ // },
|
|
|
+ /**
|
|
|
+ * 生命周期函数--监听页面显示
|
|
|
+ */
|
|
|
+ onShow: function () {
|
|
|
+
|
|
|
+ },
|
|
|
+
|
|
|
+})
|