【菜鸡记录】h5发起微信支付

h5发起微信支付需要下载微信的sdk,即jweixin。

第一步:下载jweixin-module。可以去官网下载。我参考了这位大佬的。vue中使用jweixin-module-CSDN博客

# jweixin-module

微信JS-SDK

## 安装

### NPM

```shell
npm install jweixin-module --save
```

### UMD

```http
https://unpkg.com/jweixin-module/out/index.js
```

## 使用

```js
var jweixin = require('jweixin-module')
jweixin.ready(function(){
    // TODO
});
```

## 完整API

>[微信JS-SDK说明文档](https://mp.weixin.qq.com/wiki?t=resource/res_main&id=mp1421141115)

第二步,引入(在script中引入)

// #ifdef H5
	const jweixin = require("jweixin-module")
	// #endif

第三步:调接口:

onConfirm() {
				let para = {};
				if (this.$isWechat()) {
					para = {
							pay_type: 2,
							car_no: this.itemdata.plateNumber
						},
						tradeCreate(para).then((res) => {
							if (res.code == 200) {
								this.payInfo = res.data,
									this.configData.appId = res.data.appId,
									this.configData.timestamp = res.data.timeStamp,
									this.configData.nonceStr = res.data.nonceStr,
									this.configData.signature = res.data.paySign,
									this.configData.package = res.data.packageValue,
									this.configData.sign = res.data.signType,
									setTimeout(() => {
										this.wechatPay(this.configData)
									}, 40)

							} else if (res.code == 9) {
								this.$toast('优惠券抵扣成功')
							} else {
								this.$toast(res.msg)
							}
						})
				} else if (this.$isZfb()) {
					para = {
						pay_type: 1,
						car_no: this.str
					};
					tradeCreate(para).then((res) => {
						if (res.code == 200) {
							this.tradePay(res.data)
						} else if (res.code == 9) {
							this.$toast('优惠券抵扣成功')

						} else {
							this.$toast(res.msg)
						}
					})
				}
			},

第四步:调微信支付api

wechatPay(config) {
				let $this = this
				// #ifdef H5
				jweixin.config({
					debug: false,
					appId: config.appId,
					timestamp: config.timestamp,
					nonceStr: config.nonceStr,
					signatrue: config.signature,
					jsApiList: ['chooseWXPay']
				})
				jweixin.ready(function() {
					jweixin.chooseWXPay({
						timestamp: config
							.timestamp, // 支付签名时间戳,注意微信jssdk中的所有使用timestamp字段均为小写。但最新版的支付后台生成签名使用的timeStamp字段名需大写其中的S字符
						nonceStr: config.nonceStr, // 支付签名随机串,不长于 32 位
						package: config.package, // 统一支付接口返回的prepay_id参数值,提交格式如:prepay_id=***)
						signType: config.sign, // 签名方式,默认为'SHA1',使用新版支付需传入'MD5'
						paySign: config.signature, // 支付签名
						success: function(response) {
							
						
						},
						cancel: function(re) {
							// $this.$vux.toast.show({
							// 	text: '支付已取消',
							// 	type: 'cancel'
							// })
						}
					})
				})
				// #endif
			},

第五步:小票页面(由于“点金计划”,导致没有配置该要求的项目,商户支付完成后直接返回微信,而不是一直在应用内。)。

 服务商平台公告

  • 1
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

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

余额充值