|
@@ -35,7 +35,7 @@
|
|
|
export default {
|
|
export default {
|
|
|
data() {
|
|
data() {
|
|
|
return {
|
|
return {
|
|
|
- amount: 10.0.toFixed(0), // 金额
|
|
|
|
|
|
|
+ amount: 10, // 金额
|
|
|
phone_number: '13645689854', // 客户热线电话
|
|
phone_number: '13645689854', // 客户热线电话
|
|
|
userinfo: '', // 用户信息
|
|
userinfo: '', // 用户信息
|
|
|
order_id: '', // 订单号
|
|
order_id: '', // 订单号
|
|
@@ -44,7 +44,7 @@
|
|
|
sub_appid: '',
|
|
sub_appid: '',
|
|
|
card_number: '',
|
|
card_number: '',
|
|
|
user_name: '',
|
|
user_name: '',
|
|
|
- test: getApp().globalData.test
|
|
|
|
|
|
|
+ test: getApp().globalData.test // 获取全局变量,控制是否是测试环境
|
|
|
};
|
|
};
|
|
|
},
|
|
},
|
|
|
onLoad(options) {
|
|
onLoad(options) {
|
|
@@ -66,7 +66,7 @@
|
|
|
this.userinfo = JSON.parse(item)
|
|
this.userinfo = JSON.parse(item)
|
|
|
// 更新存储的用户信息
|
|
// 更新存储的用户信息
|
|
|
uni.setStorageSync('userinfo_storage_key', this.userinfo)
|
|
uni.setStorageSync('userinfo_storage_key', this.userinfo)
|
|
|
- } else if (value != '') {
|
|
|
|
|
|
|
+ } else if (JSON.stringify(value) !== '{}') {
|
|
|
// 处理JSON字符串
|
|
// 处理JSON字符串
|
|
|
// this.userinfo = value.replace(/"/g, "'");
|
|
// this.userinfo = value.replace(/"/g, "'");
|
|
|
this.userinfo = value;
|
|
this.userinfo = value;
|
|
@@ -75,6 +75,9 @@
|
|
|
console.log(e)
|
|
console.log(e)
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
|
|
+ if (this.test) //测试环境
|
|
|
|
|
+ this.amount = 0.01
|
|
|
|
|
+
|
|
|
this.sub_appid = this.userinfo.sub_appid
|
|
this.sub_appid = this.userinfo.sub_appid
|
|
|
this.card_number = this.userinfo.card_number
|
|
this.card_number = this.userinfo.card_number
|
|
|
this.user_name = this.userinfo.name
|
|
this.user_name = this.userinfo.name
|
|
@@ -127,10 +130,10 @@
|
|
|
'access_token': this.access_token,
|
|
'access_token': this.access_token,
|
|
|
'sub_appid': this.sub_appid,
|
|
'sub_appid': this.sub_appid,
|
|
|
'user_id': this.card_number,
|
|
'user_id': this.card_number,
|
|
|
- 'order_id': this.order_id = get_order_id('shuifei'),
|
|
|
|
|
|
|
+ 'order_id': this.order_id = this.$getOrderId('shuifei'),
|
|
|
'amount': this.amount * 100,
|
|
'amount': this.amount * 100,
|
|
|
'order_type': 1,
|
|
'order_type': 1,
|
|
|
- // 'callback_url': 'http://x3ys5i.natappfree.cc'
|
|
|
|
|
|
|
+ // 'callback_url': 'http://wvwviw.natappfree.cc/HotWaters/wxpayrecharge.action'
|
|
|
'callback_url': this.$code_base_url + '/HotWater/wxpayrecharge.action'
|
|
'callback_url': this.$code_base_url + '/HotWater/wxpayrecharge.action'
|
|
|
}
|
|
}
|
|
|
})
|
|
})
|
|
@@ -142,38 +145,65 @@
|
|
|
// 调起支付
|
|
// 调起支付
|
|
|
pay_amount() {
|
|
pay_amount() {
|
|
|
var OpenMidas = require("@/static/openMidas.js") // 引入小程序目录下的SDK文件
|
|
var OpenMidas = require("@/static/openMidas.js") // 引入小程序目录下的SDK文件
|
|
|
|
|
+ if (this.test) { // 是否是测试环境
|
|
|
|
|
+ // 设置支付配置
|
|
|
|
|
+ wx['OpenMidasConfig'] = {
|
|
|
|
|
+ apiCommonConf: {
|
|
|
|
|
+ version: "weixiao"
|
|
|
|
|
+ },
|
|
|
|
|
+ cgiDomain: {
|
|
|
|
|
+ test: "midas.weixiao.qq.com/api", // 私有化参数联系微卡客服进行获取
|
|
|
|
|
+ },
|
|
|
|
|
+ webDomain: "https://midas.weixiao.qq.com/h5", // 私有化参数联系微卡客服进行获取
|
|
|
|
|
+ sandboxWebDomain: "https://midas.weixiao.qq.com/h5" // 私有化参数联系微卡客服进行获取
|
|
|
|
|
+ }
|
|
|
|
|
|
|
|
- // 设置支付配置
|
|
|
|
|
- wx['OpenMidasConfig'] = {
|
|
|
|
|
- apiCommonConf: {
|
|
|
|
|
- version: "weixiao"
|
|
|
|
|
- },
|
|
|
|
|
- cgiDomain: {
|
|
|
|
|
- test: "midas.weixiao.qq.com/api", // 私有化参数联系微卡客服进行获取
|
|
|
|
|
- },
|
|
|
|
|
- webDomain: "https://midas.weixiao.qq.com/h5", // 私有化参数联系微卡客服进行获取
|
|
|
|
|
- sandboxWebDomain: "https://midas.weixiao.qq.com/h5" // 私有化参数联系微卡客服进行获取
|
|
|
|
|
- }
|
|
|
|
|
-
|
|
|
|
|
- var payInfo = this.pay_info; // 请求mppay接口返回的数据
|
|
|
|
|
- // var appMetaData = "card_number=" + this.card_number + "&user_name=" + this.user_name + "&account=" + this
|
|
|
|
|
- // .amount; // 自定义回调数据
|
|
|
|
|
|
|
+ var payInfo = this.pay_info; // 请求mppay接口返回的数据
|
|
|
|
|
+ // var appMetaData = "card_number=" + this.card_number + "&user_name=" + this.user_name + "&account=" + this
|
|
|
|
|
+ // .amount; // 自定义回调数据
|
|
|
|
|
+ OpenMidas.init("test");
|
|
|
|
|
+ } else {
|
|
|
|
|
+ // 设置支付配置
|
|
|
|
|
+ wx['OpenMidasConfig'] = {
|
|
|
|
|
+ apiCommonConf: {
|
|
|
|
|
+ version: "weixiao"
|
|
|
|
|
+ },
|
|
|
|
|
+ cgiDomain: {
|
|
|
|
|
+ release: "midas.weixiao.qq.com/api", // 私有化参数联系微卡客服进行获取
|
|
|
|
|
+ },
|
|
|
|
|
+ webDomain: "https://midas.weixiao.qq.com/h5", // 私有化参数联系微卡客服进行获取
|
|
|
|
|
+ sandboxWebDomain: "https://midas.weixiao.qq.com/h5" // 私有化参数联系微卡客服进行获取
|
|
|
|
|
+ }
|
|
|
|
|
|
|
|
- OpenMidas.init("test");
|
|
|
|
|
|
|
+ var payInfo = this.pay_info; // 请求mppay接口返回的数据
|
|
|
|
|
+ // var appMetaData = "card_number=" + this.card_number + "&user_name=" + this.user_name + "&account=" + this
|
|
|
|
|
+ // .amount; // 自定义回调数据
|
|
|
|
|
+ OpenMidas.init("release");
|
|
|
|
|
+ }
|
|
|
OpenMidas.pay(
|
|
OpenMidas.pay(
|
|
|
payInfo,
|
|
payInfo,
|
|
|
// function(resultCode, innerCode, resultMsg, appMetaData) {
|
|
// function(resultCode, innerCode, resultMsg, appMetaData) {
|
|
|
function(resultCode, innerCode, resultMsg) {
|
|
function(resultCode, innerCode, resultMsg) {
|
|
|
- console.log(resultCode); // 支付响应状态码
|
|
|
|
|
- console.log(innerCode); // 支付响应内部错误码
|
|
|
|
|
- console.log(resultMsg); // 支付响应说明
|
|
|
|
|
- console.log(appMetaData); // 自定义回调数据
|
|
|
|
|
-
|
|
|
|
|
- // todo:处理业务逻辑
|
|
|
|
|
- uni.showToast({
|
|
|
|
|
- title: resultMsg,
|
|
|
|
|
- icon: 'success'
|
|
|
|
|
- })
|
|
|
|
|
|
|
+ // console.log(resultCode); // 支付响应状态码
|
|
|
|
|
+ // console.log(innerCode); // 支付响应内部错误码
|
|
|
|
|
+ // console.log(resultMsg); // 支付响应说明
|
|
|
|
|
+ // console.log(appMetaData); // 自定义回调数据
|
|
|
|
|
+
|
|
|
|
|
+ if (resultCode == 0) {
|
|
|
|
|
+ let pay_info_storage_key = {}
|
|
|
|
|
+ pay_info_storage_key.resultCode = resultCode
|
|
|
|
|
+ pay_info_storage_key.resultMsg = resultMsg
|
|
|
|
|
+ // 保存用户充值成功
|
|
|
|
|
+ uni.setStorageSync('pay_info_storage_key', pay_info_storage_key)
|
|
|
|
|
+ uni.navigateBack({
|
|
|
|
|
+ delta: 1
|
|
|
|
|
+ })
|
|
|
|
|
+ } else {
|
|
|
|
|
+ uni.showToast({
|
|
|
|
|
+ title: '支付异常',
|
|
|
|
|
+ icon: 'success'
|
|
|
|
|
+ })
|
|
|
|
|
+ }
|
|
|
}
|
|
}
|
|
|
// },
|
|
// },
|
|
|
// appMetaData
|
|
// appMetaData
|
|
@@ -183,7 +213,7 @@
|
|
|
* 输入充值金额
|
|
* 输入充值金额
|
|
|
*/
|
|
*/
|
|
|
onInput(e) {
|
|
onInput(e) {
|
|
|
- if (this.test) {
|
|
|
|
|
|
|
+ if (this.test) { // 测试环境
|
|
|
return
|
|
return
|
|
|
}
|
|
}
|
|
|
|
|
|
|
@@ -215,7 +245,7 @@
|
|
|
* 输入框,失去焦点时
|
|
* 输入框,失去焦点时
|
|
|
*/
|
|
*/
|
|
|
onBlur() {
|
|
onBlur() {
|
|
|
- if (this.test) {
|
|
|
|
|
|
|
+ if (this.test) { // 测试环境
|
|
|
return
|
|
return
|
|
|
}
|
|
}
|
|
|
if (this.amount < 10) {
|
|
if (this.amount < 10) {
|
|
@@ -232,7 +262,7 @@
|
|
|
* 调用接口实现充值功能
|
|
* 调用接口实现充值功能
|
|
|
*/
|
|
*/
|
|
|
chongzhi() {
|
|
chongzhi() {
|
|
|
- if (this.test) {
|
|
|
|
|
|
|
+ if (this.test) { // 测试环境
|
|
|
uni.showModal({
|
|
uni.showModal({
|
|
|
title: '提示',
|
|
title: '提示',
|
|
|
content: '您选择了充值:¥' + this.amount + ' 元',
|
|
content: '您选择了充值:¥' + this.amount + ' 元',
|
|
@@ -285,34 +315,6 @@
|
|
|
}
|
|
}
|
|
|
}
|
|
}
|
|
|
}
|
|
}
|
|
|
- /**
|
|
|
|
|
- * 时间生成订单号
|
|
|
|
|
- */
|
|
|
|
|
- function get_order_id(head) {
|
|
|
|
|
- const date = new Date()
|
|
|
|
|
-
|
|
|
|
|
- let year = date.getFullYear()
|
|
|
|
|
- let month = date.getMonth() + 1
|
|
|
|
|
- let day = date.getDate()
|
|
|
|
|
- let hour = date.getHours()
|
|
|
|
|
- let minute = date.getMinutes()
|
|
|
|
|
- let second = date.getSeconds()
|
|
|
|
|
- let millisecond = date.getMilliseconds()
|
|
|
|
|
- let len_mill = millisecond.toString().length
|
|
|
|
|
-
|
|
|
|
|
- month = month > 9 ? month : '0' + month
|
|
|
|
|
- day = day > 9 ? day : '0' + day
|
|
|
|
|
- second = second > 9 ? second : '0' + second
|
|
|
|
|
- if (len_mill == 1) {
|
|
|
|
|
- millisecond = (Math.floor(Math.random() * 9000) + 10000).toString() + millisecond
|
|
|
|
|
- } else if (len_mill == 2) {
|
|
|
|
|
- millisecond = (Math.floor(Math.random() * 900) + 1000).toString() + millisecond
|
|
|
|
|
- } else if (len_mill == 3) {
|
|
|
|
|
- millisecond = (Math.floor(Math.random() * 900) + 100).toString() + millisecond
|
|
|
|
|
- }
|
|
|
|
|
-
|
|
|
|
|
- return `${head}${year}${month}${day}${hour}${minute}${second}${millisecond}`
|
|
|
|
|
- }
|
|
|
|
|
</script>
|
|
</script>
|
|
|
|
|
|
|
|
<style lang="scss" scoped>
|
|
<style lang="scss" scoped>
|