orcrist-wechat
Version:
for Orcrist Wechat sdk
29 lines (25 loc) • 935 B
text/typescript
/**
* 跳转支付 API
* @param params:{ payload, success, error } payload = {timestamp, nonceStr, prepayId, paySign}
*/
export async function pay({
payload,
success = () => {},
error = (res) => {},
}) {
const w: any = window;
const { timestamp, nonceStr, prepayId, paySign } = payload;
w.wx.chooseWXPay({
timestamp, // 支付签名时间戳,注意微信jssdk中的所有使用timestamp字段均为小写。但最新版的支付后台生成签名使用的timeStamp字段名需大写其中的S字符
nonceStr, // 支付签名随机串,不长于 32 位
package: prepayId, // 统一支付接口返回的prepay_id参数值,提交格式如:prepay_id=\*\*\*)
signType: "MD5", // 签名方式,默认为'SHA1',使用新版支付需传入'MD5'
paySign, // 支付签名
success,
fail: (res) => {
error(res);
throw new Error(res.message);
},
});
}
export default pay;