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