微信小程式 免密代扣
阿新 • • 發佈:2018-12-12
1.定義好pay.wxml
<view class='btn_box'> <navigator target='miniProgram' extra-data='{{extraData}}' path='pages/index/index' app-id='wxbd687630cd02ce1d' hover-class="none"> <view class='btn_btn nor_linear_bg'>開通免密支付</view> </navigator> </view>
2.設定好pay.js引數處理
var util = require('../../utils/util.js'); const app = getApp(); Page({ onShow: function (options) { console.log(options,'pay.js start'); }, data:{ extraData:'', localCity:'' }, onLoad: function() { this.setData({ extraData:util.getextraData(), localCity:wx.getStorageSync(util.key.cityName) || app.globalData.baseInfo.cityName }) } })
繫結免密簽證引數設定:
function getextraData() { const app = getApp(); var extraDataValue = { appid: app.globalData.baseInfo.appId, mch_id: app.globalData.baseInfo.mchId, sub_mch_id: app.globalData.baseInfo.subMchId, notify_url: app.globalData.baseInfo.notifyUrl, contract_code: config.contractCode, contract_display_account: app.globalData.baseInfo.contractDisplayAccount, plan_id: app.globalData.baseInfo.planId, request_serial: config.requestSerial, timestamp: config.timestamp, sub_appid: app.globalData.baseInfo.subAppId }; var extraDataSortValue = getSort(extraDataValue); var signValue = getSign(extraDataSortValue, app.globalData.baseInfo.appSecret); extraDataValue['sign'] = signValue; log(TAG, "signSign=[" + signValue + "]length=" + String(signValue).length); return extraDataValue; }
例如:
3.app.js中 處理繫結後返回值
onShow: function (options) {
let that = this;
var bindStatus = wx.getStorageSync(util.key.bindStatus) || 0;
if (options.scene == 1038) {
var errorCode = options.referrerInfo && options.referrerInfo.extraData && options.referrerInfo.extraData.return_code ? options.referrerInfo.extraData.return_code:'';
if (errorCode == 'SUCCESS') {
var appid = options.referrerInfo.appId;
var contractId = options.referrerInfo.extraData.contract_id;
console.log("簽約成功");
that.globalData.baseInfo.appid = appid;
that.globalData.baseInfo.contractId = contractId;
that.globalData.baseInfo.contractIds = contractId;
that.globalData.baseInfo.bindStatus = 1;
wx.setStorageSync(util.key.bindStatus, 1);
//add by wupeng for jump scan
//認證繫結後通過navigateBack跳轉到首頁scan可以直接退出
var pagelist = getCurrentPages();
var len = pagelist.length;
var init = 0;
var index = 0;
for (var i = 0; i < len; i++) {
if (pagelist[i].route.indexOf("scan/scan") >= 0) {//看路由裡面是否有首頁
init = 1;
index = i;
}
}
if (init == 1) {
wx.navigateBack({
delta: len - index - 1
});
} else {
wx.reLaunch({
url: "../scan/scan"//這個是預設的單頁
});
}
//end add by wupeng 20180921
} else {
var msg = options.referrerInfo.extraData.return_msg;
wx.showModal({
title: errorCode,
content: msg,
});
console.log(TAG + ':簽約失敗');
}
}
// }
},