Blog
首页
文档
收藏
关于
  • 在线转换时间戳 (opens new window)
  • 在线压缩图片 (opens new window)
  • Float-Double转二进制 (opens new window)
  • 文件转Hex字符串 (opens new window)

HiuZing

🍑
首页
文档
收藏
关于
  • 在线转换时间戳 (opens new window)
  • 在线压缩图片 (opens new window)
  • Float-Double转二进制 (opens new window)
  • 文件转Hex字符串 (opens new window)
  • 前端面试题

  • JavaScript

  • Vue2

  • port

  • CSS

  • Node.js

  • JavaScript优化

  • uniapp

    • uniapp-上传图片
    • uniapp-支付(支付宝和微信)
    • uniapp-复制(设置系统剪贴板)
    • uniapp-rich-text无法处理video问题
    • uniapp-生产和开发环境
    • uniapp-设置全局变量
    • uniapp-自定义导航栏
    • uniapp-跨域
    • uniapp-获取用户手机号
    • uniapp-打包发布
    • uniapp-蓝牙
  • Mini Program

  • TypeScript

  • 面向对象编程

  • UI组件

  • Plugin

  • Vue3

  • 性能优化

  • Axios

  • 状态管理

  • React

  • Mock

  • Icon

  • Template

  • 构建工具

  • 项目规范配置

  • Taro

  • SVG

  • React Native

  • 前端
  • uniapp
HiuZing
2022-08-02

uniapp-支付(支付宝和微信)

// 支付
submit() {
	uni.request({
		url: `${config.URL}Checkout/orders`, //請求接口
		header: {
			'Access-Token': uni.getStorageSync('userinfo').token || '',
			// 'storeId':uni.getStorageSync('userinfo').userId || '',
			'platform': 'H5'
		},
		method: 'POST',
		data: {
			goodsid: this.detailList.goods_id,
			userid: uni.getStorageSync('userinfo').userId,
			isBox: 0,
			pay_type: this.payDict[this.payIndex]
		},
		success: (res) => {

			if (res.data.status == 500) {
				return this.$showToast(res.data.message)
			}
            
			const newUrl = res.data

			// 假设支付类型为微信
			if (this.payIndex == 0 || this.payIndex == 3) {
				// #ifdef H5
				location.href = newUrl
				// #endif
				// #ifdef APP-PLUS
				const platform = uni.getSystemInfoSync().platform
				const webview = plus.webview.create(); // 创建一个webview

				switch (platform) {
					case 'android':
						plus.webview.open(newUrl);
						break;
					case 'ios':
						plus.webview.open(newUrl);
						// webview.loadURL(newUrl,{'Referer':'https://www.web3metadao.cn/'});
                        //解决ios支付完成后,打开safari浏览器的bug
						break;
					default:
						plus.webview.open(newUrl);
						// webview.loadURL(newUrl,{'Referer':'https://www.web3metadao.cn/'});
						break;
				}
				// #endif
				this.payType = false
			}

			// 如果支付类型为支付宝
			if (this.payIndex == 1 || this.payIndex == 4) {
				// 将接口返回的form表单显示到页面
				document.querySelector('body').innerHTML = newUrl;
				// 调用submit方法
				document.forms[0].submit()
			}

			// 支付类型为积分
			this.getList()
		},

	});
},

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
上次更新: 2024/08/14, 04:14:33
uniapp-上传图片
uniapp-复制(设置系统剪贴板)

← uniapp-上传图片 uniapp-复制(设置系统剪贴板)→

最近更新
01
React Native 使用SVG
08-13
02
Docker基础命令
08-04
03
算数逻辑单元
07-30
更多文章>
Theme by Vdoing | Copyright © 2021-2024 WeiXiaojing | 友情链接
  • 跟随系统
  • 浅色模式
  • 深色模式
  • 阅读模式