Commit 6ab0a404 by zeven

集成支付宝刷脸支付

parent 9a7bfa2a
......@@ -5,5 +5,6 @@ module.exports = {
"react-native/no-inline-styles": 0,
"no-unused-vars": 2,
"no-eval": 0,
curly: 0,
}
};
android @ f5d21a87
Subproject commit 3f5301de4268f6fd7567abfcba2646c277fa0d13
Subproject commit f5d21a876424a9e6b5c618be639dd0e15dae96d0
......@@ -80,6 +80,12 @@ export default {
*faceinfo(action, {call}) {
return yield call(api.faceinfo, action);
},
*alipayinfo(action, {call}) {
return yield call(api.alipayinfo, action);
},
*smilepay(action, {call}) {
return yield call(api.smilepay, action);
},
*wxauthinfo(action, {call}) {
delete action.type;
return yield call(api.wxauthinfo, action);
......
......@@ -521,12 +521,13 @@ const CounterMixins = ComposeComponent => {
};
// 付款码支付
barcodepay = async (code, facepay, openid) => {
barcodepay = async (code, facepay, openid, fToken) => {
if (this.barcodeBusy) {
return true;
}
const isWxpay = code.toString().match(/1[0-5]\d{16}/);
const isAlipay = code.toString().match(/^(2[5-9]|30)\d{14,22}$/);
const isAlipay =
fToken || code.toString().match(/^(2[5-9]|30)\d{14,22}$/);
if (!isWxpay && !isAlipay) {
return false;
}
......@@ -540,6 +541,7 @@ const CounterMixins = ComposeComponent => {
facepay,
noBarcode,
openid,
fToken,
});
if (res.code !== 1) {
await this.setState({voiceModal: true, voiceTitle: res.msg});
......
......@@ -18,7 +18,9 @@ import WxFacepay from '../utils/WxFacepay';
import {width} from '../utils/screen';
import Speech from '../utils/Speech';
import delay from '../utils/delay';
import Smilepay from '../utils/Smilepay';
import {leaveTalkCall, onTalkCall} from '../utils/agora';
import Toast from '../components/Toast';
let pageSize = 8; // 分页大小
window.pageSize = pageSize;
......@@ -32,6 +34,7 @@ class VerticalPage extends Component {
maskVisible: true,
visibleActive: false,
talkCall: 2, // 0请求通话,1通话中,2,已挂断通话,待机状态
faceType: 'wxpay',
};
async componentWillMount() {
......@@ -42,6 +45,11 @@ class VerticalPage extends Component {
this.storeKey = await AsyncStorage.getItem('KEY');
if (!this.init) {
this.init = await WxFacepay.init();
if (!this.init) {
// 微信刷脸失败,启动支付宝刷脸
this.init = true;
this.setState({faceType: 'alipay'});
}
}
}
......@@ -104,6 +112,14 @@ class VerticalPage 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;
};
authinfo = async () => {
const rawdata = await WxFacepay.rawdata();
const {data} = await this.props.dispatch({type: 'goods/faceinfo', rawdata});
......@@ -195,7 +211,6 @@ class VerticalPage extends Component {
}
if (res.face_code) {
await this.props.barcodepay(res.face_code, true, res.sub_openid);
// const ret = await this.props.barcodepay(res.face_code, true);
// const result = { ...params, payresult: ret };
// if (ret !== 'SUCCESS') result.payresult = 'ERROR';
......@@ -204,6 +219,31 @@ class VerticalPage extends Component {
}
};
smilepay = async () => {
const {goodsArr} = this.props;
if (goodsArr.length === 0) {
this.props.speak('请先扫描商品条码,再刷脸支付', true);
return;
}
await this.alipayinfo();
if (!this.alipayInfo || !this.alipayInfo.metaInfo) {
this.props.speak('刷脸支付启动失败,请重新刷脸或扫码支付', true);
return;
}
const {data} = await this.props.dispatch({
type: 'goods/smilepay',
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;
}
await this.props.barcodepay(res.fToken, true, null, res.fToken);
}
};
onCall = async () => {
const {talkCall} = this.state;
if (talkCall === 2) {
......@@ -417,6 +457,10 @@ class VerticalPage extends Component {
});
this.totalPrice = totalPrice;
this.totalCount = totalCount;
if (this.state.faceType === 'alipay')
styles.guide = {...styles.guide, backgroundColor: '#1b7dc7'};
const facepay =
this.state.faceType === 'wxpay' ? this.wxFacepay : this.smilepay;
return (
<View style={styles.main}>
<View style={styles.header}>
......@@ -545,7 +589,7 @@ class VerticalPage extends Component {
{/* })}*/}
{/*</View>*/}
<View style={styles.shadow} />
<Touch onPress={this.wxFacepay}>
<Touch onPress={facepay}>
<View style={styles.guide}>
<Text style={styles.guideText}>点击进入</Text>
<Image
......@@ -583,7 +627,7 @@ class VerticalPage extends Component {
</View>
</View>
<View style={styles.faceScan}>
<Touch onPress={this.wxFacepay}>
<Touch onPress={facepay}>
<View>
<Image
source={require('../assets/Vertical/face.gif')}
......@@ -592,7 +636,11 @@ class VerticalPage extends Component {
/>
<View style={styles.facePay}>
<Image
source={require('../assets/Vertical/wxpay.png')}
source={
this.state.faceType === 'wxpay'
? require('../assets/Vertical/wxpay.png')
: require('../assets/Vertical/alipay01.png')
}
style={styles.payImage}
alt=""
/>
......
......@@ -9,10 +9,10 @@ export function getBags() {
return axios.get('/store/goods/bags');
}
export function barcodepay({ids, code, facepay, noBarcode, openid}) {
export function barcodepay({ids, code, facepay, noBarcode, openid, fToken}) {
return axios.post(
'/store/goods/barcodepay',
qs.stringify({ids, code, facepay, noBarcode, openid}),
qs.stringify({ids, code, facepay, noBarcode, openid, fToken}),
);
}
......@@ -44,6 +44,17 @@ export function faceinfo({rawdata}) {
return axios.post('/store/goods/faceinfo', qs.stringify({rawdata}));
}
export function alipayinfo() {
return axios.post('/store/goods/alipayinfo');
}
export function smilepay({zimmetainfo, service_id, service_params}) {
return axios.post(
'/store/goods/smilepay',
qs.stringify({zimmetainfo, service_id, service_params}),
);
}
export function wxauthinfo(action) {
return axios.post('/common/wxpay/faceAuth', action);
}
import {NativeModules} from 'react-native';
export default NativeModules.Smilepay;
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