本插件分装了微信刷脸支付Android SDK v2.21.114版本。
微信刷脸支付官方文档:
https://pay.weixin.qq.com/wiki/doc/wxfacepay/develop/android/facepay.html
本插件实现封装了SDK中的5个方法:
1、程序启动时初始化 initWxpayface
2、获取数据 getWxpayfaceRawdata
3、人脸识别 getWxpayfaceCode(获取用户信息)
4、释放资源 releaseWxpayface
5、启动防火墙配置 enableFirewall
有异步返回信息的方法会通过globalEvent的形式进行返回信息,具体请参考示例代码。
具体刷脸支付业务流程的实现,请参考官方文档。
<template> <view> <view> <button @click="getversion()">getversion</button> <button @click="initWxpayface()">initWxpayface</button> <button @click="getWxpayfaceRawdata()">getWxpayfaceRawdata</button> <button @click="getWxpayfaceCode()">getWxpayfaceCode</button> <button @click="releaseWxpayface()">releaseWxpayface</button> <button @click="enableFirewall()">enableFirewall</button> <button @click="openfacepay()">完整流程</button> </view> <text v-for="(item,index) in msglist">{{item}}\n</text> </view> </template> <script> const wxfacepayzz = uni.requireNativePlugin('zzzili-wxfacepayzz'); export default { data() { return { msglist: [] } }, onLoad() { this.msglist.push('start test print') }, methods: { getversion: function() { this.msglist.push(wxfacepayzz.getVersion()); }, initWxpayface: function() { var map = { ip: "192.168.1.1", //若没有代理,则不需要此行 port: "8888", //若没有代理,则不需要此行 user: "mEtnUser", //若没有代理,则不需要此行 passwd: "mEtnPassword", //若没有代理,则不需要此行 proxy_type: 1, //若没有代理,则不需要此行 perform_mode: "LOW_PERFORM" //低性能表现,默认关闭美颜等 }; var that = this; this.msglist.push('wxfacepayzz.getVersion()' + wxfacepayzz.initWxpayface(map, function(res) { that.msglist.push(JSON.stringify(res)); })); }, getWxpayfaceRawdata: function() { var that = this; this.msglist.push('wxfacepayzz.getWxpayfaceRawdata()' + wxfacepayzz.getWxpayfaceRawdata(function(res) { that.msglist.push(JSON.stringify(res)); })); }, getWxpayfaceCode: function() { var map = { appid: "123456", mch_id: "123456", store_id: "123456", out_trade_no: "123456", total_fee: "0.01", face_authtype: "FACEPAY", authinfo: "124156565", face_code_type: "1" }; var that = this; this.msglist.push('wxfacepayzz.getWxpayfaceCode()' + wxfacepayzz.getWxpayfaceCode(map, function(res) { //wxpayfaceCallBack that.msglist.push(JSON.stringify(res)); }, function(res) { //updateResultWxpayfaceCallBack that.msglist.push(JSON.stringify(res)); })); }, releaseWxpayface: function() { this.msglist.push('wxfacepayzz.releaseWxpayface()' + wxfacepayzz.releaseWxpayface()); }, enableFirewall: function() { var mchId = "123456"; var subMchId = "456789"; var that = this; this.msglist.push('wxfacepayzz.enableFirewall()' + wxfacepayzz.enableFirewall(mchId, subMchId, function(res) { that.msglist.push(JSON.stringify(res)); })); }, openfacepay(){ var that = this; //1.初始化 wxfacepayzz.initWxpayface({},function(res){ console.log(res); //2.获取rawdata wxfacepayzz.getWxpayfaceRawdata(function(res2){ console.log(res2); / //3.根据返回的rawdata数据,调用Api接口:获取调用凭证,得到参数authinfo / //4.进行人脸识别 var map = { appid: "123456", mch_id: "123456", store_id: "123456", out_trade_no: "123456", total_fee: "0.01", face_authtype: "FACEPAY", authinfo: "124156565", face_code_type: "1" }; wxfacepayzz.getWxpayfaceCode(map, function(res3) { //wxpayfaceCallBack console.log(res3); //5.释放资源 wxfacepayzz.releaseWxpayface() }, function(res4) { //updateResultWxpayfaceCallBack console.log(res4); //5.释放资源 wxfacepayzz.releaseWxpayface() }) }) }); }, } } </script> <style> </style>