Commit 4afa48be by zeven

对接支付宝刷脸进店接口

parent 6ab0a404
...@@ -10,8 +10,10 @@ import OrderDetailsModal from '../components/OrderDetailsModal'; ...@@ -10,8 +10,10 @@ import OrderDetailsModal from '../components/OrderDetailsModal';
import delay from '../utils/delay'; import delay from '../utils/delay';
import Speech from '../utils/Speech'; import Speech from '../utils/Speech';
import WxFacepay from '../utils/WxFacepay'; import WxFacepay from '../utils/WxFacepay';
import Smilepay from '../utils/Smilepay';
import phone from '../assets/Vertical/phone.png'; import phone from '../assets/Vertical/phone.png';
import {onTalkCall, leaveTalkCall} from '../utils/agora'; import {onTalkCall, leaveTalkCall} from '../utils/agora';
import Toast from '../components/Toast';
const {width} = Dimensions.get('screen'); const {width} = Dimensions.get('screen');
...@@ -28,18 +30,21 @@ class FacePage extends Component { ...@@ -28,18 +30,21 @@ class FacePage extends Component {
current: 1, current: 1,
tip: '', tip: '',
tipsModal: false, tipsModal: false,
faceType: 'wxpay',
}; };
async componentWillMount() { async componentWillMount() {
this.storeKey = await AsyncStorage.getItem('KEY'); this.storeKey = await AsyncStorage.getItem('KEY');
let contact = await AsyncStorage.getItem('CONTACT'); let contact = await AsyncStorage.getItem('CONTACT');
let storeName = await AsyncStorage.getItem('NAME'); let storeName = await AsyncStorage.getItem('NAME');
this.setState({ this.setState({contact, storeName});
contact,
storeName,
});
if (!this.init) { if (!this.init) {
this.init = await WxFacepay.init(); this.init = await WxFacepay.init();
if (!this.init) {
// 微信刷脸失败,启动支付宝刷脸
this.init = true;
this.setState({faceType: 'alipay'});
}
} }
} }
...@@ -169,11 +174,15 @@ class FacePage extends Component { ...@@ -169,11 +174,15 @@ class FacePage extends Component {
} }
}; };
face = () => {
this.state.faceType === 'wxpay' ? this.wechatFace() : this.smileFace();
};
// device 代表当前打开的门 // device 代表当前打开的门
handleScaleChange = async ({count}) => { handleScaleChange = async ({count}) => {
if (count === -1) { if (count === -1) {
// 重力感应开始识别 // 重力感应开始识别
this.wechatFace(); this.face();
} else if (count === 0) { } else if (count === 0) {
// 重力感应归零 // 重力感应归零
this.leaveC(); this.leaveC();
...@@ -281,6 +290,39 @@ class FacePage extends Component { ...@@ -281,6 +290,39 @@ class FacePage extends Component {
} }
}; };
alipayinfo = async () => {
const {data} = await this.props.dispatch({type: 'goods/alipayinfo'});
this.alipayInfo = await Smilepay.init(data);
if (this.alipayInfo.code === '1000')
this.alipayInfo.metaInfo = JSON.parse(this.alipayInfo.metaInfo);
return this.alipayInfo;
};
smileFace = async () => {
await this.alipayinfo();
if (!this.alipayInfo || !this.alipayInfo.metaInfo) {
this.props.speak('刷脸支付启动失败,请重新刷脸或扫码支付', true);
return;
}
const {data} = await this.props.dispatch({
type: 'goods/smilepay',
service_id: 'auth',
zimmetainfo: this.alipayInfo.metaInfo,
});
if (data.code === 1) {
const res = await Smilepay.verify(JSON.parse(data.data));
if (res.code !== '1000') {
Toast.show(res.msg);
return;
}
const ret = await this.props.dispatch({
type: 'store/wxdoor',
fToken: res.fToken,
});
this.handleDoorLogin(ret);
}
};
// 语音通话请求 // 语音通话请求
onCall = async () => { onCall = async () => {
const {talkCall} = this.state; const {talkCall} = this.state;
...@@ -341,6 +383,11 @@ class FacePage extends Component { ...@@ -341,6 +383,11 @@ class FacePage extends Component {
tipsModal, tipsModal,
} = this.state; } = this.state;
let {dispatch} = this.props; let {dispatch} = this.props;
if (this.state.faceType === 'alipay') {
styles.header = {...styles.header, backgroundColor: '#1b7dc7'};
styles.btnCome = {...styles.btnCome, backgroundColor: '#1b7dc7'};
// styles.footer = {...styles.footer, backgroundColor: '#1b7dc7'};
}
return ( return (
<View style={styles.content}> <View style={styles.content}>
<PhoneModal <PhoneModal
...@@ -396,10 +443,7 @@ class FacePage extends Component { ...@@ -396,10 +443,7 @@ class FacePage extends Component {
</View> </View>
<View style={styles.face}> <View style={styles.face}>
<View style={styles.faceRecogn}> <View style={styles.faceRecogn}>
<Touch <Touch style={styles.faceGif} onPress={this.face} feedback={false}>
style={styles.faceGif}
onPress={() => this.wechatFace()}
feedback={false}>
<Image <Image
source={require('../assets/Vertical/face.gif')} source={require('../assets/Vertical/face.gif')}
style={{flex: 1, width}} style={{flex: 1, width}}
...@@ -428,14 +472,16 @@ class FacePage extends Component { ...@@ -428,14 +472,16 @@ class FacePage extends Component {
</View> </View>
)} )}
</View> </View>
<Touch <Touch onPress={this.face} style={styles.btnCome} feedback={false}>
onPress={() => this.wechatFace()}
style={styles.btnCome}
feedback={false}>
<View style={styles.click}> <View style={styles.click}>
<Image <Image
source={require('../assets/wxpay.png')} source={
this.state.faceType === 'wxpay'
? require('../assets/wxpay.png')
: require('../assets/Vertical/alipay01.png')
}
style={styles.wxpay} style={styles.wxpay}
tintColor="white"
/> />
<Text style={styles.clickText}>点击进入</Text> <Text style={styles.clickText}>点击进入</Text>
<Image source={require('../assets/up.png')} style={styles.up} /> <Image source={require('../assets/up.png')} style={styles.up} />
......
...@@ -35,10 +35,10 @@ export function door({userId}) { ...@@ -35,10 +35,10 @@ export function door({userId}) {
return axios.post('/store/door', qs.stringify({userId})); return axios.post('/store/door', qs.stringify({userId}));
} }
export function wxdoor({userId, openid, wxtoken, nickname}) { export function wxdoor({userId, openid, wxtoken, nickname, fToken}) {
return axios.post( return axios.post(
'/store/wxdoor', '/store/wxdoor',
qs.stringify({userId, openid, wxtoken, nickname}), qs.stringify({userId, openid, wxtoken, nickname, fToken}),
); );
} }
......
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