Commit 4afa48be by zeven

对接支付宝刷脸进店接口

parent 6ab0a404
......@@ -10,8 +10,10 @@ import OrderDetailsModal from '../components/OrderDetailsModal';
import delay from '../utils/delay';
import Speech from '../utils/Speech';
import WxFacepay from '../utils/WxFacepay';
import Smilepay from '../utils/Smilepay';
import phone from '../assets/Vertical/phone.png';
import {onTalkCall, leaveTalkCall} from '../utils/agora';
import Toast from '../components/Toast';
const {width} = Dimensions.get('screen');
......@@ -28,18 +30,21 @@ class FacePage extends Component {
current: 1,
tip: '',
tipsModal: false,
faceType: 'wxpay',
};
async componentWillMount() {
this.storeKey = await AsyncStorage.getItem('KEY');
let contact = await AsyncStorage.getItem('CONTACT');
let storeName = await AsyncStorage.getItem('NAME');
this.setState({
contact,
storeName,
});
this.setState({contact, storeName});
if (!this.init) {
this.init = await WxFacepay.init();
if (!this.init) {
// 微信刷脸失败,启动支付宝刷脸
this.init = true;
this.setState({faceType: 'alipay'});
}
}
}
......@@ -169,11 +174,15 @@ class FacePage extends Component {
}
};
face = () => {
this.state.faceType === 'wxpay' ? this.wechatFace() : this.smileFace();
};
// device 代表当前打开的门
handleScaleChange = async ({count}) => {
if (count === -1) {
// 重力感应开始识别
this.wechatFace();
this.face();
} else if (count === 0) {
// 重力感应归零
this.leaveC();
......@@ -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 () => {
const {talkCall} = this.state;
......@@ -341,6 +383,11 @@ class FacePage extends Component {
tipsModal,
} = this.state;
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 (
<View style={styles.content}>
<PhoneModal
......@@ -396,10 +443,7 @@ class FacePage extends Component {
</View>
<View style={styles.face}>
<View style={styles.faceRecogn}>
<Touch
style={styles.faceGif}
onPress={() => this.wechatFace()}
feedback={false}>
<Touch style={styles.faceGif} onPress={this.face} feedback={false}>
<Image
source={require('../assets/Vertical/face.gif')}
style={{flex: 1, width}}
......@@ -428,14 +472,16 @@ class FacePage extends Component {
</View>
)}
</View>
<Touch
onPress={() => this.wechatFace()}
style={styles.btnCome}
feedback={false}>
<Touch onPress={this.face} style={styles.btnCome} feedback={false}>
<View style={styles.click}>
<Image
source={require('../assets/wxpay.png')}
source={
this.state.faceType === 'wxpay'
? require('../assets/wxpay.png')
: require('../assets/Vertical/alipay01.png')
}
style={styles.wxpay}
tintColor="white"
/>
<Text style={styles.clickText}>点击进入</Text>
<Image source={require('../assets/up.png')} style={styles.up} />
......
......@@ -35,10 +35,10 @@ export function door({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(
'/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