uni-app 部分手机无法调起微信支付
uni-app 部分手机无法调起微信支付
开发环境 | 版本号 | 项目创建方式 |
---|---|---|
Mac | 3.4.7 | HBuilderX |
产品分类:uniapp/App
PC开发环境操作系统:Mac
PC开发环境操作系统版本号:3.4.7
HBuilderX类型:正式
HBuilderX版本号:3.4.7
手机系统:Android
手机系统版本号:Android 11
手机厂商:华为
手机机型:荣耀 X20 SE
页面类型:vue
vue版本:vue2
打包方式:云端
App下载地址或H5网址:https://7463-tcb-kjg1wz7iyqr1jv837c0e5-d34743-1309641310.tcb.qcloud.la/__UNI__134AAF7_0512124245.apk
示例代码:
uni.showLoading({
title: '请求数据中',
mask: false
});
var url = '';
var data;
var type;
if (this.Index == 1) {
data = {
body:this.accountId+'',
subject: "账户充值",
totalAmount: this.money,
passbackParams: "000000000",
productCode: "000000001"
}
url = '/alipay/appPay';
type = "alipay"
}
if (this.Index == 2) {
url = "/wxpay/webPay"
data = {
total_fee: this.money,
body: "账户充值",
attach: this.accountId+''
}
type = "wxpay"
}
uni.request({
url: helper.server_url + url,
method: 'POST',
data: data,
header: {
'content-type': 'application/x-www-form-urlencoded', //自定义请求头信息
'token': this.$token.token.valuetoken
},
success: res => {
if (res.data.code == 0) {
console.log("type:"+type);
uni.requestPayment({
provider: type,
orderInfo:res.data.data, //微信、支付宝订单数据
success: function(res) {
uni.showToast({
title: '支付成功',
icon: "none"
});
console.log('success:' + JSON.stringify(res));
},
fail: function(err) {
console.log('fail:' + JSON.stringify(err));
uni.showToast({
title: '支付失败,如有问题请及时联系管理员',
icon:"none"
});
}
});
} else {
uni.showToast({
title: '发起支付失败,'+res.data.message,
icon: "none"
});
}
},
fail: () => {
uni.showToast({
title: '获取支付数据失败',
icon: "none"
});
},
complete: () => {
uni.hideLoading()
}
});
操作步骤:
- app 调用微信充值
预期结果:
- 所有类型的手机都可以调起微信支付
实际结果:
- 部分手机无法调起微信支付,部分手机可以
bug描述:
2022-05-12 12:49:02.841 977-977/? I/AGPService: aps-info: visible pkgName 0 - uni.UNI134AAF7
2022-05-12 12:49:03.440 982-1718/? D/dubaid: [CpuAppStats.cpp] FindUidEntry# Uid(10032) has not package, maybe it’s already uninstalled
2022-05-12 12:49:04.193 3930-11756/? W/HONOR_AWARENESS_AppLifeFence: key : cd00f570-c759-4731-bc33-cf45c9262c2b,not contained in white list : [com.tencent.mm/com.tencent.mm.plugin.remittance.ui.RemittanceBusiResultUI, com.tencent.mm/com.tencent.mm.framework.app.UIPageFragmentActivity, com.tencent.mm/com.tencent.mm.plugin.wallet_core.ui.WalletOrderInfoNewUI, com.eg.android.AlipayGphone/com.alipay.android.msp.ui.views.MspContainerActivity, com.eg.android.AlipayGphone/com.alipay.android.msp.ui.views.MspUniRenderActivity]
2022-05-12 12:49:04.193 1541-1575/? I/StatusBarDisable: setFlags what=0 which=1 pkg=Window{86155d u0 uni.UNI134AAF7/io.dcloud.PandoraEntryActivity}
2022-05-12 12:49:04.199 2144-2765/? D/ScenarioService: new above launcher front pkgs: [com.android.packageinstaller, uni.UNI134AAF7, com.huawei.android.internal.app, com.tencent.mm, uni.UNI134AAF7, com.huawei.android.internal.app, com.tencent.mm]
2022-05-12 12:49:04.224 9768-9768/? E/Instrumentation: Uninitialized ActivityThread, likely app-created Instrumentation, disabling AppComponentFactory
java.lang.Throwable
at android.app.Instrumentation.getFactory(Instrumentation.java:1276)
at android.app.Instrumentation.newActivity(Instrumentation.java:1267)
at com.tencent.mm.splash.l.newActivity(SourceFile:64)
at com.tencent.mm.pluginguard.ActivityHookInstrumentation.newActivity(SourceFile:149)
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:3982)
at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:4295)
at android.app.servertransaction.LaunchActivityItem.execute(LaunchActivityItem.java:93)
at android.app.servertransaction.TransactionExecutor.executeCallbacks(TransactionExecutor.java:149)
at android.app.servertransaction.TransactionExecutor.execute(TransactionExecutor.java:103)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:2532)
at android.os.Handler.dispatchMessage(Handler.java:109)
at android.os.Looper.loop(Looper.java:228)
at android.app.ActivityThread.main(ActivityThread.java:8731)
at java.lang.reflect.Method.invoke(Native Method)
at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:613)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1085)
2022-05-12 12:49:04.280 1541-2233/? I/WindowManager: Changing focus from null to Window{86155d u0 uni.UNI134AAF7/io.dcloud.PandoraEntryActivity}mode 3 displayId=0
2022-05-12 12:49:04.281 1541-2233/? V/HwPhoneWindowManager: updateSystemUiColorLw window=Window{86155d u0 uni.UNI134AAF7/io.dcloud.PandoraEntryActivity},EmuiStyle=0,StatusBarColor=0x0,NavigationBarColor=0xfffcfcfc, mForceNotchStatusBar=false
2022-05-12 12:49:04.284 1541-1575/? I/StatusBarDisable: setFlags what=0 which=1 pkg=Window{86155d u0 uni.UNI134AAF7/io.dcloud.PandoraEntryActivity}
2022-05-12 12:49:04.304 1541-2233/? I/InputDispatcher: Focus entered window: Window{86155d u0 uni.UNI134AAF7/io.dcloud.PandoraEntryActivity} in display 0
2022-05-12 12:49:04.311 1541-2233/? I/WindowManager: Changing focus from Window{86155d u0 uni.UNI134AAF7/io.dcloud.PandoraEntryActivity} to nullmode 0 displayId=0
2022-05-12 12:49:04.316 2144-2765/? I/ScenarioService: refresh visibleApp:[com.tencent.mm, uni.UNI134AAF7]
2022-05-12 12:49:04.317 2144-2765/? I/PGServer: report state:14 event type:1 pid:-1 uid:-1 pkg:com.tencent.mm#uni.UNI134AAF7 to pid: 2144
2022-05-12 12:49:04.317 9768-9768/? E/Instrumentation: Uninitialized ActivityThread, likely app-created Instrumentation, disabling AppComponentFactory
java.lang.Throwable
at android.app.Instrumentation.getFactory(Instrumentation.java:1276)
at android.app.Instrumentation.newActivity(Instrumentation.java:1267)
at com.tencent.mm.splash.l.newActivity(SourceFile:64)
at com.tencent.mm.pluginguard.ActivityHookInstrumentation.newActivity(SourceFile:149)
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:3982)
at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:4295)
at android.app.servertransaction.LaunchActivityItem.execute(LaunchActivityItem.java:93)
at android.app.servertransaction.TransactionExecutor.executeCallbacks(TransactionExecutor.java:149)
at android.app.servertransaction.TransactionExecutor.execute(TransactionExecutor.java:103)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:2532)
at android.os.Handler.dispatchMessage(Handler.java:109)
at android.os.Looper.loop(Looper.java:228)
at android.app.ActivityThread.main(ActivityThread.java:8731)
at java.lang.reflect.Method.invoke(Native Method)
at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:613)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1085)
2022-05-12 12:49:04.317 977-977/? I/AGPService: aps-info: visible pkgName 0 - uni.UNI134AAF7
2022-05-12 12:49:04.337 1541-5048/? I/InputDispatcher: Focus left window: Window{86155d u0 uni.UNI134AAF7/io.dcloud.PandoraEntryActivity} in display 0
2022-05-12 12:49:04.359 1541-1671/? I/SWAP_SCENE: Entering notifySceneData notifySceneData. EventType:SWITCH_TO_FOREGROUND para:uni.UNI134AAF7
2022-05-12 12:49:04.359 1541-1671/? I/ActivityTaskManager: START u0 {flg=0x10000000 hwFlg=0x110 cmp=uni.UNI134AAF7/.wxapi.WXPayEntryActivity (has extras)} from uid 10188
2022-05-12 12:49:04.360 1541-1671/? I/ActivityTaskManager: ActivityRecord info: ActivityInfo{d46596d uni.UNI134AAF7.wxapi.WXPayEntryActivity}
2022-05-12 12:49:04.360 1541-1671/? D/ActivityTaskManager: TaskLaunchParamsModifier:task=null activity=ActivityRecord{87c5633 u0 uni.UNI134AAF7/.wxapi.WXPayEntryActivity display-from-caller=0 task-display-area=DefaultTaskDisplayArea@108011477 display-area-windowing-mode=1
2022-05-12 12:49:04.360 1541-1671/? D/ActivityTaskManager: TaskLaunchParamsModifier:task=Task{6eeb463 #1426 visible=false type=standard mode=fullscreen translucent=true A=10193:uni.UNI134AAF7 U=0 StackId=1426 sz=1} activity=ActivityRecord{87c5633 u0 uni.UNI134AAF7/.wxapi.WXPayEntryActivity t-1} display-from-task=0 task-display-area=DefaultTaskDisplayArea@108011477 display-area-windowing-mode=1 non-freeform-display
2022-05-12 12:49:04.361 1541-1671/? I/WindowManager: Changing focus from null to Window{86155d u0 uni.UNI134AAF7/io.dcloud.PandoraEntryActivity}mode 3 displayId=0
2022-05-12 12:49:04.362 1541-1671/? W/HwActivityTaskManagerServiceEx: appSwitch from: com.tencent.mm to: uni.UNI134AAF7
2022-05-12 12:49:04.363 1541-1671/? I/WindowManager: addWindowToken: displayid:0 binder:Token{d8179a2 ActivityRecord{87c5633 u0 uni.UNI134AAF7/.wxapi.WXPayEntryActivity t-1}} token:ActivityRecord{87c5633 u0 uni.UNI134AAF7/.wxapi.WXPayEntryActivity t-1}
2022-05-12 12:49:04.364 1541-1586/? D/HwGameAssistantController: UPDATE: mCurFgPkg=uni.UNI134AAF7, mCurFgPid=10631, mIsCurGame=false
2022-05-12 12:49:04.364 3930-4033/? I/HONOR_AWARENESS_AmsRegister: app switch from : com.tencent.mm to uni.UNI134AAF7 as ComponentInfo{uni.UNI134AAF7/io.dcloud.PandoraEntryActivity} label:
2022-05-12 12:49:04.364 3930-4033/? I/HONOR_AWARENESS_AppLifeCycleAbility: app exit : com.tencent.mm act : ComponentInfo{uni.UNI134AAF7/io.dcloud.PandoraEntryActivity} label :
2022-05-12 12:49:04.364 1541-1585/? I/SWAP_SCENE: Entering notifySceneData notifySceneData. EventType:APP_SWITCH_TO para:uni.UNI134AAF7
更多关于uni-app 部分手机无法调起微信支付的实战教程也可以访问 https://www.itying.com/category-93-b0.html
你好,我这边在小米10s miui13安装你的apk ,选择充值是可以拉起微信支付的,能否确保您不同手机的微信版本是一致的?
更多关于uni-app 部分手机无法调起微信支付的实战教程也可以访问 https://www.itying.com/category-93-b0.html
微信版本都是8.0.22, 同样的环境,换了个能充值的手机,自定义基座调试,一开始充值成功。多冲几次又报上面相同的错误,我们这个应用已经上线两年了,最近几个月客户抱怨部分手机微信充值调不起来。是不是新版本的微信兼容性问题呢?另外,苹果用户一直没这个问题。
回复 cmdszh: 你看一下fail的时候error中的code是不是 -1 可能的原因:签名错误、未注册APPID、项目设置APPID不正确、注册的APPID与设置的不匹配、其他异常原因等
回复 DCloud_Android_THB: fail:{“errMsg”:“requestPayment:fail [payment微信:-1]General errors”,“errCode”:-100,“code”:-100}
回复 cmdszh: 我怀疑后台返回的数据有点问题,我这边用你的app继第一次支付成功后,后面几次尝试都是失败,方便校验一下orderInfo的数据正确性吗?
回复 DCloud_Android_THB: 用双开的微信,第二个微信号支付,每次都成功。IOS 也都是每次成功。所以 orderInfo没有问题。
回复 DCloud_Android_THB: orderInfo用“微信支付接口签名校验工具”校验证过了,没有问题。
在 uni-app
中调用微信支付时,部分手机无法调起微信支付的问题可能由多种原因引起。以下是一些常见的原因及解决方法:
1. 微信版本问题
- 原因:部分手机上的微信版本过低,不支持最新的支付接口。
- 解决方法:提示用户更新微信到最新版本。
2. 支付参数问题
- 原因:支付参数(如
appId
、timeStamp
、nonceStr
、package
、signType
、paySign
等)不正确或缺失。 - 解决方法:
- 确保从后端获取的支付参数完整且正确。
- 检查
package
参数是否以prepay_id=
开头。 - 检查
signType
是否为MD5
或HMAC-SHA256
。 - 确保
paySign
的生成规则正确。
3. 签名问题
- 原因:支付签名(
paySign
)生成错误,导致微信无法验证请求的合法性。 - 解决方法:
- 检查签名算法是否正确。
- 确保参与签名的参数按照微信官方文档的顺序排列。
- 使用微信提供的签名校验工具验证签名是否正确。
4. 网络问题
- 原因:部分手机网络环境较差,导致支付请求无法正常发送。
- 解决方法:
- 提示用户检查网络连接。
- 在代码中加入重试机制。
5. 微信支付权限问题
- 原因:部分手机可能禁用了微信的支付权限。
- 解决方法:
- 提示用户检查微信的支付权限是否开启。
- 引导用户到手机设置中开启微信的支付权限。
6. uni-app 配置问题
- 原因:
uni-app
的支付模块配置不正确。 - 解决方法:
- 确保在
manifest.json
中正确配置了微信支付相关的AppID
和Universal Links
。 - 检查是否在
pages.json
中正确配置了支付页面的路由。
- 确保在
7. 微信支付 SDK 问题
- 原因:部分手机上的微信支付 SDK 可能存在兼容性问题。
- 解决方法:
- 确保
uni-app
使用的是最新版本。 - 尝试在
uni-app
中使用原生插件调用微信支付。
- 确保
8. 调试与日志
- 原因:无法确定具体问题。
- 解决方法:
- 在代码中加入日志,记录支付调用的每个步骤。
- 使用微信开发者工具或真机调试功能,查看具体的错误信息。
示例代码
以下是一个调用微信支付的示例代码:
uni.requestPayment({
provider: 'wxpay',
orderInfo: {
appId: 'wx1234567890abcdef', // 微信 AppID
timeStamp: '1630000000', // 时间戳
nonceStr: '5K8264ILTKCH16CQ2502SI8ZNMTM67VS', // 随机字符串
package: 'prepay_id=wx201410272009395522657a690389285100', // 预支付 ID
signType: 'MD5', // 签名类型
paySign: 'C380BEC2BFD727A4B6845133519F3AD6' // 签名
},
success(res) {
console.log('支付成功', res);
},
fail(err) {
console.log('支付失败', err);
}
});