大家都知道 小程序,app,网站 申请 微信支付,那么快应用呢?
在快应用中接入微信支付需要特殊处理,因为快应用本身无法直接调用微信支付SDK。以下是完整的接入方案和技术实现步骤:
快应用需使用 微信H5支付 方式(非APP支付):
youyacao.cn
)在商户平台 → 账户中心 → API安全 → 支付域名:
https://youyacao.cn
{
"features": [
{ "name": "system.pay" }
],
"config": {
"wechatPay": {
"appid": "xxxx", // 微信公众平台APPID
"h5Domain": "https://youyacao.cn" // 与商户平台配置一致
}
}
}
// 步骤1:获取支付参数(需后端生成)
async function getWechatPayParams(orderId) {
const res = await this.$http.post('/api/pay/wechat', {
order_id: orderId,
openid: this.userInfo.openid // 如果有用户体系
});
return res.data;
}
// 步骤2:调用支付
async function payWithWechat() {
try {
const params = await getWechatPayParams('ORDER123');
// 关键支付代码
const payment = require('@system.pay');
payment.pay({
orderInfo: JSON.stringify({
appid: params.appId, // 微信公众平台APPID
partnerid: params.mchId, // 商户号
prepayid: params.prepayId,
package: 'Sign=WXPay', // 固定值
noncestr: params.nonceStr,
timestamp: params.timeStamp,
sign: params.sign // 签名
}),
success: () => {
console.log('支付成功');
},
fail: (err) => {
console.error('支付失败', err);
}
});
} catch (e) {
console.error('支付异常', e);
}
}
function generateWechatPayParams($order) {
$params = [
'appId' => 'xxxxx', // 公众号APPID
'mchId' => 'xxxxx', // 商户号
'prepayId' => $order['prepay_id'], // 预支付ID
'nonceStr' => md5(uniqid()), // 随机字符串
'timeStamp' => (string)time(), // 时间戳
'package' => 'Sign=WXPay' // 固定值
];
// 生成签名
$signStr = "appId={$params['appId']}&nonceStr={$params['nonceStr']}".
"&package={$params['package']}&signType=MD5&timeStamp={$params['timeStamp']}";
$params['sign'] = strtoupper(md5($signStr . "&key=" . API_KEY));
return $params;
}
https://youyacao.cn/pay/*
错误码 | 原因 | 解决方案 |
---|---|---|
APPID_MCHID_NOT_MATCH | 商户号与APPID不匹配 | 确认公众号与商户号已绑定 |
NO_AUTH | 未开通H5支付权限 | 重新提交H5支付申请 |
INVALID_REQUEST | 签名错误 | 检查签名算法和密钥 |
# 获取沙箱密钥
curl -d "" "https://api.mch.weixin.qq.com/sandboxnew/pay/getsignkey"
按照以上步骤可实现快应用的微信支付接入,如遇审核问题,建议在申请材料中强调快应用是”基于手机厂商联盟标准的轻应用”。
原创声明:本文系作者授权腾讯云开发者社区发表,未经许可,不得转载。
如有侵权,请联系 cloudcommunity@tencent.com 删除。
原创声明:本文系作者授权腾讯云开发者社区发表,未经许可,不得转载。
如有侵权,请联系 cloudcommunity@tencent.com 删除。