盛事通掃碼功能邏輯:
微信或者盛事通app掃描用戶盛事通“亮身份”二維碼,獲取字符串標識,調取盛事通接口,獲取用戶信息
### 獲取用戶信息 接口
~~~
測試環境:http://wanglanglang.tripln.top/api/uc/mobile/shopUserService/selectShopUserByEcQrCode?id=字符串
正式環境:https://shengstapi.tripln.top/api/uc/mobile/shopUserService/selectShopUserByEcQrCode?id=字符串
~~~
### 微信掃碼
~~~~
微信端調用掃碼 (微信官方文檔)
https://developers.weixin.qq.com/miniprogram/dev/api/device/scan/wx.scanCode.html
wx.scanCode({
success (res) {
console.log(res)
}
})
~~~~
### app掃碼
~~~
引用js-sdk(npm install hd-app-js-sdk -S)
詳細文檔:http://www.hmoore.net/star409964/hd-standard/2491762
1.H5端在需要掃碼功能的時候調用此方法
2.App端識別二維碼或條形碼成功后會自動收回掃碼界面,然后將掃碼結果字符串作為參數執行接下來的回調
3.如果掃碼組件出現錯誤或異常會走promise的resolve方法。H5根據錯誤碼進行后續的業務,錯誤碼對照表如下
1000 通用性失敗錯誤碼,不確定問題出在哪里,但就是所期望的結果未達成。
1001 用戶主動取消操作,比如用戶主動點擊了返回按鈕等用戶主動中斷業務流程的情況。
1002 用戶未授權相關操作的系統權限,比如說詢問是否可以使用手機相機的時候點擊了“否”。
1003 接口錯誤,與此業務相關的接口,沒有按照約定返回可以達成業務的返回值,導致業務處理失敗。
1004 SDK錯誤,如果此業務需要調用相應的SDK來完成,在調用SDK的過程中出現SDK的錯誤會返回此錯誤碼。
1005 用戶操作不規范所導致的錯誤,比如說用戶未按照人臉識別功能的要求做完相應的動作,導致業務無法繼續的問題。
1006 App代碼級別出現錯誤或異常導致業務無法進行。
this.$hdsdk.scanQrCode().then(r => console.log).catch(r => console.error)
~~~
### 例子
~~~
例子:
scanQRCodes() {
const ua = window.navigator.userAgent.toLowerCase()
//判斷當前瀏覽器是微信,else是其他瀏覽器
if (ua.match(/MicroMessenger/i) == 'micromessenger') {
// 封裝微信簽名方法
this.$common.wxCallBack(() => {
wx.scanQRCode({
needResult: 1, // 默認為0,掃描結果由微信處理,1則直接返回掃描結果,
scanType: ['qrCode', 'barCode'], // 可以指定掃二維碼還是一維碼,默認二者都有
success: (res) => {
const result = res.resultStr
// 獲取用戶信息
this.shopUserById(result)
},
error: function(res) {
alert(res)
}
})
})
} else {
console.log('調用sdk掃碼')
this.$hdsdk.scanQrCode().then(ret => {
if (!!ret && ret.code == 0 && !!ret.data && !!ret.data.scanResult) {
// 獲取用戶信息
this.shopUserById(ret.data.scanResult)
} else {
alert(ret.codeDescription)
}
}).catch(res => {
console.log(res)
})
}
}
~~~