RxPay

介绍:

一个集成支付宝微信的支付工具

运行效果:

使用说明:

step 1

Gradle

dependencies {
        compile 'com.cuieney:rxpay-api:1.1.2'
        annotationProcessor 'com.cuieney:rxpay-compiler:1.1.2'
}

step 2

在你的AndroidManifest文件中添加权限

AndroidManifest

<uses-permission android:name="android.permission.INTERNET" />
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />
<uses-permission android:name="android.permission.ACCESS_WIFI_STATE" />
<uses-permission android:name="android.permission.READ_PHONE_STATE" />
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />

step 3

如果你需要用到微信支付的话,请仔细看一下步骤 1.在你要使用微信支付的地方添加一下注解

@WX(packageName = "微信支付注册keystore时候的包名")
public class MainActivity extends AppCompatActivity

2.在AndroidManifest添加你微信支付的appid

   <meta-data
            android:name="WX_APPID"
            android:value="wxb51b89cba83263"/>

3.在AndroidManifest的微信支付回调页面的Activity

     <activity
            android:name="xxx.xxx.xxx.wxapi.WXPayEntryActivity"
            android:exported="true"
            android:screenOrientation="portrait"
            android:windowSoftInputMode="adjustPan"
            />

上面的xxx.xxx.xxx就是你微信支付注册keystore时候的包名,报错没关系,编译会生成对应的Activity。

对应的支付宝支付AndroidManifest需要添加的是

<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>
 <activity
    android:name="com.alipay.sdk.app.H5AuthActivity"
    android:configChanges="orientation|keyboardHidden|navigation"
    android:exported="false"
    android:screenOrientation="behind"
    android:windowSoftInputMode="adjustResize|stateHidden" >
</activity>

step 4

发起支付功能

1.发起支付宝支付请求

 rxPay.requestAlipay("服务器产生的订单号")
                .subscribe(new Consumer<Boolean>() {
                    @Override
                    public void accept(Boolean aBoolean) throws Exception {
                        payState.setText("阿里支付状态:"+aBoolean);
                    }
                }, new Consumer<Throwable>() {
                    @Override
                    public void accept(Throwable throwable) throws Exception {
                        payState.setText("阿里支付状态:"+throwable.getMessage());
                    }
                });

2.发起微信支付请求

 rxPay.requestWXpay(new JSONObject(“服务器生成订单的后信息json”))
                .subscribe(new Consumer<Boolean>() {
                    @Override
                    public void accept(Boolean aBoolean) throws Exception {
                        payState.setText("微信支付状态:"+aBoolean);
                    }
                }, new Consumer<Throwable>() {
                    @Override
                    public void accept(Throwable throwable) throws Exception {
                        payState.setText("微信支付状态:"+throwable.getMessage());
                    }
                });

对应的json格式参考

687474703a2f2f75706c6f61642d696d616765732e6a69616e7368752e696f2f75706c6f61645f696d616765732f333431353833392d313633343163366562306639333866382e706e673f696d6167654d6f6772322f6175746f2d6f7269656e742f7374726970253743696d61676556696577322f322f77.png

code sample

已下载
0