|
|
@@ -26,7 +26,8 @@
|
|
|
</view>
|
|
|
<view class="add-money-list">
|
|
|
<view class="add-money-button">
|
|
|
- <button class="select-submit" :data-item="10" @tap="add_money" :class="{'bg-color':add_class1==1}">10元</button>
|
|
|
+ <button class="select-submit" :data-item="10" @tap="add_money"
|
|
|
+ :class="{'bg-color':add_class1==1}">10元</button>
|
|
|
</view>
|
|
|
<view class="add-money-button">
|
|
|
<button class="select-submit" :data-item="30" @tap="add_money">30元</button>
|
|
|
@@ -47,7 +48,7 @@
|
|
|
</view>
|
|
|
<view class="show-item">
|
|
|
<input class="input-money" placeholder="请输入金额(1-1000)" v-model:value="inputMoney"
|
|
|
- placeholder-class="#B3B3B3" @input="onInput"/>
|
|
|
+ placeholder-class="#B3B3B3" @input="onInput" />
|
|
|
</view>
|
|
|
<view class="submit-item">
|
|
|
<button class="submit" :data-rooms='room' @tap="input_money">充值</button>
|
|
|
@@ -76,7 +77,7 @@
|
|
|
campus: '', //校区
|
|
|
access_token: '',
|
|
|
sub_appid: '', //商户号
|
|
|
- order_id: '202107151048111111', //订单号
|
|
|
+ order_id: '', //订单号
|
|
|
pay_info: '',
|
|
|
item: {},
|
|
|
// storage: {},
|
|
|
@@ -91,19 +92,14 @@
|
|
|
},
|
|
|
|
|
|
onLoad: function(options) {
|
|
|
-
|
|
|
- // console.log('item:' + item);
|
|
|
+ // console.log('item:' + options.item);
|
|
|
// console.log(options.item.card_number)
|
|
|
-
|
|
|
try {
|
|
|
// 获取存储的用户数据
|
|
|
const value = uni.getStorageSync('userinfo_storage_key');
|
|
|
-
|
|
|
//将字符串解密转换成对象
|
|
|
let item = JSON.parse(decodeURIComponent(options.item));
|
|
|
-
|
|
|
// console.log(item)
|
|
|
-
|
|
|
if (JSON.stringify(item) === '{}') { // 如果没有用户信息,返回首页
|
|
|
uni.redirectTo({
|
|
|
url: '../index/index'
|
|
|
@@ -113,79 +109,49 @@
|
|
|
|
|
|
//判断item是否存在
|
|
|
if (JSON.stringify(item) != '') {
|
|
|
-
|
|
|
//判断是哪个页面传入
|
|
|
if (typeof(item.roomSelect) != 'undefined') {
|
|
|
-
|
|
|
// this.item = item;
|
|
|
-
|
|
|
this.roomSelect = item.roomSelect;
|
|
|
-
|
|
|
this.add_class = 1;
|
|
|
-
|
|
|
this.dom = item.dom;
|
|
|
-
|
|
|
console.log(this.roomSelect)
|
|
|
-
|
|
|
} else {
|
|
|
// 处理JSON字符串
|
|
|
// this.userinfo = options.item.replace(/"/g, "'");
|
|
|
this.userinfo = item;
|
|
|
+ // 更新存储的用户信息
|
|
|
+ uni.setStorageSync('userinfo_storage_key', this.userinfo)
|
|
|
// console.log(this.userinfo)
|
|
|
this.card_number = this.userinfo.card_number
|
|
|
-
|
|
|
this.campus = this.userinfo.campus
|
|
|
-
|
|
|
this.dom = this.userinfo.dorm_number
|
|
|
-
|
|
|
this.roomSelect = this.campus + this.dom
|
|
|
-
|
|
|
this.add_class = 1;
|
|
|
-
|
|
|
this.order_id = get_order_id();
|
|
|
-
|
|
|
this.sub_appid = this.userinfo.sub_appid;
|
|
|
-
|
|
|
- // this.sub_appid = this.userinfo.sub_appid
|
|
|
-
|
|
|
- // this.access_token = this.userinfo.access_token
|
|
|
-
|
|
|
- // this.storage.access_token = this.access_token
|
|
|
-
|
|
|
- // this.storage.card_number = this.card_number
|
|
|
-
|
|
|
- // uni.setStorageSync('storage_data', this.storage)
|
|
|
-
|
|
|
- // console.log(this.access_token)
|
|
|
-
|
|
|
}
|
|
|
-
|
|
|
} else if (value != '') {
|
|
|
// 处理JSON字符串
|
|
|
// this.userinfo = value.replace(/"/g, "'");
|
|
|
this.userinfo = value;
|
|
|
}
|
|
|
-
|
|
|
// console.log(this.dom)
|
|
|
// console.log(this.campus)
|
|
|
} catch (e) {
|
|
|
console.log(e)
|
|
|
}
|
|
|
+
|
|
|
+ //将缓存中的卡号进行获取
|
|
|
+ this.card_number = this.userinfo.card_number
|
|
|
|
|
|
// 查询用户信息
|
|
|
- // this.select_user_info()
|
|
|
+ this.get_valid_credentials()
|
|
|
|
|
|
// console.log('房间号' + this.dom)
|
|
|
|
|
|
//将缓存中的token码进行获取
|
|
|
- this.access_token = uni.getStorageSync('userinfo_storage_key').access_token
|
|
|
-
|
|
|
- //将缓存中的卡号进行获取
|
|
|
- this.card_number = uni.getStorageSync('userinfo_storage_key').card_number
|
|
|
-
|
|
|
-
|
|
|
- // console.log(this.access_token)
|
|
|
-
|
|
|
+ // this.access_token = uni.getStorageSync('userinfo_storage_key').access_token
|
|
|
},
|
|
|
|
|
|
methods: {
|
|
|
@@ -196,6 +162,37 @@
|
|
|
// this.arr1 = this.array1;
|
|
|
// },
|
|
|
|
|
|
+ /**
|
|
|
+ * 获取应用有效凭证
|
|
|
+ */
|
|
|
+ async get_valid_credentials() {
|
|
|
+ const res = await this.$myRequest({
|
|
|
+ host: 'wecard',
|
|
|
+ url: '/cgi-bin/oauth2/token',
|
|
|
+ method: 'POST',
|
|
|
+ header: {
|
|
|
+ 'content-type': 'application/json'
|
|
|
+ },
|
|
|
+ data: {
|
|
|
+ 'app_key': this.userinfo.appkey,
|
|
|
+ 'app_secret': this.userinfo.app_secret,
|
|
|
+ 'grant_type': 'client_credentials',
|
|
|
+ 'scope': 'base',
|
|
|
+ 'ocode': this.userinfo.ocode
|
|
|
+ }
|
|
|
+ });
|
|
|
+
|
|
|
+ if (typeof(res.data.access_token) != 'undefined') {
|
|
|
+ // 获取到应用有效凭证,保存到页面变量中
|
|
|
+ this.access_token = res.data.access_token
|
|
|
+ } else {
|
|
|
+ uni.showToast({
|
|
|
+ title: '获取凭证失败',
|
|
|
+ duration: 2000
|
|
|
+ })
|
|
|
+ }
|
|
|
+ },
|
|
|
+
|
|
|
//跳转到选择页面
|
|
|
navigateToSelect() {
|
|
|
uni.navigateTo({
|
|
|
@@ -276,49 +273,10 @@
|
|
|
|
|
|
},
|
|
|
|
|
|
- /**
|
|
|
- * 输入充值金额
|
|
|
- */
|
|
|
- onInput(e) {
|
|
|
- const v = e.detail.value
|
|
|
- this.inputMoney = 10
|
|
|
-
|
|
|
- const zero = /^(0{1,})|[^0-9]/g
|
|
|
- let final = 0
|
|
|
- if (!v) {
|
|
|
- final = 0
|
|
|
- } else {
|
|
|
- final = v.toString().replace(zero, (v) => {
|
|
|
- return 0
|
|
|
- })
|
|
|
-
|
|
|
- if (final.split('')[0] * 1 === 0) {
|
|
|
- final = final.slice(1) - 0 || 0
|
|
|
- }
|
|
|
-
|
|
|
- if (final > 1000) {
|
|
|
- final = 1000
|
|
|
- }
|
|
|
- }
|
|
|
- this.$nextTick(() => {
|
|
|
- this.inputMoney = final.toString() || '0'
|
|
|
- })
|
|
|
- // setTimeout(() => {
|
|
|
- // this.amount = final.toString() || '0'
|
|
|
- // }, 100)
|
|
|
- },
|
|
|
-
|
|
|
- //失去焦点
|
|
|
- // onBlur() {
|
|
|
- // if (this.inputMoney < 10) {
|
|
|
- // this.inputMoney = 10
|
|
|
- // }
|
|
|
- // },
|
|
|
-
|
|
|
//准备支付
|
|
|
async pay_money_start() {
|
|
|
const res = await this.$myRequest({
|
|
|
- // ip: 'http://open.wecard.qq.com',
|
|
|
+ // ip: 'https://open.wecard.qq.com',
|
|
|
host: 'wecard',
|
|
|
url: "/cgi-bin/pay/app/mppay",
|
|
|
method: 'POST',
|
|
|
@@ -333,21 +291,28 @@
|
|
|
"amount": this.addMoney * 100,
|
|
|
}
|
|
|
});
|
|
|
- // console.log(res)
|
|
|
- this.pay_info = res.data.data.pay_info
|
|
|
-
|
|
|
- // var info = decodeURIComponent(this.pay_info).substr(5,)
|
|
|
- // info = JSON.parse(info)
|
|
|
- // console.log(this.pay_info)
|
|
|
- // console.log(this.resToken.access_token)
|
|
|
-
|
|
|
- this.add_money_pay()
|
|
|
-
|
|
|
+ console.log(this.access_token)
|
|
|
+ console.log(this.sub_appid)
|
|
|
+ console.log(this.card_number)
|
|
|
+ console.log(this.order_id)
|
|
|
+ console.log(this.addMoney)
|
|
|
+ console.log(res.data)
|
|
|
+ if (res.data.code == 0) {
|
|
|
+ this.pay_info = res.data.data.pay_info
|
|
|
+ // 发起支付
|
|
|
+ this.add_money_pay()
|
|
|
+ } else {
|
|
|
+ uni.showToast({
|
|
|
+ icon: 'none',
|
|
|
+ title: res.data.message,
|
|
|
+ duration: 3000
|
|
|
+ })
|
|
|
+ }
|
|
|
},
|
|
|
|
|
|
//调起支付
|
|
|
add_money_pay() {
|
|
|
- var OpenMidas = require("../../static/openMidas.js"); // 引入小程序目录下的SDK文件
|
|
|
+ var OpenMidas = require("@/static/openMidas.js"); // 引入小程序目录下的SDK文件
|
|
|
|
|
|
// 设置支付配置
|
|
|
wx['OpenMidasConfig'] = {
|
|
|
@@ -363,7 +328,7 @@
|
|
|
|
|
|
var payInfo = this.pay_info; // 请求mppay接口返回的数据
|
|
|
// console.log(payInfo)
|
|
|
- // var appMetaData = "app=test&version=1.1"; // 自定义回调数据
|
|
|
+ var appMetaData = "app=test&version=1.1"; // 自定义回调数据
|
|
|
|
|
|
OpenMidas.init("test");
|
|
|
OpenMidas.pay(
|
|
|
@@ -376,16 +341,43 @@
|
|
|
|
|
|
// todo:处理业务逻辑
|
|
|
},
|
|
|
- // appMetaData
|
|
|
+ appMetaData
|
|
|
);
|
|
|
- }
|
|
|
+ },
|
|
|
+ /**
|
|
|
+ * 输入充值金额
|
|
|
+ */
|
|
|
+ onInput(e) {
|
|
|
+ const v = e.detail.value
|
|
|
+ this.inputMoney = 10
|
|
|
+
|
|
|
+ const zero = /^(0{1,})|[^0-9]/g
|
|
|
+ let final = 0
|
|
|
+ if (!v) {
|
|
|
+ final = 0
|
|
|
+ } else {
|
|
|
+ final = v.toString().replace(zero, (v) => {
|
|
|
+ return 0
|
|
|
+ })
|
|
|
+
|
|
|
+ if (final.split('')[0] * 1 === 0) {
|
|
|
+ final = final.slice(1) - 0 || 0
|
|
|
+ }
|
|
|
|
|
|
+ if (final > 1000) {
|
|
|
+ final = 1000
|
|
|
+ }
|
|
|
+ }
|
|
|
+ this.$nextTick(() => {
|
|
|
+ this.inputMoney = final.toString() || '0'
|
|
|
+ })
|
|
|
+ }
|
|
|
},
|
|
|
}
|
|
|
-
|
|
|
+
|
|
|
function get_order_id() {
|
|
|
const date = new Date()
|
|
|
-
|
|
|
+
|
|
|
let year = date.getFullYear()
|
|
|
let month = date.getMonth() + 1
|
|
|
let day = date.getDate()
|
|
|
@@ -393,15 +385,13 @@
|
|
|
let minute = date.getMinutes()
|
|
|
let second = date.getSeconds()
|
|
|
let millisecond = date.getMilliseconds()
|
|
|
-
|
|
|
+
|
|
|
month = month > 9 ? month : '0' + month
|
|
|
day = day > 9 ? day : '0' + day
|
|
|
second = second > 9 ? second : '0' + second
|
|
|
// 小于4位数,前补0
|
|
|
- // millisecond = millisecond < 1000 ? '00' + millisecond : millisecond
|
|
|
- // 小于4位数,前补随机数
|
|
|
- millisecond = millisecond < 1000 ? Math.floor(Math.random() * 999 + 1000) + millisecond : millisecond
|
|
|
-
|
|
|
+ millisecond = millisecond.length < 3 ? '0' + millisecond : millisecond
|
|
|
+
|
|
|
return `${year}${month}${day}${hour}${minute}${second}${millisecond}`
|
|
|
}
|
|
|
</script>
|