Browse Source

测试支付功能

zyh
gaoxs 5 years ago
parent
commit
c66a90ed50
  1. 5
      libs/order.js
  2. 51
      libs/wechat.js
  3. 4
      main.js
  4. 6
      manifest.json
  5. 10
      pages/authorization/index.vue
  6. 3
      pages/order/OrderDetails/index.vue
  7. 2
      pages/order/OrderSubmission/index.vue
  8. 4
      utils/index.js
  9. 5
      utils/request.js

5
libs/order.js

@ -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 => {

51
libs/wechat.js

@ -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

@ -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 模块中正常使用

6
manifest.json

@ -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" : {

10
pages/authorization/index.vue

@ -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>

3
pages/order/OrderDetails/index.vue

@ -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();
}

2
pages/order/OrderSubmission/index.vue

@ -286,7 +286,7 @@
data: function() {
return {
offlinePayStatus: 2,
from: "routine",
from: this.$deviceType,
// from: _isWeixin ? "weixin" : "weixinh5",
deduction: true,
isWeixin: _isWeixin,

4
utils/index.js

@ -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,

5
utils/request.js

@ -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) {

Loading…
Cancel
Save