systhinker
systhinker
  • 发布:2024-06-19 11:36
  • 更新:2024-06-19 12:02
  • 阅读:139

【报Bug】uni-pay 微信小程序的微信支付问题

分类:uniCloud

产品分类: uniCloud/App

示例代码:

config.js

// 微信支付相关  
    "wxpay": {  
        "enable": true, // 是否启用微信支付  
        // 微信 - 小程序支付  
        "mp": {  
            "appId": "wx65---------------------", // 小程序的appid  
            "secret": "5--------------------------------", // 小程序的secret  
            "mchId": "1------------------", // 商户id  
            "key": "Q-----------------------------", // v2的api key  
            "pfx": fs.readFileSync(__dirname + '/wxpay/apiclient_cert.p12'), // v2需要用到的证书  
            "v3Key": "Q-----------------------------", // v3的api key  
            "appCertPath": path.join(__dirname, 'wxpay/apiclient_cert.pem'), // v3需要用到的证书  
            "appPrivateKeyPath": path.join(__dirname, 'wxpay/apiclient_key.pem'), // v3需要用到的证书  
            "version": 2, // 启用支付的版本 2代表v2版本 3 代表v3版本  
        },  

操作步骤:

完全按uni-pay2文档配置示例程序,点击“打开收银台”或者“直接支付”就会弹出报错提示。
查了云函数uni-pay-co的日志,除了入参,后面都是报错:

 [uni-pay-co/ac1cc30-------------隐藏/331ms/ERROR] data:  { provider: 'wxpay',  
  total_fee: 1,  
  user_id: undefined,  
  openid: 'om-----------------------------隐藏',  
  order_no: 'test1718718280579',  
  out_trade_no: 'test1718718280579-1',  
  description: '测试订单',  
  type: 'test',  
  qr_code: undefined,  
  custom: { a: 'a', b: 1 },  
  other: undefined,  
  clientInfo:   
   { scene: 1001,  
     batteryLevel: 100,  
     benchmarkLevel: -1,  
     memorySize: 2048,  
     safeArea:   
      { top: 47,  
        left: 0,  
        right: 390,  
        bottom: 810,  
        width: 390,  
        height: 763 },  
     screenWidth: 390,  
     screenHeight: 844,  
     screenTop: 91,  
     windowWidth: 390,  
     windowHeight: 753,  
     statusBarHeight: 47,  
     enableDebug: false,  
     fontSizeScaleFactor: 0.96,  
     mode: 'default',  
     bluetoothEnabled: true,  
     locationEnabled: true,  
     wifiEnabled: true,  
     locationReducedAccuracy: true,  
     albumAuthorized: true,  
     bluetoothAuthorized: true,  
     cameraAuthorized: true,  
     locationAuthorized: true,  
     microphoneAuthorized: true,  
     notificationAuthorized: true,  
     notificationAlertAuthorized: true,  
     notificationBadgeAuthorized: true,  
     notificationSoundAuthorized: true,  
     phoneCalendarAuthorized: true,  
     deviceOrientation: 'portrait',  
     devicePixelRatio: 3,  
     deviceId: '17187051061335100024',  
     safeAreaInsets: { top: 47, left: 0, right: 0, bottom: 34 },  
     appId: '__UNI__3802FC5',  
     appName: 'uni-pay示例1',  
     appVersion: '1.0.0',  
     appVersionCode: '100',  
     appLanguage: 'zh-Hans',  
     uniCompileVersion: '4.15',  
     uniRuntimeVersion: '4.15',  
     uniPlatform: 'mp-weixin',  
     deviceBrand: 'devtools',  
     deviceModel: 'iPhone 12/13 (Pro)',  
     deviceType: 'phone',  
     osName: 'ios',  
     osVersion: '10.0.1',  
     hostVersion: '8.0.5',  
     hostLanguage: 'zh-CN',  
     hostName: 'WeChat',  
     hostSDKVersion: '3.4.7',  
     hostFontSizeSetting: 16,  
     windowTop: 0,  
     windowBottom: 0,  
     locale: 'zh-Hans',  
     secretType: 'none',  
     os: 'ios',  
     clientIP: '1-----------------------------隐藏',  
     userAgent: 'Mozilla/5.0 (iPhone; CPU iPhone OS 15_0 like Mac OS X) AppleWebKit/605.1.15 (KHTML, like Gecko) Version/15.0 Mobile/15E148 Safari/604.1 wechatdevtools/1.06.2404301 MicroMessenger/8.0.5 webview/',  
     platform: 'mp-weixin',  
     source: 'client',  
     requestId: 'ac1c-----------------------------隐藏' },  
  cloudInfo:   
   { provider: 'aliyun',  
     spaceId: 'mp-------------------------------------------------------------隐藏',  
     useOldSpaceId: false,  
     functionName: 'uni-pay-co',  
     functionType: 'cloudobject' },  
  wxpay_virtual: undefined }  

[uni-pay-co/ac1cc30-------------隐藏/332ms/ERROR] getOrderInfoParam:  { openid: 'o-------------隐藏',  
  body: '测试订单',  
  outTradeNo: 'test1718718280579-1',  
  totalFee: 1,  
  notifyUrl: 'https://fc-mp--------------隐藏.next.bspapp.com/uni-pay-co/payNotify/wxpay-mp',  
  tradeType: 'JSAPI' }  

[uni-pay-co/ac1cc30-------------隐藏/332ms/ERROR] err:  Error: 签名错误,请检查后再试  
    at t.default._parse (/tmp/function/@common_modules/uni-pay/index.js:1:44373)  
    at t.default._requestWxpay (/tmp/function/@common_modules/uni-pay/index.js:1:45950)  
    at <anonymous>  
    at process._tickCallback (internal/process/next_tick.js:189:7)  
[uni-pay-co/ac1cc30-------------隐藏/333ms/ERROR] errMsg:  签名错误,请检查后再试  
请求响应状态: success

预期结果:

成功支付

实际结果:

失败,报53001错误,详见bug描述

bug描述:

准备在微信小程序里面加入微信支付功能。我在插件市场下载uni-pay的示例代码,按照uni-pay2文档配置示例程序,按照要求填写了密钥和证书,一步一步按说明的弄,怎么都调不通,总是报错,试了V2、V3都不行,V2报错是“53001:签名错误,请检查后再试”,V3报错是“53001:Unsupported state or unable to authentic ate data”,请问这咋回事?

微信支付平台生成的支付密钥和证书在其它微信公众号上能够正常支付,商户号也是对的,appid和secret都没错,微信小程序后台和微信支付后台也按要求配好了,为啥这么诡异?听说uni-pay2使用的密钥格式是PKCS8格式,uni-pay2文档上是PKCS12格式,是这个原因吗?怎么从PKCS12格式转换到PKCS8格式呢?

2024-06-19 11:36 负责人:无 分享
已邀请:
DCloud_uniCloud_VK

DCloud_uniCloud_VK

按照这个文档重新生成下密钥试试
文档

  • systhinker (作者)

    就是按这个文档来的,只是没有重新生成密钥,因为还有其他小程序和公众号在用,怕造成影响。

    这个文档里面写的是P12,对吗?

    另外,这个文档有些老了,现在微信支付商户后台显示的跟截图已经不一样了。

    2024-06-19 12:49

  • systhinker (作者)

    重新生成密钥的作用是什么?能够从我发的云函数日志推测出问题所在吗?

    2024-06-19 14:27

  • DCloud_uniCloud_VK

    回复 h***@qq.com: 你截图的微信支付v2的报的错误是签名错误,那就是密钥不对或者密钥和mchId不匹配

    2024-06-19 14:31

  • DCloud_uniCloud_VK

    建议重新上传下 uni-config-center 公共模块试试

    2024-06-19 14:32

  • systhinker (作者)

    回复 DCloud_uniCloud_VK: 重传uni-config-center 试过了,问题还是一样的。密钥和mchId不匹配的问题应该不存在,因为其他小程序也在用这个商户号和密钥,支付正常。而且我也在电脑上导入f12证书,用商户号可以解密,说明两者是匹配的

    2024-06-19 15:26

  • DCloud_uniCloud_VK

    回复 h***@qq.com: 私发下你的空间id

    2024-06-19 16:00

  • systhinker (作者)

    回复 DCloud_uniCloud_VK: 已发,谢谢大佬!

    2024-06-19 17:36

  • systhinker (作者)

    回复 DCloud_uniCloud_VK: 搞定了,原来确实是密钥不对,截图微信识别错了,把0识别成O, 谢谢啦

    2024-06-20 00:12

要回复问题请先登录注册