What's RxPay ?
讓支付從此簡單下去括堤,一鍵支付功能咖刃,支持支付寶支付,微信支付
使用步驟
step 1
Gradle
dependencies {
compile 'com.cuieney.library:rxpay-api:1.0.3'
annotationProcessor 'com.cuieney.library:rxpay-compile:1.0.3'
}
step 2
在你的AndroidManifest文件中添加權限
AndroidManifest
<uses-permission android:name="android.permission.INTERNET"/>
<uses-permission android:name="android.permission.READ_PHONE_STATE"/>
<uses-permission android:name="android.permission.ACCESS_WIFI_STATE"/>
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稠通。
step 4
發(fā)起支付功能
1.發(fā)起支付寶支付請求
rxPay.requestAlipay("服務器產生的訂單號")
.subscribe(new Consumer<Boolean>() {
@Override
public void accept(Boolean aBoolean) throws Exception {
payState.setText("阿里支付狀態(tài):"+aBoolean);
}
}, new Consumer<Throwable>() {
@Override
public void accept(Throwable throwable) throws Exception {
payState.setText("阿里支付狀態(tài):"+throwable.getMessage());
}
});
2.發(fā)起微信支付請求
rxPay.requestWXpay(new JSONObject(“服務器生成訂單的后信息json”))
.subscribe(new Consumer<Boolean>() {
@Override
public void accept(Boolean aBoolean) throws Exception {
payState.setText("微信支付狀態(tài):"+aBoolean);
}
}, new Consumer<Throwable>() {
@Override
public void accept(Throwable throwable) throws Exception {
payState.setText("微信支付狀態(tài):"+throwable.getMessage());
}
});
對應的json格式參考
json.png
問題
發(fā)現(xiàn)bug或好的建議歡迎 issues or
Email cuieney@163.com
License
Copyright 2017 Cuieney Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0 Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License. ``