微信h5支付

export function chooseWXPay(params: wx.ChooseWXPayConfig) {
    return new Promise<{
        status: ‘success‘ | ‘error‘ | ‘cancel‘;
        result?: string;
        message?: string;
        [key: string]: any;
    }>((resolve, reject) => {
        if (!store.state.jssdk || !store.state.jssdk.jssdkReady) {
            Toast(`微信支付加载失败`);
            return;
        }

        wx.chooseWXPay({
            timestamp: params.timestamp,
            nonceStr: params.nonceStr,
            package: params.package,
            signType: params.signType,
            paySign: params.paySign,
            // 支付成功后的回调函数
            success: (res: WeixinJSSDKCallbackParams) => {
                if (res.errMsg === ‘chooseWXPay:ok‘) {
                    resolve({ // 支付成功
                        status: ‘success‘,
                    });
                } else if (res.errMsg === ‘chooseWXPay:cancel‘) {
                    resolve({ // 支付成功
                        status: ‘cancel‘,
                    });
                } else {
                    resolve({
                        status: ‘error‘,
                        result: res.errMsg,
                        message: res.errMsg,
                    });
                }
            },
            cancel: () => {
                resolve({ // 支付成功
                    status: ‘cancel‘,
                });
            },
            fail: (res: WeixinJSSDKCallbackParams) => {
                resolve({
                    status: ‘error‘,
                    result: res.errMsg,
                    message: res.errMsg,
                });
            },
        });
    });
}

微信h5支付

上一篇:atoi atol strtod strtol strtoul _gcvt


下一篇:微信小程序js里的this代表什么