Commit 23906d9c authored by shun's avatar shun
Browse files

init

No related merge requests found
Showing with 245 additions and 0 deletions
+245 -0
app.js 0 → 100644
// app.js
import { REQUEST } from '/utils/index.js'
const globalData = {
openid: ''
}
const methods = {
// 登录
wxLogin() {
return new Promise((resolve, reject) => {
wx.login({
success: res => {
let url = 'https://wx.wgmf.com/wechat-pay-test/miniAppPay/jscode2session?jsCode=' + res.code
REQUEST.get(url).then(res => {
if (res.statusCode === 200) {
this.globalData.openid = JSON.parse(res.data).openid
resolve(res)
}
}).catch(e => {
})
},
fail: error => {
reject(error)
}
})
})
}
}
App({
globalData,
...methods,
onLaunch: function () {
this.wxLogin()
console.log('app onLaunch')
},
onReady: function () {
console.log('app onReady')
},
onLoad: function () {
console.log('app onLoad')
}
})
\ No newline at end of file
app.json 0 → 100644
{
"pages":[
"pages/index/index",
"pages/wxPay/wxPay",
"pages/home/home",
"pages/service/service"
],
"window":{
"backgroundTextStyle":"light",
"navigationBarBackgroundColor": "#fff",
"navigationBarTitleText": "WeChat",
"navigationBarTextStyle":"black"
}
}
app.wxss 0 → 100644
/**app.wxss**/
.container {
height: 100%;
display: flex;
flex-direction: column;
align-items: center;
justify-content: space-between;
padding: 200rpx 0;
box-sizing: border-box;
}
File added
//index.js
import { REQUEST } from '../../utils/index.js'
//获取应用实例
const app = getApp()
const data = {
pageUrl: ''
}
const methods = {
init () {
}
}
Page({
data,
...methods,
onReady: function () {
console.log('index onReady')
},
onLoad: function () {
console.log('index onLoad')
app.wxLogin().then(res => {
this.setData({
pageUrl: 'https://wx.wgmf.com/dist/shop/productIndex.html?o=' + app.globalData.openid + '&v=' + new Date().getTime()
})
console.log(this.data.pageUrl)
})
}
})
{
}
\ No newline at end of file
<!--index.wxml-->
<view class="container">
<!-- <button bindtap='click'>h</button> -->
<web-view src='{{pageUrl}}'></web-view>
<!-- <web-view src='https://wx.wgmf.com/dist/shop/productIndex.html?o=oSG0Y4yX-aw5bR7G-cMediOdhPuk'></web-view> -->
</view>
/**index.wxss**/
\ No newline at end of file
//index.js
import { REQUEST } from '../../utils/index.js'
//获取应用实例
const app = getApp()
const data = {
pageUrl: ''
}
const methods = {
test () {
let url = 'https://wx.wgmf.com/wechat-pay-test/pay/bill/my201806071048484107653'
REQUEST.post(url, {
data: {
openId: 'oSG0Y4yX-aw5bR7G-cMediOdhPuk'
}
}).then(res => {
}).catch(e => {
})
}
}
Page({
data,
...methods,
onReady: function () {
console.log('index onReady')
},
onLoad: function () {
app.wxLogin().then(res => {
this.setData({
pageUrl: 'https://wx.wgmf.com/dist/shop/productIndex.html?o=' + app.globalData.openid + '&v=' + new Date().getTime()
})
})
}
})
{
}
\ No newline at end of file
<!--index.wxml-->
<view class="container">
<web-view src='{{pageUrl}}'></web-view>
</view>
\ No newline at end of file
/**index.wxss**/
\ No newline at end of file
//service.js
//获取应用实例
const app = getApp()
const data = {
username: new Date().getTime()
}
const methods = {
}
Page({
data,
...methods,
onReady: function () {
},
onLoad: function () {
}
})
{
}
\ No newline at end of file
<!--service.wxml-->
<view>
<button type="primary" size="40" session-from="sobot|{{username}}| ''" open-type="contact">联系客服</button>
</view>
\ No newline at end of file
/**service.wxss**/
\ No newline at end of file
// pages/wxPay/wxPay.js
const methods = {
click () {
wx.navigateTo({
url: 'pages/index/index'
})
}
}
Page({
data: {
payParam: '',
orderId: ''
},
onLoad: function (options) {
let param = decodeURIComponent(options.payParam)
let pay = JSON.parse(param)
this.setData({
orderId: decodeURIComponent(options.orderId)
})
console.log(options)
this.confirmPay(pay)
},
//采用小程序支付
confirmPay: function (payParams) {
// const _this = this
wx.requestPayment(
{
"timeStamp": payParams.timeStamp,
"package": payParams.packageStr,
"paySign": payParams.paySign,
"signType": payParams.signType,
"nonceStr": payParams.nonceStr,
"paySign": payParams.paySign,
//支付成功的回调
'success': function (res) {
console.log('success:' + JSON.stringify(res))
},
//支付失败的回调
'fail': function (res) {
console.log('fail:' + JSON.stringify(res))
wx.showToast({
title: '支付失败:',
icon: 'none',
})
},
'complete': function (res) {
let pages = getCurrentPages()
let prevPage = pages[pages.length - 2]
prevPage.setData({
pageUrl: 'https://wx.wgmf.com/dist/shop/orderList.html'
})
wx.navigateBack();
}
})
}
})
\ No newline at end of file
{}
\ No newline at end of file
<!--pages/wxPay/wxPay.wxml-->
<!-- <text>pages/wxPay/wxPay.wxml</text> -->
<!-- <button bindtap='confirmPay'>小程序支付</button> -->
\ No newline at end of file
.log-list {
display: flex;
flex-direction: column;
padding: 40rpx;
}
.log-item {
margin: 10rpx;
}
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment