新聞中心
img.scanQRCode
本接口應(yīng)在服務(wù)器端調(diào)用,詳細(xì)說明參見 服務(wù)端API。
本接口支持 云調(diào)用。需開發(fā)者工具版本 >= 1.02.1904090(最新 穩(wěn)定版下載)
wx-server-sdk >= 0.4.0
本接口提供基于小程序的條碼/二維碼識別的API。
調(diào)用方式:
- HTTPS 調(diào)用
- 云調(diào)用
HTTPS 調(diào)用
請求地址
POST https://api.weixin.qq.com/cv/img/qrcode?img_url=ENCODE_URL&access_token=ACCESS_TOCKEN
請求參數(shù)
| 屬性 | 類型 | 默認(rèn)值 | 必填 | 說明 |
|---|---|---|---|---|
| access_token | string | 是 | 接口調(diào)用憑證 | |
| img_url | string | 是 | 要檢測的圖片 url,傳這個則不用傳 img 參數(shù)。 | |
| img | FormData | 是 | form-data 中媒體文件標(biāo)識,有filename、filelength、content-type等信息,傳這個則不用傳 img_url。 |
返回值
Object
返回的 JSON 數(shù)據(jù)包
| 屬性 | 類型 | 說明 |
|---|---|---|
| errcode | string | 錯誤碼 |
| errmsg | string | 錯誤信息 |
使用說明
圖片說明 文件大小限制:小于2M
二維碼說明 支持條碼、二維碼、DataMatrix和PDF417的識別。 二維碼、DataMatrix會返回位置坐標(biāo),條碼和PDF417暫不返回位置坐標(biāo)。
請求數(shù)據(jù)示例
示例1:
curl https://api.weixin.qq.com/cv/img/qrcode?img_url=ENCODE_URL&access_token=ACCESS_TOCKEN
示例2:
curl -F '[email protected]' 'https://api.weixin.qq.com/cv/img/qrcode?access_token=ACCESS_TOCKEN'
返回數(shù)據(jù)示例
{
"errcode": 0,
"errmsg": "ok",
"code_results": [
{
"type_name": "QR_CODE",
"data": "http://www.qq.com",
"pos": {
"left_top": {
"x": 585,
"y": 378
},
"right_top": {
"x": 828,
"y": 378
},
"right_bottom": {
"x": 828,
"y": 618
},
"left_bottom": {
"x": 585,
"y": 618
}
}
},
{
"type_name": "QR_CODE",
"data": "https://mp.weixin.qq.com",
"pos": {
"left_top": {
"x": 185,
"y": 142
},
"right_top": {
"x": 396,
"y": 142
},
"right_bottom": {
"x": 396,
"y": 353
},
"left_bottom": {
"x": 185,
"y": 353
}
}
},
{
"type_name": "EAN_13",
"data": "5906789678957"
},
{
"type_name": "CODE_128",
"data": "50090500019191"
}
],
"img_size": {
"w": 1000,
"h": 900
}
}
云調(diào)用
云調(diào)用是小程序·云開發(fā)提供的在云函數(shù)中調(diào)用微信開放接口的能力,需要在云函數(shù)中通過 wx-server-sdk 使用。
接口方法
openapi.img.scanQRCode
需在 config.json 中配置 img.scanQRCode API 的權(quán)限, 詳情
請求參數(shù)
| 屬性 | 類型 | 默認(rèn)值 | 必填 | 說明 |
|---|---|---|---|---|
| imgUrl | string | 是 | 要檢測的圖片 url,傳這個則不用傳 img 參數(shù)。 | |
| img | FormData | 是 | form-data 中媒體文件標(biāo)識,有filename、filelength、content-type等信息,傳這個則不用傳 img_url。 |
img 的結(jié)構(gòu)
| 屬性 | 類型 | 默認(rèn)值 | 必填 | 說明 |
|---|---|---|---|---|
| contentType | string | 是 | 數(shù)據(jù)類型,傳入 MIME Type | |
| value | Buffer | 是 | 文件 Buffer |
返回值
Object
返回的 JSON 數(shù)據(jù)包
| 屬性 | 類型 | 說明 |
|---|---|---|
| errCode | string | 錯誤碼 |
| errMsg | string | 錯誤信息 |
異常
Object
拋出的異常
| 屬性 | 類型 | 說明 |
|---|---|---|
| errCode | string | 錯誤碼 |
| errMsg | string | 錯誤信息 |
errCode 的合法值
| 值 | 說明 | 最低版本 |
|---|
使用說明
圖片說明 文件大小限制:小于2M
二維碼說明 支持條碼、二維碼、DataMatrix和PDF417的識別。 二維碼、DataMatrix會返回位置坐標(biāo),條碼和PDF417暫不返回位置坐標(biāo)。
返回數(shù)據(jù)示例
{
"errcode": 0,
"errmsg": "ok",
"code_results": [
{
"type_name": "QR_CODE",
"data": "http://www.qq.com",
"pos": {
"left_top": {
"x": 585,
"y": 378
},
"right_top": {
"x": 828,
"y": 378
},
"right_bottom": {
"x": 828,
"y": 618
},
"left_bottom": {
"x": 585,
"y": 618
}
}
},
{
"type_name": "QR_CODE",
"data": "https://mp.weixin.qq.com",
"pos": {
"left_top": {
"x": 185,
"y": 142
},
"right_top": {
"x": 396,
"y": 142
},
"right_bottom": {
"x": 396,
"y": 353
},
"left_bottom": {
"x": 185,
"y": 353
}
}
},
{
"type_name": "EAN_13",
"data": "5906789678957"
},
{
"type_name": "CODE_128",
"data": "50090500019191"
}
],
"img_size": {
"w": 1000,
"h": 900
}
} 當(dāng)前文章:創(chuàng)新互聯(lián)小程序教程:微信小程序條碼/二維碼識別API
分享網(wǎng)址:http://fisionsoft.com.cn/article/coiojig.html


咨詢
建站咨詢

