Commit 6ab0a404 by zeven

集成支付宝刷脸支付

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