微信支付 vue demo 完整流程

老闆要求寫一個微信公衆號頁面,採用uni-app框架,不多介紹,自己去搜搜

以前沒有仔細做過微信支付,現在終於把整個流程順下來了,特此寫一個文檔,也希望對其他人有點幫助

首先:

npm install jweixin-module --save
//再具體的頁面引入
var jweixin = require('jweixin-module');//這是uni-app封裝好的微信js-sdk文件

其次config一下,請求後臺數據。數據簽名算法,看微信文檔,說一下,包括時間戳都要用於簽名

wxConfig(data) {
	jweixin.config({
		debug: true, //測試開一下
		appId: this.payData.param.appId, // 必填,公衆號的唯一標識
		timestamp: this.payData.param.timeStamp, // 必填,生成簽名的時間戳
		nonceStr: this.payData.param.nonceStr, // 必填,生成簽名的隨機串
		signature: this.payData.param.sign, // 必填,簽名
		jsApiList: ['chooseWXPay'] // 必填,需要使用的JS接口列表
	});
	this.beforePay();
},

然後,

beforePay() {
	let self = this;
	jweixin.ready(function() {
		jweixin.checkJsApi({
			jsApiList: ['chooseWXPay'],
			success: function(res) {
				self.choosePay();
		    }
		});
	});
	jweixin.error(function(res) {
		console.log(res, 'error');
	});
},
choosePay() {
    let self = this
	jweixin.chooseWXPay({
		timestamp: this.payData.param.timeStamp,
		nonceStr: this.payData.param.nonceStr,
		package: this.payData.param.package,
		signType: this.payData.param.signType,
		paySign: this.payData.param.sign,
		success: function(res) {
			self.userRechargeInfo()
		}
	});
},

//self.userRechargeInfo() 函數就是支付之後查詢狀態的函數,剩下的隨便你造

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章