uniapp开发H5等,公众号支付

首先需要先注册好绑定的公众号appid,这一步,我就不详细说了
H5页面使用微信支付,首先需要注册微信公众号,在设置与开发>公众号设置>功能设置中配置业务域名、JS接口安全域名、网页授权域名。支付功能页面需在此域名链接下的页面。

下面是直接的代码,需要下载好微信的JDK,然后直接复制就能用。

如果连这个都不会下载的话,私信我,我给你发安装包。

第一步:引入下载好的jdk

<script>
	import jweixin from "@/node_modules/jweixin-module"
	export default {
		data() {
			return {}
               }
     }
</script>

第二步:调接口直接用
 

wxPay(res){ //微信支付
				this.$http.post("xxxx", this.$Base64.encode(JSON.stringify(data))).then(res => {
						if (res.status == 1) {
							let response = res.result;
							jweixin.config({
								debug: false,
								appId: response.appId,
								timestamp: response.timeStamp,
								nonceStr: response.nonceStr,
								signature: response.signature,
								jsApiList: ['chooseWXPay']
							});
							jweixin.ready(function() {
								jweixin.chooseWXPay({
									timestamp: response.timeStamp,
									nonceStr: response.nonceStr,
									package: response.package,
									signType: response.signType,
									paySign: response.paySign,
									success: function() {
										this.payStatus = true
										// uni.navigateTo({
										//     url: `/pages/success/success?type=3&account=${response.account}&password=${response.password}`
										// });
										uni.showToast({
											title: '支付成功',
											icon: 'none'
										});
										uni.switchTab({
											url: '/pages/index/index.vue'
										})
									},
									cancel: function(res) {
										uni.showToast({
											title: '支付失败',
											icon: 'none'
										});
									},
									complete: function() {
										this.pay_flag = true;
									}
								});
							});
						} else {
							uni.showToast({
								title: "异常",
								icon: "error",
								duration: 2000
							})
						}
					});
			},

评论 2
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

黑云压城After

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值