测试支付功能
This commit is contained in:
@ -71,6 +71,7 @@ export function delOrderHandle(orderId) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
export function payOrderHandle(orderId, type, from) {
|
export function payOrderHandle(orderId, type, from) {
|
||||||
|
console.log(orderId, type, from, '支付')
|
||||||
return new Promise((resolve, reject) => {
|
return new Promise((resolve, reject) => {
|
||||||
uni.showLoading({ title: '加载中' })
|
uni.showLoading({ title: '加载中' })
|
||||||
payOrder(orderId, type, from)
|
payOrder(orderId, type, from)
|
||||||
@ -97,6 +98,10 @@ export function payOrderHandle(orderId, type, from) {
|
|||||||
weappPay(data.result.jsConfig).then(res => {
|
weappPay(data.result.jsConfig).then(res => {
|
||||||
resolve(data);
|
resolve(data);
|
||||||
});
|
});
|
||||||
|
case "WECHAT_APP_PAY":
|
||||||
|
weappPay(data.result.jsConfig).then(res => {
|
||||||
|
resolve(data);
|
||||||
|
});
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
.catch(err => {
|
.catch(err => {
|
||||||
|
@ -1,20 +1,47 @@
|
|||||||
|
import { getProvider } from "@/utils";
|
||||||
|
|
||||||
// 支付模块
|
// 支付模块
|
||||||
export const weappPay = (option) => {
|
export const weappPay = (option) => {
|
||||||
return new Promise((resolve, reject) => {
|
return new Promise((resolve, reject) => {
|
||||||
// 吊起微信支付
|
// 吊起微信支付
|
||||||
uni.requestPayment({
|
getProvider().then(provider => {
|
||||||
...option,
|
let orderInfo = {
|
||||||
timeStamp: option.timeStamp + '',
|
...option,
|
||||||
success: (success) => {
|
timeStamp: option.timestamp + '',
|
||||||
uni.showToast({
|
|
||||||
title: '支付成功', icon: 'success', duration: 2000
|
|
||||||
});
|
|
||||||
resolve(success)
|
|
||||||
},
|
|
||||||
fail: (error) => {
|
|
||||||
uni.showToast({ title: '支付失败', icon: 'none', duration: 2000 });
|
|
||||||
reject(error)
|
|
||||||
}
|
}
|
||||||
|
console.log({
|
||||||
|
provider: provider,
|
||||||
|
signType: "MD5",
|
||||||
|
timeStamp: orderInfo.timestamp,
|
||||||
|
nonceStr: orderInfo.noncestr,
|
||||||
|
package: orderInfo.prepayid,
|
||||||
|
signType: "MD5",
|
||||||
|
paySign: orderInfo.sign,
|
||||||
|
orderInfo,
|
||||||
|
},'发起支付')
|
||||||
|
// 调用登录接口
|
||||||
|
uni.requestPayment({
|
||||||
|
provider: provider,
|
||||||
|
signType: "MD5",
|
||||||
|
timeStamp: orderInfo.timeStamp,
|
||||||
|
nonceStr: orderInfo.noncestr,
|
||||||
|
package: orderInfo.prepayid,
|
||||||
|
signType: "MD5",
|
||||||
|
paySign: orderInfo.sign,
|
||||||
|
orderInfo,
|
||||||
|
success: (success) => {
|
||||||
|
console.log(error)
|
||||||
|
uni.showToast({
|
||||||
|
title: '支付成功', icon: 'success', duration: 2000
|
||||||
|
});
|
||||||
|
resolve(success)
|
||||||
|
},
|
||||||
|
fail: (error) => {
|
||||||
|
console.log(error)
|
||||||
|
uni.showToast({ title: '支付失败', icon: 'none', duration: 2000 });
|
||||||
|
reject(error)
|
||||||
|
}
|
||||||
|
})
|
||||||
})
|
})
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
4
main.js
4
main.js
@ -90,8 +90,8 @@ Vue.prototype.$platform = uni.getSystemInfoSync().platform
|
|||||||
|
|
||||||
// #ifdef MP-WEIXIN
|
// #ifdef MP-WEIXIN
|
||||||
// 微信小程序编译的代码
|
// 微信小程序编译的代码
|
||||||
Vue.prototype.$deviceType = 'weixin'
|
Vue.prototype.$deviceType = 'routine'
|
||||||
store.commit('UPDATE_DEVICETYPE','weixin')
|
store.commit('UPDATE_DEVICETYPE','routine')
|
||||||
// #endif
|
// #endif
|
||||||
|
|
||||||
// !!! ps 不建议在 template 中使用 $deviceType 去判断当前环境,很有可能出现 $deviceType 为 undefined 导致判断出错的问题,可以在 script 模块中正常使用
|
// !!! ps 不建议在 template 中使用 $deviceType 去判断当前环境,很有可能出现 $deviceType 为 undefined 导致判断出错的问题,可以在 script 模块中正常使用
|
||||||
|
@ -1,9 +1,9 @@
|
|||||||
{
|
{
|
||||||
"name" : "yshopmall_uni",
|
"name" : "yshopmall",
|
||||||
"appid" : "",
|
"appid" : "__UNI__C7A519E",
|
||||||
"description" : "",
|
"description" : "",
|
||||||
"versionName" : "1.0.0",
|
"versionName" : "1.0.0",
|
||||||
"versionCode" : "100",
|
"versionCode" : 1,
|
||||||
"transformPx" : false,
|
"transformPx" : false,
|
||||||
/* 5+App特有相关 */
|
/* 5+App特有相关 */
|
||||||
"app-plus" : {
|
"app-plus" : {
|
||||||
|
@ -1,7 +1,7 @@
|
|||||||
<template>
|
<template>
|
||||||
<view class="container">
|
<view class="container">
|
||||||
<view v-if="!token">
|
<view v-if="!token">
|
||||||
<view v-if="$deviceType == 'weixin'">
|
<view v-if="$deviceType == 'routine'">
|
||||||
<view class="getUserInfo">
|
<view class="getUserInfo">
|
||||||
<text>您还未允许微信登录授权,请点击下方按钮允许微信授权登录。</text>
|
<text>您还未允许微信登录授权,请点击下方按钮允许微信授权登录。</text>
|
||||||
<button type="primary" open-type="getUserInfo" @getuserinfo="getUserInfo">允许微信登录授权</button>
|
<button type="primary" open-type="getUserInfo" @getuserinfo="getUserInfo">允许微信登录授权</button>
|
||||||
@ -30,7 +30,7 @@ import { login } from '@/utils';
|
|||||||
|
|
||||||
export default {
|
export default {
|
||||||
data() {
|
data() {
|
||||||
return {
|
return {
|
||||||
};
|
};
|
||||||
},
|
},
|
||||||
computed: {
|
computed: {
|
||||||
@ -80,7 +80,7 @@ export default {
|
|||||||
}
|
}
|
||||||
},
|
},
|
||||||
onUnload() {},
|
onUnload() {},
|
||||||
mounted() {
|
mounted() {
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
</script>
|
</script>
|
||||||
@ -206,4 +206,4 @@ export default {
|
|||||||
._van-dialog {
|
._van-dialog {
|
||||||
z-index: 99999999999;
|
z-index: 99999999999;
|
||||||
}
|
}
|
||||||
</style>
|
</style>
|
||||||
|
@ -482,7 +482,7 @@ export default {
|
|||||||
status: {},
|
status: {},
|
||||||
pay: false,
|
pay: false,
|
||||||
payType: ["yue", "weixin"],
|
payType: ["yue", "weixin"],
|
||||||
from: "routine",
|
from: this.$deviceType,
|
||||||
system_store: {},
|
system_store: {},
|
||||||
mapKay: "",
|
mapKay: "",
|
||||||
mapShow: false
|
mapShow: false
|
||||||
@ -652,6 +652,7 @@ export default {
|
|||||||
},
|
},
|
||||||
async toPay(type) {
|
async toPay(type) {
|
||||||
var that = this;
|
var that = this;
|
||||||
|
console.log(type, "支付方式");
|
||||||
await payOrderHandle(this.orderInfo.orderId, type, that.from);
|
await payOrderHandle(this.orderInfo.orderId, type, that.from);
|
||||||
that.getDetail();
|
that.getDetail();
|
||||||
}
|
}
|
||||||
|
@ -286,7 +286,7 @@
|
|||||||
data: function() {
|
data: function() {
|
||||||
return {
|
return {
|
||||||
offlinePayStatus: 2,
|
offlinePayStatus: 2,
|
||||||
from: "routine",
|
from: this.$deviceType,
|
||||||
// from: _isWeixin ? "weixin" : "weixinh5",
|
// from: _isWeixin ? "weixin" : "weixinh5",
|
||||||
deduction: true,
|
deduction: true,
|
||||||
isWeixin: _isWeixin,
|
isWeixin: _isWeixin,
|
||||||
|
@ -119,7 +119,7 @@ export const replaceLogin = (msg) => {
|
|||||||
});
|
});
|
||||||
// 这里代表已经失去登录状态以及401强制推出登录了
|
// 这里代表已经失去登录状态以及401强制推出登录了
|
||||||
store.commit('LOGOUT')
|
store.commit('LOGOUT')
|
||||||
if (Vue.prototype.$deviceType == 'weixin') {
|
if (Vue.prototype.$deviceType == 'routine') {
|
||||||
// 如果是微信小程序,跳转到授权页
|
// 如果是微信小程序,跳转到授权页
|
||||||
login({
|
login({
|
||||||
fail: () => {
|
fail: () => {
|
||||||
@ -196,7 +196,7 @@ export const login = (option) => {
|
|||||||
uni.getUserInfo({
|
uni.getUserInfo({
|
||||||
provider: provider,
|
provider: provider,
|
||||||
success: function (user) {
|
success: function (user) {
|
||||||
if (Vue.prototype.$deviceType == 'weixin') {
|
if (Vue.prototype.$deviceType == 'routine') {
|
||||||
wxappAuth({
|
wxappAuth({
|
||||||
encryptedData: user.encryptedData,
|
encryptedData: user.encryptedData,
|
||||||
iv: user.iv,
|
iv: user.iv,
|
||||||
|
@ -47,14 +47,15 @@ function baseRequest(options) {
|
|||||||
// 提示错误信息
|
// 提示错误信息
|
||||||
return Promise.reject({ msg: "未登录", toLogin: true });
|
return Promise.reject({ msg: "未登录", toLogin: true });
|
||||||
}
|
}
|
||||||
|
console.log(options)
|
||||||
// 结构请求需要的参数
|
// 结构请求需要的参数
|
||||||
const { url, params, data, login, ...option } = options
|
const { url, params, data, login, ...option } = options
|
||||||
|
|
||||||
// 发起请求
|
// 发起请求
|
||||||
return fly.request(url, params || data, {
|
return fly.request(url, params || data, {
|
||||||
...option
|
...option
|
||||||
}).then(res => {
|
}).then(res => {
|
||||||
|
console.log(res)
|
||||||
const data = res.data || {};
|
const data = res.data || {};
|
||||||
if (res.status !== 200) {
|
if (res.status !== 200) {
|
||||||
|
|
||||||
|
Reference in New Issue
Block a user