客户端接入(安卓:微信,支付宝,wifi钱包)

安卓客户端接口人: 刘贝liubei@wifi.com

配置 AndroidManifest.xml

必须完成 基本接入步骤(必接) 相应的配置项,除此之外还需要配置

<manifest … >
    <uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />
    <uses-permission android:name="android.permission.READ_PHONE_STATE" />
    <uses-permission android:name="android.permission.ACCESS_WIFI_STATE" />
    <uses-permission android:name="android.permission.INTERNET" />
    <uses-permission android:name="android.permission.ACCESS_FINE_LOCATION" />
    <uses-permission android:name="android.permission.ACCESS_COARSE_LOCATION" /> <!-- common -->
    <!-- pay -->
    <!-- 网络状态监听时会用到 -->
    <!-- 上传身份证会用到 -->
    <uses-permission android:name="android.permission.CAMERA" /> <!-- pay end -->
    <uses-permission android:name="android.permission.VIBRATE" />

    <application …>
        <activity
            android:name="com.alipay.sdk.app.H5PayActivity"
            android:configChanges="orientation|keyboardHidden|navigation|screenSize"
            android:exported="false"
            android:screenOrientation="behind"
            android:windowSoftInputMode="adjustResize|stateHidden" />
        <activity android:name="com.wifi.open.xpay.wallet.WalletPayResultActivity" >
            <intent-filter>
                <action android:name="wifi.intent.action.SDK_RESULT" />

                <category android:name="android.intent.category.DEFAULT" />

                <data
                    android:host="wallet"
                    android:path="/WalletPayResultActivity"
                    android:scheme="xpay" />
            </intent-filter>
        </activity>
        <activity
            android:name="com.sdpopen.wallet.pay.wallet.activity.PayEntryActivity"
            android:exported="true"
            android:launchMode="singleInstance"
            android:theme="@style/Theme_Transparent" >
            <intent-filter>
                <action android:name="opensdk.intent.action.SEND_PAY_REQ" />
                <action android:name="wifi.intent.action.AUTH_PAY" />
                <action android:name="wifi.intent.action.SEND_PAY_REQ" />
                <action android:name="wallet.intent.action.IN_APP_PAY" />

                <category android:name="android.intent.category.DEFAULT" />
            </intent-filter>
        </activity>
        <activity android:name="com.wifi.open.xpay.PayActivity" />
        <!-- 银行卡管理列表  start -->
        <activity
            android:name="com.sdpopen.wallet.bankmanager.activity.BankQuotaActivity"
            android:launchMode="singleTop"
            android:screenOrientation="portrait"
            android:theme="@style/wifipay_AppTheme" />
        <activity
            android:name="com.sdpopen.wallet.bankmanager.activity.UnBindCardActivity"
            android:theme="@style/wifipay_AppTheme" /> <!-- 银行卡管理列表  end -->
        <!-- common start -->
        <activity
            android:name="com.sdpopen.wallet.common.walletsdk_common.activity.SMSValidatorActivity"
            android:screenOrientation="portrait"
            android:theme="@style/wifipay_AppTheme" />
        <activity
            android:name="com.sdpopen.wallet.common.walletsdk_common.login.activity.LoginActivity"
            android:screenOrientation="portrait"
            android:theme="@style/wifipay_AppTheme" />
        <activity
            android:name="com.sdpopen.wallet.common.walletsdk_common.activity.AccountWebActivity"
            android:theme="@style/wifipay_AppTheme" />
        <activity
            android:name="com.sdpopen.wallet.common.plugin_bindcard.activity.BindCardActivity"
            android:screenOrientation="portrait"
            android:theme="@style/wifipay_AppTheme"
            android:windowSoftInputMode="stateVisible" >
            <intent-filter>
                <action android:name="android.intent.action.VIEW" />

                <category android:name="android.intent.category.DEFAULT" />
                <category android:name="android.intent.category.BROWSABLE" />

                <data
                    android:host="bindcard"
                    android:scheme="opensdk" />
            </intent-filter>
        </activity>
        <activity
            android:name="com.sdpopen.wallet.common.plugin_paypassword.activity.ModifyNewPPActivity"
            android:screenOrientation="portrait"
            android:theme="@style/wifipay_AppTheme" />
        <activity
            android:name="com.sdpopen.wallet.common.plugin_paypassword.activity.ModifyOldPPActivity"
            android:screenOrientation="portrait"
            android:theme="@style/wifipay_AppTheme" />
        <activity
            android:name="com.sdpopen.wallet.common.plugin_paypassword.activity.ModifyRepeatPPActivity"
            android:screenOrientation="portrait"
            android:theme="@style/wifipay_AppTheme" />
        <activity
            android:name="com.sdpopen.wallet.common.plugin_paypassword.activity.RetrievePPActivity"
            android:screenOrientation="portrait"
            android:theme="@style/wifipay_AppTheme" />
        <activity
            android:name="com.sdpopen.wallet.common.plugin_paypassword.activity.ResetPPActivity"
            android:screenOrientation="portrait"
            android:theme="@style/wifipay_AppTheme" />
        <activity
            android:name="com.sdpopen.wallet.common.plugin_paypassword.activity.ResetPPRepeatActivity"
            android:screenOrientation="portrait"
            android:theme="@style/wifipay_AppTheme" />
        <activity
            android:name="com.sdpopen.wallet.common.plugin_paypassword.activity.PasswordSettingActivity"
            android:screenOrientation="portrait"
            android:theme="@style/wifipay_AppTheme" />
        <activity
            android:name="com.sdpopen.wallet.common.plugin_paypassword.activity.PasswordRepeatActivity"
            android:screenOrientation="portrait"
            android:theme="@style/wifipay_AppTheme" /> <!-- common end -->
        <!-- component  start -->
        <activity
            android:name="com.sdpopen.wallet.pay.wallet.activity.ValidatorIDCardActivity"
            android:launchMode="singleTop"
            android:screenOrientation="portrait"
            android:theme="@style/wifipay_AppTheme" />
        <activity
            android:name="com.sdpopen.wallet.walletsdk_home.setting.PersonalDataActivity"
            android:launchMode="singleTop"
            android:screenOrientation="portrait"
            android:theme="@style/wifipay_AppTheme" /> <!-- home end -->
        <!-- pay start -->
        <activity
            android:name="com.sdpopen.wallet.pay.wallet.activity.PassWordActivity"
            android:launchMode="singleTop"
            android:screenOrientation="portrait"
            android:theme="@style/wifipay_CashierTheme" />
        <activity
            android:name="com.sdpopen.wallet.pay.wallet.activity.SelectCardActivity"
            android:launchMode="singleTop"
            android:theme="@style/WP_SelectCardTheme" />
        <activity
            android:name="com.sdpopen.wallet.pay.wallet.activity.PayResultActivity"
            android:launchMode="singleTop"
            android:screenOrientation="portrait"
            android:theme="@style/wifipay_AppTheme" /> <!-- 调起收银台返回的信息或者异常 -->
        <activity
            android:name="com.sdpopen.wallet.pay.wallet.activity.AuthenticationActivity"
            android:exported="false"
            android:launchMode="singleTop"
            android:screenOrientation="portrait"
            android:theme="@style/wifipay_AppTheme" />
        <activity
            android:name="com.sdpopen.wallet.pay.wallet.activity.TakePhotoActivity"
            android:launchMode="singleTop"
            android:screenOrientation="landscape"
            android:theme="@style/wifipay_AppTheme_NoTitle" />
        <activity
            android:name="com.sdpopen.wallet.pay.wallet.activity.TakePhotoResultActivity"
            android:launchMode="singleTop"
            android:screenOrientation="portrait"
            android:theme="@style/wifipay_AppTheme"
            android:windowSoftInputMode="stateAlwaysHidden" />

        <!-- 必须是应用包名下wxapi包内建同名WXPayEntryActivity, 
             此Activity只需继承自com.wifi.open.xpay.PayResultActivity, 无需其他任何实现-->
        <activity android:name="{应用包名}.wxapi.WXPayEntryActivity"
                android:exported="true"
                android:launchMode="singleTop"/></application>    
</manifest>

导入资源文件

  • 将res-pay.zip解压后合并到App工程目录下的res目录中
  • 将pay-libs/wallet/res-wallet.zip解压后合并到App工程目录下的res目录中
  • 将pay-libs放到工程目录libs下

初始化钱包

//appId 和 merchantId
WKXPay.initWallet("xxxx", "yyyy");

调用收银台界面 PayParam

//支付时传入payParam JSON字符串,参数见上面链接
WKXPay.pay(activity, payParam, new XPay.Callback() {
    @Override 
    public void onPayResult (int payStatus, String msg){
        Log.e("XPay", "pay result: " + payStatus + "; msg:" + msg);
    }
});

PayStatus

参数值 参数名称 描述
0 PAY_CANCEL 支付取消
1 PAY_SUCCESS 支付成功
-1 PAY_INVALID 支付无效,不需要等待结果,一定是失败的
-2 PAY_ERROR 支付异常,可能支付成功也可能支付失败
2 PAY_LIFE_CYCLE 支付页面生命周期

设置生产\测试环境

XPayConfig.IS_TEST = BuildConfig.DEBUG;

混淆设置

# Alipay
-dontwarn android.net.**
-keep class android.net.SSLCertificateSocketFactory{*;}

-keep class com.alipay.android.app.IAlixPay{*;}
-keep class com.alipay.android.app.IAlixPay$Stub{*;}
-keep class com.alipay.android.app.IRemoteServiceCallback{*;}
-keep class com.alipay.android.app.IRemoteServiceCallback$Stub{*;}
-keep class com.alipay.sdk.app.PayTask{ public *;}
-keep class com.alipay.sdk.app.AuthTask{ public *;}
-keep class com.alipay.sdk.app.H5PayCallback {
    <fields>;
    <methods>;
}
-keep class com.alipay.android.phone.mrpc.core.** { *; }
-keep class com.alipay.apmobilesecuritysdk.** { *; }
-keep class com.alipay.mobile.framework.service.annotation.** { *; }
-keep class com.alipay.mobilesecuritysdk.face.** { *; }
-keep class com.alipay.tscenter.biz.rpc.** { *; }
-keep class org.json.alipay.** { *; }
-keep class com.alipay.tscenter.** { *; }
-keep class com.ta.utdid2.** { *;}
-keep class com.ut.device.** { *;}

# Weixin Pay
-keep class com.tencent.mm.opensdk.** {*;}
-keep class com.tencent.mm.sdk.** {*;}

#Wifi Pay
-keep class com.sdpopen.**{*;}
-keep class com.shengpay.**{*;}
-keep class com.wifipay.common.security.**{*;}

注意要点

如果使用 build.gradle,注意添加下面,避免jni 找不到so 奔溃。

sourceSets {
    main() {
        jniLibs.srcDirs = ['libs']
    }
}