小说小程序前端代码仓库(小程序)
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 

40 lines
1.2 KiB

// #ifdef H5
import jWeixin from './lib/jweixin-module.js'
// #endif
/**
* 调用微信支付 - Promise版本
* @param {Object} res - 支付参数对象,包含appId、timeStamp、nonceStr等必要信息
* @returns {Promise} 返回Promise对象,成功时resolve,失败时reject
*/
export function wxPay(res) {
return new Promise((resolve, reject) => {
// JSSDK配置成功后的回调
jWeixin.ready(function() {
// 调用微信支付接口
jWeixin.chooseWXPay({
appId: res.result.appId,
timestamp: res.result.timeStamp, // 支付签名时间戳
nonceStr: res.result.nonceStr, // 支付签名随机串
package: res.result.packageValue, // 统一支付接口返回的prepay_id参数值
signType: res.result.signType, // 签名类型,默认为MD5
paySign: res.result.paySign, // 支付签名
success: function(result) {
resolve(result);
},
fail: function(error) {
reject(error);
},
cancel: function(cancelResult) {
reject({ type: 'cancel', data: cancelResult });
}
});
});
// JSSDK配置失败处理
jWeixin.error(function(error) {
reject({ type: 'config_error', data: error });
});
});
}