Commit f1c8fc67 by zeven

微信刷脸自动保存输入的手机号

parent 3e50cc82
android @ 4c28e562
Subproject commit ae144fb06f21278eac9ee5357c0dd64ba36079c0
Subproject commit 4c28e562126ae5cc53882fd42320875f460e7c6a
......@@ -22,6 +22,7 @@ import {width, setSpText, scaleSize} from '../utils/screen';
import {qrHost} from '../utils/config';
import Icons from 'react-native-vector-icons/MaterialIcons';
import AutoClick from '../utils/AutoClick';
import validity from '../utils/validity';
@connect(({admin}) => ({admin}))
class FacePage extends Component {
......@@ -46,6 +47,8 @@ class FacePage extends Component {
setting: false,
};
phone = ''; // 监听用户输入手机
async componentWillMount() {
this.storeKey = await AsyncStorage.getItem('KEY');
let contact = await AsyncStorage.getItem('CONTACT');
......@@ -61,8 +64,22 @@ class FacePage extends Component {
}
const setting = await AutoClick.isSettingsOn();
if (!setting) this.setState({setting: true}); // 展示按钮
DeviceEventEmitter.addListener('wxpayfaceRegister', () => {
this.wechatFace(); // 点击开通重新调用
DeviceEventEmitter.addListener('wxpayfaceRegister', async () => {
if (this.faceBusy) return;
this.faceBusy = true;
await this.wechatFace(); // 点击开通重新调用
this.faceBusy = false;
});
// 监听微信输入手机号事件
DeviceEventEmitter.addListener('wxpayfaceInput', ({text}) => {
if (!text) return;
const match = /^\[(.+)\]$/.exec(text);
if (!match) return;
text = match[1];
if (text === '删除')
this.phone = this.phone.substr(0, this.phone.length - 1);
else this.phone += text;
if (this.phone.length > 11) this.phone = this.phone.substr(-11);
});
}
......@@ -340,29 +357,30 @@ class FacePage extends Component {
// 返回错误自动重新识别
res = (await WxFacepay.faceinfo(params)) || {};
}
if (!res.openid) {
// 返回错误出现二维码扫码
Speech.speak('请扫码开门');
this.setQrcode({action: this.action, tip: '请扫码开门', qrcode: true});
}
if (window.socket) {
// 返回结果,立即重新连接socket
window.socket.connect();
}
if (!res.openid) {
// 没识别到人脸不开门
// 返回错误出现二维码扫码
this.phone = '';
Speech.speak('请扫码开门');
this.setQrcode({action: this.action, tip: '请扫码开门', qrcode: true});
return;
}
if (res.sub_openid) {
res.openid = res.sub_openid;
}
this.loading(true);
const ret = await this.props.dispatch({
const action = {
type: 'store/wxdoor',
openid: res.openid,
wxtoken: res.token,
nickname: res.nickname,
});
};
if (validity.phone.test(this.phone)) action.phone = this.phone;
const ret = await this.props.dispatch(action);
this.phone = '';
this.loading(false);
this.handleDoorLogin(ret);
}
......
......@@ -35,10 +35,18 @@ export function door({userId}) {
return axios.post('/store/door', qs.stringify({userId}));
}
export function wxdoor({userId, openid, wxtoken, nickname, alipayUid, fToken}) {
export function wxdoor({
userId,
openid,
wxtoken,
nickname,
alipayUid,
fToken,
phone,
}) {
return axios.post(
'/store/wxdoor',
qs.stringify({userId, openid, wxtoken, nickname, alipayUid, fToken}),
qs.stringify({userId, openid, wxtoken, nickname, alipayUid, fToken, phone}),
);
}
......
export const total = /^(\d+)(.\d{0,2})?$/;
export default {total};
export const phone = /^1[3-9]\d{9}$/;
export default {total, phone};
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment