收藏
回答

为什么调用微信自带的OCR接口会显示wx.ocr不存在,请升级客户端?

/*下面一段代码实现的是调用微信OCR接口并实现对图片文字的提取功能,
 但是一定会判定(!wx.ocr)然后结束程序,不知道为什么
*/
startProcess() {
    if (!this.data.imgPath || this.data.errorMsg) return;
    
    if (!wx.ocr) {
      wx.showToast({
        title: '当前微信版本不支持文字识别',
        icon: 'none',
        duration: 3000
      });
      console.error('wx.ocr 不存在,请升级微信客户端');
      return;
    }
    
    this.setData({ isProcessing: true });
    
    wx.ocr({
      type: 'ocrGeneral',
      filePath: this.data.imgPath,
      success: (res) => {
        // 处理结果
        const text = res.words_result.map(item => item.words).join('\n');
        this.setData({
          isProcessing: false,
          showResult: true,
          recognizedText: text
        });
      },
      fail: (err) => {
        console.error('OCR 失败:', err);
        this.setData({ isProcessing: false });
        
        // 错误处理
        if (err.errMsg.includes('auth deny')) {
          wx.showModal({
            title: '权限申请',
            content: '需要文字识别权限以提取图片中的文字',
            success: (res) => {
              if (res.confirm) {
                wx.openSetting(); // 打开设置页让用户授权
              }
            }
          });
        } else if (err.errMsg.includes('no permission')) {
          wx.showToast({
            title: '无文字识别权限',
            icon: 'none'
          });
        }
      }
    });
  }


求求了,我真的很需要帮助

回答关注问题邀请回答
收藏

2 个回答

登录 后发表内容