gpt4 book ai didi

android - 通过 HCE 付款

转载 作者:行者123 更新时间:2023-12-05 00:02:17 26 4
gpt4 key购买 nike

我一直在开发需要实现触碰付款的应用程序。我能够将 HCE 服务与 NFC 终端连接。
现在我的问题是接下来的步骤是什么,用它进行实际付款?
我到处搜索,但找不到合适的文件。请帮我。
下面是我编写的将 HCE 服务连接到 NFC 终端的代码。
Android list

<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.nfcemulator">

<uses-permission android:name="android.permission.NFC" />

<uses-feature android:name="android.hardware.nfc.hce"
android:required="true" />

<application
android:allowBackup="true"
android:icon="@mipmap/ic_launcher"
android:label="@string/app_name"
android:roundIcon="@mipmap/ic_launcher_round"
android:supportsRtl="true"
android:theme="@style/Theme.NFCEmulator">

<activity
android:name=".MainActivity"
android:exported="true">
<intent-filter>
<action android:name="android.intent.action.MAIN" />

<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>

<service
android:name=".service.HCEService"
android:exported="true"
android:permission="android.permission.BIND_NFC_SERVICE">
<intent-filter>
<action android:name="android.nfc.cardemulation.action.HOST_APDU_SERVICE" />
</intent-filter>

<meta-data
android:name="android.nfc.cardemulation.host_apdu_service"
android:resource="@xml/apduservice" />
</service>

</application>

</manifest>
HCE服务
class HCEService: HostApduService() {

companion object {
val TAG = "Host Card Emulator"
val STATUS_SUCCESS = "9000"
val STATUS_FAILED = "6F00"
val CLA_NOT_SUPPORTED = "6E00"
val INS_NOT_SUPPORTED = "6D00"
val AID = "A0000002471001"
val SELECT_INS = "A4"
val DEFAULT_CLA = "00"
val MIN_APDU_LENGTH = 12
}

override fun onDeactivated(reason: Int) {
Log.d(TAG, "Deactivated: " + reason)
}

override fun processCommandApdu(commandApdu: ByteArray?, extras: Bundle?): ByteArray {

if (commandApdu == null) {
return Utils.hexStringToByteArray(STATUS_FAILED)
}

val hexCommandApdu = Utils.toHex(commandApdu)
if (hexCommandApdu.length < MIN_APDU_LENGTH) {
return Utils.hexStringToByteArray(STATUS_FAILED)
}

if (hexCommandApdu.substring(0, 2) != DEFAULT_CLA) {
return Utils.hexStringToByteArray(CLA_NOT_SUPPORTED)
}

if (hexCommandApdu.substring(2, 4) != SELECT_INS) {
return Utils.hexStringToByteArray(INS_NOT_SUPPORTED)
}

if (hexCommandApdu.substring(10, 24) == AID) {
return Utils.hexStringToByteArray(STATUS_SUCCESS)
} else {
return Utils.hexStringToByteArray(STATUS_FAILED)
}

}

}
apduservices.xml
<?xml version="1.0" encoding="utf-8"?>
<host-apdu-service xmlns:android="http://schemas.android.com/apk/res/android"
android:description="@string/hce_service"
android:requireDeviceUnlock="false">
<aid-group android:description="@string/aid_groups"
android:category="other">
<aid-filter android:name="325041592E5359532E4444463031"/>
</aid-group>
</host-apdu-service>

最佳答案

我认为您在较低级别上使用了此功能,考虑到使用 Google Pay 时提供此功能(它支持 NFC 支付和在线购买),这是不必要的。
All you need to know about Google Pay if you’re a developer
Flutter 支付插件是为您的 Android 应用添加支付功能的最快方法。
Google Pay introduces a Flutter plugin for payments
Pay plugin 1.0.6

关于android - 通过 HCE 付款,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/70394836/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com